The function begin_transaction takes a boolean argument that indicates what type of synchroniz开发者_运维百科ation should be done; physical when true or logical when false.
What does it mean when it refers to "physical", or hard, synchronization?
I am not exactly sure about the Java equivalents, but:
Logical synchronization means that any DB changes get written from the DBMS cache to the filesystem. In C you would do that using fprintf/fwrite/write/etc.
Physical synchronization means the above, with the added operation of asking the OS to push said changes to the permanent storage (hard drive, SSD, whatever) rather than keeping them in the filesystem cache. That ensures that those changes are not lost if anything untowards happens. On a Linux/POSIX system that would imply calling the fsync() or fdatasync() system calls.
EDIT:
Apparently the equivalent of fsync() in Java is FileDescriptor.sync():
http://download.oracle.com/javase/1.4.2/docs/api/java/io/FileDescriptor.html#
The point is that to achieve true ACID semantics for a DB, all transactions should be synchronized to the permanent storage medium. Otherwise your application would have to be able to deal with transactions that failed silently - the DBMS would push the transactions to the filesystem and return successfully, but then the changes could get lost if e.g. the system lost power.
The problem with physical synchronization is that it can have a significant impact on performance. Hard drives can handle a limited number of transactions per second (SSDs are a lot faster at this), which is why the first thing to do to improve DB performance is to bundle inserts in larger transactions.
精彩评论