Commit 6e1b04dc authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Implement DB_ENV->log_flush. Fixes #393.

git-svn-id: file:///svn/tokudb@2610 c7de825b-a66e-492c-adef-691d508d4ae1
parent 886a1481
/* -*- 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;
}
...@@ -336,11 +336,10 @@ static int toku_env_log_archive(DB_ENV * env, char **list[], u_int32_t flags) { ...@@ -336,11 +336,10 @@ static int toku_env_log_archive(DB_ENV * env, char **list[], u_int32_t flags) {
return 0; 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); HANDLE_PANICKED_ENV(env);
env=env; lsn=lsn; // 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.
toku_ydb_barf(); return toku_logger_fsync(env->i->logger);
return 1;
} }
static int toku_env_set_cachesize(DB_ENV * env, u_int32_t gbytes, u_int32_t bytes, int ncache) { static int toku_env_set_cachesize(DB_ENV * env, u_int32_t gbytes, u_int32_t bytes, int ncache) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment