Skip to content

Commit

Permalink
Build tags, docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Sep 18, 2023
1 parent 2d91760 commit 5535abc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ jobs:
- name: Test
run: go test -v ./...

- name: Test no locks
run: go test -v -tags sqlite3_nolock .
if: matrix.os == 'ubuntu-latest'

- name: Test BSD locks
run: go test -v -tags sqlite3_bsd ./...
run: go test -v -tags sqlite3_flock ./...
if: matrix.os == 'macos-latest'

- name: Coverage report
Expand All @@ -58,6 +62,6 @@ jobs:
amend: 'true'
reuse-go: 'true'
if: |
matrix.os == 'ubuntu-latest' &&
github.event_name == 'push'
github.event_name == 'push' &&
matrix.os == 'ubuntu-latest'
continue-on-error: true
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,25 @@ On Linux, macOS and illumos, this module uses
to synchronize access to database files.
OFD locks are fully compatible with process-associated POSIX advisory locks.

On BSD Unixes, this module uses
On BSD Unixes, this module may use
[BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2).
BSD locks may _not_ be compatible with process-associated POSIX advisory locks
(they are on FreeBSD).
BSD locks may _not_ be compatible with process-associated POSIX advisory locks.

##### TL;DR

In all platforms for which this package builds,
it is safe to use it to access databases concurrently from multiple goroutines.

Additionally, on Windows, Linux, macOS, illumos and FreeBSD,
it is _also_ safe to use it to access databases concurrently
it should be safe to use it to access databases concurrently,
from multiple goroutines, processes, and
with _other_ implementations of SQLite.

On other BSDs, where this might be unsafe,
[this test](vfs/lock_test.go) should fail.
If the package does not build for your platform,
see [this](vfs/README.md#portability).

#### Testing

The pure Go VFS is tested by running SQLite's
[mptest](https://github.com/sqlite/sqlite/blob/master/mptest/mptest.c)
on Linux, macOS and Windows;
BSD code paths are tested on macOS using the `sqlite3_bsd` build tag.
on Linux, macOS and Windows.
Performance is tested by running
[speedtest1](https://github.com/sqlite/sqlite/blob/master/test/speedtest1.c).

Expand Down
26 changes: 25 additions & 1 deletion vfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,28 @@ It replaces the default VFS with a pure Go implementation,
that is tested on Linux, macOS and Windows,
but which should also work on illumos and the various BSDs.

It also exposes interfaces that should allow you to implement your own custom VFSes.
It also exposes interfaces that should allow you to implement your own custom VFSes.

## Portability

This package is tested on Linux, macOS and Windows,
but it should also work on FreeBSD and illumos
(code paths for those plaforms are tested on macOS and Linux, respectively).

In all platforms for which this package builds,
it should be safe to use it to access databases concurrently,
from multiple goroutines, processes, and
with _other_ implementations of SQLite.

If the package does not build for your platform,
you may try to use the `sqlite3_flock` and `sqlite3_nolock` build tags.
These are only minimally tested and concurrency test failures should be expected.

The `sqlite3_flock` tag uses
[BSD locks](https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2).
It should be safe to access databases concurrently from multiple goroutines and processes,
but **not** with _other_ implementations of SQLite
(_unless_ these are _also_ configured to use `flock`).

The `sqlite3_nolock` tag uses no locking at all.
Database corruption is the likely result from concurrent write access.
2 changes: 1 addition & 1 deletion vfs/os_bsd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build freebsd || openbsd || netbsd || dragonfly || (darwin && sqlite3_bsd)
//go:build sqlite3_flock || freebsd

package vfs

Expand Down
2 changes: 1 addition & 1 deletion vfs/os_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !sqlite3_bsd
//go:build !sqlite3_flock

package vfs

Expand Down
2 changes: 1 addition & 1 deletion vfs/os_nolock.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build sqlite3_nolock && solaris && !illumos
//go:build sqlite3_nolock && unix && !(linux || darwin || freebsd || illumos)

package vfs

Expand Down
2 changes: 1 addition & 1 deletion vfs/os_ofd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux || illumos
//go:build (linux || illumos) && !sqlite3_flock

package vfs

Expand Down
2 changes: 1 addition & 1 deletion vfs/os_std_alloc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !linux && (!darwin || sqlite3_bsd)
//go:build !linux && (!darwin || sqlite3_flock)

package vfs

Expand Down
2 changes: 1 addition & 1 deletion vfs/os_std_sync.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !linux && (!darwin || sqlite3_bsd)
//go:build !linux && (!darwin || sqlite3_flock)

package vfs

Expand Down

0 comments on commit 5535abc

Please sign in to comment.