47 #define STRLENOF(s) (sizeof(s)-1)
55 #define S(s) s, STRLENOF(s)
77 fprintf(stderr,
"%s: line %" Z "d: unsupported VERSION %d\n",
87 fprintf(stderr,
"%s: line %" Z "d: unsupported FORMAT %s\n",
98 fprintf(stderr,
"%s: line %" Z "d: unsupported type %s\n",
105 if (ptr) *ptr =
'\0';
108 fprintf(stderr,
"%s: line %" Z "d: invalid mapaddr %s\n",
115 if (ptr) *ptr =
'\0';
118 fprintf(stderr,
"%s: line %" Z "d: invalid mapsize %s\n",
125 if (ptr) *ptr =
'\0';
128 fprintf(stderr,
"%s: line %" Z "d: invalid maxreaders %s\n",
144 fprintf(stderr,
"%s: line %" Z "d: unexpected format\n",
149 fprintf(stderr,
"%s: line %" Z "d: unrecognized keyword ignored: %s\n",
159 fprintf(stderr,
"%s: line %" Z "d: unexpected end of input\n",
179 unsigned char *c1, *c2, *end;
191 if (fgets(
buf->mv_data,
buf->mv_size, stdin) ==
NULL) {
202 if (fgets(
buf->mv_data,
buf->mv_size, stdin) ==
NULL) {
209 len = strlen((
char *)c1);
213 while (c1[
len-1] !=
'\n') {
214 buf->mv_data = realloc(
buf->mv_data,
buf->mv_size*2);
217 fprintf(stderr,
"%s: line %" Z "d: out of memory, line too long\n",
223 if (fgets((
char *)c1,
buf->mv_size+1, stdin) ==
NULL) {
229 len = strlen((
char *)c1);
232 c1 = c2 =
buf->mv_data;
273 c2 =
out->mv_data =
buf->mv_data;
274 out->mv_size = c1 - c2;
281 fprintf(stderr,
"usage: %s [-V] [-f input] [-n] [-s name] [-N] [-T] dbpath\n",
prog);
285 int main(
int argc,
char *argv[])
293 int envflags = 0, putflags = 0;
309 while ((
i =
getopt(argc, argv,
"f:ns:NTV")) != EOF) {
317 fprintf(stderr,
"%s: %s: reopen: %s\n",
351 fprintf(stderr,
"mdb_env_create failed, error %d %s\n", rc,
mdb_strerror(rc));
368 fprintf(stderr,
"mdb_env_open failed, error %d %s\n", rc,
mdb_strerror(rc));
386 fprintf(stderr,
"mdb_txn_begin failed, error %d %s\n", rc,
mdb_strerror(rc));
392 fprintf(stderr,
"mdb_open failed, error %d %s\n", rc,
mdb_strerror(rc));
398 fprintf(stderr,
"mdb_cursor_open failed, error %d %s\n", rc,
mdb_strerror(rc));
409 fprintf(stderr,
"%s: line %" Z "d: failed to read key value\n",
prog,
lineno);
417 fprintf(stderr,
"mdb_cursor_put failed, error %d %s\n", rc,
mdb_strerror(rc));
424 fprintf(stderr,
"%s: line %" Z "d: txn_commit: %s\n",
430 fprintf(stderr,
"mdb_txn_begin failed, error %d %s\n", rc,
mdb_strerror(rc));
435 fprintf(stderr,
"mdb_cursor_open failed, error %d %s\n", rc,
mdb_strerror(rc));
444 fprintf(stderr,
"%s: line %" Z "d: txn_commit: %s\n",
std::ofstream out("events_result.xml")
main entry point for tests
#define MDB_VERSION_STRING
The full library version as a C string.
#define MDB_KEYEXIST
key/data pair already exists
int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Store by cursor.
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
Open an environment handle.
void mdb_env_close(MDB_env *env)
Close the environment and release the memory map.
void mdb_dbi_close(MDB_env *env, MDB_dbi dbi)
Close a database handle.
void mdb_txn_abort(MDB_txn *txn)
Abandon all the operations of the transaction instead of saving them.
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
char * mdb_strerror(int err)
Return a string describing a given error code.
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.
int mdb_env_set_mapsize(MDB_env *env, size_t size)
Set the size of the memory map to use for this environment.
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs)
Set the maximum number of named databases for the environment.
int mdb_env_create(MDB_env **env)
Create an LMDB environment handle.
int mdb_env_get_maxkeysize(MDB_env *env)
Get the maximum size of keys and MDB_DUPSORT data we can write.
#define mdb_open(txn, name, flags, dbi)
Compat with version <= 0.9.4, avoid clash with libmdb from MDB Tools project.
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers)
Set the maximum number of threads/reader slots for the environment.
#define MDB_INTEGERKEY
numeric keys in native byte order: either unsigned int or size_t.
#define MDB_DUPFIXED
with MDB_DUPSORT, sorted dup items have fixed size
#define MDB_INTEGERDUP
with MDB_DUPSORT, dups are MDB_INTEGERKEY-style integers
#define MDB_DUPSORT
use sorted duplicates
#define MDB_REVERSEKEY
use reverse string keys
#define MDB_REVERSEDUP
with MDB_DUPSORT, use reverse string dups
#define MDB_CREATE
create DB if not already existing
#define MDB_FIXEDMAP
mmap at a fixed address (experimental)
#define MDB_NOSUBDIR
no environment directory
unsigned int me_maxreaders
max reader slots in the environment
#define MDB_NOOVERWRITE
For put: Don't write if the key already exists.
size_t me_mapsize
Size of the data memory map.
#define MDB_NODUPDATA
Only for MDB_DUPSORT For put: don't write if the key and data pair already exist.
void * me_mapaddr
Address of map, if fixed.
size_t mv_size
size of the data item
void * mv_data
address of the data item
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
int main(int argc, char *argv[])
static int unhex(unsigned char *c2)
static void readhdr(void)
static int readline(MDB_val *out, MDB_val *buf)
static void env_close(MDB_env *env) noexcept
static void txn_abort(MDB_txn *txn) noexcept
const struct ncbi::grid::netcache::search::fields::KEY key
int strncmp(const char *str1, const char *str2, size_t count)
Cursors are used for all DB operations.
The database environment.
Information about the environment.
Generic structure used for passing keys and data in and out of the database.