Commit 1f93212a authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

log_code.c compiles to log_code.o. Addresses #11

git-svn-id: file:///svn/tokudb@715 c7de825b-a66e-492c-adef-691d508d4ae1
parent 202cd97c
......@@ -130,7 +130,7 @@ void toku_serialize_brtnode_to(int fd, DISKOFF off, DISKOFF size, BRTNODE node)
//printf("%s:%d w.ndone=%d (childkeylen[%d]=%d\n", __FILE__, __LINE__, w.ndone, i, node->childkeylens[i]);
}
for (i=0; i<node->u.n.n_children; i++) {
wbuf_diskoff(&w, node->u.n.children[i]);
wbuf_DISKOFF(&w, node->u.n.children[i]);
//printf("%s:%d w.ndone=%d\n", __FILE__, __LINE__, w.ndone);
}
......@@ -450,20 +450,20 @@ int toku_serialize_brt_header_to_wbuf (struct wbuf *wbuf, struct brt_header *h)
wbuf_int (wbuf, size);
wbuf_int (wbuf, h->flags);
wbuf_int (wbuf, h->nodesize);
wbuf_diskoff(wbuf, h->freelist);
wbuf_diskoff(wbuf, h->unused_memory);
wbuf_DISKOFF(wbuf, h->freelist);
wbuf_DISKOFF(wbuf, h->unused_memory);
wbuf_int (wbuf, h->n_named_roots);
if (h->n_named_roots>0) {
int i;
for (i=0; i<h->n_named_roots; i++) {
char *s = h->names[i];
unsigned int l = 1+strlen(s);
wbuf_diskoff(wbuf, h->roots[i]);
wbuf_DISKOFF(wbuf, h->roots[i]);
wbuf_bytes (wbuf, s, l);
assert(l>0 && s[l-1]==0);
}
} else {
wbuf_diskoff(wbuf, h->unnamed_root);
wbuf_DISKOFF(wbuf, h->unnamed_root);
}
assert(wbuf->ndone<=wbuf->size);
return 0;
......
......@@ -18,7 +18,7 @@ typedef long long TXNID;
typedef struct {
int len;
char *data;
} BYTESTRING;
} *BYTESTRING;
/* Make the LSN be a struct instead of an integer so that we get better type checking. */
typedef struct __toku_lsn { u_int64_t lsn; } LSN;
......
......@@ -38,3 +38,24 @@ struct tokutxn {
};
int tokulogger_finish (TOKULOGGER logger, struct wbuf *wbuf);
static inline int toku_logsizeof_u_int32_t (u_int32_t v __attribute__((__unused__))) {
return 4;
}
static inline int toku_logsizeof_FILENUM (FILENUM v __attribute__((__unused__))) {
return 4;
}
static inline int toku_logsizeof_DISKOFF (DISKOFF v __attribute__((__unused__))) {
return 8;
}
static inline int toku_logsizeof_TXNID (TXNID txnid __attribute__((__unused__))) {
return 8;
}
static inline int toku_logsizeof_BYTESTRING (BYTESTRING bs) {
return 4+bs->len;
}
......@@ -160,10 +160,10 @@ int tokulogger_log_brt_insert_with_no_overwrite (TOKULOGGER logger,
struct wbuf wbuf;
wbuf_init(&wbuf, buf, buflen) ;
wbuf_char(&wbuf, LT_INSERT_WITH_NO_OVERWRITE);
wbuf_lsn (&wbuf, logger->lsn); logger->lsn.lsn++;
wbuf_txnid(&wbuf, txnid);
wbuf_filenum(&wbuf, fileid);
wbuf_diskoff(&wbuf, diskoff);
wbuf_LSN (&wbuf, logger->lsn); logger->lsn.lsn++;
wbuf_TXNID(&wbuf, txnid);
wbuf_FILENUM(&wbuf, fileid);
wbuf_DISKOFF(&wbuf, diskoff);
wbuf_bytes(&wbuf, key, keylen);
wbuf_bytes(&wbuf, val, vallen);
return tokulogger_finish (logger, &wbuf);
......@@ -186,11 +186,11 @@ int tokulogger_log_phys_add_or_delete_in_leaf (DB *db, TOKUTXN txn, DISKOFF disk
struct wbuf wbuf;
wbuf_init(&wbuf, buf, buflen) ;
wbuf_char(&wbuf, is_add ? LT_INSERT_WITH_NO_OVERWRITE : LT_DELETE);
wbuf_lsn (&wbuf, txn->logger->lsn);
wbuf_LSN (&wbuf, txn->logger->lsn);
txn->logger->lsn.lsn++;
wbuf_txnid(&wbuf, txn->txnid64);
wbuf_filenum(&wbuf, db->i->fileid);
wbuf_diskoff(&wbuf, diskoff);
wbuf_TXNID(&wbuf, txn->txnid64);
wbuf_FILENUM(&wbuf, db->i->fileid);
wbuf_DISKOFF(&wbuf, diskoff);
wbuf_bytes(&wbuf, kv_pair_key_const(pair), keylen);
wbuf_bytes(&wbuf, kv_pair_val_const(pair), vallen);
return tokulogger_finish(txn->logger, &wbuf);
......@@ -206,9 +206,9 @@ int tokulogger_log_commit (TOKUTXN txn) {
unsigned char buf[buflen];
wbuf_init(&wbuf, buf, buflen);
wbuf_char(&wbuf, LT_COMMIT);
wbuf_lsn (&wbuf, txn->logger->lsn);
wbuf_LSN (&wbuf, txn->logger->lsn);
txn->logger->lsn.lsn++;
wbuf_txnid(&wbuf, txn->txnid64);
wbuf_TXNID(&wbuf, txn->txnid64);
int r = tokulogger_finish(txn->logger, &wbuf);
if (r!=0) return r;
int result;
......@@ -224,7 +224,7 @@ int tokulogger_log_checkpoint (TOKULOGGER logger, LSN *lsn) {
unsigned char buf[buflen];
wbuf_init(&wbuf, buf, buflen);
wbuf_char(&wbuf, LT_CHECKPOINT);
wbuf_lsn (&wbuf, logger->lsn);
wbuf_LSN (&wbuf, logger->lsn);
*lsn = logger->lsn;
logger->lsn.lsn++;
return tokulogger_log_bytes(logger, wbuf.ndone, wbuf.buf);
......@@ -255,12 +255,12 @@ int tokulogger_log_block_rename (TOKULOGGER logger, FILENUM fileid, DISKOFF oldd
struct wbuf wbuf;
wbuf_init (&wbuf, buf, buflen) ;
wbuf_char (&wbuf, LT_BLOCK_RENAME);
wbuf_lsn (&wbuf, logger->lsn);
wbuf_LSN (&wbuf, logger->lsn);
logger->lsn.lsn++;
wbuf_filenum(&wbuf, fileid);
wbuf_diskoff(&wbuf, olddiskoff);
wbuf_diskoff(&wbuf, newdiskoff);
wbuf_diskoff(&wbuf, parentdiskoff);
wbuf_FILENUM(&wbuf, fileid);
wbuf_DISKOFF(&wbuf, olddiskoff);
wbuf_DISKOFF(&wbuf, newdiskoff);
wbuf_DISKOFF(&wbuf, parentdiskoff);
wbuf_int (&wbuf, childnum);
return tokulogger_finish(logger, &wbuf);
}
......@@ -280,9 +280,9 @@ int tokulogger_log_fcreate (TOKUTXN txn, const char *fname, int mode) {
struct wbuf wbuf;
wbuf_init (&wbuf, buf, buflen);
wbuf_char (&wbuf, LT_FCREATE);
wbuf_lsn (&wbuf, txn->logger->lsn);
wbuf_LSN (&wbuf, txn->logger->lsn);
txn->logger->lsn.lsn++;
wbuf_txnid(&wbuf, txn->txnid64);
wbuf_TXNID(&wbuf, txn->txnid64);
wbuf_bytes(&wbuf, fname, fnamelen);
wbuf_int (&wbuf, mode);
return tokulogger_finish(txn->logger, &wbuf);
......@@ -304,11 +304,11 @@ int tokulogger_log_fopen (TOKUTXN txn, const char * fname, FILENUM filenum) {
struct wbuf wbuf;
wbuf_init (&wbuf, buf, buflen);
wbuf_char (&wbuf, LT_FOPEN);
wbuf_lsn (&wbuf, txn->logger->lsn);
wbuf_LSN (&wbuf, txn->logger->lsn);
txn->logger->lsn.lsn++;
wbuf_txnid(&wbuf, txn->txnid64);
wbuf_TXNID(&wbuf, txn->txnid64);
wbuf_bytes(&wbuf, fname, fnamelen);
wbuf_filenum(&wbuf, filenum);
wbuf_FILENUM(&wbuf, filenum);
return tokulogger_finish(txn->logger, &wbuf);
}
......@@ -346,10 +346,10 @@ int tokulogger_log_header (TOKUTXN txn, FILENUM filenum, struct brt_header *h) {
struct wbuf wbuf;
wbuf_init(&wbuf, buf, buflen);
wbuf_char(&wbuf, LT_FHEADER);
wbuf_lsn (&wbuf, txn->logger->lsn);
wbuf_LSN (&wbuf, txn->logger->lsn);
txn->logger->lsn.lsn++;
wbuf_txnid(&wbuf, txn->txnid64);
wbuf_filenum(&wbuf, filenum);
wbuf_TXNID(&wbuf, txn->txnid64);
wbuf_FILENUM(&wbuf, filenum);
r=toku_serialize_brt_header_to_wbuf(&wbuf, h);
if (r!=0) return r;
r=tokulogger_finish(txn->logger, &wbuf);
......@@ -374,11 +374,11 @@ int tokulogger_log_newbrtnode (TOKUTXN txn, FILENUM filenum, DISKOFF offset, u_i
struct wbuf wbuf;
wbuf_init (&wbuf, buf, buflen);
wbuf_char(&wbuf, LT_NEWBRTNODE);
wbuf_lsn (&wbuf, txn->logger->lsn);
wbuf_LSN (&wbuf, txn->logger->lsn);
txn->logger->lsn.lsn++;
wbuf_txnid(&wbuf, txn->txnid64);
wbuf_filenum(&wbuf, filenum);
wbuf_diskoff(&wbuf, offset);
wbuf_TXNID(&wbuf, txn->txnid64);
wbuf_FILENUM(&wbuf, filenum);
wbuf_DISKOFF(&wbuf, offset);
wbuf_int(&wbuf, height);
wbuf_int(&wbuf, nodesize);
wbuf_char(&wbuf, is_dup_sort_mode);
......
......@@ -26,4 +26,22 @@ int tokulogger_log_header (TOKUTXN, FILENUM, struct brt_header *);
int tokulogger_log_newbrtnode (TOKUTXN txn, FILENUM filenum, DISKOFF offset, u_int32_t height, u_int32_t nodesize, char is_dup_sort_mode, u_int32_t rand4fingerprint);
int tokulogger_fsync (TOKULOGGER logger);
int toku_fread_u_int32_t_nocrclen (FILE *f, u_int32_t *v);
int toku_fread_u_int32_t (FILE *f, u_int32_t *v, u_int32_t *crc, u_int32_t *len);
int toku_fread_LSN (FILE *f, LSN *lsn, u_int32_t *crc, u_int32_t *len);
int toku_fread_FILENUM (FILE *f, FILENUM *filenum, u_int32_t *crc, u_int32_t *len);
int toku_fread_DISKOFF (FILE *f, DISKOFF *diskoff, u_int32_t *crc, u_int32_t *len);
int toku_fread_TXNID (FILE *f, TXNID *txnid, u_int32_t *crc, u_int32_t *len);
// fills in the bs with malloced data.
int toku_fread_BYTESTRING (FILE *f, BYTESTRING *bs, u_int32_t *crc, u_int32_t *len);
int toku_logprint_LSN (FILE *outf, FILE *inf, u_int32_t *crc, u_int32_t *len);
int toku_logprint_TXNID (FILE *outf, FILE *inf, u_int32_t *crc, u_int32_t *len);
int toku_logprint_BYTESTRING (FILE *outf, FILE *inf, u_int32_t *crc, u_int32_t *len);
int toku_logprint_FILENUM (FILE *outf, FILE *inf, u_int32_t *crc, u_int32_t *len);
int toku_logprint_DISKOFF (FILE *outf, FILE *inf, u_int32_t *crc, u_int32_t *len);
int toku_logprint_u_int32_t (FILE *outf, FILE *inf, u_int32_t *crc, u_int32_t *len);
#endif
......@@ -98,11 +98,11 @@ void generate_log_writer (void) {
fprintf2(cf, hf, ", %s %s", ft->type, ft->name));
fprintf(hf, ");\n");
fprintf(cf, ") {\n");
fprintf(cf, " const int buflen= (1 // log command\n");
fprintf(cf, " +8 // lsn\n");
fprintf(cf, " const unsigned int buflen= (1 // log command\n");
fprintf(cf, " +8 // lsn\n");
DO_FIELDS(ft, lt,
fprintf(cf, " +toku_logsizeof_%s(%s)\n", ft->type, ft->name));
fprintf(cf, " +8 // crc + len\n");
fprintf(cf, " +toku_logsizeof_%s(%s)\n", ft->type, ft->name));
fprintf(cf, " +8 // crc + len\n");
fprintf(cf, " );\n");
fprintf(cf, " struct wbuf wbuf;\n");
fprintf(cf, " char *buf = toku_malloc(buflen);\n");
......@@ -133,14 +133,15 @@ void generate_log_reader (void) {
fprintf2(cf, hf, "int tokulog_fread_%s (FILE *infile, struct logtype_%s *data, char cmd)", lt->name, lt->name);
fprintf(hf, ";\n");
fprintf(cf, " {\n");
fprintf(cf, " int r=0, actual_len=1;\n");
fprintf(cf, " int r=0;\n");
fprintf(cf, " u_int32_t actual_len=1;\n");
fprintf(cf, " u_int32_t crc = toku_crc32(0, &cmd, 1);\n");
fprintf(cf, " r=toku_fread_%-16s(infile, &data->%-16s, &crc, &actual_len); if (r!=0) return r;\n", "LSN", "lsn");
DO_FIELDS(ft, lt,
fprintf(cf, " r=toku_fread_%-16s(infile, &data->%-16s, &crc, &actual_len); if (r!=0) return r;\n", ft->type, ft->name));
fprintf(cf, " u_int32_t crc_in_file, len_in_file;\n");
fprintf(cf, " r=toku_fread_u_int32_t(infile, &crc_in_file); actual_len+=4; if (r!=0) return r;\n");
fprintf(cf, " r=toku_fread_u_int32_t(infile, &len_in_file); actual_len+=4; if (r!=0) return r;\n");
fprintf(cf, " r=toku_fread_u_int32_t_nocrclen(infile, &crc_in_file); actual_len+=4; if (r!=0) return r;\n");
fprintf(cf, " r=toku_fread_u_int32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;\n");
fprintf(cf, " if (crc_in_file!=crc || len_in_file!=actual_len) return DB_BADFORMAT;\n");
fprintf(cf, " return 0;\n");
fprintf(cf, "}\n\n");
......@@ -162,10 +163,10 @@ void generate_logprint (void) {
fprintf(cf, " r = toku_logprint_%-16s(outf, f, &crc, &len); if (r!=0) return r;\n", "LSN");
DO_FIELDS(ft, lt,
fprintf(cf, " r = toku_logprint_%-16s(outf, f, &crc, &len); if (r!=0) return r;\n", ft->type));
fprintf(cf, " r = toku_fread_u_int32_t (f, &crc_in_file); len+=4; if (r!=0) return r;\n");
fprintf(cf, " r = toku_fread_u_int32_t_nocrclen (f, &crc_in_file); len+=4; if (r!=0) return r;\n");
fprintf(cf, " fprintf(outf, \" crc=%%d\", crc_in_file);\n");
fprintf(cf, " if (crc_in_file!=crc) fprintf(outf, \" actual_crc=%%d\", crc);\n");
fprintf(cf, " r = toku_fread_u_int32_t (f, &len_in_file); len+=4; if (r!=0) return r;\n");
fprintf(cf, " r = toku_fread_u_int32_t_nocrclen (f, &len_in_file); len+=4; if (r!=0) return r;\n");
fprintf(cf, " fprintf(outf, \" len=%%d\", len_in_file);\n");
fprintf(cf, " if (len_in_file!=len) fprintf(outf, \" actual_len=%%d\", len);\n");
fprintf(cf, " if (len_in_file!=len || crc_in_file!=crc) return DB_BADFORMAT;\n");
......
......@@ -89,19 +89,27 @@ static void wbuf_ulonglong (struct wbuf *w, unsigned long long ull) {
wbuf_int(w, ull&0xFFFFFFFF);
}
static void wbuf_diskoff (struct wbuf *w, DISKOFF off) {
static inline void wbuf_BYTESTRING (struct wbuf *w, BYTESTRING v) {
wbuf_bytes(w, v->data, v->len);
}
static inline void wbuf_u_int32_t (struct wbuf *w, u_int32_t v) {
wbuf_int(w, v);
}
static inline void wbuf_DISKOFF (struct wbuf *w, DISKOFF off) {
wbuf_ulonglong(w, off);
}
static inline void wbuf_txnid (struct wbuf *w, TXNID tid) {
static inline void wbuf_TXNID (struct wbuf *w, TXNID tid) {
wbuf_ulonglong(w, tid);
}
static inline void wbuf_lsn (struct wbuf *w, LSN lsn) {
static inline void wbuf_LSN (struct wbuf *w, LSN lsn) {
wbuf_ulonglong(w, lsn.lsn);
}
static inline void wbuf_filenum (struct wbuf *w, FILENUM fileid) {
static inline void wbuf_FILENUM (struct wbuf *w, FILENUM fileid) {
wbuf_int(w, fileid.fileid);
}
......
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