Commit f9f364ff authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4644], merge fix to main

git-svn-id: file:///svn/toku/tokudb@41513 c7de825b-a66e-492c-adef-691d508d4ae1
parent 36eb33a1
...@@ -4260,8 +4260,18 @@ toku_brtheader_checkpoint (CACHEFILE cf, int fd, void *header_v) { ...@@ -4260,8 +4260,18 @@ toku_brtheader_checkpoint (CACHEFILE cf, int fd, void *header_v) {
r = toku_serialize_brt_header_to(fd, ch); r = toku_serialize_brt_header_to(fd, ch);
if (r!=0) goto handle_error; if (r!=0) goto handle_error;
ch->dirty = 0; // this is only place this bit is cleared (in checkpoint_header) ch->dirty = 0; // this is only place this bit is cleared (in checkpoint_header)
} else
// fsync the cachefile
r = toku_cachefile_fsync(cf);
if (r!=0) {
goto handle_error;
}
h->checkpoint_count++; // checkpoint succeeded, next checkpoint will save to alternate header location
h->checkpoint_lsn = ch->checkpoint_lsn; //Header updated.
}
else {
toku_block_translation_note_skipped_checkpoint(ch->blocktable); toku_block_translation_note_skipped_checkpoint(ch->blocktable);
}
if (0) { if (0) {
handle_error: handle_error:
if (h->panic) r = h->panic; if (h->panic) r = h->panic;
...@@ -4277,26 +4287,15 @@ handle_error: ...@@ -4277,26 +4287,15 @@ handle_error:
} }
// Really write everything to disk (fsync dictionary), then free unused disk space // free unused disk space
// (i.e. tell BlockAllocator to liberate blocks used by previous checkpoint). // (i.e. tell BlockAllocator to liberate blocks used by previous checkpoint).
// Must have access to fd (protected) // Must have access to fd (protected)
int int
toku_brtheader_end_checkpoint (CACHEFILE cachefile, int fd, void *header_v) { toku_brtheader_end_checkpoint (CACHEFILE UU(cachefile), int fd, void *header_v) {
struct brt_header *h = header_v; struct brt_header *h = header_v;
int r = h->panic; int r = h->panic;
if (r==0) { if (r==0) {
assert(h->type == BRTHEADER_CURRENT); assert(h->type == BRTHEADER_CURRENT);
struct brt_header *ch = h->checkpoint_header;
BOOL checkpoint_success_so_far = (BOOL)(ch->checkpoint_count==h->checkpoint_count+1 && ch->dirty==0);
if (checkpoint_success_so_far) {
r = toku_cachefile_fsync(cachefile);
if (r!=0)
toku_block_translation_note_failed_checkpoint(h->blocktable);
else {
h->checkpoint_count++; // checkpoint succeeded, next checkpoint will save to alternate header location
h->checkpoint_lsn = ch->checkpoint_lsn; //Header updated.
}
}
toku_block_translation_note_end_checkpoint(h->blocktable, fd, h); toku_block_translation_note_end_checkpoint(h->blocktable, fd, h);
} }
if (h->checkpoint_header) { // could be NULL only if panic was true at begin_checkpoint if (h->checkpoint_header) { // could be NULL only if panic was true at begin_checkpoint
......
...@@ -3844,7 +3844,6 @@ toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger, ...@@ -3844,7 +3844,6 @@ toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger,
{ // have just written data blocks, so next write the translation and header for each open dictionary { // have just written data blocks, so next write the translation and header for each open dictionary
CACHEFILE cf; CACHEFILE cf;
//cachefiles_in_checkpoint is protected by the checkpoint_safe_lock
for (cf = ct->cachefiles_in_checkpoint; cf; cf=cf->next_in_checkpoint) { for (cf = ct->cachefiles_in_checkpoint; cf; cf=cf->next_in_checkpoint) {
if (cf->checkpoint_userdata) { if (cf->checkpoint_userdata) {
rwlock_prefer_read_lock(&cf->fdlock, ct->mutex); rwlock_prefer_read_lock(&cf->fdlock, ct->mutex);
...@@ -3866,9 +3865,27 @@ toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger, ...@@ -3866,9 +3865,27 @@ toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger,
} }
} }
} }
cachetable_unlock(ct);
// For testing purposes only. Dictionary has been fsync-ed to disk but log has not yet been written.
if (testcallback_f) {
testcallback_f(testextra);
}
if (logger) {
int r = toku_log_end_checkpoint(logger, NULL,
1, // want the end_checkpoint to be fsync'd
ct->lsn_of_checkpoint_in_progress.lsn,
0,
ct->checkpoint_num_files,
ct->checkpoint_num_txns);
assert(r==0);
toku_logger_note_checkpoint(logger, ct->lsn_of_checkpoint_in_progress);
}
cachetable_lock(ct);
{ // everything has been written to file (or at least OS internal buffer)... {
// ... so fsync and call checkpoint-end function in block translator // everything has been written to file and fsynced
// ... call checkpoint-end function in block translator
// to free obsolete blocks on disk used by previous checkpoint // to free obsolete blocks on disk used by previous checkpoint
CACHEFILE cf; CACHEFILE cf;
//cachefiles_in_checkpoint is protected by the checkpoint_safe_lock //cachefiles_in_checkpoint is protected by the checkpoint_safe_lock
...@@ -3916,20 +3933,6 @@ toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger, ...@@ -3916,20 +3933,6 @@ toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger,
} }
} }
// For testing purposes only. Dictionary has been fsync-ed to disk but log has not yet been written.
if (testcallback_f)
testcallback_f(testextra);
if (logger) {
int r = toku_log_end_checkpoint(logger, NULL,
1, // want the end_checkpoint to be fsync'd
ct->lsn_of_checkpoint_in_progress.lsn,
0,
ct->checkpoint_num_files,
ct->checkpoint_num_txns);
assert(r==0);
toku_logger_note_checkpoint(logger, ct->lsn_of_checkpoint_in_progress);
}
brt_end_checkpoint(); brt_end_checkpoint();
panic: panic:
......
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