Commit 57075d4e authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Don't always fill with zeros. Fixes #917. Gives some speedups on random.

git-svn-id: file:///svn/tokudb@4543 c7de825b-a66e-492c-adef-691d508d4ae1
parent 219b9ea8
......@@ -50,6 +50,7 @@ typedef struct brtnode *BRTNODE;
struct brtnode {
enum typ_tag tag;
unsigned int nodesize;
int ever_been_written;
unsigned int flags;
DISKOFF thisnodename; // The size of the node allocated on disk. Not all is necessarily in use.
// These two LSNs are used to decide when to make a copy of a node instead of overwriting it.
......
......@@ -197,9 +197,12 @@ void toku_serialize_brtnode_to (int fd, DISKOFF off, BRTNODE node) {
//write_now: printf("%s:%d Writing %d bytes\n", __FILE__, __LINE__, w.ndone);
{
ssize_t r=pwrite(fd, w.buf, (size_t)node->nodesize, off); // write the whole buffer, including the zeros
// If the node has never been written, then write the whole buffer, including the zeros
//size_t n_to_write = node->nodesize;
size_t n_to_write = node->ever_been_written ? w.ndone : node->nodesize;
ssize_t r=pwrite(fd, w.buf, n_to_write, off);
if (r<0) printf("r=%ld errno=%d\n", (long)r, errno);
assert(r==(ssize_t)node->nodesize);
assert(r==(ssize_t)n_to_write);
}
if (calculated_size!=w.ndone)
......@@ -222,6 +225,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode) {
if (0) { died0: toku_free(result); }
return r;
}
result->ever_been_written = 1;
{
u_int32_t datasize_n;
r = pread(fd, &datasize_n, sizeof(datasize_n), off +8+4+8);
......
......@@ -366,6 +366,7 @@ int toku_create_new_brtnode (BRT t, BRTNODE *result, int height, TOKULOGGER logg
assert(n);
assert(t->h->nodesize>0);
//printf("%s:%d malloced %lld (and malloc again=%lld)\n", __FILE__, __LINE__, name, malloc_diskblock(t, t->nodesize));
n->ever_been_written = 0;
initialize_brtnode(t, n, name, height);
*result = n;
assert(n->nodesize>0);
......@@ -1872,6 +1873,7 @@ static int setup_initial_brt_root_node (BRT t, DISKOFF offset, TOKULOGGER logger
int r;
TAGMALLOC(BRTNODE, node);
assert(node);
node->ever_been_written = 0;
//printf("%s:%d\n", __FILE__, __LINE__);
initialize_brtnode(t, node,
offset, /* the location is one nodesize offset from 0. */
......@@ -2269,6 +2271,7 @@ static int brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk,
r=malloc_diskblock(&newroot_diskoff, brt, new_nodesize, logger);
assert(r==0);
assert(newroot);
newroot->ever_been_written = 0;
if (brt->database_name==0) {
toku_log_changeunnamedroot(logger, (LSN*)0, 0, toku_cachefile_filenum(brt->cf), *rootp, newroot_diskoff);
} else {
......
......@@ -23,6 +23,7 @@ static void test_serialize(void) {
// source_brt.fd=fd;
char *hello_string;
sn.nodesize = nodesize;
sn.ever_been_written = 0;
sn.flags = 0x11223344;
sn.thisnodename = sn.nodesize*20;
sn.disk_lsn.lsn = 789;
......
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