mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
SQLite: Add tuning options to configuration
This commit is contained in:
parent
ec49f5d550
commit
3e8ff836aa
2 changed files with 30 additions and 0 deletions
|
@ -18,5 +18,14 @@ export {
|
||||||
|
|
||||||
## Name of the table used for storing data.
|
## Name of the table used for storing data.
|
||||||
table_name: string;
|
table_name: string;
|
||||||
|
|
||||||
|
## Key/value table for passing tuning parameters when opening
|
||||||
|
## the database. These must be pairs that can be passed to the
|
||||||
|
## ``pragma`` command in sqlite.
|
||||||
|
tuning_params: table[string] of string &default=table(
|
||||||
|
["journal_mode"] = "WAL",
|
||||||
|
["synchronous"] = "normal",
|
||||||
|
["temp_store"] = "memory"
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,21 @@ ErrorResult SQLite::DoOpen(RecordValPtr options) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto tuning_params = options->GetField<TableVal>("tuning_params")->ToMap();
|
||||||
|
for ( const auto& [k, v] : tuning_params ) {
|
||||||
|
auto ks = k->AsListVal()->Idx(0)->AsStringVal();
|
||||||
|
auto vs = v->AsStringVal();
|
||||||
|
std::string cmd = util::fmt("pragma %s = %s", ks->ToStdStringView().data(), vs->ToStdStringView().data());
|
||||||
|
|
||||||
|
if ( int res = sqlite3_exec(db, cmd.c_str(), NULL, NULL, &errorMsg); res != SQLITE_OK ) {
|
||||||
|
std::string err = util::fmt("Error executing tuning pragma statement: %s", errorMsg);
|
||||||
|
Error(err.c_str());
|
||||||
|
sqlite3_free(errorMsg);
|
||||||
|
Close();
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static std::map<std::string, std::string> statements =
|
static std::map<std::string, std::string> statements =
|
||||||
{{"put", util::fmt("insert into %s (key_str, value_str, expire_time) values(?, ?, ?)", table_name.c_str())},
|
{{"put", util::fmt("insert into %s (key_str, value_str, expire_time) values(?, ?, ?)", table_name.c_str())},
|
||||||
{"put_update",
|
{"put_update",
|
||||||
|
@ -89,6 +104,12 @@ void SQLite::Close() {
|
||||||
|
|
||||||
prepared_stmts.clear();
|
prepared_stmts.clear();
|
||||||
|
|
||||||
|
char* errmsg;
|
||||||
|
if ( int res = sqlite3_exec(db, "pragma optimize", NULL, NULL, &errmsg); res != SQLITE_OK ) {
|
||||||
|
Error(util::fmt("Sqlite failed to optimize at shutdown: %s", errmsg));
|
||||||
|
sqlite3_free(&errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
if ( int res = sqlite3_close_v2(db); res != SQLITE_OK )
|
if ( int res = sqlite3_close_v2(db); res != SQLITE_OK )
|
||||||
Error("Sqlite could not close connection");
|
Error("Sqlite could not close connection");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue