Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct AttrDb

auto dbPath = cacheDir / (fingerprint.to_string(HashFormat::Base16, false) + ".sqlite");

state->db = SQLite(dbPath);
state->db = SQLite(dbPath, {.useWAL = settings.useSQLiteWAL});
state->db.isCache();
state->db.exec(schema);

Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct CacheImpl : Cache
auto dbPath = (getCacheDir() / "fetcher-cache-v4.sqlite").string();
createDirs(dirOf(dbPath));

state->db = SQLite(dbPath);
state->db = SQLite(dbPath, {.useWAL = settings.useSQLiteWAL});
state->db.isCache();
state->db.exec(schema);

Expand Down
3 changes: 2 additions & 1 deletion src/libstore-tests/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gtest/gtest.h>
#include <rapidcheck/gtest.h>
#include "nix/store/globals.hh"
#include "nix/store/sqlite.hh"
#include <sqlite3.h>

Expand Down Expand Up @@ -48,7 +49,7 @@ TEST(NarInfoDiskCacheImpl, create_and_read)

// We're going to pay special attention to the id field because we had a bug
// that changed it.
db = SQLite(dbPath);
db = SQLite(dbPath, {.useWAL = settings.useSQLiteWAL});
getIds.create(db, "select id from BinaryCaches where url = 'http://foo'");

{
Expand Down
8 changes: 7 additions & 1 deletion src/libstore/include/nix/store/sqlite.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ struct SQLite

SQLite() {}

SQLite(const std::filesystem::path & path, SQLiteOpenMode mode = SQLiteOpenMode::Normal);
struct Settings
{
SQLiteOpenMode mode = SQLiteOpenMode::Normal;
bool useWAL;
};

SQLite(const std::filesystem::path & path, Settings && settings);
SQLite(const SQLite & from) = delete;
SQLite & operator=(const SQLite & from) = delete;

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void LocalStore::openDB(State & state, bool create)
auto openMode = config->readOnly ? SQLiteOpenMode::Immutable
: create ? SQLiteOpenMode::Normal
: SQLiteOpenMode::NoCreate;
state.db = SQLite(std::filesystem::path(dbDir) / "db.sqlite", openMode);
state.db = SQLite(std::filesystem::path(dbDir) / "db.sqlite", {.mode = openMode, .useWAL = settings.useSQLiteWAL});

#ifdef __CYGWIN__
/* The cygwin version of sqlite3 has a patch which calls
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache

createDirs(dirOf(dbPath));

state->db = SQLite(dbPath);
state->db = SQLite(dbPath, {.useWAL = settings.useSQLiteWAL});

state->db.isCache();

Expand Down
8 changes: 4 additions & 4 deletions src/libstore/sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void traceSQL(void * x, const char * sql)
notice("SQL<[%1%]>", sql);
};

SQLite::SQLite(const std::filesystem::path & path, SQLiteOpenMode mode)
SQLite::SQLite(const std::filesystem::path & path, Settings && settings)
{
// Work around a ZFS issue where SQLite's truncate() call on
// db.sqlite-shm can randomly take up to a few seconds. See
Expand All @@ -89,10 +89,10 @@ SQLite::SQLite(const std::filesystem::path & path, SQLiteOpenMode mode)
// useSQLiteWAL also indicates what virtual file system we need. Using
// `unix-dotfile` is needed on NFS file systems and on Windows' Subsystem
// for Linux (WSL) where useSQLiteWAL should be false by default.
const char * vfs = settings.useSQLiteWAL ? 0 : "unix-dotfile";
bool immutable = mode == SQLiteOpenMode::Immutable;
const char * vfs = settings.useWAL ? 0 : "unix-dotfile";
bool immutable = settings.mode == SQLiteOpenMode::Immutable;
int flags = immutable ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
if (mode == SQLiteOpenMode::Normal)
if (settings.mode == SQLiteOpenMode::Normal)
flags |= SQLITE_OPEN_CREATE;
auto uri = "file:" + percentEncode(path.string()) + "?immutable=" + (immutable ? "1" : "0");
int ret = sqlite3_open_v2(uri.c_str(), &db, SQLITE_OPEN_URI | flags, vfs);
Expand Down
Loading