diff --git a/newbrt/brt.c b/newbrt/brt.c index 0673f424ede..6ddb846b238 100644 --- a/newbrt/brt.c +++ b/newbrt/brt.c @@ -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; diff --git a/newbrt/brt.h b/newbrt/brt.h index d0ad1f4ec79..d00b0b0991b 100644 --- a/newbrt/brt.h +++ b/newbrt/brt.h @@ -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 diff --git a/newbrt/brt_header.c b/newbrt/brt_header.c index 5333c3f7ef2..46817b77c90 100644 --- a/newbrt/brt_header.c +++ b/newbrt/brt_header.c @@ -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 + ); +} + + diff --git a/newbrt/brt_header.h b/newbrt/brt_header.h index 2897bf3b623..9c99e5016f7 100644 --- a/newbrt/brt_header.h +++ b/newbrt/brt_header.h @@ -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