Commit ec3a43ed authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

log-test checks to see if we can find log numbers

git-svn-id: file:///svn/tokudb@106 c7de825b-a66e-492c-adef-691d508d4ae1
parent 09975d1a
...@@ -51,6 +51,7 @@ brt-serialize.o: brt.h cachetable.h memory.h mdict.h pma.h brttypes.h brt-intern ...@@ -51,6 +51,7 @@ brt-serialize.o: brt.h cachetable.h memory.h mdict.h pma.h brttypes.h brt-intern
header-io.o: brttypes.h brt-internal.h memory.h header-io.o: brttypes.h brt-internal.h memory.h
mdict-test: hashtable.o pma.o memory.o mdict-test: hashtable.o pma.o memory.o
brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o hashtable.o brt-serialize.o brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o hashtable.o brt-serialize.o
log-test: log.o memory.o
brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o hashtable.o pma.o key.o ybt.o brt.o cachetable.o brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o hashtable.o pma.o key.o ybt.o brt.o cachetable.o
......
#include "yerror.h"
#include <stdio.h>
#define LOGGER_BUF_SIZE (1<<20) #define LOGGER_BUF_SIZE (1<<20)
typedef struct tokulogger *TOKULOGGER; typedef struct tokulogger *TOKULOGGER;
struct tokulogger { struct tokulogger {
...@@ -8,3 +11,5 @@ struct tokulogger { ...@@ -8,3 +11,5 @@ struct tokulogger {
char buf[LOGGER_BUF_SIZE]; char buf[LOGGER_BUF_SIZE];
int n_in_buf; int n_in_buf;
}; };
int tokulogger_find_next_unused_log_file(const char *directory, long long *result);
#include "log-internal.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#define dname "log-test-dir"
#define rmrf "rm -rf " dname "/"
int main (int argc __attribute__((__unused__)),
char *argv[] __attribute__((__unused__))) {
int r;
long long lognum;
system(rmrf);
r = mkdir(dname, 0700); assert(r==0);
r = tokulogger_find_next_unused_log_file(dname,&lognum);
assert(r==0 && lognum==0LL);
r = creat(dname "/log01.tokulog", 0700); assert(r>=0);
r = close(r); assert(r==0);
r = tokulogger_find_next_unused_log_file(dname,&lognum);
assert(r==0 && lognum==2LL);
r = creat(dname "/log123456789012345.tokulog", 0700); assert(r>=0);
r = close(r); assert(r==0);
r = tokulogger_find_next_unused_log_file(dname,&lognum);
assert(r==0 && lognum==123456789012346LL);
r = creat(dname "/log3.tokulog", 0700); assert(r>=0);
r = close(r); assert(r==0);
r = tokulogger_find_next_unused_log_file(dname,&lognum);
assert(r==0 && lognum==123456789012346LL);
return 0;
}
#include "log-internal.h" #include "log-internal.h"
#include "yerror.h" #include "memory.h"
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
int find_next_unused_log_file(const char *directory, long long *result) { int tokulogger_find_next_unused_log_file(const char *directory, long long *result) {
DIR *d=opendir(directory); DIR *d=opendir(directory);
long long max=-1; long long max=-1;
struct dirent *de; struct dirent *de;
...@@ -20,19 +20,19 @@ int find_next_unused_log_file(const char *directory, long long *result) { ...@@ -20,19 +20,19 @@ int find_next_unused_log_file(const char *directory, long long *result) {
return 0; return 0;
} }
int create_and_open_logger (const char *directory) { int tokulogger_create_and_open_logger (const char *directory) {
TAGMALLOC(TOKULOGGER, result); TAGMALLOC(TOKULOGGER, result);
if (result==0) return -1; if (result==0) return -1;
int r; int r;
long long nexti; long long nexti;
r = find_next_unused_log_file(directory, &nexti); r = tokulogger_find_next_unused_log_file(directory, &nexti);
if (r!=0) { if (r!=0) {
died0: died0:
toku_free(result); toku_free(result);
return nexti; return nexti;
} }
result->directory = toku_strdup(directory); result->directory = toku_strdup(directory);
if (result->directory!=0) oto died0; if (result->directory!=0) goto died0;
result->f = 0; result->f = 0;
result->next_log_file_number = nexti; result->next_log_file_number = nexti;
result->n_in_buf = 0; result->n_in_buf = 0;
......
...@@ -3,4 +3,4 @@ enum pma_errors { BRT_OK=0, BRT_ALREADY_THERE = -2, BRT_KEYEMPTY=-3 }; ...@@ -3,4 +3,4 @@ enum pma_errors { BRT_OK=0, BRT_ALREADY_THERE = -2, BRT_KEYEMPTY=-3 };
enum typ_tag { TYP_BRTNODE = 0xdead0001, enum typ_tag { TYP_BRTNODE = 0xdead0001,
TYP_CACHETABLE, TYP_PAIR, /* for cachetables */ TYP_CACHETABLE, TYP_PAIR, /* for cachetables */
TYP_PMA, TYP_PMA,
TYP_LOGGER }; TYP_TOKULOGGER };
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