Skip to content

Instantly share code, notes, and snippets.

@ilyalukyanov
Last active December 17, 2015 17:19
Show Gist options
  • Save ilyalukyanov/5644971 to your computer and use it in GitHub Desktop.
Save ilyalukyanov/5644971 to your computer and use it in GitHub Desktop.
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];
srandom(time(NULL));
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);
}
mdb_env_close(env);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment