Commit 0363b169 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Get rid of almost all compiler warnings in newbrt. Addresses #1185.

git-svn-id: file:///svn/tokudb.1131b+1080a+1185@6381 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8ae6c215
...@@ -37,18 +37,20 @@ VISIBILITY=-fvisibility=hidden ...@@ -37,18 +37,20 @@ VISIBILITY=-fvisibility=hidden
endif endif
endif endif
CFLAGS = -Wall $(FORMAT) $(OPTFLAGS) $(GCOV_FLAGS) $(PROF_FLAGS) $(FPICFLAGS) $(SHADOW) $(VISIBILITY) CFLAGS = -Werror -Wall $(FORMAT) $(OPTFLAGS) $(GCOV_FLAGS) $(PROF_FLAGS) $(FPICFLAGS) $(SHADOW) $(VISIBILITY)
ifneq ($(CC),icc) ifneq ($(CC),icc)
CFLAGS += -Werror -Wextra -Wcast-align -Wbad-function-cast -Wmissing-noreturn -g3 -ggdb3 CFLAGS += -Wextra -Wcast-align -Wbad-function-cast -Wmissing-noreturn -g3 -ggdb3
else else
CFLAGS += -g CFLAGS += -g
CFLAGS += -diag-disable 177 # Don't complain about static variables that are not used. CFLAGS += -diag-disable 177 # Don't complain about static variables that are not used.
#CFLAGS += -diag-disable 188 # Don't complain about enumerated type mixed with another type.
CFLAGS += -diag-disable 589 # Don't complain about goto into a block that skips initializing variables. GCC catches the actual uninitialized variables. CFLAGS += -diag-disable 589 # Don't complain about goto into a block that skips initializing variables. GCC catches the actual uninitialized variables.
CFLAGS += -diag-disable 981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call. CFLAGS += -diag-disable 981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call.
CFLAGS += -diag-disable 1324 # Don't complain about rdtsc clobbering its registers more than once. CFLAGS += -diag-disable 1324 # Don't complain about rdtsc clobbering its registers more than once.
endif endif
LDFLAGS = $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS) -lz -lpthread LDFLAGS = $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS) -lz -lpthread
CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=500 # Need XOPEN_SOURCE=600 to get strtoll()
CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=600
# Add -Wconversion # Add -Wconversion
......
This diff is collapsed.
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
static int dump_data = 1; static int dump_data = 1;
void print_item (bytevec val, ITEMLEN len) { static void
print_item (bytevec val, ITEMLEN len) {
printf("\""); printf("\"");
ITEMLEN i; ITEMLEN i;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
...@@ -25,7 +26,8 @@ void print_item (bytevec val, ITEMLEN len) { ...@@ -25,7 +26,8 @@ void print_item (bytevec val, ITEMLEN len) {
printf("\""); printf("\"");
} }
void dump_header (int f, struct brt_header **header) { static void
dump_header (int f, struct brt_header **header) {
struct brt_header *h; struct brt_header *h;
int r; int r;
r = toku_deserialize_brtheader_from (f, header_blocknum, &h); assert(r==0); r = toku_deserialize_brtheader_from (f, header_blocknum, &h); assert(r==0);
...@@ -33,19 +35,19 @@ void dump_header (int f, struct brt_header **header) { ...@@ -33,19 +35,19 @@ void dump_header (int f, struct brt_header **header) {
if (h->layout_version==BRT_LAYOUT_VERSION_6) printf(" layout_version<=6\n"); if (h->layout_version==BRT_LAYOUT_VERSION_6) printf(" layout_version<=6\n");
else printf(" layout_version=%d\n", h->layout_version); else printf(" layout_version=%d\n", h->layout_version);
printf(" dirty=%d\n", h->dirty); printf(" dirty=%d\n", h->dirty);
printf(" nodesize=%d\n", h->nodesize); printf(" nodesize=%u\n", h->nodesize);
printf(" free_blocks=%" PRId64 "\n", h->free_blocks.b); printf(" free_blocks=%" PRId64 "\n", h->free_blocks.b);
printf(" unused_memory=%" PRId64 "\n", h->unused_blocks.b); printf(" unused_memory=%" PRId64 "\n", h->unused_blocks.b);
if (h->n_named_roots==-1) { if (h->n_named_roots==-1) {
printf(" unnamed_root=%" PRId64 "\n", h->roots[0].b); printf(" unnamed_root=%" PRId64 "\n", h->roots[0].b);
printf(" flags=%d\n", h->flags_array[0]); printf(" flags=%u\n", h->flags_array[0]);
} else { } else {
printf(" n_named_roots=%d\n", h->n_named_roots); printf(" n_named_roots=%d\n", h->n_named_roots);
if (h->n_named_roots>=0) { if (h->n_named_roots>=0) {
int i; int i;
for (i=0; i<h->n_named_roots; i++) { for (i=0; i<h->n_named_roots; i++) {
printf(" %s -> %" PRId64 "\n", h->names[i], h->roots[i].b); printf(" %s -> %" PRId64 "\n", h->names[i], h->roots[i].b);
printf(" flags=%d\n", h->flags_array[i]); printf(" flags=%u\n", h->flags_array[i]);
} }
} }
} }
...@@ -77,24 +79,26 @@ void dump_header (int f, struct brt_header **header) { ...@@ -77,24 +79,26 @@ void dump_header (int f, struct brt_header **header) {
} }
} }
int print_le(OMTVALUE lev, u_int32_t UU(idx), void *UU(v)) { static int
print_le (OMTVALUE lev, u_int32_t UU(idx), void *UU(v)) {
LEAFENTRY le=lev; LEAFENTRY le=lev;
print_leafentry(stdout, le); print_leafentry(stdout, le);
printf("\n"); printf("\n");
return 0; return 0;
} }
void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) { static void
dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) {
BRTNODE n; BRTNODE n;
int r = toku_deserialize_brtnode_from (f, blocknum, 0 /*pass zero for hash, it doesn't matter*/, &n, h); int r = toku_deserialize_brtnode_from (f, blocknum, 0 /*pass zero for hash, it doesn't matter*/, &n, h);
assert(r==0); assert(r==0);
assert(n!=0); assert(n!=0);
printf("brtnode\n"); printf("brtnode\n");
printf(" nodesize =%u\n", n->nodesize); printf(" nodesize =%u\n", n->nodesize);
printf(" sizeonddisk =%d\n", toku_serialize_brtnode_size(n)); printf(" sizeonddisk =%u\n", toku_serialize_brtnode_size(n));
printf(" flags =%u\n", n->flags); printf(" flags =%u\n", n->flags);
printf(" thisnodename=%" PRId64 "\n", n->thisnodename.b); printf(" thisnodename=%" PRId64 "\n", n->thisnodename.b);
printf(" disk_lsn =%" PRId64 "\n", n->disk_lsn.lsn); printf(" disk_lsn =%" PRIu64 "\n", n->disk_lsn.lsn);
//printf(" log_lsn =%lld\n", n->log_lsn.lsn); // The log_lsn is a memory-only value. //printf(" log_lsn =%lld\n", n->log_lsn.lsn); // The log_lsn is a memory-only value.
printf(" height =%d\n", n->height); printf(" height =%d\n", n->height);
printf(" layout_version=%d\n", n->layout_version); printf(" layout_version=%d\n", n->layout_version);
...@@ -114,7 +118,7 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) { ...@@ -114,7 +118,7 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) {
printf(" subleafentry_estimates={"); printf(" subleafentry_estimates={");
for (i=0; i<n->u.n.n_children; i++) { for (i=0; i<n->u.n.n_children; i++) {
if (i>0) printf(" "); if (i>0) printf(" ");
printf("%lld", (unsigned long long)(BNC_SUBTREE_LEAFENTRY_ESTIMATE(n, i))); printf("%llu", (unsigned long long)(BNC_SUBTREE_LEAFENTRY_ESTIMATE(n, i)));
} }
printf("}\n"); printf("}\n");
printf(" pivots:\n"); printf(" pivots:\n");
...@@ -130,7 +134,7 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) { ...@@ -130,7 +134,7 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) {
printf(" children:\n"); printf(" children:\n");
for (i=0; i<n->u.n.n_children; i++) { for (i=0; i<n->u.n.n_children; i++) {
printf(" child %d: %" PRId64 "\n", i, BNC_BLOCKNUM(n, i).b); printf(" child %d: %" PRId64 "\n", i, BNC_BLOCKNUM(n, i).b);
printf(" buffer contains %d bytes (%d items)\n", BNC_NBYTESINBUF(n, i), toku_fifo_n_entries(BNC_BUFFER(n,i))); printf(" buffer contains %u bytes (%d items)\n", BNC_NBYTESINBUF(n, i), toku_fifo_n_entries(BNC_BUFFER(n,i)));
if (dump_data) { if (dump_data) {
FIFO_ITERATE(BNC_BUFFER(n,i), key, keylen, data, datalen, typ, xid, FIFO_ITERATE(BNC_BUFFER(n,i), key, keylen, data, datalen, typ, xid,
({ ({
...@@ -147,7 +151,7 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) { ...@@ -147,7 +151,7 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) {
} }
printf("HUH?"); printf("HUH?");
ok: ok:
printf(" xid=%"PRId64" ", xid); printf(" xid=%"PRIu64" ", xid);
print_item(key, keylen); print_item(key, keylen);
if (datalen>0) { if (datalen>0) {
printf(" "); printf(" ");
...@@ -159,23 +163,25 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) { ...@@ -159,23 +163,25 @@ void dump_node (int f, BLOCKNUM blocknum, struct brt_header *h) {
} }
} }
} else { } else {
printf(" n_bytes_in_buffer=%d\n", n->u.l.n_bytes_in_buffer); printf(" n_bytes_in_buffer=%u\n", n->u.l.n_bytes_in_buffer);
printf(" items_in_buffer =%d\n", toku_omt_size(n->u.l.buffer)); printf(" items_in_buffer =%u\n", toku_omt_size(n->u.l.buffer));
if (dump_data) toku_omt_iterate(n->u.l.buffer, print_le, 0); if (dump_data) toku_omt_iterate(n->u.l.buffer, print_le, 0);
} }
toku_brtnode_free(&n); toku_brtnode_free(&n);
} }
void readline(char *line, int maxline) { static void
readline (char *line, int maxline) {
int i = 0; int i = 0;
int c; int c;
while ((c = getchar()) != EOF && c != '\n' && i < maxline) { while ((c = getchar()) != EOF && c != '\n' && i < maxline) {
line[i++] = c; line[i++] = (char)c;
} }
line[i++] = 0; line[i++] = 0;
} }
int split_fields(char *line, char *fields[], int maxfields) { static int
split_fields (char *line, char *fields[], int maxfields) {
int i; int i;
for (i=0; i<maxfields; i++, line=NULL) { for (i=0; i<maxfields; i++, line=NULL) {
fields[i] = strtok(line, " "); fields[i] = strtok(line, " ");
...@@ -221,7 +227,6 @@ int main (int argc, const char *argv[]) { ...@@ -221,7 +227,6 @@ int main (int argc, const char *argv[]) {
toku_brtheader_free(h); toku_brtheader_free(h);
dump_header(f, &h); dump_header(f, &h);
} else if (strcmp(fields[0], "node") == 0 && nfields == 2) { } else if (strcmp(fields[0], "node") == 0 && nfields == 2) {
long long strtoll(char *, char **, int);
BLOCKNUM off = make_blocknum(strtoll(fields[1], NULL, 10)); BLOCKNUM off = make_blocknum(strtoll(fields[1], NULL, 10));
dump_node(f, off, h); dump_node(f, off, h);
} else if (strcmp(fields[0], "dumpdata") == 0 && nfields == 2) { } else if (strcmp(fields[0], "dumpdata") == 0 && nfields == 2) {
......
...@@ -458,9 +458,9 @@ static PAIR remove_from_hash_chain (PAIR remove_me, PAIR list) { ...@@ -458,9 +458,9 @@ static PAIR remove_from_hash_chain (PAIR remove_me, PAIR list) {
// if it has been modified within the current checkpoint regime (hence non-strict inequality) // if it has been modified within the current checkpoint regime (hence non-strict inequality)
// and the last time it was written was in a previous checkpoint regime (strict inequality) // and the last time it was written was in a previous checkpoint regime (strict inequality)
static BOOL need_to_rename_p (CACHETABLE t, PAIR p) { static BOOL need_to_rename_p (CACHETABLE t, PAIR p) {
return (p->dirty return (BOOL)(p->dirty
&& p->modified_lsn.lsn>=t->lsn_of_checkpoint.lsn // nonstrict && p->modified_lsn.lsn>=t->lsn_of_checkpoint.lsn // nonstrict
&& p->written_lsn.lsn < t->lsn_of_checkpoint.lsn); // strict && p->written_lsn.lsn < t->lsn_of_checkpoint.lsn); // strict
} }
// Remove a pair from the cachetable // Remove a pair from the cachetable
...@@ -514,7 +514,7 @@ static void cachetable_write_pair(CACHETABLE ct, PAIR p) { ...@@ -514,7 +514,7 @@ static void cachetable_write_pair(CACHETABLE ct, PAIR p) {
cachetable_unlock(ct); cachetable_unlock(ct);
#endif #endif
// write callback // write callback
p->flush_callback(p->cachefile, p->key, p->value, p->extraargs, p->size, p->dirty && p->write_me, TRUE, p->flush_callback(p->cachefile, p->key, p->value, p->extraargs, p->size, (BOOL)(p->dirty && p->write_me), TRUE,
ct->lsn_of_checkpoint, need_to_rename_p(ct, p)); ct->lsn_of_checkpoint, need_to_rename_p(ct, p));
#if DO_CALLBACK_USLEEP #if DO_CALLBACK_USLEEP
usleep(DO_CALLBACK_USLEEP); usleep(DO_CALLBACK_USLEEP);
...@@ -573,7 +573,7 @@ static void cachetable_complete_write_pair (CACHETABLE ct, PAIR p, BOOL do_remov ...@@ -573,7 +573,7 @@ static void cachetable_complete_write_pair (CACHETABLE ct, PAIR p, BOOL do_remov
static void flush_and_remove (CACHETABLE ct, PAIR p, int write_me) { static void flush_and_remove (CACHETABLE ct, PAIR p, int write_me) {
p->writing = 1; p->writing = 1;
ct->size_writing += p->size; assert(ct->size_writing >= 0); ct->size_writing += p->size; assert(ct->size_writing >= 0);
p->write_me = write_me; p->write_me = (char)(write_me?1:0);
#if DO_WRITER_THREAD #if DO_WRITER_THREAD
if (!p->dirty || !p->write_me) { if (!p->dirty || !p->write_me) {
// evictions without a write can be run in the current thread // evictions without a write can be run in the current thread
...@@ -588,7 +588,7 @@ static void flush_and_remove (CACHETABLE ct, PAIR p, int write_me) { ...@@ -588,7 +588,7 @@ static void flush_and_remove (CACHETABLE ct, PAIR p, int write_me) {
} }
static unsigned long toku_maxrss=0; static unsigned long toku_maxrss=0;
unsigned long toku_get_maxrss(void) __attribute__((__visibility__("default")));
unsigned long toku_get_maxrss(void) { unsigned long toku_get_maxrss(void) {
return toku_maxrss; return toku_maxrss;
} }
...@@ -597,7 +597,7 @@ static unsigned long check_maxrss (void) __attribute__((__unused__)); ...@@ -597,7 +597,7 @@ static unsigned long check_maxrss (void) __attribute__((__unused__));
static unsigned long check_maxrss (void) { static unsigned long check_maxrss (void) {
pid_t pid = getpid(); pid_t pid = getpid();
char fname[100]; char fname[100];
snprintf(fname, sizeof(fname), "/proc/%u/statm", pid); snprintf(fname, sizeof(fname), "/proc/%d/statm", pid);
FILE *f = fopen(fname, "r"); FILE *f = fopen(fname, "r");
unsigned long ignore, rss; unsigned long ignore, rss;
fscanf(f, "%lu %lu", &ignore, &rss); fscanf(f, "%lu %lu", &ignore, &rss);
...@@ -645,7 +645,7 @@ static int cachetable_insert_at(CACHEFILE cachefile, u_int32_t fullhash, CACHEKE ...@@ -645,7 +645,7 @@ static int cachetable_insert_at(CACHEFILE cachefile, u_int32_t fullhash, CACHEKE
memset(p, 0, sizeof *p); memset(p, 0, sizeof *p);
ctpair_rwlock_init(&p->rwlock); ctpair_rwlock_init(&p->rwlock);
p->fullhash = fullhash; p->fullhash = fullhash;
p->dirty = dirty; //printf("%s:%d p=%p dirty=%d\n", __FILE__, __LINE__, p, p->dirty); p->dirty = (char)(dirty ? 1 : 0); //printf("%s:%d p=%p dirty=%d\n", __FILE__, __LINE__, p, p->dirty);
p->size = size; p->size = size;
p->writing = 0; p->writing = 0;
p->key = key; p->key = key;
...@@ -678,10 +678,12 @@ static unsigned long long hash_histogram[hash_histogram_max]; ...@@ -678,10 +678,12 @@ static unsigned long long hash_histogram[hash_histogram_max];
void print_hash_histogram (void) { void print_hash_histogram (void) {
int i; int i;
for (i=0; i<hash_histogram_max; i++) for (i=0; i<hash_histogram_max; i++)
if (hash_histogram[i]) printf("%d:%lld ", i, hash_histogram[i]); if (hash_histogram[i]) printf("%d:%llu ", i, hash_histogram[i]);
printf("\n"); printf("\n");
} }
void note_hash_count (int count) {
static void
note_hash_count (int count) {
if (count>=hash_histogram_max) count=hash_histogram_max-1; if (count>=hash_histogram_max) count=hash_histogram_max-1;
hash_histogram[count]++; hash_histogram[count]++;
} }
...@@ -806,7 +808,7 @@ int toku_cachetable_unpin(CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash, ...@@ -806,7 +808,7 @@ int toku_cachetable_unpin(CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash,
if (p->key.b==key.b && p->cachefile==cachefile) { if (p->key.b==key.b && p->cachefile==cachefile) {
assert(p->rwlock.pinned>0); assert(p->rwlock.pinned>0);
ctpair_read_unlock(&p->rwlock); ctpair_read_unlock(&p->rwlock);
p->dirty |= dirty; if (dirty) p->dirty = TRUE;
if (size != 0) { if (size != 0) {
t->size_current -= p->size; if (p->writing) t->size_writing -= p->size; t->size_current -= p->size; if (p->writing) t->size_writing -= p->size;
p->size = size; p->size = size;
...@@ -1187,7 +1189,7 @@ void toku_cachetable_print_state (CACHETABLE ct) { ...@@ -1187,7 +1189,7 @@ void toku_cachetable_print_state (CACHETABLE ct) {
for (i=0; i<ct->table_size; i++) { for (i=0; i<ct->table_size; i++) {
PAIR p = ct->table[i]; PAIR p = ct->table[i];
if (p != 0) { if (p != 0) {
printf("t[%d]=", i); printf("t[%u]=", i);
for (p=ct->table[i]; p; p=p->hash_chain) { for (p=ct->table[i]; p; p=p->hash_chain) {
printf(" {%"PRId64", %p, dirty=%d, pin=%d, size=%ld}", p->key.b, p->cachefile, p->dirty, p->rwlock.pinned, p->size); printf(" {%"PRId64", %p, dirty=%d, pin=%d, size=%ld}", p->key.b, p->cachefile, p->dirty, p->rwlock.pinned, p->size);
} }
......
...@@ -181,4 +181,7 @@ void toku_cachetable_verify (CACHETABLE t); ...@@ -181,4 +181,7 @@ void toku_cachetable_verify (CACHETABLE t);
// Not for use in production, but useful for testing. // Not for use in production, but useful for testing.
void print_hash_histogram (void) __attribute__((__visibility__("default"))); void print_hash_histogram (void) __attribute__((__visibility__("default")));
// Useful for debugging.
static unsigned long toku_get_maxrss(void) __attribute__((__visibility__("default")));
#endif #endif
...@@ -90,7 +90,7 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d ...@@ -90,7 +90,7 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
} }
} }
struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_start + fifo->memory_used); struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_start + fifo->memory_used);
entry->type = type; entry->type = (unsigned char)type;
entry->xid = xid; entry->xid = xid;
entry->keylen = keylen; entry->keylen = keylen;
memcpy(entry->key, key, keylen); memcpy(entry->key, key, keylen);
...@@ -125,7 +125,7 @@ int toku_fifo_peek_cmdstruct (FIFO fifo, BRT_CMD cmd, DBT*key, DBT*data) { ...@@ -125,7 +125,7 @@ int toku_fifo_peek_cmdstruct (FIFO fifo, BRT_CMD cmd, DBT*key, DBT*data) {
unsigned int keylen,datalen; unsigned int keylen,datalen;
int r = toku_fifo_peek(fifo, &keyb, &keylen, &datab, &datalen, &type, &cmd->xid); int r = toku_fifo_peek(fifo, &keyb, &keylen, &datab, &datalen, &type, &cmd->xid);
if (r!=0) return r; if (r!=0) return r;
cmd->type=type; cmd->type=(enum brt_cmd_type)type;
toku_fill_dbt(key, keyb, keylen); toku_fill_dbt(key, keyb, keylen);
toku_fill_dbt(data, datab, datalen); toku_fill_dbt(data, datab, datalen);
cmd->u.id.key=key; cmd->u.id.key=key;
......
...@@ -29,7 +29,7 @@ u_int32_t toku_calccrc32_kvpair_struct (const struct kv_pair *kvp) { ...@@ -29,7 +29,7 @@ u_int32_t toku_calccrc32_kvpair_struct (const struct kv_pair *kvp) {
#endif #endif
u_int32_t toku_calc_fingerprint_cmd (u_int32_t type, TXNID xid, const void *key, u_int32_t keylen, const void *val, u_int32_t vallen) { u_int32_t toku_calc_fingerprint_cmd (u_int32_t type, TXNID xid, const void *key, u_int32_t keylen, const void *val, u_int32_t vallen) {
unsigned char type_c = type; unsigned char type_c = (unsigned char)type;
unsigned int a = htonl(xid>>32); unsigned int a = htonl(xid>>32);
unsigned int b = htonl(xid&0xffffffff); unsigned int b = htonl(xid&0xffffffff);
struct x1764 mm; struct x1764 mm;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "brt-internal.h" #include "brt-internal.h"
#include "toku_assert.h" #include "toku_assert.h"
#include "key.h"
#include <string.h> #include <string.h>
#if 0 #if 0
...@@ -90,7 +91,8 @@ int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2le ...@@ -90,7 +91,8 @@ int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2le
#endif #endif
void toku_test_keycompare (void) { void
toku_test_keycompare (void) {
assert(toku_keycompare("a",1, "a",1)==0); assert(toku_keycompare("a",1, "a",1)==0);
assert(toku_keycompare("aa",2, "a",1)>0); assert(toku_keycompare("aa",2, "a",1)>0);
assert(toku_keycompare("a",1, "aa",2)<0); assert(toku_keycompare("a",1, "aa",2)<0);
...@@ -102,11 +104,13 @@ void toku_test_keycompare (void) { ...@@ -102,11 +104,13 @@ void toku_test_keycompare (void) {
assert(toku_keycompare("aaaaa",3, "aaaba",3)==0); assert(toku_keycompare("aaaaa",3, "aaaba",3)==0);
} }
int toku_default_compare_fun (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) { int
toku_default_compare_fun (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
return toku_keycompare(a->data, a->size, b->data, b->size); return toku_keycompare(a->data, a->size, b->data, b->size);
} }
int toku_dont_call_this_compare_fun (DB *db __attribute__((__unused__)), const DBT *a __attribute__((__unused__)), const DBT*b __attribute__((__unused__))) { int
toku_dont_call_this_compare_fun (DB *db __attribute__((__unused__)), const DBT *a __attribute__((__unused__)), const DBT*b __attribute__((__unused__))) {
assert(0); assert(0);
return 0; return 0;
} }
...@@ -133,9 +133,12 @@ static u_int32_t disksize_le_provpair (TXNID txnid __attribute__((__unused__)), ...@@ -133,9 +133,12 @@ static u_int32_t disksize_le_provpair (TXNID txnid __attribute__((__unused__)),
return 1 + 8 + 4 + 4 + klen + plen; return 1 + 8 + 4 + 4 + klen + plen;
} }
u_int32_t leafentry_disksize_internal (LEAFENTRY le) {
static u_int32_t
leafentry_disksize_internal (LEAFENTRY le) {
LESWITCHCALL(le, disksize); LESWITCHCALL(le, disksize);
} }
u_int32_t leafentry_disksize (LEAFENTRY le) { u_int32_t leafentry_disksize (LEAFENTRY le) {
u_int32_t m = leafentry_memsize(le); u_int32_t m = leafentry_memsize(le);
u_int32_t d = leafentry_disksize_internal(le); u_int32_t d = leafentry_disksize_internal(le);
...@@ -206,7 +209,7 @@ static int print_le_committed (u_int32_t keylen, void *key, u_int32_t vallen, vo ...@@ -206,7 +209,7 @@ static int print_le_committed (u_int32_t keylen, void *key, u_int32_t vallen, vo
static int print_le_both (TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval, FILE *outf) { static int print_le_both (TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval, FILE *outf) {
fprintf(outf, "{B: "); fprintf(outf, "{B: ");
fprintf(outf, " xid=%" PRId64, xid); fprintf(outf, " xid=%" PRIu64, xid);
fprintf(outf, " key="); fprintf(outf, " key=");
toku_print_BYTESTRING(outf, klen, kval); toku_print_BYTESTRING(outf, klen, kval);
toku_print_BYTESTRING(outf, clen, cval); toku_print_BYTESTRING(outf, clen, cval);
...@@ -218,7 +221,7 @@ static int print_le_both (TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, ...@@ -218,7 +221,7 @@ static int print_le_both (TXNID xid, u_int32_t klen, void *kval, u_int32_t clen,
static int print_le_provdel (TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, FILE *outf) { static int print_le_provdel (TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, FILE *outf) {
fprintf(outf, "{D: "); fprintf(outf, "{D: ");
fprintf(outf, " xid=%" PRId64, xid); fprintf(outf, " xid=%" PRIu64, xid);
fprintf(outf, " key="); fprintf(outf, " key=");
toku_print_BYTESTRING(outf, klen, kval); toku_print_BYTESTRING(outf, klen, kval);
fprintf(outf, " committed="); fprintf(outf, " committed=");
...@@ -229,7 +232,7 @@ static int print_le_provdel (TXNID xid, u_int32_t klen, void *kval, u_int32_t cl ...@@ -229,7 +232,7 @@ static int print_le_provdel (TXNID xid, u_int32_t klen, void *kval, u_int32_t cl
static int print_le_provpair (TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval, FILE *outf) { static int print_le_provpair (TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval, FILE *outf) {
fprintf(outf, "{P: "); fprintf(outf, "{P: ");
fprintf(outf, " xid=%" PRId64, xid); fprintf(outf, " xid=%" PRIu64, xid);
fprintf(outf, " key="); fprintf(outf, " key=");
toku_print_BYTESTRING(outf, klen, kval); toku_print_BYTESTRING(outf, klen, kval);
fprintf(outf, " provisional="); fprintf(outf, " provisional=");
......
/* -*- mode: C; c-basic-offset: 4 -*- */ /* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#define _XOPEN_SOURCE 500
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
...@@ -39,7 +38,8 @@ char *toku_strdup_in_rollback(TOKUTXN txn, const char *s) { ...@@ -39,7 +38,8 @@ char *toku_strdup_in_rollback(TOKUTXN txn, const char *s) {
return toku_memdup_in_rollback(txn, s, strlen(s)+1); return toku_memdup_in_rollback(txn, s, strlen(s)+1);
} }
int toku_logger_fsync_null(int fd __attribute__((__unused__))) { static int
toku_logger_fsync_null(int fd __attribute__((__unused__))) {
return 0; return 0;
} }
...@@ -51,7 +51,7 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu ...@@ -51,7 +51,7 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu
while ((de=readdir(d))) { while ((de=readdir(d))) {
if (de==0) return errno; if (de==0) return errno;
long long thisl; long long thisl;
int r = sscanf(de->d_name, "log%llu.tokulog", &thisl); int r = sscanf(de->d_name, "log%lld.tokulog", &thisl);
if (r==1 && thisl>max) max=thisl; if (r==1 && thisl>max) max=thisl;
} }
*result=max+1; *result=max+1;
...@@ -59,7 +59,8 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu ...@@ -59,7 +59,8 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu
return r; return r;
} }
int logfilenamecompare (const void *ap, const void *bp) { static int
logfilenamecompare (const void *ap, const void *bp) {
char *a=*(char**)ap; char *a=*(char**)ap;
char *b=*(char**)bp; char *b=*(char**)bp;
return strcmp(a,b); return strcmp(a,b);
...@@ -79,7 +80,7 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp) { ...@@ -79,7 +80,7 @@ int toku_logger_find_logfiles (const char *directory, char ***resultp) {
while ((de=readdir(d))) { while ((de=readdir(d))) {
if (de==0) return errno; if (de==0) return errno;
long long thisl; long long thisl;
int r = sscanf(de->d_name, "log%llu.tokulog", &thisl); int r = sscanf(de->d_name, "log%lld.tokulog", &thisl);
if (r!=1) continue; // Skip over non-log files. if (r!=1) continue; // Skip over non-log files.
if (n_results+1>=result_limit) { if (n_results+1>=result_limit) {
result_limit*=2; result_limit*=2;
...@@ -155,7 +156,7 @@ static int open_logfile (TOKULOGGER logger) { ...@@ -155,7 +156,7 @@ static int open_logfile (TOKULOGGER logger) {
int r; int r;
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%012lld.tokulog", logger->directory, logger->next_log_file_number);
if (logger->write_log_files) { if (logger->write_log_files) {
logger->fd = creat(fname, O_EXCL | 0700); if (logger->fd==-1) return errno; logger->fd = creat(fname, O_EXCL | 0700); if (logger->fd==-1) return errno;
} else { } else {
...@@ -548,10 +549,11 @@ int toku_logger_log_fopen (TOKUTXN txn, const char * fname, FILENUM filenum) { ...@@ -548,10 +549,11 @@ int toku_logger_log_fopen (TOKUTXN txn, const char * fname, FILENUM filenum) {
return toku_log_fopen (txn->logger, (LSN*)0, 0, toku_txn_get_txnid(txn), bs, filenum); return toku_log_fopen (txn->logger, (LSN*)0, 0, toku_txn_get_txnid(txn), bs, filenum);
} }
int toku_fread_u_int8_t_nocrclen (FILE *f, u_int8_t *v) { static int
toku_fread_u_int8_t_nocrclen (FILE *f, u_int8_t *v) {
int vi=fgetc(f); int vi=fgetc(f);
if (vi==EOF) return -1; if (vi==EOF) return -1;
u_int8_t vc=vi; u_int8_t vc=(u_int8_t)vi;
*v = vc; *v = vc;
return 0; return 0;
} }
...@@ -559,7 +561,7 @@ int toku_fread_u_int8_t_nocrclen (FILE *f, u_int8_t *v) { ...@@ -559,7 +561,7 @@ int toku_fread_u_int8_t_nocrclen (FILE *f, u_int8_t *v) {
int toku_fread_u_int8_t (FILE *f, u_int8_t *v, struct x1764 *mm, u_int32_t *len) { int toku_fread_u_int8_t (FILE *f, u_int8_t *v, struct x1764 *mm, u_int32_t *len) {
int vi=fgetc(f); int vi=fgetc(f);
if (vi==EOF) return -1; if (vi==EOF) return -1;
u_int8_t vc=vi; u_int8_t vc=(u_int8_t)vi;
x1764_add(mm, &vc, 1); x1764_add(mm, &vc, 1);
(*len)++; (*len)++;
*v = vc; *v = vc;
...@@ -592,7 +594,9 @@ int toku_fread_u_int32_t (FILE *f, u_int32_t *v, struct x1764 *checksum, u_int32 ...@@ -592,7 +594,9 @@ int toku_fread_u_int32_t (FILE *f, u_int32_t *v, struct x1764 *checksum, u_int32
(c3<<0)); (c3<<0));
return 0; return 0;
} }
int toku_fread_int32_t (FILE *f, int32_t *v, struct x1764 *checksum, u_int32_t *len) {
static int
toku_fread_int32_t (FILE *f, int32_t *v, struct x1764 *checksum, u_int32_t *len) {
u_int32_t uv; u_int32_t uv;
int r = toku_fread_u_int32_t(f, &uv, checksum, len); int r = toku_fread_u_int32_t(f, &uv, checksum, len);
int32_t rv = uv; int32_t rv = uv;
...@@ -600,7 +604,8 @@ int toku_fread_int32_t (FILE *f, int32_t *v, struct x1764 *checksum, u_int32_t * ...@@ -600,7 +604,8 @@ int toku_fread_int32_t (FILE *f, int32_t *v, struct x1764 *checksum, u_int32_t *
return r; return r;
} }
int toku_fread_u_int64_t (FILE *f, u_int64_t *v, struct x1764 *checksum, u_int32_t *len) { static int
toku_fread_u_int64_t (FILE *f, u_int64_t *v, struct x1764 *checksum, u_int32_t *len) {
u_int32_t v1,v2; u_int32_t v1,v2;
int r; int r;
r=toku_fread_u_int32_t(f, &v1, checksum, len); if (r!=0) return r; r=toku_fread_u_int32_t(f, &v1, checksum, len); if (r!=0) return r;
...@@ -673,14 +678,14 @@ int toku_logprint_LSN (FILE *outf, FILE *inf, const char *fieldname, struct x176 ...@@ -673,14 +678,14 @@ int toku_logprint_LSN (FILE *outf, FILE *inf, const char *fieldname, struct x176
LSN v; LSN v;
int r = toku_fread_LSN(inf, &v, checksum, len); int r = toku_fread_LSN(inf, &v, checksum, len);
if (r!=0) return r; if (r!=0) return r;
fprintf(outf, " %s=%" PRId64, fieldname, v.lsn); fprintf(outf, " %s=%" PRIu64, fieldname, v.lsn);
return 0; return 0;
} }
int toku_logprint_TXNID (FILE *outf, FILE *inf, const char *fieldname, struct x1764 *checksum, u_int32_t *len, const char *format __attribute__((__unused__))) { int toku_logprint_TXNID (FILE *outf, FILE *inf, const char *fieldname, struct x1764 *checksum, u_int32_t *len, const char *format __attribute__((__unused__))) {
TXNID v; TXNID v;
int r = toku_fread_TXNID(inf, &v, checksum, len); int r = toku_fread_TXNID(inf, &v, checksum, len);
if (r!=0) return r; if (r!=0) return r;
fprintf(outf, " %s=%" PRId64, fieldname, v); fprintf(outf, " %s=%" PRIu64, fieldname, v);
return 0; return 0;
} }
...@@ -708,7 +713,7 @@ int toku_logprint_u_int32_t (FILE *outf, FILE *inf, const char *fieldname, struc ...@@ -708,7 +713,7 @@ int toku_logprint_u_int32_t (FILE *outf, FILE *inf, const char *fieldname, struc
} }
void toku_print_BYTESTRING (FILE *outf, u_int32_t len, char *data) { void toku_print_BYTESTRING (FILE *outf, u_int32_t len, char *data) {
fprintf(outf, "{len=%d data=\"", len); fprintf(outf, "{len=%u data=\"", len);
u_int32_t i; u_int32_t i;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
switch (data[i]) { switch (data[i]) {
...@@ -756,7 +761,7 @@ int toku_logprint_LOGGEDBRTHEADER (FILE *outf, FILE *inf, const char *fieldname, ...@@ -756,7 +761,7 @@ int toku_logprint_LOGGEDBRTHEADER (FILE *outf, FILE *inf, const char *fieldname,
LOGGEDBRTHEADER v; LOGGEDBRTHEADER v;
int r = toku_fread_LOGGEDBRTHEADER(inf, &v, checksum, len); int r = toku_fread_LOGGEDBRTHEADER(inf, &v, checksum, len);
if (r!=0) return r; if (r!=0) return r;
fprintf(outf, " %s={size=%d flags=%d nodesize=%d free_blocks=%" PRId64 " unused_memory=%" PRId64 " n_named_roots=%d", fieldname, v.size, v.flags, v.nodesize, v.free_blocks.b, v.unused_blocks.b, v.n_named_roots); fprintf(outf, " %s={size=%u flags=%u nodesize=%u free_blocks=%" PRId64 " unused_memory=%" PRId64 " n_named_roots=%d", fieldname, v.size, v.flags, v.nodesize, v.free_blocks.b, v.unused_blocks.b, v.n_named_roots);
return 0; return 0;
} }
...@@ -766,10 +771,10 @@ int toku_logprint_INTPAIRARRAY (FILE *outf, FILE *inf, const char *fieldname, st ...@@ -766,10 +771,10 @@ int toku_logprint_INTPAIRARRAY (FILE *outf, FILE *inf, const char *fieldname, st
u_int32_t i; u_int32_t i;
int r = toku_fread_INTPAIRARRAY(inf, &v, checksum, len); int r = toku_fread_INTPAIRARRAY(inf, &v, checksum, len);
if (r!=0) return r; if (r!=0) return r;
fprintf(outf, " %s={size=%d array={", fieldname, v.size); fprintf(outf, " %s={size=%u array={", fieldname, v.size);
for (i=0; i<v.size; i++) { for (i=0; i<v.size; i++) {
if (i!=0) fprintf(outf, " "); if (i!=0) fprintf(outf, " ");
fprintf(outf, "{%d %d}", v.array[i].a, v.array[i].b); fprintf(outf, "{%u %u}", v.array[i].a, v.array[i].b);
} }
toku_free(v.array); toku_free(v.array);
return 0; return 0;
...@@ -817,7 +822,8 @@ TOKULOGGER toku_txn_logger (TOKUTXN txn) { ...@@ -817,7 +822,8 @@ TOKULOGGER toku_txn_logger (TOKUTXN txn) {
return txn ? txn->logger : 0; return txn ? txn->logger : 0;
} }
int toku_abort_logentry_commit (struct logtype_commit *le __attribute__((__unused__)), TOKUTXN txn) { static int
toku_abort_logentry_commit (struct logtype_commit *le __attribute__((__unused__)), TOKUTXN txn) {
toku_logger_panic(txn->logger, EINVAL); toku_logger_panic(txn->logger, EINVAL);
return EINVAL; return EINVAL;
} }
...@@ -994,7 +1000,7 @@ int toku_maybe_spill_rollbacks (TOKUTXN txn) { ...@@ -994,7 +1000,7 @@ int toku_maybe_spill_rollbacks (TOKUTXN txn) {
assert(txn->rollentry_filename==0); assert(txn->rollentry_filename==0);
txn->rollentry_filename = toku_malloc(fnamelen); txn->rollentry_filename = toku_malloc(fnamelen);
if (txn->rollentry_filename==0) return errno; if (txn->rollentry_filename==0) return errno;
snprintf(txn->rollentry_filename, fnamelen, "%s/__rolltmp.XXXXXX", txn->logger->directory); snprintf(txn->rollentry_filename, fnamelen, "%s%s", txn->logger->directory, filenamepart);
txn->rollentry_fd = mkstemp(txn->rollentry_filename); txn->rollentry_fd = mkstemp(txn->rollentry_filename);
if (txn->rollentry_fd==-1) return errno; if (txn->rollentry_fd==-1) return errno;
} }
......
...@@ -238,14 +238,15 @@ static void __attribute__((format (printf, 3, 4))) fprintf2 (FILE *f1, FILE *f2, ...@@ -238,14 +238,15 @@ static void __attribute__((format (printf, 3, 4))) fprintf2 (FILE *f1, FILE *f2,
FILE *hf=0, *cf=0; FILE *hf=0, *cf=0;
void generate_enum_internal (char *enum_name, char *enum_prefix, const struct logtype *lts) { static void
generate_enum_internal (char *enum_name, char *enum_prefix, const struct logtype *lts) {
char used_cmds[256]; char used_cmds[256];
int count=0; int count=0;
memset(used_cmds, 0, 256); memset(used_cmds, 0, 256);
fprintf(hf, "enum %s {", enum_name); fprintf(hf, "enum %s {", enum_name);
DO_STRUCTS(lt, lts, DO_STRUCTS(lt, lts,
({ ({
unsigned char cmd = lt->command_and_flags&0xff; unsigned char cmd = (unsigned char)(lt->command_and_flags&0xff);
if (count!=0) fprintf(hf, ","); if (count!=0) fprintf(hf, ",");
count++; count++;
fprintf(hf, "\n"); fprintf(hf, "\n");
...@@ -257,12 +258,14 @@ void generate_enum_internal (char *enum_name, char *enum_prefix, const struct lo ...@@ -257,12 +258,14 @@ void generate_enum_internal (char *enum_name, char *enum_prefix, const struct lo
} }
void generate_enum (void) { static void
generate_enum (void) {
generate_enum_internal("lt_cmd", "LT", logtypes); generate_enum_internal("lt_cmd", "LT", logtypes);
generate_enum_internal("rt_cmd", "RT", rollbacks); generate_enum_internal("rt_cmd", "RT", rollbacks);
} }
void generate_log_struct (void) { static void
generate_log_struct (void) {
DO_LOGTYPES(lt, DO_LOGTYPES(lt,
({ fprintf(hf, "struct logtype_%s {\n", lt->name); ({ fprintf(hf, "struct logtype_%s {\n", lt->name);
fprintf(hf, " %-16s lsn;\n", "LSN"); fprintf(hf, " %-16s lsn;\n", "LSN");
...@@ -305,7 +308,8 @@ void generate_log_struct (void) { ...@@ -305,7 +308,8 @@ void generate_log_struct (void) {
} }
void generate_dispatch (void) { static void
generate_dispatch (void) {
fprintf(hf, "#define rolltype_dispatch(s, funprefix) ({ switch((s)->cmd) {\\\n"); fprintf(hf, "#define rolltype_dispatch(s, funprefix) ({ switch((s)->cmd) {\\\n");
DO_ROLLBACKS(lt, fprintf(hf, " case RT_%s: funprefix ## %s (&(s)->u.%s); break;\\\n", lt->name, lt->name, lt->name)); DO_ROLLBACKS(lt, fprintf(hf, " case RT_%s: funprefix ## %s (&(s)->u.%s); break;\\\n", lt->name, lt->name, lt->name));
fprintf(hf, " }})\n"); fprintf(hf, " }})\n");
...@@ -338,7 +342,8 @@ void generate_dispatch (void) { ...@@ -338,7 +342,8 @@ void generate_dispatch (void) {
fprintf(hf, " }})\n"); fprintf(hf, " }})\n");
} }
void generate_log_writer (void) { static void
generate_log_writer (void) {
DO_LOGTYPES(lt, ({ DO_LOGTYPES(lt, ({
fprintf2(cf, hf, "int toku_log_%s (TOKULOGGER logger, LSN *lsnp, int do_fsync", lt->name); fprintf2(cf, hf, "int toku_log_%s (TOKULOGGER logger, LSN *lsnp, int do_fsync", lt->name);
DO_FIELDS(ft, lt, fprintf2(cf, hf, ", %s %s", ft->type, ft->name)); DO_FIELDS(ft, lt, fprintf2(cf, hf, ", %s %s", ft->type, ft->name));
...@@ -357,7 +362,7 @@ void generate_log_writer (void) { ...@@ -357,7 +362,7 @@ void generate_log_writer (void) {
fprintf(cf, " if (lbytes==0) return errno;\n"); fprintf(cf, " if (lbytes==0) return errno;\n");
fprintf(cf, " wbuf_init(&wbuf, &lbytes->bytes[0], buflen);\n"); fprintf(cf, " wbuf_init(&wbuf, &lbytes->bytes[0], buflen);\n");
fprintf(cf, " wbuf_int(&wbuf, buflen);\n"); fprintf(cf, " wbuf_int(&wbuf, buflen);\n");
fprintf(cf, " wbuf_char(&wbuf, '%c');\n", 0xff&lt->command_and_flags); fprintf(cf, " wbuf_char(&wbuf, '%c');\n", (char)(0xff&lt->command_and_flags));
fprintf(cf, " ml_lock(&logger->input_lock);\n"); fprintf(cf, " ml_lock(&logger->input_lock);\n");
fprintf(cf, " logger->lsn.lsn++;\n"); fprintf(cf, " logger->lsn.lsn++;\n");
fprintf(cf, " LSN lsn = logger->lsn;\n"); fprintf(cf, " LSN lsn = logger->lsn;\n");
...@@ -373,7 +378,8 @@ void generate_log_writer (void) { ...@@ -373,7 +378,8 @@ void generate_log_writer (void) {
})); }));
} }
void generate_log_reader (void) { static void
generate_log_reader (void) {
DO_LOGTYPES(lt, ({ DO_LOGTYPES(lt, ({
fprintf(cf, "static int toku_log_fread_%s (FILE *infile, struct logtype_%s *data, struct x1764 *checksum)", lt->name, lt->name); fprintf(cf, "static int toku_log_fread_%s (FILE *infile, struct logtype_%s *data, struct x1764 *checksum)", lt->name, lt->name);
fprintf(cf, " {\n"); fprintf(cf, " {\n");
...@@ -399,9 +405,9 @@ void generate_log_reader (void) { ...@@ -399,9 +405,9 @@ void generate_log_reader (void) {
fprintf(cf, " r = toku_fread_u_int32_t(infile, &len1, &checksum, &ignorelen); if (r!=0) return r;\n"); fprintf(cf, " r = toku_fread_u_int32_t(infile, &len1, &checksum, &ignorelen); if (r!=0) return r;\n");
fprintf(cf, " int cmd=fgetc(infile);\n"); fprintf(cf, " int cmd=fgetc(infile);\n");
fprintf(cf, " if (cmd==EOF) return EOF;\n"); fprintf(cf, " if (cmd==EOF) return EOF;\n");
fprintf(cf, " char cmdchar = cmd;\n"); fprintf(cf, " char cmdchar = (char)cmd;\n");
fprintf(cf, " x1764_add(&checksum, &cmdchar, 1);\n"); fprintf(cf, " x1764_add(&checksum, &cmdchar, 1);\n");
fprintf(cf, " le->cmd=cmd;\n"); fprintf(cf, " le->cmd=(enum lt_cmd)cmd;\n");
fprintf(cf, " switch ((enum lt_cmd)cmd) {\n"); fprintf(cf, " switch ((enum lt_cmd)cmd) {\n");
DO_LOGTYPES(lt, ({ DO_LOGTYPES(lt, ({
fprintf(cf, " case LT_%s:\n", lt->name); fprintf(cf, " case LT_%s:\n", lt->name);
...@@ -412,7 +418,8 @@ void generate_log_reader (void) { ...@@ -412,7 +418,8 @@ void generate_log_reader (void) {
fprintf(cf, "}\n\n"); fprintf(cf, "}\n\n");
} }
void generate_logprint (void) { static void
generate_logprint (void) {
unsigned maxnamelen=0; unsigned maxnamelen=0;
fprintf2(cf, hf, "int toku_logprint_one_record(FILE *outf, FILE *f)"); fprintf2(cf, hf, "int toku_logprint_one_record(FILE *outf, FILE *f)");
fprintf(hf, ";\n"); fprintf(hf, ";\n");
...@@ -427,15 +434,15 @@ void generate_logprint (void) { ...@@ -427,15 +434,15 @@ void generate_logprint (void) {
fprintf(cf, " cmd=fgetc(f);\n"); fprintf(cf, " cmd=fgetc(f);\n");
fprintf(cf, " if (cmd==EOF) return DB_BADFORMAT;\n"); fprintf(cf, " if (cmd==EOF) return DB_BADFORMAT;\n");
fprintf(cf, " u_int32_t len_in_file, len=1+4; // cmd + len1\n"); fprintf(cf, " u_int32_t len_in_file, len=1+4; // cmd + len1\n");
fprintf(cf, " char charcmd = cmd;\n"); fprintf(cf, " char charcmd = (char)cmd;\n");
fprintf(cf, " x1764_add(&checksum, &charcmd, 1);\n"); fprintf(cf, " x1764_add(&checksum, &charcmd, 1);\n");
fprintf(cf, " switch ((enum lt_cmd)cmd) {\n"); fprintf(cf, " switch ((enum lt_cmd)cmd) {\n");
DO_LOGTYPES(lt, ({ if (strlen(lt->name)>maxnamelen) maxnamelen=strlen(lt->name); })); DO_LOGTYPES(lt, ({ if (strlen(lt->name)>maxnamelen) maxnamelen=strlen(lt->name); }));
DO_LOGTYPES(lt, ({ DO_LOGTYPES(lt, ({
unsigned char cmd = 0xff&lt->command_and_flags; unsigned char cmd = (unsigned char)(0xff&lt->command_and_flags);
fprintf(cf, " case LT_%s: \n", lt->name); fprintf(cf, " case LT_%s: \n", lt->name);
// We aren't using the log reader here because we want better diagnostics as soon as things go wrong. // We aren't using the log reader here because we want better diagnostics as soon as things go wrong.
fprintf(cf, " fprintf(outf, \"%%-%ds \", \"%s\");\n", maxnamelen, lt->name); fprintf(cf, " fprintf(outf, \"%%-%us \", \"%s\");\n", maxnamelen, lt->name);
if (isprint(cmd)) fprintf(cf," fprintf(outf, \" '%c':\");\n", cmd); if (isprint(cmd)) fprintf(cf," fprintf(outf, \" '%c':\");\n", cmd);
else fprintf(cf," fprintf(outf, \"0%03o:\");\n", cmd); else fprintf(cf," fprintf(outf, \"0%03o:\");\n", cmd);
fprintf(cf, " r = toku_logprint_%-16s(outf, f, \"lsn\", &checksum, &len, 0); if (r!=0) return r;\n", "LSN"); fprintf(cf, " r = toku_logprint_%-16s(outf, f, \"lsn\", &checksum, &len, 0); if (r!=0) return r;\n", "LSN");
...@@ -451,8 +458,8 @@ void generate_logprint (void) { ...@@ -451,8 +458,8 @@ void generate_logprint (void) {
fprintf(cf, " fprintf(outf, \" crc=%%08x\", crc_in_file);\n"); fprintf(cf, " fprintf(outf, \" crc=%%08x\", crc_in_file);\n");
fprintf(cf, " if (crc_in_file!=actual_murmur) fprintf(outf, \" actual_fingerprint=%%08x\", actual_murmur);\n"); fprintf(cf, " if (crc_in_file!=actual_murmur) fprintf(outf, \" actual_fingerprint=%%08x\", actual_murmur);\n");
fprintf(cf, " r = toku_fread_u_int32_t_nocrclen (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, " fprintf(outf, \" len=%%u\", 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) fprintf(outf, \" actual_len=%%u\", len);\n");
fprintf(cf, " if (len_in_file!=len || crc_in_file!=actual_murmur) return DB_BADFORMAT;\n"); fprintf(cf, " if (len_in_file!=len || crc_in_file!=actual_murmur) return DB_BADFORMAT;\n");
fprintf(cf, " };\n"); fprintf(cf, " };\n");
fprintf(cf, " fprintf(outf, \"\\n\");\n"); fprintf(cf, " fprintf(outf, \"\\n\");\n");
...@@ -464,7 +471,8 @@ void generate_logprint (void) { ...@@ -464,7 +471,8 @@ void generate_logprint (void) {
fprintf(cf, "}\n\n"); fprintf(cf, "}\n\n");
} }
void generate_rollbacks (void) { static void
generate_rollbacks (void) {
DO_ROLLBACKS(lt, ({ DO_ROLLBACKS(lt, ({
fprintf2(cf, hf, "int toku_logger_save_rollback_%s (TOKUTXN txn", lt->name); fprintf2(cf, hf, "int toku_logger_save_rollback_%s (TOKUTXN txn", lt->name);
DO_FIELDS(ft, lt, fprintf2(cf, hf, ", %s %s", ft->type, ft->name)); DO_FIELDS(ft, lt, fprintf2(cf, hf, ", %s %s", ft->type, ft->name));
...@@ -478,7 +486,7 @@ void generate_rollbacks (void) { ...@@ -478,7 +486,7 @@ void generate_rollbacks (void) {
} }
fprintf(cf, " struct roll_entry *v = toku_malloc_in_rollback(txn, sizeof(*v));\n"); fprintf(cf, " struct roll_entry *v = toku_malloc_in_rollback(txn, sizeof(*v));\n");
fprintf(cf, " if (v==0) return errno;\n"); fprintf(cf, " if (v==0) return errno;\n");
fprintf(cf, " v->cmd = %d;\n", lt->command_and_flags&0xff); fprintf(cf, " v->cmd = (enum rt_cmd)%u;\n", lt->command_and_flags&0xff);
DO_FIELDS(ft, lt, fprintf(cf, " v->u.%s.%s = %s;\n", lt->name, ft->name, ft->name)); DO_FIELDS(ft, lt, fprintf(cf, " v->u.%s.%s = %s;\n", lt->name, ft->name, ft->name));
fprintf(cf, " v->prev = txn->newest_logentry;\n"); fprintf(cf, " v->prev = txn->newest_logentry;\n");
fprintf(cf, " v->next = 0;\n"); fprintf(cf, " v->next = 0;\n");
...@@ -496,7 +504,7 @@ void generate_rollbacks (void) { ...@@ -496,7 +504,7 @@ void generate_rollbacks (void) {
fprintf(hf, ";\n"); fprintf(hf, ";\n");
fprintf(cf, " {\n"); fprintf(cf, " {\n");
fprintf(cf, " u_int32_t ndone_at_start = wbuf->ndone;\n"); fprintf(cf, " u_int32_t ndone_at_start = wbuf->ndone;\n");
fprintf(cf, " wbuf_char(wbuf, '%c');\n", 0xff&lt->command_and_flags); fprintf(cf, " wbuf_char(wbuf, '%c');\n", (char)(0xff&lt->command_and_flags));
DO_FIELDS(ft, lt, fprintf(cf, " wbuf_%s(wbuf, %s);\n", ft->type, ft->name)); DO_FIELDS(ft, lt, fprintf(cf, " wbuf_%s(wbuf, %s);\n", ft->type, ft->name));
fprintf(cf, " wbuf_int(wbuf, 4+wbuf->ndone - ndone_at_start);\n"); fprintf(cf, " wbuf_int(wbuf, 4+wbuf->ndone - ndone_at_start);\n");
fprintf(cf, "}\n"); fprintf(cf, "}\n");
...@@ -537,7 +545,7 @@ void generate_rollbacks (void) { ...@@ -537,7 +545,7 @@ void generate_rollbacks (void) {
fprintf2(cf, hf, "int toku_parse_rollback(unsigned char *buf, u_int32_t n_bytes, struct roll_entry **itemp, MEMARENA ma)"); fprintf2(cf, hf, "int toku_parse_rollback(unsigned char *buf, u_int32_t n_bytes, struct roll_entry **itemp, MEMARENA ma)");
fprintf(hf, ";\n"); fprintf(hf, ";\n");
fprintf(cf, " {\n assert(n_bytes>0);\n struct roll_entry *item = malloc_in_memarena(ma, sizeof(*item));\n item->cmd=buf[0];\n"); fprintf(cf, " {\n assert(n_bytes>0);\n struct roll_entry *item = malloc_in_memarena(ma, sizeof(*item));\n item->cmd=(enum rt_cmd)(buf[0]);\n");
fprintf(cf, " struct rbuf rc = {buf, n_bytes, 1};\n"); fprintf(cf, " struct rbuf rc = {buf, n_bytes, 1};\n");
fprintf(cf, " switch(item->cmd) {\n"); fprintf(cf, " switch(item->cmd) {\n");
DO_ROLLBACKS(lt, ({ DO_ROLLBACKS(lt, ({
......
...@@ -34,7 +34,8 @@ void memarena_clear (MEMARENA ma) { ...@@ -34,7 +34,8 @@ void memarena_clear (MEMARENA ma) {
ma->buf_used = 0; ma->buf_used = 0;
} }
size_t round_to_page (size_t size) { static size_t
round_to_page (size_t size) {
const size_t PAGE_SIZE = 4096; const size_t PAGE_SIZE = 4096;
const size_t result = PAGE_SIZE+((size-1)&~(PAGE_SIZE-1)); const size_t result = PAGE_SIZE+((size-1)&~(PAGE_SIZE-1));
assert(0==(result&(PAGE_SIZE-1))); // make sure it's aligned assert(0==(result&(PAGE_SIZE-1))); // make sure it's aligned
......
...@@ -330,9 +330,9 @@ static inline BOOL will_need_rebalance(OMT omt, node_idx n_idx, int leftmod, int ...@@ -330,9 +330,9 @@ static inline BOOL will_need_rebalance(OMT omt, node_idx n_idx, int leftmod, int
// the other is to take ceil(n/2) // the other is to take ceil(n/2)
u_int32_t weight_left = nweight(omt, n->left) + leftmod; u_int32_t weight_left = nweight(omt, n->left) + leftmod;
u_int32_t weight_right = nweight(omt, n->right) + rightmod; u_int32_t weight_right = nweight(omt, n->right) + rightmod;
return ((1+weight_left < (1+1+weight_right)/2) return (BOOL)((1+weight_left < (1+1+weight_right)/2)
|| ||
(1+weight_right < (1+1+weight_left)/2)); (1+weight_right < (1+1+weight_left)/2));
} }
static inline void insert_internal(OMT omt, node_idx *n_idxp, OMTVALUE value, u_int32_t index, node_idx **rebalance_idx) { static inline void insert_internal(OMT omt, node_idx *n_idxp, OMTVALUE value, u_int32_t index, node_idx **rebalance_idx) {
......
This diff is collapsed.
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
int toku_continue_on_assert_failure=0; int toku_continue_on_assert_failure=0;
void toku_assert_failed_but_continue_anyway (void) __attribute__((noinline)); static void toku_assert_failed_but_continue_anyway (void) __attribute__((noinline));
void toku_assert_failed_but_continue_anyway (void) { static void
toku_assert_failed_but_continue_anyway (void) {
printf("Assertion failed, but continuing anyway\n"); printf("Assertion failed, but continuing anyway\n");
} }
......
...@@ -14,9 +14,8 @@ static struct toku_trace { ...@@ -14,9 +14,8 @@ static struct toku_trace {
static int toku_next_trace = 0; static int toku_next_trace = 0;
#endif #endif
void toku_add_trace_mem(const char *str, int n) __attribute__((__visibility__("default"))); void toku_add_trace_mem (const char *str __attribute__((unused)),
void toku_add_trace_mem(const char *str __attribute__((unused)), int n __attribute__((unused))) {
int n __attribute__((unused))) {
#if USE_RDTSC && NTRACE #if USE_RDTSC && NTRACE
int i = toku_next_trace++; int i = toku_next_trace++;
if (toku_next_trace >= NTRACE) toku_next_trace = 0; if (toku_next_trace >= NTRACE) toku_next_trace = 0;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// performance: we trade speed for size by not compressing the trace // performance: we trade speed for size by not compressing the trace
// entries. // entries.
void toku_add_trace_mem(const char *str, int n); void toku_add_trace_mem(const char *str, int n) __attribute__((__visibility__("default")));
// add an entry to the end of the trace which consists of a string // add an entry to the end of the trace which consists of a string
// pointer, a number, and the processor timestamp // pointer, a number, and the processor timestamp
......
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