Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test to reproduce a bug in LightningDB: assertion during near 32,5k-th commit
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "lmdb.h"
int main(int argc,char * argv[])
int i = 0, j = 0, rc;
MDB_env *env;
MDB_val key, data;
MDB_stat mst;
MDB_cursor *cursor;
int count;
int *values;
char sval[32];
count = 1000000;
values = (int *)malloc(count*sizeof(int));
for(i = 0;i<count;i++) {
values[i] = i;
rc = mdb_env_create(&env);
rc = mdb_env_set_mapsize(env, 100000000);
rc = mdb_env_open(env, "testdb", 0, 0664);
key.mv_size = sizeof(int);
key.mv_data = sval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
printf("Adding %d values\n", count);
for (i=0;i<count;i++) {
MDB_txn *txn;
MDB_dbi dbi;
rc = mdb_txn_begin(env, NULL, 0, &txn);
rc = mdb_open(txn, NULL, 0, &dbi);
sprintf(sval, "%03x %d foo bar", values[i], values[i]);
rc = mdb_put(txn, dbi, &key, &data, 0);
rc = mdb_txn_commit(txn);
mdb_close(env, dbi);
printf("%i\n", i);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment