ud3tn/include/cla/storage/cla_sqlite.h
Felix Walter 8aaf458a1f cla_sqlite: Set busy timeout to 100 ms
Read transactions need a short, blocking, lock for the database, during
which no write transaction can be started - this means the interaction
of the agent, TX, and RX tasks may block each other if anything takes
longer than 1 ms. Thus, we increase the timeout for blocking locks to
100 ms to significantly reduce that probability.

See: https://www.sqlite.org/src/doc/204dbc15a682125c/doc/wal-lock.md

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 11:16:07 +02:00

54 lines
1.5 KiB
C

// SPDX-License-Identifier: AGPL-3.0-or-later
#ifndef CLA_SQLITE_H
#define CLA_SQLITE_H
#include "agents/storage/storage_agent.pb.h"
#include "cla/cla.h"
#include "ud3tn/bundle_processor.h"
#include "ud3tn/result.h"
#include <stddef.h>
#include <sqlite3.h>
// Length of the SQLiteAgent queue.
#ifndef CLA_SQLITE_AGENT_QUEUE_LENGTH
#define CLA_SQLITE_AGENT_QUEUE_LENGTH 10
#endif // CLA_SQLITE_AGENT_QUEUE_LENGTH
// Set a SQLite busy timeout in milliseconds. Set to zero to turn off.
// See: https://www.sqlite.org/c3ref/busy_timeout.html
// Especially under load and with concurrent access to the storage agent it is
// necessary to use a timeout to prevent SQLITE_BUSY errors.
// See also: https://www.sqlite.org/src/doc/204dbc15a682125c/doc/wal-lock.md
#ifndef CLA_SQLITE_BUSY_TIMEOUT_MS
#define CLA_SQLITE_BUSY_TIMEOUT_MS 100
#endif // CLA_SQLITE_BUSY_TIMEOUT
// The node ID that the SQLite CLA will register (create a FIB entry) for.
#ifndef CLA_SQLITE_NODE_ID
#define CLA_SQLITE_NODE_ID "dtn:storage"
#endif // CLA_SQLITE_NODE_ID
enum cla_sqlite_command_type {
SQLITE_COMMAND_UNDEFINED, /* 0x00 */
SQLITE_COMMAND_STORAGE_CALL, /* 0x01 */
SQLITE_COMMAND_FINALIZE, /* 0x02 */
};
struct cla_sqlite_command {
enum cla_sqlite_command_type type;
StorageCall storage_call;
};
const char *sqlite_name_get(void);
struct cla_config *sqlite_create(
const char *const options[],
const size_t option_count,
const struct bundle_agent_interface *bundle_agent_interface
);
#endif /* CLA_SQLITE_H */