Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade lmdb v0.9.24 #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions lmdb/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func ExampleEnv() {
if err != nil {
panic(err)
}
_ = dbi
}

// This example shows the basic operations used when creating and working with
Expand Down Expand Up @@ -673,6 +674,7 @@ func ExampleTxn_OpenDBI() {
if err != nil {
panic(err)
}
_ = dbi
}

// When Create is passed to Txn.OpenDBI() the database will be created if it
Expand All @@ -687,6 +689,7 @@ func ExampleTxn_OpenDBI_create() {
if err != nil {
panic(err)
}
_ = dbi
}

// When a non-existent database is opened without the Create flag the errno is
Expand All @@ -699,6 +702,7 @@ func ExampleTxn_OpenDBI_notFound() {
return err
})
log.Print(err) // mdb_dbi_open: MDB_NOTFOUND: No matching key/data pair found
_ = dbi
}

// When the number of open named databases in an environment reaches the value
Expand All @@ -712,6 +716,7 @@ func ExampleTxn_OpenDBI_dBsFull() {
return err
})
log.Print(err) // mdb_dbi_open: MDB_DBS_FULL: Environment maxdbs limit reached
_ = dbi
}

// Txn.OpenRoot does not need to be called with the Create flag. And
Expand All @@ -725,6 +730,7 @@ func ExampleTxn_OpenRoot() {
if err != nil {
panic(err)
}
_ = dbi
}

// Txn.OpenRoot may also be called without flags inside View transactions
Expand Down Expand Up @@ -798,6 +804,8 @@ func ExampleTxn_Get() {

return nil
})
_ = str
_ = p2
}

// This example demonstrates the use of PutReserve to store a string value in
Expand Down
93 changes: 71 additions & 22 deletions lmdb/lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@
*
* Fix: Check for stale readers periodically, using the
* #mdb_reader_check function or the \ref mdb_stat_1 "mdb_stat" tool.
* Stale writers will be cleared automatically on some systems:
* Stale writers will be cleared automatically on most systems:
* - Windows - automatic
* - BSD, systems using SysV semaphores - automatic
* - Linux, systems using POSIX mutexes with Robust option - automatic
* - not on BSD, systems using POSIX semaphores.
* Otherwise just make all programs using the database close it;
* the lockfile is always reset on first open of the environment.
*
* - On BSD systems or others configured with MDB_USE_POSIX_SEM,
* - On BSD systems or others configured with MDB_USE_SYSV_SEM or
* MDB_USE_POSIX_SEM,
* startup can fail due to semaphores owned by another userid.
*
* Fix: Open and close the database as the user which owns the
Expand Down Expand Up @@ -135,7 +136,7 @@
*
* @author Howard Chu, Symas Corporation.
*
* @copyright Copyright 2011-2016 Howard Chu, Symas Corp. All rights reserved.
* @copyright Copyright 2011-2020 Howard Chu, Symas Corp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
Expand Down Expand Up @@ -166,6 +167,8 @@
#define _LMDB_H_

#include <sys/types.h>
#include <inttypes.h>
#include <limits.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -178,6 +181,32 @@ typedef int mdb_mode_t;
typedef mode_t mdb_mode_t;
#endif

#ifdef _WIN32
# define MDB_FMT_Z "I"
#else
# define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */
#endif

#ifndef MDB_VL32
/** Unsigned type used for mapsize, entry counts and page/transaction IDs.
*
* It is normally size_t, hence the name. Defining MDB_VL32 makes it
* uint64_t, but do not try this unless you know what you are doing.
*/
typedef size_t mdb_size_t;
# define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */
/** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
# define MDB_PRIy(t) MDB_FMT_Z #t
/** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
# define MDB_SCNy(t) MDB_FMT_Z #t
#else
typedef uint64_t mdb_size_t;
# define MDB_SIZE_MAX UINT64_MAX
# define MDB_PRIy(t) PRI##t##64
# define MDB_SCNy(t) SCN##t##64
# define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
#endif

/** An abstraction for a file handle.
* On POSIX systems file handles are small integers. On Windows
* they're opaque pointers.
Expand All @@ -200,7 +229,7 @@ typedef int mdb_filehandle_t;
/** Library minor version */
#define MDB_VERSION_MINOR 9
/** Library patch version */
#define MDB_VERSION_PATCH 19
#define MDB_VERSION_PATCH 70

/** Combine args a,b,c into a single integer for easy version comparisons */
#define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
Expand All @@ -210,7 +239,7 @@ typedef int mdb_filehandle_t;
MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)

/** The release date of this library version */
#define MDB_VERSION_DATE "December 28, 2016"
#define MDB_VERSION_DATE "December 19, 2015"

/** A stringifier for the version info */
#define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
Expand Down Expand Up @@ -303,6 +332,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
#define MDB_NORDAHEAD 0x800000
/** don't initialize malloc'd memory before writing to datafile */
#define MDB_NOMEMINIT 0x1000000
/** use the previous snapshot rather than the latest one */
#define MDB_PREVSNAPSHOT 0x2000000
/** @} */

/** @defgroup mdb_dbi_open Database Flags
Expand All @@ -312,7 +343,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
#define MDB_REVERSEKEY 0x02
/** use sorted duplicates */
#define MDB_DUPSORT 0x04
/** numeric keys in native byte order: either unsigned int or size_t.
/** numeric keys in native byte order, either unsigned int or #mdb_size_t.
* (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
* The keys must all be of the same size. */
#define MDB_INTEGERKEY 0x08
/** with #MDB_DUPSORT, sorted dup items have fixed size */
Expand Down Expand Up @@ -370,7 +402,7 @@ typedef enum MDB_cursor_op {
MDB_GET_BOTH, /**< Position at key/data pair. Only for #MDB_DUPSORT */
MDB_GET_BOTH_RANGE, /**< position at key, nearest data. Only for #MDB_DUPSORT */
MDB_GET_CURRENT, /**< Return key/data at current cursor position */
MDB_GET_MULTIPLE, /**< Return key and up to a page of duplicate data items
MDB_GET_MULTIPLE, /**< Return up to a page of duplicate data items
from current cursor position. Move cursor to prepare
for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
MDB_LAST, /**< Position at last key/data item */
Expand All @@ -379,7 +411,7 @@ typedef enum MDB_cursor_op {
MDB_NEXT, /**< Position at next data item */
MDB_NEXT_DUP, /**< Position at next data item of current key.
Only for #MDB_DUPSORT */
MDB_NEXT_MULTIPLE, /**< Return key and up to a page of duplicate data items
MDB_NEXT_MULTIPLE, /**< Return up to a page of duplicate data items
from next cursor position. Move cursor to prepare
for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
MDB_NEXT_NODUP, /**< Position at first data item of next key */
Expand All @@ -390,7 +422,7 @@ typedef enum MDB_cursor_op {
MDB_SET, /**< Position at specified key */
MDB_SET_KEY, /**< Position at specified key, return key + data */
MDB_SET_RANGE, /**< Position at first key greater than or equal to specified key. */
MDB_PREV_MULTIPLE /**< Position at previous page and return key and up to
MDB_PREV_MULTIPLE /**< Position at previous page and return up to
a page of duplicate data items. Only for #MDB_DUPFIXED */
} MDB_cursor_op;

Expand Down Expand Up @@ -448,27 +480,29 @@ typedef enum MDB_cursor_op {
#define MDB_BAD_VALSIZE (-30781)
/** The specified DBI was changed unexpectedly */
#define MDB_BAD_DBI (-30780)
/** Unexpected problem - txn should abort */
#define MDB_PROBLEM (-30779)
/** The last defined error code */
#define MDB_LAST_ERRCODE MDB_BAD_DBI
#define MDB_LAST_ERRCODE MDB_PROBLEM
/** @} */

/** @brief Statistics for a database in the environment */
typedef struct MDB_stat {
unsigned int ms_psize; /**< Size of a database page.
This is currently the same for all databases. */
unsigned int ms_depth; /**< Depth (height) of the B-tree */
size_t ms_branch_pages; /**< Number of internal (non-leaf) pages */
size_t ms_leaf_pages; /**< Number of leaf pages */
size_t ms_overflow_pages; /**< Number of overflow pages */
size_t ms_entries; /**< Number of data items */
mdb_size_t ms_branch_pages; /**< Number of internal (non-leaf) pages */
mdb_size_t ms_leaf_pages; /**< Number of leaf pages */
mdb_size_t ms_overflow_pages; /**< Number of overflow pages */
mdb_size_t ms_entries; /**< Number of data items */
} MDB_stat;

/** @brief Information about the environment */
typedef struct MDB_envinfo {
void *me_mapaddr; /**< Address of map, if fixed */
size_t me_mapsize; /**< Size of the data memory map */
size_t me_last_pgno; /**< ID of the last used page */
size_t me_last_txnid; /**< ID of the last committed transaction */
mdb_size_t me_mapsize; /**< Size of the data memory map */
mdb_size_t me_last_pgno; /**< ID of the last used page */
mdb_size_t me_last_txnid; /**< ID of the last committed transaction */
unsigned int me_maxreaders; /**< max reader slots in the environment */
unsigned int me_numreaders; /**< max reader slots used in the environment */
} MDB_envinfo;
Expand Down Expand Up @@ -614,6 +648,12 @@ int mdb_env_create(MDB_env **env);
* caller is expected to overwrite all of the memory that was
* reserved in that case.
* This flag may be changed at any time using #mdb_env_set_flags().
* <li>#MDB_PREVSNAPSHOT
* Open the environment with the previous snapshot rather than the latest
* one. This loses the latest transaction, but may help work around some
* types of corruption. If opened with write access, this must be the
* only process using the environment. This flag is automatically reset
* after a write transaction is successfully committed.
* </ul>
* @param[in] mode The UNIX permissions to set on created files and semaphores.
* This parameter is ignored on Windows.
Expand Down Expand Up @@ -842,7 +882,7 @@ int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
* an active write transaction.
* </ul>
*/
int mdb_env_set_mapsize(MDB_env *env, size_t size);
int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size);

/** @brief Set the maximum number of threads/reader slots for the environment.
*
Expand Down Expand Up @@ -955,6 +995,10 @@ int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func);
* <ul>
* <li>#MDB_RDONLY
* This transaction will not perform any write operations.
* <li>#MDB_NOSYNC
* Don't flush system buffers to disk when committing this transaction.
* <li>#MDB_NOMETASYNC
* Flush system buffers but omit metadata flush when committing this transaction.
* </ul>
* @param[out] txn Address where the new #MDB_txn handle will be stored
* @return A non-zero error value on failure and 0 on success. Some possible
Expand Down Expand Up @@ -987,7 +1031,7 @@ MDB_env *mdb_txn_env(MDB_txn *txn);
* @param[in] txn A transaction handle returned by #mdb_txn_begin()
* @return A transaction ID, valid if input is an active transaction.
*/
size_t mdb_txn_id(MDB_txn *txn);
mdb_size_t mdb_txn_id(MDB_txn *txn);

/** @brief Commit all the operations of a transaction into the database.
*
Expand Down Expand Up @@ -1097,7 +1141,8 @@ int mdb_txn_renew(MDB_txn *txn);
* keys must be unique and may have only a single data item.
* <li>#MDB_INTEGERKEY
* Keys are binary integers in native byte order, either unsigned int
* or size_t, and will be sorted as such.
* or #mdb_size_t, and will be sorted as such.
* (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
* The keys must all be of the same size.
* <li>#MDB_DUPFIXED
* This flag may only be used in combination with #MDB_DUPSORT. This option
Expand Down Expand Up @@ -1510,6 +1555,10 @@ int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
/** @brief Delete current key/data pair
*
* This function deletes the key/data pair to which the cursor refers.
* This does not invalidate the cursor, so operations such as MDB_NEXT
* can still be used on it.
* Both MDB_NEXT and MDB_GET_CURRENT will return the same record after
* this operation.
* @param[in] cursor A cursor handle returned by #mdb_cursor_open()
* @param[in] flags Options for this operation. This parameter
* must be set to 0 or one of the values described here.
Expand Down Expand Up @@ -1538,7 +1587,7 @@ int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
* <li>EINVAL - cursor is not initialized, or an invalid parameter was specified.
* </ul>
*/
int mdb_cursor_count(MDB_cursor *cursor, size_t *countp);
int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp);

/** @brief Compare two data items according to a particular database.
*
Expand Down
Loading