Skip to content

Commit 1a223fa

Browse files
authored
Update README.md
1 parent 12111a6 commit 1a223fa

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

vfs/README.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
This package implements the SQLite [OS Interface](https://sqlite.org/vfs.html) (aka VFS).
44

5-
It replaces the default SQLite VFS with a **pure Go** implementation.
6-
7-
It also exposes [interfaces](https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs#VFS)
5+
It replaces the default SQLite VFS with a **pure Go** implementation,
6+
and exposes [interfaces](https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs#VFS)
87
that should allow you to implement your own custom VFSes.
98

109
Since it is a from scratch reimplementation,
1110
there are naturally some ways it deviates from the original.
1211

13-
The main differences are [file locking](#file-locking) and [WAL mode](write-ahead-logging) support.
12+
The main differences are [file locking](#file-locking) and [WAL mode](#write-ahead-logging) support.
1413

1514
### File Locking
1615

@@ -22,21 +21,22 @@ On Linux and macOS, this module uses
2221
to synchronize access to database files.
2322
OFD locks are fully compatible with POSIX advisory locks.
2423

25-
On BSD Unixes, this module uses
26-
[BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2).
27-
On BSD, macOS, and illumos, these locks are fully compatible with POSIX advisory locks;
28-
on Linux and z/OS, they are fully functional, but incompatible with POSIX advisory locks.
29-
However, concurrency is always reduced with BSD locks
30-
(`BEGIN IMMEDIATE` behaves the same as `BEGIN EXCLUSIVE`).
31-
You can opt into BSD locks with the `sqlite3_flock` build tag.
24+
This module can also use
25+
[BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2),
26+
albeit with reduced concurrency (`BEGIN IMMEDIATE` behaves like `BEGIN EXCLUSIVE`).
27+
On BSD, macOS, and illumos, BSD locks are fully compatible with POSIX advisory locks;
28+
on Linux and z/OS, they are fully functional, but incompatible;
29+
elsewhere, they are very likely broken.
30+
BSD locks are the default on BSD and illumos,
31+
but you can opt into them with the `sqlite3_flock` build tag.
3232

3333
On Windows, this module uses `LockFileEx` and `UnlockFileEx`,
3434
like SQLite.
3535

36-
On all other platforms, file locking is not supported, and you must use
36+
Otherwise, file locking is not supported, and you must use
3737
[`nolock=1`](https://sqlite.org/uri.html#urinolock)
3838
(or [`immutable=1`](https://sqlite.org/uri.html#uriimmutable))
39-
to open database files.\
39+
to open database files.
4040
To use the [`database/sql`](https://pkg.go.dev/database/sql) driver
4141
with `nolock=1` you must disable connection pooling by calling
4242
[`db.SetMaxOpenConns(1)`](https://pkg.go.dev/database/sql#DB.SetMaxOpenConns).
@@ -50,41 +50,37 @@ On 64-bit Linux and macOS, this module uses `mmap` to implement
5050
[shared-memory for the WAL-index](https://sqlite.org/wal.html#implementation_of_shared_memory_for_the_wal_index),
5151
like SQLite.
5252

53-
To allow `mmap` to work, each connection needs to reserve up to 4GB of address space.\
54-
To limit the amount of address space each connection needs,
53+
To allow `mmap` to work, each connection needs to reserve up to 4GB of address space.
54+
To limit the address space each connection reserves,
5555
use [`WithMemoryLimitPages`](../tests/testcfg/testcfg.go).
5656

57-
On Windows, and with BSD locks, [WAL](https://sqlite.org/wal.html) support is
58-
[limited](https://sqlite.org/wal.html#noshm).
59-
`EXCLUSIVE` locking mode can be set to create, read, and write WAL databases.\
57+
Otherwise, [WAL support is limited](https://sqlite.org/wal.html#noshm),
58+
and `EXCLUSIVE` locking mode must be set to create, read, and write WAL databases.
6059
To use `EXCLUSIVE` locking mode with the
6160
[`database/sql`](https://pkg.go.dev/database/sql) driver
6261
you must disable connection pooling by calling
6362
[`db.SetMaxOpenConns(1)`](https://pkg.go.dev/database/sql#DB.SetMaxOpenConns).
6463

65-
On all other platforms, where file locking is not supported, WAL mode is disabled.
66-
6764
You can use [`vfs.SupportsSharedMemory`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs#SupportsSharedMemory)
6865
to check if your build supports shared memory.
6966

7067
### Batch-Atomic Write
7168

7269
On 64-bit Linux, this module supports [batch-atomic writes](https://sqlite.org/cgi/src/technote/714)
73-
with the F2FS filesystem.
70+
on the F2FS filesystem.
7471

7572
### Build Tags
7673

7774
The VFS can be customized with a few build tags:
78-
- `sqlite3_flock` forces the use of BSD locks; it can be used on z/OS for locking support,
79-
and elsewhere to test the BSD locks.
75+
- `sqlite3_flock` forces the use of BSD locks; it can be used on z/OS to enable locking,
76+
and elsewhere to test BSD locks.
8077
- `sqlite3_nosys` prevents importing [`x/sys`](https://pkg.go.dev/golang.org/x/sys);
8178
disables locking _and_ shared memory on all platforms.
8279
- `sqlite3_noshm` disables shared memory on all platforms.
8380

84-
> [!CAUTION]
85-
> If file locking is incompatible with POSIX advisory locks,
86-
> accessing databases concurrently with this package and other SQLite implementations
87-
> is unsafe, and will eventually corrupt data.
88-
> This will only be the case if you explicitly opt into BSD locks with `sqlite3_flock`.
89-
> The SQLite [`unix-flock`](https://sqlite.org/compile.html#enable_locking_style) VFS
90-
> is always compatible with `sqlite3_flock`.
81+
> [!IMPORTANT]
82+
> The default configuration of this package is compatible with
83+
> the standard [Unix and Windows SQLite VFSes](https://sqlite.org/vfs.html#multiple_vfses);
84+
> `sqlite3_flock` is compatible with the [`unix-flock` VFS](https://sqlite.org/compile.html#enable_locking_style).
85+
> If incompatible file locking is used, accessing databases concurrently with _other_ SQLite libraries
86+
> will eventually corrupt data.

0 commit comments

Comments
 (0)