Commit 6fd626d6 authored by John Esmet's avatar John Esmet

FT-274 Use ybt functions for descriptor memory management, which is

safer and more readable.
parent 14adf6f9
...@@ -153,15 +153,7 @@ deserialize_descriptor_from_rbuf(struct rbuf *rb, DESCRIPTOR desc, int layout_ve ...@@ -153,15 +153,7 @@ deserialize_descriptor_from_rbuf(struct rbuf *rb, DESCRIPTOR desc, int layout_ve
uint32_t size; uint32_t size;
bytevec data; bytevec data;
rbuf_bytes(rb, &data, &size); rbuf_bytes(rb, &data, &size);
bytevec data_copy = data; toku_memdup_dbt(&desc->dbt, data, size);
if (size > 0) {
data_copy = toku_memdup(data, size); //Cannot keep the reference from rbuf. Must copy.
lazy_assert(data_copy);
} else {
lazy_assert(size==0);
data_copy = NULL;
}
toku_fill_dbt(&desc->dbt, data_copy, size);
} }
static int static int
...@@ -194,12 +186,10 @@ deserialize_descriptor_from(int fd, BLOCK_TABLE bt, DESCRIPTOR desc, int layout_ ...@@ -194,12 +186,10 @@ deserialize_descriptor_from(int fd, BLOCK_TABLE bt, DESCRIPTOR desc, int layout_
goto exit; goto exit;
} }
} }
{
struct rbuf rb = {.buf = dbuf, .size = (unsigned int) size, .ndone = 0}; struct rbuf rb = { .buf = dbuf, .size = (unsigned int) size, .ndone = 0 };
//Not temporary; must have a toku_memdup'd copy. deserialize_descriptor_from_rbuf(&rb, desc, layout_version);
deserialize_descriptor_from_rbuf(&rb, desc, layout_version); lazy_assert(deserialize_descriptor_size(desc, layout_version) + 4 == size);
}
lazy_assert(deserialize_descriptor_size(desc, layout_version)+4 == size);
toku_free(dbuf); toku_free(dbuf);
} }
} }
...@@ -436,10 +426,10 @@ int deserialize_ft_versioned(int fd, struct rbuf *rb, FT *ftp, uint32_t version) ...@@ -436,10 +426,10 @@ int deserialize_ft_versioned(int fd, struct rbuf *rb, FT *ftp, uint32_t version)
if (r != 0) { if (r != 0) {
goto exit; goto exit;
} }
// initialize for svn #4541 // initialize for svn #4541
// TODO: use real dbt function toku_clone_dbt(&ft->cmp_descriptor.dbt, ft->descriptor.dbt);
ft->cmp_descriptor.dbt.size = ft->descriptor.dbt.size;
ft->cmp_descriptor.dbt.data = toku_xmemdup(ft->descriptor.dbt.data, ft->descriptor.dbt.size);
// Version 13 descriptors had an extra 4 bytes that we don't read // Version 13 descriptors had an extra 4 bytes that we don't read
// anymore. Since the header is going to think it's the current // anymore. Since the header is going to think it's the current
// version if it gets written out, we need to write the descriptor in // version if it gets written out, we need to write the descriptor in
......
...@@ -120,10 +120,8 @@ ft_destroy(FT ft) { ...@@ -120,10 +120,8 @@ ft_destroy(FT ft) {
assert(ft->h->type == FT_CURRENT); assert(ft->h->type == FT_CURRENT);
toku_blocktable_destroy(&ft->blocktable); toku_blocktable_destroy(&ft->blocktable);
ft->cmp.destroy(); ft->cmp.destroy();
// TODO: use real dbt function toku_destroy_dbt(&ft->descriptor.dbt);
if (ft->descriptor.dbt.data) toku_free(ft->descriptor.dbt.data); toku_destroy_dbt(&ft->cmp_descriptor.dbt);
// TODO: use real dbt function
if (ft->cmp_descriptor.dbt.data) toku_free(ft->cmp_descriptor.dbt.data);
toku_ft_destroy_reflock(ft); toku_ft_destroy_reflock(ft);
toku_free(ft->h); toku_free(ft->h);
} }
...@@ -913,26 +911,14 @@ toku_ft_update_descriptor_with_fd(FT ft, DESCRIPTOR desc, int fd) { ...@@ -913,26 +911,14 @@ toku_ft_update_descriptor_with_fd(FT ft, DESCRIPTOR desc, int fd) {
toku_serialize_descriptor_contents_to_fd(fd, desc, offset); toku_serialize_descriptor_contents_to_fd(fd, desc, offset);
// cleanup the old descriptor and set the in-memory descriptor to the new one // cleanup the old descriptor and set the in-memory descriptor to the new one
// TODO: use real dbt function toku_destroy_dbt(&ft->descriptor.dbt);
if (ft->descriptor.dbt.data) { toku_clone_dbt(&ft->descriptor.dbt, desc->dbt);
toku_free(ft->descriptor.dbt.data);
}
// TODO: use real dbt function
ft->descriptor.dbt.size = desc->dbt.size;
ft->descriptor.dbt.data = toku_memdup(desc->dbt.data, desc->dbt.size);
} }
void toku_ft_update_cmp_descriptor(FT ft) { void toku_ft_update_cmp_descriptor(FT ft) {
// TODO: use real dbt function // cleanup the old cmp descriptor and clone it as the in-memory descriptor
if (ft->cmp_descriptor.dbt.data != NULL) { toku_destroy_dbt(&ft->cmp_descriptor.dbt);
toku_free(ft->cmp_descriptor.dbt.data); toku_clone_dbt(&ft->cmp_descriptor.dbt, ft->descriptor.dbt);
}
// TODO: use real dbt function
ft->cmp_descriptor.dbt.size = ft->descriptor.dbt.size;
ft->cmp_descriptor.dbt.data = toku_xmemdup(
ft->descriptor.dbt.data,
ft->descriptor.dbt.size
);
} }
DESCRIPTOR toku_ft_get_descriptor(FT_HANDLE ft_handle) { DESCRIPTOR toku_ft_get_descriptor(FT_HANDLE ft_handle) {
......
...@@ -565,11 +565,12 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, uint32_t f ...@@ -565,11 +565,12 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, uint32_t f
HANDLE_DB_ILLEGAL_WORKING_PARENT_TXN(db, txn); HANDLE_DB_ILLEGAL_WORKING_PARENT_TXN(db, txn);
int r = 0; int r = 0;
TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL; TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL;
DBT old_descriptor;
bool is_db_hot_index = ((flags & DB_IS_HOT_INDEX) != 0); bool is_db_hot_index = ((flags & DB_IS_HOT_INDEX) != 0);
bool update_cmp_descriptor = ((flags & DB_UPDATE_CMP_DESCRIPTOR) != 0); bool update_cmp_descriptor = ((flags & DB_UPDATE_CMP_DESCRIPTOR) != 0);
toku_init_dbt(&old_descriptor); DBT old_descriptor_dbt;
toku_init_dbt(&old_descriptor_dbt);
if (!db_opened(db) || !descriptor || (descriptor->size>0 && !descriptor->data)){ if (!db_opened(db) || !descriptor || (descriptor->size>0 && !descriptor->data)){
r = EINVAL; r = EINVAL;
goto cleanup; goto cleanup;
...@@ -582,23 +583,12 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, uint32_t f ...@@ -582,23 +583,12 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, uint32_t f
if (r != 0) { goto cleanup; } if (r != 0) { goto cleanup; }
} }
// TODO: use toku_clone_dbt(&old-descriptor, db->descriptor); toku_clone_dbt(&old_descriptor_dbt, db->descriptor->dbt);
old_descriptor.size = db->descriptor->dbt.size; toku_ft_change_descriptor(db->i->ft_handle, &old_descriptor_dbt, descriptor,
old_descriptor.data = toku_memdup(db->descriptor->dbt.data, db->descriptor->dbt.size); true, ttxn, update_cmp_descriptor);
toku_ft_change_descriptor(
db->i->ft_handle,
&old_descriptor,
descriptor,
true,
ttxn,
update_cmp_descriptor
);
cleanup: cleanup:
if (old_descriptor.data) { toku_destroy_dbt(&old_descriptor_dbt);
toku_free(old_descriptor.data);
}
return r; return r;
} }
......
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