diff --git a/src/tests/test_logflush.c b/src/tests/test_logflush.c new file mode 100644 index 0000000000000000000000000000000000000000..9813f865617cca9048801f6d3e6d69e89be52b60 --- /dev/null +++ b/src/tests/test_logflush.c @@ -0,0 +1,66 @@ +/* -*- mode: C; c-basic-offset: 4 -*- */ +#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." + +#include <db.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/mman.h> +#include "test.h" + +// Return the offset +int grep_for_in_logs(const char *str) { +#ifdef TOKUDB +#define lname DIR "//log000000000000.tokulog" +#else +#define lname DIR "//log.0000000001" +#endif + int fd = open(lname, O_RDONLY); + assert(fd>=0); + struct stat statbuf; + int r = fstat(fd, &statbuf); + assert(r==0); + void *addr_v = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + assert(addr_v!=MAP_FAILED); + char *fstr = addr_v; + int searchlen=strlen(str); + int i; + for (i=0; i+searchlen<statbuf.st_size; i++) { + if (memcmp(str, fstr+i, searchlen)==0) { + return i; + } + } + return -1; +} + +int main (int argc, char *argv[]) { + int r; + DB_ENV *env; + DB *db; + DB_TXN *tid; + + system("rm -rf " DIR); + r=mkdir(DIR, 0777); assert(r==0); + r=db_env_create(&env, 0); assert(r==0); + r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, 0777); CKERR(r); + r=db_create(&db, env, 0); CKERR(r); + r=env->txn_begin(env, 0, &tid, 0); assert(r==0); + r=db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, 0777); CKERR(r); + r=tid->commit(tid, 0); assert(r==0); + + { + DBT key,data; + char hello[]="hello"; + char there[]="there"; + r=env->txn_begin(env, 0, &tid, 0); CKERR(r); + r=db->put(db, tid, + dbt_init(&key, hello, sizeof(hello)), + dbt_init(&data, there, sizeof(there)), + 0); + r=grep_for_in_logs(hello); + assert(r==-1); + r=env->log_flush(env, 0); CKERR(r); + r=grep_for_in_logs(hello); + assert(r>=0); + } + return 0; +} diff --git a/src/ydb.c b/src/ydb.c index ad39a2a8452d924ab58207a65ac4be5b50b67333..0196cf44d537368c87e0bc34d09f7bb389cf7971 100644 --- a/src/ydb.c +++ b/src/ydb.c @@ -336,11 +336,10 @@ static int toku_env_log_archive(DB_ENV * env, char **list[], u_int32_t flags) { return 0; } -static int toku_env_log_flush(DB_ENV * env, const DB_LSN * lsn) { +static int toku_env_log_flush(DB_ENV * env, const DB_LSN * lsn __attribute__((__unused__))) { HANDLE_PANICKED_ENV(env); - env=env; lsn=lsn; - toku_ydb_barf(); - return 1; + // We just flush everything. MySQL uses lsn==0 which means flush everything. For anyone else using the log, it is correct to flush too much, so we are OK. + return toku_logger_fsync(env->i->logger); } static int toku_env_set_cachesize(DB_ENV * env, u_int32_t gbytes, u_int32_t bytes, int ncache) {