diff --git a/consumer/store-sqlite/store.go b/consumer/store-sqlite/store.go index 4a3b8743..380b0fe4 100644 --- a/consumer/store-sqlite/store.go +++ b/consumer/store-sqlite/store.go @@ -21,10 +21,10 @@ import ( "time" "unsafe" + "github.com/jgraettinger/gorocksdb" "github.com/mattn/go-sqlite3" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/jgraettinger/gorocksdb" "go.gazette.dev/core/broker/client" "go.gazette.dev/core/consumer" pc "go.gazette.dev/core/consumer/protocol" @@ -168,21 +168,20 @@ func NewStore(recorder *recoverylog.Recorder) (*Store, error) { // The "gazette_checkpoint" table is then created, and any provided statements // are prepared and added to Store.Stmts in the same order as provided to Open. // -// store.Open( -// // Create myTable if it doesn't yet exist: -// `CREATE TABLE IF NOT EXISTS myTable ( -// id BLOB PRIMARY KEY NOT NULL, -// valueOne INTEGER, -// valueTwo TEXT -// );`, -// // Statement for querying on valueOne: -// `SELECT id, valueTwo FROM myTable WHERE valueOne > ?;`, -// // Statement for upserting into myTable: -// `INSERT INTO myTable(id, valueOne, valueTwo) VALUES(:id, :one, :two) -// ON CONFLICT(id) DO UPDATE SET valueOne = valueOne + :one, valueTwo = :two`, -// ) -// // store.Stmts[0] is now prepared for queries, and store.Stmts[1] for upserts. -// +// store.Open( +// // Create myTable if it doesn't yet exist: +// `CREATE TABLE IF NOT EXISTS myTable ( +// id BLOB PRIMARY KEY NOT NULL, +// valueOne INTEGER, +// valueTwo TEXT +// );`, +// // Statement for querying on valueOne: +// `SELECT id, valueTwo FROM myTable WHERE valueOne > ?;`, +// // Statement for upserting into myTable: +// `INSERT INTO myTable(id, valueOne, valueTwo) VALUES(:id, :one, :two) +// ON CONFLICT(id) DO UPDATE SET valueOne = valueOne + :one, valueTwo = :two`, +// ) +// // store.Stmts[0] is now prepared for queries, and store.Stmts[1] for upserts. func (s *Store) Open(bootstrapSQL string, statements ...string) error { // Finish initialization and open page DB. s.PageDBOptions.SetEnv(s.PageDBEnv) @@ -253,8 +252,9 @@ func (s *Store) Open(bootstrapSQL string, statements ...string) error { // database name (which is held constant across Store recoveries) to a URI // specific to this *Store instance and which is suited for ATTACH-ing to the // primary database. Eg: -// URIForDB("sept_2019.db") => -// "file:sept_2019.db?_journal_mode=WAL&other-setting=bar&vfs=store-123456&..." +// +// URIForDB("sept_2019.db") => +// "file:sept_2019.db?_journal_mode=WAL&other-setting=bar&vfs=store-123456&..." func (s *Store) URIForDB(name string) string { return "file:" + name + "?" + s.SQLiteURIValues.Encode() } @@ -339,6 +339,12 @@ func (s *Store) Destroy() { C.recFSFree(s.vfs) } + // Column family handles must be closed before the DB is. + for _, c := range s.PageDBColumns { + c.Destroy() + } + s.PageDBColumns = nil + if s.pages != nil { s.pages.Close() } @@ -362,14 +368,13 @@ func (s *Store) pageDBPath() string { // the linked SQLite library was built with. See https://www.sqlite.org/compile.html // for a full listing. Note the "SQLITE_" prefix is dropped in the returned set: // -// map[string]struct{ -// "COMPILER=gcc-8.3.0": {}, -// "ENABLE_BATCH_ATOMIC_WRITE": {}, -// "ENABLE_COLUMN_METADATA": {}, -// "ENABLE_DBSTAT_VTAB": {}, -// ... etc ... -// } -// +// map[string]struct{ +// "COMPILER=gcc-8.3.0": {}, +// "ENABLE_BATCH_ATOMIC_WRITE": {}, +// "ENABLE_COLUMN_METADATA": {}, +// "ENABLE_DBSTAT_VTAB": {}, +// ... etc ... +// } func SQLiteCompiledOptions() (map[string]struct{}, error) { var db, err = sql.Open("sqlite3", ":memory:") if err != nil { diff --git a/go.mod b/go.mod index ebbe2e30..c4345b7b 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/jgraettinger/urkel v0.1.2 github.com/klauspost/compress v1.13.5 github.com/lib/pq v1.10.2 - github.com/mattn/go-sqlite3 v2.0.3+incompatible + github.com/mattn/go-sqlite3 v1.14.24 github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.1 diff --git a/go.sum b/go.sum index c70c9693..1b4e7d31 100644 --- a/go.sum +++ b/go.sum @@ -328,8 +328,8 @@ github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= -github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= +github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=