More progress. Right now the translation table is overwriting the actual data. Addresses #1000, #1080, #1131.

git-svn-id: file:///svn/tokudb.1131b+1080a@6107 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
Bradley C. Kuszmaul 2013-04-16 23:57:18 -04:00 committed by Yoni Fogel
parent 7e5a096387
commit 21be0ea0ef
4 changed files with 32 additions and 10 deletions

View file

@ -556,11 +556,14 @@ void toku_verify_counts (BRTNODE node) {
int toku_serialize_brt_header_size (struct brt_header *h) {
unsigned int size = (+8 // "tokudata"
+4 // size
+4 // tree's nodesize
+4 // version
+8 // freelist
+8 // unused memory
+4); // n_named_roots
+4 // tree's nodesize
+8 // free blocks
+8 // unused blocks
+4 // n_named_roots
+8 // max_blocknum_translated
+8 // block_translation_address_on_disk
);
if (h->n_named_roots<0) {
size+=(+8 // diskoff
+4 // flags
@ -587,7 +590,7 @@ int toku_serialize_brt_header_to_wbuf (struct wbuf *wbuf, struct brt_header *h)
wbuf_BLOCKNUM(wbuf, h->free_blocks);
wbuf_BLOCKNUM(wbuf, h->unused_blocks);
wbuf_int (wbuf, h->n_named_roots);
if (h->block_translation_address_on_disk !=0 ) {
if (h->block_translation_address_on_disk != 0) {
block_allocator_free_block(h->block_allocator, h->block_translation_address_on_disk);
}
block_allocator_alloc_block(h->block_allocator, 4 + 8*h->max_blocknum_translated, &h->block_translation_address_on_disk);
@ -627,13 +630,16 @@ int toku_serialize_brt_header_to (int fd, struct brt_header *h) {
{
struct wbuf w;
u_int64_t size = 4 + h->max_blocknum_translated * 8; // 4 for the checksum
printf("%s:%d writing translation table of size %ld\n", __FILE__, __LINE__, size);
wbuf_init(&w, toku_malloc(size), size);
u_int64_t i;
for (i=0; i<h->max_blocknum_translated; i++) {
wbuf_ulonglong(&w, h->block_translation[i].diskoff);
wbuf_ulonglong(&w, h->block_translation[i].size);
}
wbuf_int(&w, x1764_finish(&w.checksum));
u_int32_t checksum = x1764_finish(&w.checksum);
printf("%s:%d writing to %ld, checksum=%d offset=%d size=%ld\n", __FILE__, __LINE__, h->block_translation_address_on_disk, checksum, w.ndone, size);
wbuf_int(&w, checksum);
ssize_t nwrote = pwrite(fd, w.buf, size, h->block_translation_address_on_disk);
assert(nwrote==(ssize_t)size);
toku_free(w.buf);
@ -670,10 +676,9 @@ int deserialize_brtheader (u_int32_t size, int fd, DISKOFF off, struct brt_heade
h->block_translation_address_on_disk = rbuf_diskoff(&rc);
// Set up the the block translation buffer.
create_block_allocator(&h->block_allocator, h->nodesize);
if (h->max_blocknum_translated == 0) {
if (h->block_translation_address_on_disk == 0) {
h->block_translation = 0;
} else {
//
block_allocator_alloc_block_at(h->block_allocator, h->block_translation_address_on_disk, h->block_translation_size_on_disk);
XMALLOC_N(h->max_blocknum_translated, h->block_translation);
unsigned char *XMALLOC_N(h->block_translation_size_on_disk, tbuf);
@ -684,7 +689,9 @@ int deserialize_brtheader (u_int32_t size, int fd, DISKOFF off, struct brt_heade
{
// check the checksum
u_int32_t x1764 = x1764_memory(tbuf, h->block_translation_size_on_disk - 4);
u_int32_t stored_x1764 = ntohl(*(int*)(tbuf + h->block_translation_size_on_disk - 4));
u_int64_t offset = h->block_translation_size_on_disk - 4;
printf("%s:%d read from %ld (x1764 offset=%ld) size=%ld\n", __FILE__, __LINE__, h->block_translation_address_on_disk, offset, h->block_translation_size_on_disk);
u_int32_t stored_x1764 = ntohl(*(int*)(tbuf + offset));
assert(x1764 == stored_x1764);
}
// now read all that data.

View file

@ -33,6 +33,7 @@
#include <sys/time.h>
#include <unistd.h>
#include "block_allocator.h"
#include "toku_assert.h"
#include "brt-internal.h"
#include "key.h"
@ -2155,6 +2156,11 @@ static int brt_alloc_init_header(BRT t, const char *dbname, TOKUTXN txn) {
t->h->nodesize=t->nodesize;
t->h->free_blocks = make_blocknum(-1);
t->h->unused_blocks=make_blocknum(2);
t->h->max_blocknum_translated = 0;
t->h->block_translation = 0;
t->h->block_translation_size_on_disk = 0;
t->h->block_translation_address_on_disk = 0;
create_block_allocator(&t->h->block_allocator, t->nodesize);
toku_fifo_create(&t->h->fifo);
t->root_put_counter = global_root_put_counter++;
if (dbname) {

View file

@ -20,7 +20,7 @@
#include "cachetable-rwlock.h"
// execute the cachetable callbacks using a writer thread 0->no 1->yes
#define DO_WRITER_THREAD 1
#define DO_WRITER_THREAD 0
#if DO_WRITER_THREAD
static void *cachetable_writer(void *);
#endif

View file

@ -10,6 +10,15 @@
{
compress_is_not_valgrind_clean2
Memcheck:Cond
fun:longest_match
fun:deflate_fast
fun:deflate
fun:compress2
}
{
compress_is_not_valgrind_clean3
Memcheck:Cond
obj:/usr/lib64/libz.so.1.2.3
obj:/usr/lib64/libz.so.1.2.3
fun:deflate