Commit 80c9a926 authored by Yoni Fogel's avatar Yoni Fogel

fixes #6160 Skip taking input lock for pure fsyncs. This might improve group commit.

Cleaned up maybe_fsync code.

git-svn-id: file:///svn/toku/tokudb@53946 c7de825b-a66e-492c-adef-691d508d4ae1
parent 40f0f759
...@@ -382,7 +382,7 @@ generate_get_timestamp(void) { ...@@ -382,7 +382,7 @@ generate_get_timestamp(void) {
fprintf(cf, " return tv.tv_sec * 1000000ULL + tv.tv_usec;\n"); fprintf(cf, " return tv.tv_sec * 1000000ULL + tv.tv_usec;\n");
fprintf(cf, "}\n"); fprintf(cf, "}\n");
} }
static void static void
generate_log_writer (void) { generate_log_writer (void) {
generate_get_timestamp(); generate_get_timestamp();
...@@ -455,7 +455,7 @@ generate_log_writer (void) { ...@@ -455,7 +455,7 @@ generate_log_writer (void) {
fprintf(cf, " wbuf_nocrc_int(&wbuf, buflen);\n"); fprintf(cf, " wbuf_nocrc_int(&wbuf, buflen);\n");
fprintf(cf, " assert(wbuf.ndone==buflen);\n"); fprintf(cf, " assert(wbuf.ndone==buflen);\n");
fprintf(cf, " logger->inbuf.n_in_buf += buflen;\n"); fprintf(cf, " logger->inbuf.n_in_buf += buflen;\n");
fprintf(cf, " toku_logger_maybe_fsync(logger, logger->lsn, do_fsync);\n"); fprintf(cf, " toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);\n");
fprintf(cf, "}\n\n"); fprintf(cf, "}\n\n");
}); });
} }
......
...@@ -491,16 +491,12 @@ void toku_logger_fsync (TOKULOGGER logger) ...@@ -491,16 +491,12 @@ void toku_logger_fsync (TOKULOGGER logger)
// Implementation note: Acquire the output condition lock, then the output permission, then release the output condition lock, then get the input lock. // Implementation note: Acquire the output condition lock, then the output permission, then release the output condition lock, then get the input lock.
// Then release everything. // Then release everything.
{ {
ml_lock(&logger->input_lock); toku_logger_maybe_fsync(logger, logger->inbuf.max_lsn_in_buf, true, false);
logger->input_lock_ctr++;
toku_logger_maybe_fsync(logger, logger->inbuf.max_lsn_in_buf, true);
} }
void toku_logger_fsync_if_lsn_not_fsynced (TOKULOGGER logger, LSN lsn) { void toku_logger_fsync_if_lsn_not_fsynced (TOKULOGGER logger, LSN lsn) {
if (logger->write_log_files) { if (logger->write_log_files) {
ml_lock(&logger->input_lock); toku_logger_maybe_fsync(logger, lsn, true, false);
logger->input_lock_ctr++;
toku_logger_maybe_fsync(logger, lsn, true);
} }
} }
...@@ -725,16 +721,18 @@ bool toku_logger_txns_exist(TOKULOGGER logger) ...@@ -725,16 +721,18 @@ bool toku_logger_txns_exist(TOKULOGGER logger)
} }
void toku_logger_maybe_fsync(TOKULOGGER logger, LSN lsn, int do_fsync) void toku_logger_maybe_fsync(TOKULOGGER logger, LSN lsn, int do_fsync, bool holds_input_lock)
// Effect: If fsync is nonzero, then make sure that the log is flushed and synced at least up to lsn. // Effect: If fsync is nonzero, then make sure that the log is flushed and synced at least up to lsn.
// Entry: Holds input lock. The log entry has already been written to the input buffer. // Entry: Holds input lock iff 'holds_input_lock'. The log entry has already been written to the input buffer.
// Exit: Holds no locks. // Exit: Holds no locks.
// The input lock may be released and then reacquired. Thus this function does not run atomically with respect to other threads. // The input lock may be released and then reacquired. Thus this function does not run atomically with respect to other threads.
{ {
if (do_fsync) { if (holds_input_lock) {
// reacquire the locks (acquire output permission first)
logger->input_lock_ctr++; logger->input_lock_ctr++;
ml_unlock(&logger->input_lock); ml_unlock(&logger->input_lock);
}
if (do_fsync) {
// reacquire the locks (acquire output permission first)
LSN fsynced_lsn; LSN fsynced_lsn;
bool already_done = wait_till_output_already_written_or_output_buffer_available(logger, lsn, &fsynced_lsn); bool already_done = wait_till_output_already_written_or_output_buffer_available(logger, lsn, &fsynced_lsn);
if (already_done) { if (already_done) {
...@@ -745,7 +743,7 @@ void toku_logger_maybe_fsync(TOKULOGGER logger, LSN lsn, int do_fsync) ...@@ -745,7 +743,7 @@ void toku_logger_maybe_fsync(TOKULOGGER logger, LSN lsn, int do_fsync)
ml_lock(&logger->input_lock); ml_lock(&logger->input_lock);
logger->input_lock_ctr++; logger->input_lock_ctr++;
swap_inbuf_outbuf(logger); swap_inbuf_outbuf(logger);
logger->input_lock_ctr++; logger->input_lock_ctr++;
...@@ -763,9 +761,6 @@ void toku_logger_maybe_fsync(TOKULOGGER logger, LSN lsn, int do_fsync) ...@@ -763,9 +761,6 @@ void toku_logger_maybe_fsync(TOKULOGGER logger, LSN lsn, int do_fsync)
toku_logfilemgr_update_last_lsn(logger->logfilemgr, logger->written_lsn); toku_logfilemgr_update_last_lsn(logger->logfilemgr, logger->written_lsn);
} }
release_output(logger, fsynced_lsn); release_output(logger, fsynced_lsn);
} else {
logger->input_lock_ctr++;
ml_unlock(&logger->input_lock);
} }
} }
......
...@@ -112,9 +112,9 @@ int toku_logger_write_inbuf (TOKULOGGER logger); ...@@ -112,9 +112,9 @@ int toku_logger_write_inbuf (TOKULOGGER logger);
// Rationale: When the buffer becomes nearly full, call this function so that more can be put in. // Rationale: When the buffer becomes nearly full, call this function so that more can be put in.
// Implementation note: Since the output lock is acquired first, we must release the input lock, and then grab both in the right order. // Implementation note: Since the output lock is acquired first, we must release the input lock, and then grab both in the right order.
void toku_logger_maybe_fsync (TOKULOGGER logger, LSN lsn, int do_fsync); void toku_logger_maybe_fsync (TOKULOGGER logger, LSN lsn, int do_fsync, bool holds_input_lock);
// Effect: If fsync is nonzero, then make sure that the log is flushed and synced at least up to lsn. // Effect: If fsync is nonzero, then make sure that the log is flushed and synced at least up to lsn.
// Entry: Holds input lock. // Entry: Holds input lock iff 'holds_input_lock'.
// Exit: Holds no locks. // Exit: Holds no locks.
// Discussion: How does the logger work: // Discussion: How does the logger work:
......
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