MySQL Workbench:启动事务似乎在回滚之前提交(MySQL Workbench: Start Transaction seems to be committed before rollback)
我写了一堆删除语句并将它们包装在一个事务中:
start transaction; delete a... delete b... delete c... rollback;
我的想法是,我希望删除发生在事务中,该事务将在完成时回滚。 如果步骤失败,我希望成功的步骤也可以回滚。
令我懊恼的是
delete a
工作,删除几千行,delete b
失败,但当我重新声明时,所有来自a的记录似乎都消失了。这是因为交易还在开放吗? 我尝试过:
set session transaction isolation level read committed; select a.*
并回到零行,所以我认为情况并非如此。 删除是否成功? 如果是这样,我怎样才能防止这种情况发生,直到我能保证完整的查询?
I wrote a bunch of delete statements and wrapped them in a transaction:
start transaction; delete a... delete b... delete c... rollback;
The idea is I would want the deletes to occur inside a transaction which would rollback upon completion. If a step failed along the way, I would want the successful steps to be rolled back as well.
To my chagrin
delete a
worked, removing a few thousand rows,delete b
failed, but when I reran the statements all the records from a appeared to be gone.Is this because the transaction is still open? I tried doing:
set session transaction isolation level read committed; select a.*
and got back zero rows so I think that is not the case. Was the successful
a
delete committed? And if so, how do I prevent that from happening until I can guarantee a full working query?
原文:https://stackoverflow.com/questions/37400283
最满意答案
这是一个想法的骨架:
#!/bin/bash exec 5< <(sleep 4; pwd) while true do if read -t 0 -u 5 dummy then echo Data available cat <&5 break else echo No data fi sleep 1 done
从Bash参考手册:
如果timeout为0,则read立即返回,而不尝试读取和数据。 如果输入在指定的文件描述符上可用,则退出状态为0,否则为非零。
想法是使用带有
-t 0
读取(具有零超时)和-u 5
(从文件描述符5读取)以立即检查数据可用性。当然,这只是展示概念的玩具循环。
Here is the skeleton of an idea :
#!/bin/bash exec 5< <(sleep 4; pwd) while true do if read -t 0 -u 5 dummy then echo Data available cat <&5 break else echo No data fi sleep 1 done
From the Bash reference manual :
If timeout is 0, read returns immediately, without trying to read and data. The exit status is 0 if input is available on the specified file descriptor, non-zero otherwise.
The idea is to use read with
-t 0
(to have zero timeout) and-u 5
(read from file descriptor 5) to instantly check for data availability.Of course this is just a toy loop to demonstrate the concept.
相关问答
更多-
如何检查存储在变量中的给定文件描述符是否仍然有效?(How to check if a given file descriptor stored in a variable is still valid?)[2023-05-16]
fcntl(fd, F_GETFD)是检查fd是否为有效的打开文件描述符的最经济的方法。 如果您需要批量检查,使用poll为零超时,并且events成员设置为0,并在返回后在POLLNVAL中检查POLLNVAL更有效。 这就是说,“检查给定资源句柄是否仍然有效”的操作几乎总是从根本上不正确。 资源句柄释放后(例如fd close d),其值可能会被重新分配给您分配的下一个此类资源。 如果有任何剩余的引用可能会被使用,他们会错误地操作新资源而不是旧资源。 因此,真正的答案可能是:如果您不知道程序的逻辑,那么 ... -
我假设你说在关闭套接字后你的应用程序可以继续合理地继续运行吗? 看起来更好的方法是获得一个中介线程,通知来自任何工作线程的套接字关闭请求,通知其他线程该套接字现在已经死了,并负责关闭套接字本身。 这消除了对失败原因的担忧,因为它全部在单个线程中处理。 I assume you're saying it's possible for your application to reasonably continue after shutting down the socket? It seems that a b ...
-
将两个重定向器放在同一行上: cat 3<<222889 0<&3 I am reading a string into file descriptor 3 which is copied to standrad input 222889 然后cat只输出here文档中的所有内容。 Place both redirectors on the same line: cat 3<<222889 0<&3 I am reading a string into file descriptor 3 which ...
-
从InputStream读取时SocketException错误的文件描述符(SocketException bad file descriptor when reading from InputStream)[2021-08-07]
根据 Socket#getOutputStream类的文档 : 的getOutputStream OutputStream getOutputStream() 返回此套接字的输出流。 如果此套接字具有关联的通道,则生成的输出流将其所有操作委托给通道。 如果通道处于非阻塞模式,则输出流的写入操作将抛出IllegalBlockingModeException。 关闭返回的OutputStream将关闭关联的套接字。 这里需要注意的是: 关闭返回的OutputStream将关闭关联的套接字。 在您的代码中,在您写 ... -
您希望fcntl()检查fd上的读/写设置: #include
#include int r; r = fcntl(fd, F_GETFL); if (r == -1) /* Error */ if (r & O_RDONLY) /* Read Only */ else if (r & O_WRONLY) /* Write Only */ else if (r & O_RDWR) /* Read/Write */ ... -
我不知道有多少个字符存储在管道的读取端 不要担心。 有一些优点(例如原子性)不会尝试写入/读取超过PIPE_BUF字节。 实际上,无论如何,你可能会得到一堆简短的阅读。 #define READ_BUFFER_SIZE PIPE_BUF unsigned char mybuffer[READ_BUFFER_SIZE]; ssize_t bytesread = 1; while ((bytesread = read(pipefd, mybuffer, READ_BUFFER_SIZE)) > 0) { ...
-
从另一个线程写入时,我可以从一个线程上读取文件描述符吗?(Can I read from a file descriptor on one thread while writing from another?)[2024-03-07]
是的,你可以使用串口完成,没问题。 您也可以使用常规文件来执行此操作,但这可能会让您感到困惑,因为您必须仔细管理文件的内容,以便读取器和写入器不会相互踩踏并特别小心地管理搜索指针(使用不依赖于搜索指针的pread()和pwrite() )。 显然,由于串行端口具有独立的输入和输出方向,并且没有寻道指针的概念,因此它更直接。 Yes, you can do that with a serial port, no problem. You could do it with a regular file too, ... -
指定文件描述符编号?(specifying file descriptor number?)[2021-10-13]
我相信你是对的,有时文件描述符可能已经在使用中。 我从http://tldp.org/LDP/abs/html/io-redirection.html#FTN.AEN17716得到了这个 “使用文件描述符5可能会导致问题。当Bash创建子进程时,与exec一样,子进程继承fd 5(请参阅Chet Ramey的归档电子邮件, SUBJECT:RE:文件描述符5保持打开状态 )。独自一人。“ 对此的解决方案在bash手册的第3.6节第2节中有详细说明。 可以在文件描述符号之前的每个重定向可以改为在{varnam ... -
这是一个想法的骨架: #!/bin/bash exec 5< <(sleep 4; pwd) while true do if read -t 0 -u 5 dummy then echo Data available cat <&5 break else echo No data fi sleep 1 done 从Bash参考手册: 如果timeout为0,则read立即返回,而不尝试读取和数据。 如果输入在指定的文件描述符上可用,则退出状态为 ...
-
您似乎将DisplayMsgFun对象的副本传递给std::thread构造函数,这意味着原始副本被销毁,并根据您的析构函数自动调用::close 。 You appear to be passing a copy of the DisplayMsgFun object to the std::thread constructor, which means that the original copy gets destroyed, automatically calling ::close per you ...