From 2dc358d4a8a865f469419d7c81955dcb7dc7a4ef Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 13 Mar 2025 23:27:50 +0800 Subject: [PATCH] Add the rest of functions used in HaxIRCd --- lmdb/env.ha | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++--- lmdb/reader.ha | 8 ++++++++ lmdb/txn.ha | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/lmdb/env.ha b/lmdb/env.ha index e4f1a0959f74a41dd1a56467ffbe7486a94b177c..b68d2844ff5e19ad1f1c78c46294505a98f84f73 100644 --- a/lmdb/env.ha +++ b/lmdb/env.ha @@ -39,9 +39,9 @@ // how the operating system has allocated memory to shared libraries and other uses. // The feature is highly experimental. // - [[NOSUBDIR]]: // By default, LMDB creates its environment in a directory whose -// pathname is given in \b path, and creates its data and lock files -// under that directory. With this option, \b path is used as-is for -// the database main data file. The database lock file is the \b path +// pathname is given in path, and creates its data and lock files +// under that directory. With this option, path is used as-is for +// the database main data file. The database lock file is the path // with "-lock" appended. // - [[RDONLY]]: // Open the environment in read-only mode. No write operations will be @@ -146,3 +146,59 @@ // // Parameters: // - env: An environment handle returned by [[env_create]] export @symbol("mdb_env_close") fn env_close(env: *env) void; + +// Set the size of the memory map to use for this environment. +// +// The size should be a multiple of the OS page size. The default is +// 10485760 bytes. The size of the memory map is also the maximum size +// of the database. The value should be chosen as large as possible, +// to accommodate future growth of the database. +// +// This function should be called after [[env_create]] and before [[env_open]]. +// It may be called at later times if no transactions are active in +// this process. Note that the library does not check for this condition, +// the caller must ensure it explicitly. +// +// The new size takes effect immediately for the current process but +// will not be persisted to any others until a write transaction has been +// committed by the current process. Also, only mapsize increases are +// persisted into the environment. +// +// If the mapsize is increased by another process, and data has grown +// beyond the range of the current mapsize, [[txn_begin]] will +// return [[MAP_RESIZED]]. This function may be called with a size +// of zero to adopt the new size. +// +// Any attempt to set a size smaller than the space already consumed +// by the environment will be silently changed to the current size of the used space. +// +// Parameters +// - env: An environment handle returned by [[env_create]] +// - size: The size in bytes +// +// Return value: A non-zero error value on failure and 0 on success. Some possible +// errors are: +// - EINVAL - an invalid parameter was specified, or the environment has +// an active write transaction. +export @symbol("mdb_env_set_mapsize") fn env_set_mapsize(env: *env, size_: size) int; + +// Set the maximum number of named databases for the environment. +// +// This function is only needed if multiple databases will be used in the +// environment. Simpler applications that use the environment as a single +// unnamed database can ignore this option. +// +// This function may only be called after [[env_create]] and before [[env_open]]. +// +// Currently a moderate number of slots are cheap but a huge number gets +// expensive: 7-120 words per transaction, and every [[dbi_open]] +// does a linear search of the opened slots. +// +// Parameters +// - env: An environment handle returned by [[env_create]] +// - dbs: The maximum number of databases +// +// Return value: A non-zero error value on failure and 0 on success. Some possible +// errors are: +// - EINVAL - an invalid parameter was specified, or the environment is already open. +export @symbol("mdb_env_set_maxdbs") fn env_set_maxdbs(env: *env, dbs: dbi) int; diff --git a/lmdb/reader.ha b/lmdb/reader.ha new file mode 100644 index 0000000000000000000000000000000000000000..3d899fc27b7263c47919ecb3caeefcd3c4684408 --- /dev/null +++ b/lmdb/reader.ha @@ -0,0 +1,8 @@ +// Check for stale entries in the reader lock table. +// +// Parameters +// - env: An environment handle returned by [[env_create]] +// - dead: Number of stale slots that were cleared +// +// Return value: 0 on success, non-zero on failure. +export @symbol("mdb_reader_check") fn reader_check(env: *env, dead: int) int; diff --git a/lmdb/txn.ha b/lmdb/txn.ha new file mode 100644 index 0000000000000000000000000000000000000000..01ef45811dcc21bff5aad93ff6d737685b4a4397 --- /dev/null +++ b/lmdb/txn.ha @@ -0,0 +1,62 @@ +// Create a transaction for use with the environment. +// +// The transaction handle may be discarded using [[txn_abort]] or [[txn_commit]]. +// +// A transaction and its cursors must only be used by a single +// thread, and a thread may only have a single transaction at a time. +// If [[NOTLS]] is in use, this does not apply to read-only transactions. +// +// Cursors may not span transactions. +// +// Parameters +// - env: An environment handle returned by [[env_create]] +// - parent: If this parameter is non-NULL, the new transaction +// will be a nested transaction, with the transaction indicated by parent +// as its parent. Transactions may be nested to any level. A parent +// transaction and its cursors may not issue any other operations than +// mdb_txn_commit and mdb_txn_abort while it has active child transactions. +// - flags: Special options for this transaction. This parameter +// must be set to 0 or by bitwise OR'ing together one or more of the +// values described here. +// - txn: Address where the new [[txn]] handle will be stored +// +// Flags +// - [[MDB_RDONLY]] +// This transaction will not perform any write operations. +// +// Return value: A non-zero error value on failure and 0 on success. Some possible +// errors are: +// - [[PANIC]] - a fatal error occurred earlier and the environment +// - must be shut down. +// - [[MAP_RESIZED]] - another process wrote data beyond this MDB_env's +// - mapsize and this environment's map must be resized as well. +// - See [[env_set_mapsize]]. +// - [[READERS_FULL]] - a read-only transaction was requested and +// - the reader lock table is full. See [[env_set_maxreaders]]. +// - ENOMEM - out of memory. +export @symbol("mdb_txn_begin") fn txn_begin(env: *env, parent: *txn, flags: uint, txn: nullable **txn) int; + +// Commit all the operations of a transaction into the database. +// +// The transaction handle is freed. It and its cursors must not be used +// again after this call, except with [[cursor_renew]]. +// +// Parameters +// - txn: A transaction handle returned by [[txn_begin]] +// +// Return value: A non-zero error value on failure and 0 on success. Some possible +// errors are: +// - EINVAL - an invalid parameter was specified. +// - ENOSPC - no more disk space. +// - EIO - a low-level I/O error occurred while writing. +// - ENOMEM - out of memory. +export @symbol("mdb_txn_commit") fn txn_commit(txn: *txn) int; + +// Abandon all the operations of the transaction instead of saving them. +// +// The transaction handle is freed. It and its cursors must not be used +// again after this call, except with [[cursor_renew]]. +// +// Parameters +// - txn: A transaction handle returned by [[txn_begin]] +export @symbol("mdb_txn_abort") fn txn_abort(txn: *txn) int; -- 2.48.1