Commit 7535abf3 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Start implementing a logger

git-svn-id: file:///svn/tokudb@104 c7de825b-a66e-492c-adef-691d508d4ae1
parent a4a9ef7b
#define LOGGER_BUF_SIZE (1<<20)
typedef struct tokulogger *TOKULOGGER;
struct tokulogger {
enum typ_tag tag;
char *directory;
FILE *f;
int next_log_file_number;
char buf[LOGGER_BUF_SIZE];
int n_in_buf;
};
#include "log-internal.h"
#include "yerror.h"
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
int find_next_unused_log_file(const char *directory, long long *result) {
DIR *d=opendir(directory);
long long max=-1;
struct dirent *de;
if (d==0) return errno;
while ((de=readdir(d))) {
if (de==0) return -errno;
long long thisl;
int r = sscanf(de->d_name, "log%llu.tokulog", &thisl);
if (r==1 && thisl>max) max=thisl;
}
*result=max+1;
return 0;
}
int create_and_open_logger (const char *directory) {
TAGMALLOC(TOKULOGGER, result);
if (result==0) return -1;
int r;
long long nexti;
r = find_next_unused_log_file(directory, &nexti);
if (r!=0) {
died0:
toku_free(result);
return nexti;
}
result->directory = toku_strdup(directory);
if (result->directory!=0) oto died0;
result->f = 0;
result->next_log_file_number = nexti;
result->n_in_buf = 0;
return 0;
}
...@@ -2,4 +2,5 @@ enum pma_errors { BRT_OK=0, BRT_ALREADY_THERE = -2, BRT_KEYEMPTY=-3 }; ...@@ -2,4 +2,5 @@ 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 };
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