zeek/testing/btest/broker/store/brokerstore-backend-sqlite-wal-mode.zeek
Arne Welzel f35cf228dc broker/store: Extend SQLiteOptions around data safety and performance
Add configurability of synchronous and journal_mode for SQLite backed
Broker data stores. Setting these to synchronous=normal and journal_mode=wal
can significantly improve throughput at the cost of some durability in
the presence of power loss or OS crash. In the context of Zeek, this is
likely more than acceptable.

Additionally, add integrity_check and failure_mode options to support deleting
and re-opening a corrupted SQLite database at store creation.

Closes #2698
2023-01-30 10:25:37 +01:00

43 lines
1.3 KiB
Text

# @TEST-DOC: Configure a broker store to be in WAL mode withou journal_mode NORMAL.
# @TEST-REQUIRES: sqlite3 --version
# @TEST-EXEC: zeek -b %INPUT > out 2>&1
#
# This is poking a bit at SQLite internals, but because WAL mode
# was flipped on, expect a wal and a shm file to exist.
# @TEST-EXEC: test -f path_to_db.sqlite || ls -lha >> out
# @TEST-EXEC: test -f path_to_db.sqlite-shm || ls -lha >> out
# @TEST-EXEC: test -f path_to_db.sqlite-wal || ls -lha >> out
# More poking, running sqlite3 should detect WAL mode, and the store
# table has 100 entries.
#
# @TEST-EXEC: sqlite3 ./path_to_db.sqlite 'PRAGMA journal_mode' >> out;
# @TEST-EXEC: sqlite3 ./path_to_db.sqlite 'select count(*) from store' >> out;
#
# @TEST-EXEC: btest-diff out
@load base/frameworks/broker/store
global test_store: opaque of Broker::Store;
global test_table: table[string] of count &broker_store="test_store_42";
event zeek_init()
{
test_store = Broker::create_master(
"test_store_42",
Broker::SQLITE,
Broker::BackendOptions(
$sqlite=Broker::SQLiteOptions(
$path="path_to_db.sqlite",
$synchronous=Broker::SQLITE_SYNCHRONOUS_NORMAL,
$journal_mode=Broker::SQLITE_JOURNAL_MODE_WAL,
),
),
);
local rows = 100;
local i = 0;
while ( ++i <= rows )
test_table[cat(|test_table|)] = i;
print fmt("populated %s rows", rows);
}