lmdb-test: workaround for MDB_FIXEDMAP to avoid sporadic failures.

Change-Id: I6ba993ff50956d328fd76326c67aa83dff20ce48
This commit is contained in:
Leo Yuriev 2015-08-23 15:20:01 +03:00
parent 537fc0fe1a
commit 6a3efb82eb
9 changed files with 170 additions and 18 deletions

14
mdb.c
View File

@ -4184,8 +4184,8 @@ mdb_env_map(MDB_env *env, void *addr)
if (ftruncate(env->me_fd, env->me_mapsize) < 0)
return errno;
}
env->me_map = mmap(addr, env->me_mapsize, prot, MAP_SHARED,
env->me_fd, 0);
env->me_map = mmap(addr, env->me_mapsize, prot, MAP_SHARED, env->me_fd, 0);
if (env->me_map == MAP_FAILED) {
env->me_map = NULL;
return errno;
@ -4195,11 +4195,9 @@ mdb_env_map(MDB_env *env, void *addr)
/* Turn off readahead. It's harmful when the DB is larger than RAM. */
#ifdef MADV_RANDOM
madvise(env->me_map, env->me_mapsize, MADV_RANDOM);
#else
#ifdef POSIX_MADV_RANDOM
#elif defined(POSIX_MADV_RANDOM)
posix_madvise(env->me_map, env->me_mapsize, POSIX_MADV_RANDOM);
#endif /* POSIX_MADV_RANDOM */
#endif /* MADV_RANDOM */
#endif /* MADV_RANDOM & POSIX_MADV_RANDOM */
}
/* Can happen because the address argument to mmap() is just a
@ -4207,8 +4205,10 @@ mdb_env_map(MDB_env *env, void *addr)
* The MAP_FIXED flag would prevent that, but then mmap could
* instead unmap existing pages to make room for the new map.
*/
if (addr && env->me_map != addr)
if (addr && env->me_map != addr) {
errno = 0; /* LY: clean errno as a hit for this case */
return EBUSY; /* TODO: Make a new MDB_* error code? */
}
/* Lock meta pages to avoid unexpected write,
* before the data pages would be synchronized. */

View File

@ -14,6 +14,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -21,6 +24,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
@ -34,6 +41,8 @@ int main(int argc,char * argv[])
int count;
int *values;
char sval[32] = "";
int env_oflags;
struct stat db_stat, exe_stat;
srand(time(NULL));
@ -47,7 +56,19 @@ int main(int argc,char * argv[])
E(mdb_env_create(&env));
E(mdb_env_set_maxreaders(env, 1));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
E(mdb_dbi_open(txn, NULL, 0, &dbi));

View File

@ -23,6 +23,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -30,6 +33,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
@ -42,6 +49,8 @@ int main(int argc,char * argv[])
int count;
int *values;
char sval[32] = "";
int env_oflags;
struct stat db_stat, exe_stat;
srand(time(NULL));
@ -53,11 +62,25 @@ int main(int argc,char * argv[])
}
E(mdb_env_create(&env));
E(mdb_env_set_maxreaders(env, 1));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
/* LY: especially here we always needs MDB_NOSYNC
* for testing mdb_env_close_ex() and "redo-to-steady" on open. */
env_oflags |= MDB_NOSYNC;
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
if (mdb_dbi_open(txn, "id1", MDB_CREATE, &dbi) == MDB_SUCCESS)
@ -144,7 +167,7 @@ int main(int argc,char * argv[])
mdb_env_close_ex(env, 1);
E(mdb_env_create(&env));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
printf("check-preset-c.cursor-next\n");
E(mdb_env_stat(env, &mst));

View File

@ -17,6 +17,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -24,6 +27,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
@ -36,6 +43,8 @@ int main(int argc,char * argv[])
int count;
int *values;
char sval[32] = "";
int env_oflags;
struct stat db_stat, exe_stat;
srand(time(NULL));
@ -50,7 +59,19 @@ int main(int argc,char * argv[])
E(mdb_env_set_maxreaders(env, 1));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
if (mdb_dbi_open(txn, "id2", MDB_CREATE, &dbi) == MDB_SUCCESS)

View File

@ -17,6 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -24,6 +27,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
@ -37,6 +44,8 @@ int main(int argc,char * argv[])
int *values;
char sval[32];
char kval[sizeof(int)];
int env_oflags;
struct stat db_stat, exe_stat;
srand(time(NULL));
@ -52,7 +61,19 @@ int main(int argc,char * argv[])
E(mdb_env_create(&env));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
if (mdb_dbi_open(txn, "id3", MDB_CREATE, &dbi) == MDB_SUCCESS)

View File

@ -17,6 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -24,6 +27,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
@ -37,6 +44,8 @@ int main(int argc,char * argv[])
int *values;
char sval[8];
char kval[sizeof(int)];
int env_oflags;
struct stat db_stat, exe_stat;
memset(sval, 0, sizeof(sval));
@ -50,7 +59,19 @@ int main(int argc,char * argv[])
E(mdb_env_create(&env));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
if (mdb_dbi_open(txn, "id4", MDB_CREATE, &dbi) == MDB_SUCCESS)

View File

@ -17,6 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -24,6 +27,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
@ -37,6 +44,8 @@ int main(int argc,char * argv[])
int *values;
char sval[32];
char kval[sizeof(int)];
int env_oflags;
struct stat db_stat, exe_stat;
srand(time(NULL));
@ -52,7 +61,19 @@ int main(int argc,char * argv[])
E(mdb_env_create(&env));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
if (mdb_dbi_open(txn, "id5", MDB_CREATE, &dbi) == MDB_SUCCESS)

View File

@ -17,6 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
@ -24,6 +27,10 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
char dkbuf[1024];
int main(int argc,char * argv[])
@ -37,13 +44,27 @@ int main(int argc,char * argv[])
MDB_cursor *cursor;
long kval;
char *sval;
int env_oflags;
struct stat db_stat, exe_stat;
srand(time(NULL));
E(mdb_env_create(&env));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(stat("/proc/self/exe", &exe_stat)?errno:0);
E(stat(DBPATH "/.", &db_stat)?errno:0);
env_oflags = MDB_FIXEDMAP | MDB_NOSYNC;
if (major(db_stat.st_dev) != major(exe_stat.st_dev)) {
/* LY: Assume running inside a CI-environment:
* 1) don't use FIXEDMAP to avoid EBUSY in case collision,
* which could be inspired by address space randomisation feature.
* 2) drop MDB_NOSYNC expecting that DBPATH is at a tmpfs or some dedicated storage.
*/
env_oflags = 0;
}
E(mdb_env_open(env, DBPATH, env_oflags, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
if (mdb_dbi_open(txn, "id6", MDB_CREATE, &dbi) == MDB_SUCCESS)

View File

@ -25,6 +25,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#include "lmdb.h"
@ -33,7 +34,9 @@
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
#define DBPATH "./testdb"
#ifndef DBPATH
# define DBPATH "./testdb"
#endif
struct t0 {
struct rusage ru;
@ -124,7 +127,7 @@ static void wbench(int flags, int mb, int count, int salt)
E(mdb_env_create(&env));
E(mdb_env_set_mapsize(env, (1ull << 20) * mb));
E(mdb_env_open(env, "./testdb", flags, 0664));
E(mdb_env_open(env, DBPATH, flags, 0664));
key.mv_size = sizeof(key_value);
key.mv_data = &key_value;