mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Add new file doc/F2FS.txt, containing notes on the way SQLite uses the F2FS atomic commit feature.
FossilOrigin-Name: 59efb1bfaba12742379aae45c8c796ca539f089af9e553a3a55d6899a9c583c8
This commit is contained in:
87
doc/F2FS.txt
Normal file
87
doc/F2FS.txt
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
|
||||||
|
SQLite's OS layer contains the following definitions used in F2FS related
|
||||||
|
calls:
|
||||||
|
|
||||||
|
#define F2FS_IOCTL_MAGIC 0xf5
|
||||||
|
#define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
|
||||||
|
#define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
|
||||||
|
#define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
|
||||||
|
#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
|
||||||
|
#define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, u32)
|
||||||
|
#define F2FS_FEATURE_ATOMIC_WRITE 0x0004
|
||||||
|
|
||||||
|
After opening a database file on Linux (including Android), SQLite determines
|
||||||
|
whether or not a file supports F2FS atomic commits as follows:
|
||||||
|
|
||||||
|
u32 flags = 0;
|
||||||
|
rc = ioctl(fd, F2FS_IOC_GET_FEATURES, &flags);
|
||||||
|
if( rc==0 && (flags & F2FS_FEATURE_ATOMIC_WRITE) ){
|
||||||
|
/* File supports F2FS atomic commits */
|
||||||
|
}else{
|
||||||
|
/* File does NOT support F2FS atomic commits */
|
||||||
|
}
|
||||||
|
|
||||||
|
where "fd" is the file-descriptor open on the database file.
|
||||||
|
|
||||||
|
Usually, when writing to a database file that supports atomic commits, SQLite
|
||||||
|
accumulates the entire transaction in heap memory, deferring all writes to the
|
||||||
|
db file until the transaction is committed.
|
||||||
|
|
||||||
|
When it is time to commit a transaction on a file that supports atomic
|
||||||
|
commits, SQLite does:
|
||||||
|
|
||||||
|
/* Take an F_WRLCK lock on the database file. This prevents any other
|
||||||
|
** SQLite clients from reading or writing the file until the lock
|
||||||
|
** is released. */
|
||||||
|
rc = fcntl(fd, F_SETLK, ...);
|
||||||
|
if( rc!=0 ) goto failed;
|
||||||
|
|
||||||
|
rc = ioctl(fd, F2FS_IOC_START_ATOMIC_WRITE);
|
||||||
|
if( rc!=0 ) goto fallback_to_legacy_journal_commit;
|
||||||
|
|
||||||
|
foreach (dirty page){
|
||||||
|
rc = write(fd, ...dirty page...);
|
||||||
|
if( rc!=0 ){
|
||||||
|
ioctl(fd, F2FS_IOC_ABORT_VOLATILE_WRITE);
|
||||||
|
goto fallback_to_legacy_journal_commit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ioctl(fd, F2FS_IOC_COMMIT_ATOMIC_WRITE);
|
||||||
|
if( rc!=0 ){
|
||||||
|
ioctl(fd, F2FS_IOC_ABORT_VOLATILE_WRITE);
|
||||||
|
goto fallback_to_legacy_journal_commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we get there, the transaction has been successfully
|
||||||
|
** committed to persistent storage. The following call
|
||||||
|
** relinquishes the F_WRLCK lock. */
|
||||||
|
fcntl(fd, F_SETLK, ...);
|
||||||
|
|
||||||
|
Assumptions:
|
||||||
|
|
||||||
|
1. After either of the F2FS_IOC_ABORT_VOLATILE_WRITE calls return,
|
||||||
|
the database file is in the state that it was in before
|
||||||
|
F2FS_IOC_START_ATOMIC_WRITE was invoked. Even if the ioctl()
|
||||||
|
fails - we're ignoring the return code.
|
||||||
|
|
||||||
|
This is true regardless of the type of error that occurred in
|
||||||
|
ioctl() or write().
|
||||||
|
|
||||||
|
2. If the system fails before the F2FS_IOC_COMMIT_ATOMIC_WRITE is
|
||||||
|
completed, then following a reboot the database file is in the
|
||||||
|
state that it was in before F2FS_IOC_START_ATOMIC_WRITE was invoked.
|
||||||
|
Or, if the write was commited right before the system failed, in a
|
||||||
|
state indicating that all write() calls were successfully committed
|
||||||
|
to persistent storage before the failure occurred.
|
||||||
|
|
||||||
|
3. If the process crashes before the F2FS_IOC_COMMIT_ATOMIC_WRITE is
|
||||||
|
completed then the file is automatically restored to the state that
|
||||||
|
it was in before F2FS_IOC_START_ATOMIC_WRITE was called. This occurs
|
||||||
|
before the posix advisory lock is automatically dropped - there is
|
||||||
|
no chance that another client will be able to read the file in a
|
||||||
|
half-committed state before the rollback operation occurs.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
|||||||
C If\san\sSQLITE_IOERR\serror\sis\sencountered\sas\spart\sof\san\satomic\scommit\son\san\sF2FS\nfile-system,\sretry\sthe\scommit\sin\slegacy\sjournal\smode.
|
C Add\snew\sfile\sdoc/F2FS.txt,\scontaining\snotes\son\sthe\sway\sSQLite\suses\sthe\sF2FS\satomic\scommit\sfeature.
|
||||||
D 2018-07-14T20:25:13.305
|
D 2018-07-16T20:44:00.735
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F Makefile.in 0a3a6c81e6fcb969ff9106e882f0a08547014ba463cb6beca4c4efaecc924ee6
|
F Makefile.in 0a3a6c81e6fcb969ff9106e882f0a08547014ba463cb6beca4c4efaecc924ee6
|
||||||
@ -36,6 +36,7 @@ F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55
|
|||||||
F configure a46cba271ae08d635a1f331384c04563bdd37adb3d63cbdcffb1d91babfb64f5 x
|
F configure a46cba271ae08d635a1f331384c04563bdd37adb3d63cbdcffb1d91babfb64f5 x
|
||||||
F configure.ac 18c93e8bbeec8254832c4ea90eb06e7187fd150ef098baed02467eeb374afb17
|
F configure.ac 18c93e8bbeec8254832c4ea90eb06e7187fd150ef098baed02467eeb374afb17
|
||||||
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
|
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
|
||||||
|
F doc/F2FS.txt c1d4a0ae9711cfe0e1d8b019d154f1c29e0d3abfe820787ba1e9ed7691160fcd
|
||||||
F doc/lemon.html ac63db056bce24b7368e29319cd1a7eb5f1798cc85922d96a80b6c3a4ff9f51b
|
F doc/lemon.html ac63db056bce24b7368e29319cd1a7eb5f1798cc85922d96a80b6c3a4ff9f51b
|
||||||
F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710
|
F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710
|
||||||
F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a
|
F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a
|
||||||
@ -1748,10 +1749,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P 148d9b61471a874a16a9ec9c9603da03cadb3a40662fb550af51cb36212426b1
|
P 1c41250f67ac5de423b0426ef2ab8fe3303278a270225920033933ca9609592a
|
||||||
R 49a0ed84c0ce130af574e6c49ed456cc
|
R 2220ce8debd68fb6b704ee2986103f77
|
||||||
T *branch * exp-retry-atomic-commit
|
|
||||||
T *sym-exp-retry-atomic-commit *
|
|
||||||
T -sym-trunk *
|
|
||||||
U dan
|
U dan
|
||||||
Z b2768f20163b2f8528694b9d7a295551
|
Z 3478246bf34685cf426f48a9a3e3b106
|
||||||
|
@ -1 +1 @@
|
|||||||
1c41250f67ac5de423b0426ef2ab8fe3303278a270225920033933ca9609592a
|
59efb1bfaba12742379aae45c8c796ca539f089af9e553a3a55d6899a9c583c8
|
Reference in New Issue
Block a user