Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add checksum VFS shim as an opt-in feature #1310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattyhall
Copy link

@mattyhall mattyhall commented Dec 18, 2024

I am working on a project that would like to turn checksumming on in SQLite, using the checksum VFS shim (see https://www.sqlite.org/cksumvfs.html). This extension isn't in the amalgamation and can either be statically or dynamically linked, but it would be easier if we could toggle it on and off using Go tags like the other features.

The code in this PR is a work in progress (missing documentation, an example, updating the README etc) to see if it is something you are interested in. A user can build with the tag cksumvfs and then use like so:

// We need to set the number of reserved bytes to at least 8 so the checksum can be included
sql.Register("sqlite3_with_chksum", &sqlite3.SQLiteDriver{
	ConnectHook: func(conn *sqlite3.SQLiteConn) error {
		return conn.SetFileControlInt("", sqlite3.SQLITE_FCNTL_RESERVE_BYTES, 8)
	},
})

db, err := sql.Open("sqlite3_with_chksum", "./foo.db")
if err != nil {
	log.Fatal(err)
}
defer db.Close()

// This makes the checksum VFS be the default, wrapping the previous default
sqlite3.InitCksumVFS()

// Corrupted pages will now cause an ErrIoErrData extended error to be returned

Questions

  1. Is this something the project would be interesting in having?
  2. Is it ok to just merge the code into the amalgamation - I took this approach from the user auth stuff? In terms of compile times I think it should be ok - the checksum implementation is only ~900 LOC/~40 small functions (src)
  3. If this isn't wanted is there a way to statically link it into sqlite using this library?

Please let me know what you think - if it's something you'd be happy to accept I'll go and clean this up a bit and add the documentation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant