Commit 574016ff authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

More logging stuff

git-svn-id: file:///svn/tokudb@623 c7de825b-a66e-492c-adef-691d508d4ae1
parent de6a462f
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage # GCOV_FLAGS = -fprofile-arcs -ftest-coverage
# PROF_FLAGS = -pg # PROF_FLAGS = -pg
OPTFLAGS = -O2 # OPTFLAGS = -O2
ifeq ($(CYGWIN),cygwin) ifeq ($(CYGWIN),cygwin)
else else
...@@ -35,12 +35,14 @@ REGRESSION_TESTS = \ ...@@ -35,12 +35,14 @@ REGRESSION_TESTS = \
cachetable-test2 \ cachetable-test2 \
hashtest \ hashtest \
brt-test \ brt-test \
test_oexcl \
# This line intentially kept commented so I can have a \ on the end of the previous line # This line intentially kept commented so I can have a \ on the end of the previous line
BINS = $(REGRESSION_TESTS) \ BINS = $(REGRESSION_TESTS) \
benchmark-test \ benchmark-test \
randbrt \ randbrt \
randdb4 \ randdb4 \
logdump \
# This line intentially kept commented so I can have a \ on the end of the previous line # This line intentially kept commented so I can have a \ on the end of the previous line
logdump: LDFLAGS+=-lz logdump: LDFLAGS+=-lz
...@@ -48,6 +50,7 @@ logdump: LDFLAGS+=-lz ...@@ -48,6 +50,7 @@ logdump: LDFLAGS+=-lz
libs: log.o libs: log.o
bins: $(BINS) bins: $(BINS)
check: bins check: bins
$(DTOOL) ./test_oexcl
$(DTOOL) ./ybt-test $(DTOOL) ./ybt-test
$(DTOOL) ./pma-test $(DTOOL) ./pma-test
$(DTOOL) ./cachetable-test $(DTOOL) ./cachetable-test
...@@ -111,6 +114,7 @@ benchmark-test.o: brt.h ../include/db.h ...@@ -111,6 +114,7 @@ benchmark-test.o: brt.h ../include/db.h
clean: clean:
rm -rf $(REGRESSION_TESTS) $(BINS) *.o *.bb *.bbg *.da rm -rf $(REGRESSION_TESTS) $(BINS) *.o *.bb *.bbg *.da
rm -rf test_oexcl.c.tmp
randdb4: LOADLIBES=-ldb randdb4: LOADLIBES=-ldb
randbrt: brt.o hashtable.o cachetable.o memory.o brt-serialize.o randbrt: brt.o hashtable.o cachetable.o memory.o brt-serialize.o
......
...@@ -31,7 +31,7 @@ void setup (void) { ...@@ -31,7 +31,7 @@ void setup (void) {
int r; int r;
unlink(fname); unlink(fname);
r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0); r = brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = open_brt(fname, 0, 1, &t, nodesize, ct, default_compare_fun); assert(r==0); r = open_brt(fname, 0, 1, &t, nodesize, ct, NULL_TXN, default_compare_fun); assert(r==0);
} }
void shutdown (void) { void shutdown (void) {
......
This diff is collapsed.
...@@ -1237,7 +1237,7 @@ int brt_set_dup_compare(BRT brt, int (*dup_compare)(DB *, const DBT*, const DBT* ...@@ -1237,7 +1237,7 @@ int brt_set_dup_compare(BRT brt, int (*dup_compare)(DB *, const DBT*, const DBT*
return 0; return 0;
} }
int brt_open(BRT t, const char *fname, const char *dbname, int is_create, CACHETABLE cachetable) { int brt_open(BRT t, const char *fname, const char *dbname, int is_create, CACHETABLE cachetable, TOKUTXN txn __attribute__((__unused__))) {
/* If dbname is NULL then we setup to hold a single tree. Otherwise we setup an array. */ /* If dbname is NULL then we setup to hold a single tree. Otherwise we setup an array. */
int r; int r;
...@@ -1389,7 +1389,7 @@ int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags) { ...@@ -1389,7 +1389,7 @@ int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags) {
return r ? r : r2; return r ? r : r2;
} }
int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, int nodesize, CACHETABLE cachetable, int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, int nodesize, CACHETABLE cachetable, TOKUTXN txn,
int (*compare_fun)(DB*,const DBT*,const DBT*)) { int (*compare_fun)(DB*,const DBT*,const DBT*)) {
BRT brt; BRT brt;
int r; int r;
...@@ -1400,7 +1400,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, ...@@ -1400,7 +1400,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
brt_set_nodesize(brt, nodesize); brt_set_nodesize(brt, nodesize);
brt_set_bt_compare(brt, compare_fun); brt_set_bt_compare(brt, compare_fun);
r = brt_open(brt, fname, dbname, is_create, cachetable); r = brt_open(brt, fname, dbname, is_create, cachetable, txn);
if (r != 0) { if (r != 0) {
return r; return r;
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "cachetable.h" #include "cachetable.h"
#include "log.h" #include "log.h"
typedef struct brt *BRT; typedef struct brt *BRT;
int open_brt (const char *fname, const char *dbname, int is_create, BRT *, int nodesize, CACHETABLE, int(*)(DB*,const DBT*,const DBT*)); int open_brt (const char *fname, const char *dbname, int is_create, BRT *, int nodesize, CACHETABLE, TOKUTXN, int(*)(DB*,const DBT*,const DBT*));
int brt_create(BRT *); int brt_create(BRT *);
int brt_set_flags(BRT, int flags); int brt_set_flags(BRT, int flags);
...@@ -18,7 +18,7 @@ int brt_set_nodesize(BRT, int nodesize); ...@@ -18,7 +18,7 @@ int brt_set_nodesize(BRT, int nodesize);
int brt_set_bt_compare(BRT, int (*bt_compare)(DB *, const DBT*, const DBT*)); int brt_set_bt_compare(BRT, int (*bt_compare)(DB *, const DBT*, const DBT*));
int brt_set_dup_compare(BRT, int (*dup_compare)(DB *, const DBT*, const DBT*)); int brt_set_dup_compare(BRT, int (*dup_compare)(DB *, const DBT*, const DBT*));
int brt_set_cachetable(BRT, CACHETABLE); int brt_set_cachetable(BRT, CACHETABLE);
int brt_open(BRT, const char *fname, const char *dbname, int is_create, CACHETABLE ct); int brt_open(BRT, const char *fname, const char *dbname, int is_create, CACHETABLE ct, TOKUTXN txn);
int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags); int brt_remove_subdb(BRT brt, const char *dbname, u_int32_t flags);
int brt_insert (BRT, DBT *, DBT *, DB*, TOKUTXN); int brt_insert (BRT, DBT *, DBT *, DB*, TOKUTXN);
......
...@@ -22,6 +22,6 @@ typedef enum __toku_bool { FALSE=0, TRUE=1} BOOL; ...@@ -22,6 +22,6 @@ typedef enum __toku_bool { FALSE=0, TRUE=1} BOOL;
typedef struct tokulogger *TOKULOGGER; typedef struct tokulogger *TOKULOGGER;
#define NULL_LOGGER ((TOKULOGGER)0) #define NULL_LOGGER ((TOKULOGGER)0)
typedef struct tokutxn *TOKUTXN; typedef struct tokutxn *TOKUTXN;
#define NULL_TXN ((TOKUTXN)0)
#endif #endif
...@@ -86,13 +86,11 @@ int create_cachetable(CACHETABLE *result, long size_limit, LSN initial_lsn, TOKU ...@@ -86,13 +86,11 @@ int create_cachetable(CACHETABLE *result, long size_limit, LSN initial_lsn, TOKU
return 0; return 0;
} }
int cachetable_openf (CACHEFILE *cf, CACHETABLE t, const char *fname, int flags, mode_t mode) { static int cachetable_openfd (CACHEFILE *cf, CACHETABLE t, int fd) {
int r; int r;
CACHEFILE extant; CACHEFILE extant;
struct stat statbuf; struct stat statbuf;
struct fileid fileid; struct fileid fileid;
int fd = open(fname, flags, mode);
if (fd<0) return errno;
memset(&fileid, 0, sizeof(fileid)); memset(&fileid, 0, sizeof(fileid));
r=fstat(fd, &statbuf); r=fstat(fd, &statbuf);
assert(r==0); assert(r==0);
...@@ -120,6 +118,12 @@ int cachetable_openf (CACHEFILE *cf, CACHETABLE t, const char *fname, int flags, ...@@ -120,6 +118,12 @@ int cachetable_openf (CACHEFILE *cf, CACHETABLE t, const char *fname, int flags,
} }
} }
int cachetable_openf (CACHEFILE *cf, CACHETABLE t, const char *fname, int flags, mode_t mode) {
int fd = open(fname, flags, mode);
if (fd<0) return errno;
return cachetable_openfd (cf, t, fd);
}
CACHEFILE remove_cf_from_list (CACHEFILE cf, CACHEFILE list) { CACHEFILE remove_cf_from_list (CACHEFILE cf, CACHEFILE list) {
if (list==0) return 0; if (list==0) return 0;
else if (list==cf) { else if (list==cf) {
......
...@@ -23,7 +23,9 @@ enum { ...@@ -23,7 +23,9 @@ enum {
LT_DELETE = 'D', LT_DELETE = 'D',
LT_INSERT_WITH_NO_OVERWRITE = 'I', LT_INSERT_WITH_NO_OVERWRITE = 'I',
LT_CHECKPOINT = 'P', LT_CHECKPOINT = 'P',
LT_BLOCK_RENAME = 'R' LT_BLOCK_RENAME = 'R',
LT_FCREATE_TMP = 'T',
LT_UNLINK = 'U'
}; };
struct tokutxn { struct tokutxn {
......
...@@ -58,7 +58,7 @@ int tokulogger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) { ...@@ -58,7 +58,7 @@ int tokulogger_log_bytes(TOKULOGGER logger, int nbytes, void *bytes) {
int fnamelen = strlen(logger->directory)+50; int fnamelen = strlen(logger->directory)+50;
char fname[fnamelen]; char fname[fnamelen];
snprintf(fname, fnamelen, "%s/log%012llu.tokulog", logger->directory, logger->next_log_file_number); snprintf(fname, fnamelen, "%s/log%012llu.tokulog", logger->directory, logger->next_log_file_number);
fprintf(stderr, "%s:%d creat(%s, ...)\n", __FILE__, __LINE__, fname); //fprintf(stderr, "%s:%d creat(%s, ...)\n", __FILE__, __LINE__, fname);
logger->fd = creat(fname, O_EXCL | 0700); logger->fd = creat(fname, O_EXCL | 0700);
if (logger->fd==-1) return errno; if (logger->fd==-1) return errno;
logger->next_log_file_number++; logger->next_log_file_number++;
...@@ -92,7 +92,7 @@ int tokulogger_log_close(TOKULOGGER *loggerp) { ...@@ -92,7 +92,7 @@ int tokulogger_log_close(TOKULOGGER *loggerp) {
TOKULOGGER logger = *loggerp; TOKULOGGER logger = *loggerp;
int r = 0; int r = 0;
if (logger->fd!=-1) { if (logger->fd!=-1) {
printf("%s:%d closing log: n_in_buf=%d\n", __FILE__, __LINE__, logger->n_in_buf); //printf("%s:%d closing log: n_in_buf=%d\n", __FILE__, __LINE__, logger->n_in_buf);
if (logger->n_in_buf>0) { if (logger->n_in_buf>0) {
r = write(logger->fd, logger->buf, logger->n_in_buf); r = write(logger->fd, logger->buf, logger->n_in_buf);
if (r==-1) return errno; if (r==-1) return errno;
...@@ -263,6 +263,41 @@ int tokulogger_log_block_rename (TOKULOGGER logger, FILENUM fileid, DISKOFF oldd ...@@ -263,6 +263,41 @@ int tokulogger_log_block_rename (TOKULOGGER logger, FILENUM fileid, DISKOFF oldd
return tokulogger_finish(logger, &wbuf); return tokulogger_finish(logger, &wbuf);
} }
int tokulogger_log_fcreate_tmp (TOKUTXN txn, const char *fname, int mode) {
if (txn==0) return 0;
const int fnamelen = strlen(fname);
const int buflen = (+1 // log command
+4 // length of fname
+fnamelen
+4 // mode
+8 // crc & len
);
unsigned char buf[buflen];
struct wbuf wbuf;
wbuf_init (&wbuf, buf, buflen);
wbuf_char (&wbuf, LT_FCREATE_TMP);
wbuf_bytes(&wbuf, fname, fnamelen);
wbuf_int (&wbuf, mode);
return tokulogger_finish(txn->logger, &wbuf);
}
int tokulogger_log_unlink (TOKUTXN txn, const char *fname) {
if (txn==0) return 0;
const int fnamelen = strlen(fname);
const int buflen = (+1 // log command
+4 // length of fname
+fnamelen
+8 // crc & len
);
unsigned char buf[buflen];
struct wbuf wbuf;
wbuf_init (&wbuf, buf, buflen);
wbuf_char (&wbuf, LT_UNLINK);
wbuf_bytes(&wbuf, fname, fnamelen);
return tokulogger_finish(txn->logger, &wbuf);
};
/* /*
int brtenv_checkpoint (BRTENV env) { int brtenv_checkpoint (BRTENV env) {
init the checkpointing lock init the checkpointing lock
......
...@@ -16,4 +16,8 @@ int tokulogger_log_block_rename (TOKULOGGER logger, FILENUM fileid, DISKOFF oldd ...@@ -16,4 +16,8 @@ int tokulogger_log_block_rename (TOKULOGGER logger, FILENUM fileid, DISKOFF oldd
int tokutxn_begin (TOKUTXN /*parent*/,TOKUTXN *, TXNID txnid64, TOKULOGGER logger); int tokutxn_begin (TOKUTXN /*parent*/,TOKUTXN *, TXNID txnid64, TOKULOGGER logger);
int tokulogger_log_fcreate_tmp (TOKUTXN, const char */*fname*/, int /*mode*/);
int tokulogger_log_unlink (TOKUTXN, const char */*fname*/);
#endif #endif
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define fname __FILE__ ".tmp"
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
unlink(fname);
int fd0 = open (fname, O_RDWR|O_CREAT|O_EXCL, 0777);
assert(fd0>=0);
int fd1 = open (fname, O_RDWR|O_CREAT|O_EXCL, 0777);
assert(fd1==-1);
assert(errno==EEXIST);
return 0;
}
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