Use sqlite3_file_control(SQLITE_FCNTL_PERSIST_WAL) to persist WAL

Previously, Litestream would avoid closing the SQLite3 connection
in order to ensure that the WAL file was not cleaned up by the
database if it was the last connection. This commit changes the
behavior by introducing a file control call to perform the same
action. This allows us to close the database file normally in all
cases.
This commit is contained in:
Ben Johnson
2022-01-28 15:05:21 -07:00
parent a34a92c0b9
commit cca838b671
4 changed files with 32 additions and 23 deletions

View File

@@ -178,7 +178,7 @@ func (c *ReplicateCommand) Run(ctx context.Context) (err error) {
// Close closes all open databases.
func (c *ReplicateCommand) Close() (err error) {
for _, db := range c.DBs {
if e := db.SoftClose(); e != nil {
if e := db.Close(); e != nil {
log.Printf("error closing db: path=%s err=%s", db.Path(), e)
if err == nil {
err = e