Skip to content

Commit

Permalink
WT-2296 Yield instead of sleep if the wrlsn thread is finding work.
Browse files Browse the repository at this point in the history
  • Loading branch information
sueloverso committed Jan 19, 2016
1 parent 027d079 commit c5527a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/conn/conn_log.c
Expand Up @@ -511,7 +511,7 @@ typedef struct {
* write_lsn in LSN order after the buffer is written to the log file.
*/
int
__wt_log_wrlsn(WT_SESSION_IMPL *session)
__wt_log_wrlsn(WT_SESSION_IMPL *session, int *yield)
{
WT_CONNECTION_IMPL *conn;
WT_DECL_RET;
Expand Down Expand Up @@ -550,6 +550,8 @@ __wt_log_wrlsn(WT_SESSION_IMPL *session)
* based on the release LSN, and then look for them in order.
*/
if (written_i > 0) {
if (yield != NULL)
*yield = 0;
WT_INSERTION_SORT(written, written_i,
WT_LOG_WRLSN_ENTRY, WT_WRLSN_ENTRY_CMP_LT);
/*
Expand Down Expand Up @@ -660,22 +662,30 @@ __log_wrlsn_server(void *arg)
WT_CONNECTION_IMPL *conn;
WT_DECL_RET;
WT_SESSION_IMPL *session;
int yield;

session = arg;
conn = S2C(session);
yield = 0;
while (F_ISSET(conn, WT_CONN_LOG_SERVER_RUN)) {
/*
* Write out any log record buffers.
*/
WT_ERR(__wt_log_wrlsn(session));
WT_ERR(__wt_cond_wait(session, conn->log_wrlsn_cond, 10000));
WT_ERR(__wt_log_wrlsn(session, &yield));
/*
* If __wt_log_wrlsn did work we want to yield instead of sleep.
*/
if (yield++ < 1000)
__wt_yield();
else
WT_ERR(__wt_cond_wait(session, conn->log_wrlsn_cond, 10000));
}
/*
* On close we need to do this one more time because there could
* be straggling log writes that need to be written.
*/
WT_ERR(__wt_log_force_write(session, 1));
WT_ERR(__wt_log_wrlsn(session));
WT_ERR(__wt_log_wrlsn(session, NULL));
if (0) {
err: __wt_err(session, ret, "log wrlsn server error");
}
Expand Down
2 changes: 1 addition & 1 deletion src/include/extern.h
Expand Up @@ -261,7 +261,7 @@ extern int __wt_connection_init(WT_CONNECTION_IMPL *conn);
extern int __wt_connection_destroy(WT_CONNECTION_IMPL *conn);
extern int __wt_logmgr_reconfig(WT_SESSION_IMPL *session, const char **cfg);
extern int __wt_log_truncate_files( WT_SESSION_IMPL *session, WT_CURSOR *cursor, const char *cfg[]);
extern int __wt_log_wrlsn(WT_SESSION_IMPL *session);
extern int __wt_log_wrlsn(WT_SESSION_IMPL *session, int *yield);
extern int __wt_logmgr_create(WT_SESSION_IMPL *session, const char *cfg[]);
extern int __wt_logmgr_open(WT_SESSION_IMPL *session);
extern int __wt_logmgr_destroy(WT_SESSION_IMPL *session);
Expand Down
4 changes: 2 additions & 2 deletions src/log/log.c
Expand Up @@ -47,7 +47,7 @@ __wt_log_flush_lsn(WT_SESSION_IMPL *session, WT_LSN *lsn, bool start)
conn = S2C(session);
log = conn->log;
WT_RET(__wt_log_force_write(session, 1));
WT_RET(__wt_log_wrlsn(session));
WT_RET(__wt_log_wrlsn(session, NULL));
if (start)
*lsn = log->write_start_lsn;
else
Expand Down Expand Up @@ -771,7 +771,7 @@ __log_newfile(WT_SESSION_IMPL *session, bool conn_open, bool *created)
WT_ASSERT(session, F_ISSET(session, WT_SESSION_LOCKED_SLOT));
while (log->log_close_fh != NULL) {
WT_STAT_FAST_CONN_INCR(session, log_close_yields);
WT_RET(__wt_log_wrlsn(session));
WT_RET(__wt_log_wrlsn(session, NULL));
if (++yield_cnt > 10000)
return (EBUSY);
__wt_yield();
Expand Down

0 comments on commit c5527a9

Please sign in to comment.