Commit 8e65b617 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4875], move descriptor code to brt_header.c

git-svn-id: file:///svn/toku/tokudb@43525 c7de825b-a66e-492c-adef-691d508d4ae1
parent af6602f1
......@@ -3140,43 +3140,6 @@ verify_builtin_comparisons_consistent(BRT t, u_int32_t flags) {
return 0;
}
int toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd)
// Effect: Change the descriptor in a tree (log the change, make sure it makes it to disk eventually).
// Updates to the descriptor must be performed while holding some sort of lock. (In the ydb layer
// there is a row lock on the directory that provides exclusion.)
{
int r = 0;
DISKOFF offset;
// 4 for checksum
toku_realloc_descriptor_on_disk(h->blocktable, toku_serialize_descriptor_size(d)+4, &offset, h);
r = toku_serialize_descriptor_contents_to_fd(fd, d, offset);
if (r) {
goto cleanup;
}
if (h->descriptor.dbt.data) {
toku_free(h->descriptor.dbt.data);
}
h->descriptor.dbt.size = d->dbt.size;
h->descriptor.dbt.data = toku_memdup(d->dbt.data, d->dbt.size);
r = 0;
cleanup:
return r;
}
static void
brt_update_cmp_descriptor(BRT t) {
if (t->h->cmp_descriptor.dbt.data != NULL) {
toku_free(t->h->cmp_descriptor.dbt.data);
}
t->h->cmp_descriptor.dbt.size = t->h->descriptor.dbt.size;
t->h->cmp_descriptor.dbt.data = toku_xmemdup(
t->h->descriptor.dbt.data,
t->h->descriptor.dbt.size
);
}
int
toku_brt_change_descriptor(
BRT t,
......@@ -3232,7 +3195,7 @@ toku_brt_change_descriptor(
if (r!=0) goto cleanup;
if (update_cmp_descriptor) {
brt_update_cmp_descriptor(t);
toku_brtheader_update_cmp_descriptor(t->h);
}
cleanup:
return r;
......
......@@ -30,8 +30,6 @@ typedef int(*BRT_GET_CALLBACK_FUNCTION)(ITEMLEN keylen, bytevec key, ITEMLEN val
int toku_open_brt (const char *fname, int is_create, BRT *, int nodesize, int basementnodesize, enum toku_compression_method compression_method, CACHETABLE, TOKUTXN, int(*)(DB *,const DBT*,const DBT*)) __attribute__ ((warn_unused_result));
int toku_brt_change_descriptor(BRT t, const DBT* old_descriptor, const DBT* new_descriptor, BOOL do_log, TOKUTXN txn, BOOL update_cmp_descriptor);
int toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd);
// Note: See the locking discussion in brt.c for toku_brt_change_descriptor and toku_update_descriptor.
// See the brt.c file for what this toku_redirect_brt does
......
......@@ -930,3 +930,43 @@ toku_brtheader_stat64 (struct brt_header* h, struct brtstat64_s *s) {
s->verify_time_sec = h->time_of_last_verification;
}
// TODO: (Zardosht), once the fdlock has been removed from cachetable, remove
// fd as parameter and access it in this function
int
toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd)
// Effect: Change the descriptor in a tree (log the change, make sure it makes it to disk eventually).
// Updates to the descriptor must be performed while holding some sort of lock. (In the ydb layer
// there is a row lock on the directory that provides exclusion.)
{
int r = 0;
DISKOFF offset;
// 4 for checksum
toku_realloc_descriptor_on_disk(h->blocktable, toku_serialize_descriptor_size(d)+4, &offset, h);
r = toku_serialize_descriptor_contents_to_fd(fd, d, offset);
if (r) {
goto cleanup;
}
if (h->descriptor.dbt.data) {
toku_free(h->descriptor.dbt.data);
}
h->descriptor.dbt.size = d->dbt.size;
h->descriptor.dbt.data = toku_memdup(d->dbt.data, d->dbt.size);
r = 0;
cleanup:
return r;
}
void
toku_brtheader_update_cmp_descriptor(struct brt_header* h) {
if (h->cmp_descriptor.dbt.data != NULL) {
toku_free(h->cmp_descriptor.dbt.data);
}
h->cmp_descriptor.dbt.size = h->descriptor.dbt.size;
h->cmp_descriptor.dbt.data = toku_xmemdup(
h->descriptor.dbt.data,
h->descriptor.dbt.size
);
}
......@@ -63,5 +63,9 @@ void toku_brtheader_set_new_root_blocknum(struct brt_header* h, CACHEKEY new_roo
LSN toku_brt_checkpoint_lsn(struct brt_header* h) __attribute__ ((warn_unused_result));
int toku_brtheader_set_panic(struct brt_header *h, int panic, char *panic_string) __attribute__ ((warn_unused_result));
void toku_brtheader_stat64 (struct brt_header* h, struct brtstat64_s *s);
int toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd);
// Note: See the locking discussion in brt.c for toku_brt_change_descriptor and toku_update_descriptor.
void toku_brtheader_update_cmp_descriptor(struct brt_header* h);
#endif
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