diff options
author | Luke Chen <luke.chen@mongodb.com> | 2018-11-26 14:26:36 +1100 |
---|---|---|
committer | Luke Chen <luke.chen@mongodb.com> | 2018-11-26 14:26:36 +1100 |
commit | 406d650b57a00bbc66e616ebbb5b22112a0621aa (patch) | |
tree | c245e765d3c6eadc7b9be82e216557cf2e43159e /src/third_party/wiredtiger/src/txn/txn_timestamp.c | |
parent | da22c83c0e2d4d9b1e014b183a21898443dbc128 (diff) | |
download | mongo-406d650b57a00bbc66e616ebbb5b22112a0621aa.tar.gz |
Import wiredtiger: 74aa2f92a95596196d8ff131cdf015850613c893 from branch mongodb-4.2
ref: a065c83d8d..74aa2f92a9
for: 4.1.6
WT-3756 Adjust pre-allocated file amount downward if we're not using them quickly enough
WT-4381 Reset session statistics as on WT_SESSION::reset()
WT-4394 Reduce Evergreen Ubuntu build variant runtime by splitting up 'make check' tests
WT-4419 big-endian machines incorrectly configure little-endian crc32c support
WT-4427 Make WiredTiger timestamps always on and 8 bytes
WT-4440 Force a copy of the stable timestamp for clarity
Diffstat (limited to 'src/third_party/wiredtiger/src/txn/txn_timestamp.c')
-rw-r--r-- | src/third_party/wiredtiger/src/txn/txn_timestamp.c | 470 |
1 files changed, 164 insertions, 306 deletions
diff --git a/src/third_party/wiredtiger/src/txn/txn_timestamp.c b/src/third_party/wiredtiger/src/txn/txn_timestamp.c index 3cb8bf79ef7..b58152f8599 100644 --- a/src/third_party/wiredtiger/src/txn/txn_timestamp.c +++ b/src/third_party/wiredtiger/src/txn/txn_timestamp.c @@ -8,7 +8,6 @@ #include "wt_internal.h" -#ifdef HAVE_TIMESTAMPS /* AUTOMATIC FLAG VALUE GENERATION START */ #define WT_TXN_TS_ALREADY_LOCKED 0x1u #define WT_TXN_TS_INCLUDE_CKPT 0x2u @@ -19,26 +18,19 @@ * __wt_timestamp_to_hex_string -- * Convert a timestamp to hex string representation. */ -int -__wt_timestamp_to_hex_string( - WT_SESSION_IMPL *session, char *hex_timestamp, const wt_timestamp_t *ts_src) +void +__wt_timestamp_to_hex_string(char *hex_timestamp, wt_timestamp_t ts) { - wt_timestamp_t ts; - - __wt_timestamp_set(&ts, ts_src); + char *p, v; - if (__wt_timestamp_iszero(&ts)) { + if (ts == 0) { hex_timestamp[0] = '0'; hex_timestamp[1] = '\0'; - return (0); + return; } -#if WT_TIMESTAMP_SIZE == 8 - { - char *p, v; - - for (p = hex_timestamp; ts.val != 0; ts.val >>= 4) - *p++ = (char)__wt_hex((u_char)(ts.val & 0x0f)); + for (p = hex_timestamp; ts != 0; ts >>= 4) + *p++ = (char)__wt_hex((u_char)(ts & 0x0f)); *p = '\0'; /* Reverse the string. */ @@ -47,26 +39,6 @@ __wt_timestamp_to_hex_string( *p-- = *hex_timestamp; *hex_timestamp++ = v; } - WT_UNUSED(session); - } -#else - { - WT_ITEM hexts; - size_t len; - uint8_t *tsp; - - /* Avoid memory allocation: set up an item guaranteed large enough. */ - hexts.data = hexts.mem = hex_timestamp; - hexts.memsize = 2 * WT_TIMESTAMP_SIZE + 1; - /* Trim leading zeros. */ - for (tsp = ts.ts, len = WT_TIMESTAMP_SIZE; - len > 0 && *tsp == 0; - ++tsp, --len) - ; - WT_RET(__wt_raw_to_hex(session, tsp, len, &hexts)); - } -#endif - return (0); } /* @@ -74,15 +46,15 @@ __wt_timestamp_to_hex_string( * Output a verbose message along with the specified timestamp. */ void -__wt_verbose_timestamp(WT_SESSION_IMPL *session, - const wt_timestamp_t *ts, const char *msg) +__wt_verbose_timestamp( + WT_SESSION_IMPL *session, wt_timestamp_t ts, const char *msg) { - char timestamp_buf[2 * WT_TIMESTAMP_SIZE + 1]; + char timestamp_buf[WT_TS_HEX_SIZE]; - if (!WT_VERBOSE_ISSET(session, WT_VERB_TIMESTAMP) || - (__wt_timestamp_to_hex_string(session, timestamp_buf, ts) != 0)) - return; + if (!WT_VERBOSE_ISSET(session, WT_VERB_TIMESTAMP)) + return; + __wt_timestamp_to_hex_string(timestamp_buf, ts); __wt_verbose(session, WT_VERB_TIMESTAMP, "Timestamp %s : %s", timestamp_buf, msg); } @@ -95,19 +67,6 @@ int __wt_txn_parse_timestamp_raw(WT_SESSION_IMPL *session, const char *name, wt_timestamp_t *timestamp, WT_CONFIG_ITEM *cval) { - __wt_timestamp_set_zero(timestamp); - - if (cval->len == 0) - return (0); - - /* Protect against unexpectedly long hex strings. */ - if (cval->len > 2 * WT_TIMESTAMP_SIZE) - WT_RET_MSG(session, EINVAL, - "%s timestamp too long '%.*s'", - name, (int)cval->len, cval->str); - -#if WT_TIMESTAMP_SIZE == 8 - { static const int8_t hextable[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -128,7 +87,18 @@ __wt_txn_parse_timestamp_raw(WT_SESSION_IMPL *session, const char *name, int hex_val; const char *hex_itr; - for (ts.val = 0, hex_itr = cval->str, len = cval->len; len > 0; --len) { + *timestamp = 0; + + if (cval->len == 0) + return (0); + + /* Protect against unexpectedly long hex strings. */ + if (cval->len > 2 * sizeof(wt_timestamp_t)) + WT_RET_MSG(session, EINVAL, + "%s timestamp too long '%.*s'", + name, (int)cval->len, cval->str); + + for (ts = 0, hex_itr = cval->str, len = cval->len; len > 0; --len) { if ((size_t)*hex_itr < WT_ELEMENTS(hextable)) hex_val = hextable[(size_t)*hex_itr++]; else @@ -137,47 +107,10 @@ __wt_txn_parse_timestamp_raw(WT_SESSION_IMPL *session, const char *name, WT_RET_MSG(session, EINVAL, "Failed to parse %s timestamp '%.*s'", name, (int)cval->len, cval->str); - ts.val = (ts.val << 4) | (uint64_t)hex_val; + ts = (ts << 4) | (uint64_t)hex_val; } - __wt_timestamp_set(timestamp, &ts); - } -#else - { - WT_DECL_RET; - WT_ITEM ts; - wt_timestamp_t tsbuf; - size_t hexlen; - const char *hexts; - char padbuf[2 * WT_TIMESTAMP_SIZE + 1]; - - /* - * The decoding function assumes it is decoding data produced by dump - * and so requires an even number of hex digits. - */ - if ((cval->len & 1) == 0) { - hexts = cval->str; - hexlen = cval->len; - } else { - padbuf[0] = '0'; - memcpy(padbuf + 1, cval->str, cval->len); - hexts = padbuf; - hexlen = cval->len + 1; - } - - /* Avoid memory allocation to decode timestamps. */ - ts.data = ts.mem = tsbuf.ts; - ts.memsize = sizeof(tsbuf.ts); - - if ((ret = __wt_nhex_to_raw(session, hexts, hexlen, &ts)) != 0) - WT_RET_MSG(session, ret, "Failed to parse %s timestamp '%.*s'", - name, (int)cval->len, cval->str); - WT_ASSERT(session, ts.size <= WT_TIMESTAMP_SIZE); + *timestamp = ts; - /* Copy the raw value to the end of the timestamp. */ - memcpy(timestamp->ts + WT_TIMESTAMP_SIZE - ts.size, - ts.data, ts.size); - } -#endif return (0); } @@ -190,7 +123,7 @@ __wt_txn_parse_timestamp(WT_SESSION_IMPL *session, const char *name, wt_timestamp_t *timestamp, WT_CONFIG_ITEM *cval) { WT_RET(__wt_txn_parse_timestamp_raw(session, name, timestamp, cval)); - if (cval->len != 0 && __wt_timestamp_iszero(timestamp)) + if (cval->len != 0 && *timestamp == 0) WT_RET_MSG(session, EINVAL, "Failed to parse %s timestamp '%.*s': zero not permitted", name, (int)cval->len, cval->str); @@ -207,9 +140,9 @@ __txn_get_pinned_timestamp( WT_SESSION_IMPL *session, wt_timestamp_t *tsp, uint32_t flags) { WT_CONNECTION_IMPL *conn; - WT_DECL_TIMESTAMP(tmp_ts) WT_TXN *txn; WT_TXN_GLOBAL *txn_global; + wt_timestamp_t tmp_ts; bool include_oldest, txn_has_write_lock; conn = S2C(session); @@ -222,18 +155,14 @@ __txn_get_pinned_timestamp( if (!txn_has_write_lock) __wt_readlock(session, &txn_global->rwlock); - if (include_oldest) - __wt_timestamp_set(&tmp_ts, &txn_global->oldest_timestamp); - else - __wt_timestamp_set_zero(&tmp_ts); + + tmp_ts = include_oldest ? txn_global->oldest_timestamp : 0; /* Check for a running checkpoint */ if (LF_ISSET(WT_TXN_TS_INCLUDE_CKPT) && - !__wt_timestamp_iszero(&txn_global->checkpoint_timestamp) && - (__wt_timestamp_iszero(&tmp_ts) || - __wt_timestamp_cmp(&txn_global->checkpoint_timestamp, &tmp_ts) < - 0)) - __wt_timestamp_set(&tmp_ts, &txn_global->checkpoint_timestamp); + txn_global->checkpoint_timestamp != 0 && + (tmp_ts == 0 || txn_global->checkpoint_timestamp < tmp_ts)) + tmp_ts = txn_global->checkpoint_timestamp; if (!txn_has_write_lock) __wt_readunlock(session, &txn_global->rwlock); @@ -249,9 +178,8 @@ __txn_get_pinned_timestamp( * A zero timestamp is possible here only when the oldest * timestamp is not accounted for. */ - if (__wt_timestamp_iszero(&tmp_ts) || - __wt_timestamp_cmp(&txn->read_timestamp, &tmp_ts) < 0) - __wt_timestamp_set(&tmp_ts, &txn->read_timestamp); + if (tmp_ts == 0 || txn->read_timestamp < tmp_ts) + tmp_ts = txn->read_timestamp; /* * We break on the first active txn on the list. */ @@ -259,9 +187,9 @@ __txn_get_pinned_timestamp( } __wt_readunlock(session, &txn_global->read_timestamp_rwlock); - if (!include_oldest && __wt_timestamp_iszero(&tmp_ts)) + if (!include_oldest && tmp_ts == 0) return (WT_NOTFOUND); - __wt_timestamp_set(tsp, &tmp_ts); + *tsp = tmp_ts; return (0); } @@ -288,9 +216,8 @@ __txn_global_query_timestamp( if (WT_STRING_MATCH("all_committed", cval.str, cval.len)) { if (!txn_global->has_commit_timestamp) return (WT_NOTFOUND); - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - __wt_timestamp_set(&ts, &txn_global->commit_timestamp)); - WT_ASSERT(session, !__wt_timestamp_iszero(&ts)); + ts = txn_global->commit_timestamp; + WT_ASSERT(session, ts != 0); /* Skip the lock if there are no running transactions. */ if (TAILQ_EMPTY(&txn_global->commit_timestamph)) @@ -303,24 +230,22 @@ __txn_global_query_timestamp( if (txn->clear_commit_q) continue; - __wt_timestamp_set( - &tmpts, &txn->first_commit_timestamp); - WT_ASSERT(session, !__wt_timestamp_iszero(&tmpts)); - __wt_timestamp_subone(&tmpts); + tmpts = txn->first_commit_timestamp; + WT_ASSERT(session, tmpts != 0); + tmpts -= 1; - if (__wt_timestamp_cmp(&tmpts, &ts) < 0) - __wt_timestamp_set(&ts, &tmpts); + if (tmpts < ts) + ts = tmpts; break; } __wt_readunlock(session, &txn_global->commit_timestamp_rwlock); } else if (WT_STRING_MATCH("last_checkpoint", cval.str, cval.len)) /* Read-only value forever. No lock needed. */ - __wt_timestamp_set(&ts, &txn_global->last_ckpt_timestamp); + ts = txn_global->last_ckpt_timestamp; else if (WT_STRING_MATCH("oldest", cval.str, cval.len)) { if (!txn_global->has_oldest_timestamp) return (WT_NOTFOUND); - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - __wt_timestamp_set(&ts, &txn_global->oldest_timestamp)); + ts = txn_global->oldest_timestamp; } else if (WT_STRING_MATCH("oldest_reader", cval.str, cval.len)) WT_RET(__txn_get_pinned_timestamp( session, &ts, WT_TXN_TS_INCLUDE_CKPT)); @@ -329,17 +254,16 @@ __txn_global_query_timestamp( WT_TXN_TS_INCLUDE_CKPT | WT_TXN_TS_INCLUDE_OLDEST)); else if (WT_STRING_MATCH("recovery", cval.str, cval.len)) /* Read-only value forever. No lock needed. */ - __wt_timestamp_set(&ts, &txn_global->recovery_timestamp); + ts = txn_global->recovery_timestamp; else if (WT_STRING_MATCH("stable", cval.str, cval.len)) { if (!txn_global->has_stable_timestamp) return (WT_NOTFOUND); - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - __wt_timestamp_set(&ts, &txn_global->stable_timestamp)); + ts = txn_global->stable_timestamp; } else WT_RET_MSG(session, EINVAL, "unknown timestamp query %.*s", (int)cval.len, cval.str); -done: __wt_timestamp_set(tsp, &ts); +done: *tsp = ts; return (0); } @@ -362,20 +286,19 @@ __txn_query_timestamp( WT_RET(__wt_config_gets(session, cfg, "get", &cval)); if (WT_STRING_MATCH("commit", cval.str, cval.len)) - __wt_timestamp_set(tsp, &txn->commit_timestamp); + *tsp = txn->commit_timestamp; else if (WT_STRING_MATCH("first_commit", cval.str, cval.len)) - __wt_timestamp_set(tsp, &txn->first_commit_timestamp); + *tsp = txn->first_commit_timestamp; else if (WT_STRING_MATCH("prepare", cval.str, cval.len)) - __wt_timestamp_set(tsp, &txn->prepare_timestamp); + *tsp = txn->prepare_timestamp; else if (WT_STRING_MATCH("read", cval.str, cval.len)) - __wt_timestamp_set(tsp, &txn->read_timestamp); + *tsp = txn->read_timestamp; else WT_RET_MSG(session, EINVAL, "unknown timestamp query %.*s", (int)cval.len, cval.str); return (0); } -#endif /* * __wt_txn_query_timestamp -- @@ -386,7 +309,6 @@ int __wt_txn_query_timestamp(WT_SESSION_IMPL *session, char *hex_timestamp, const char *cfg[], bool global_txn) { -#ifdef HAVE_TIMESTAMPS wt_timestamp_t ts; if (global_txn) @@ -394,18 +316,10 @@ __wt_txn_query_timestamp(WT_SESSION_IMPL *session, else WT_RET(__txn_query_timestamp(session, &ts, cfg)); - return (__wt_timestamp_to_hex_string(session, hex_timestamp, &ts)); -#else - WT_UNUSED(hex_timestamp); - WT_UNUSED(cfg); - WT_UNUSED(global_txn); - - WT_RET_MSG(session, ENOTSUP, - "requires a version of WiredTiger built with timestamp support"); -#endif + __wt_timestamp_to_hex_string(hex_timestamp, ts); + return (0); } -#ifdef HAVE_TIMESTAMPS /* * __wt_txn_update_pinned_timestamp -- * Update the pinned timestamp (the oldest timestamp that has to be @@ -430,12 +344,9 @@ __wt_txn_update_pinned_timestamp(WT_SESSION_IMPL *session, bool force) return (ret == WT_NOTFOUND ? 0 : ret); if (txn_global->has_pinned_timestamp && !force) { - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - __wt_timestamp_set( - &last_pinned_timestamp, &txn_global->pinned_timestamp)); + last_pinned_timestamp = txn_global->pinned_timestamp; - if (__wt_timestamp_cmp( - &pinned_timestamp, &last_pinned_timestamp) <= 0) + if (pinned_timestamp <= last_pinned_timestamp) return (0); } @@ -450,25 +361,23 @@ __wt_txn_update_pinned_timestamp(WT_SESSION_IMPL *session, bool force) return (ret == WT_NOTFOUND ? 0 : ret); } - if (!txn_global->has_pinned_timestamp || force || __wt_timestamp_cmp( - &txn_global->pinned_timestamp, &pinned_timestamp) < 0) { - __wt_timestamp_set( - &txn_global->pinned_timestamp, &pinned_timestamp); + if (!txn_global->has_pinned_timestamp || force || + txn_global->pinned_timestamp < pinned_timestamp) { + txn_global->pinned_timestamp = pinned_timestamp; txn_global->has_pinned_timestamp = true; - txn_global->oldest_is_pinned = __wt_timestamp_cmp( - &txn_global->pinned_timestamp, - &txn_global->oldest_timestamp) == 0; - txn_global->stable_is_pinned = __wt_timestamp_cmp( - &txn_global->pinned_timestamp, - &txn_global->stable_timestamp) == 0; + txn_global->oldest_is_pinned = + txn_global->pinned_timestamp == + txn_global->oldest_timestamp; + txn_global->stable_is_pinned = + txn_global->pinned_timestamp == + txn_global->stable_timestamp; __wt_verbose_timestamp(session, - &pinned_timestamp, "Updated pinned timestamp"); + pinned_timestamp, "Updated pinned timestamp"); } __wt_writeunlock(session, &txn_global->rwlock); return (0); } -#endif /* * __wt_txn_global_set_timestamp -- @@ -478,7 +387,14 @@ int __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) { WT_CONFIG_ITEM commit_cval, oldest_cval, stable_cval; - bool has_commit, has_oldest, has_stable; + WT_CONFIG_ITEM cval; + WT_TXN_GLOBAL *txn_global; + wt_timestamp_t commit_ts, oldest_ts, stable_ts; + wt_timestamp_t last_oldest_ts, last_stable_ts; + char hex_timestamp[2][WT_TS_HEX_SIZE]; + bool force, has_commit, has_oldest, has_stable; + + txn_global = &S2C(session)->txn_global; WT_STAT_CONN_INCR(session, txn_set_ts); WT_RET(__wt_config_gets_def(session, @@ -503,17 +419,6 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) if (!has_commit && !has_oldest && !has_stable) return (0); -#ifdef HAVE_TIMESTAMPS - { - WT_CONFIG_ITEM cval; - WT_TXN_GLOBAL *txn_global; - wt_timestamp_t commit_ts, oldest_ts, stable_ts; - wt_timestamp_t last_oldest_ts, last_stable_ts; - char hex_timestamp[2][2 * WT_TIMESTAMP_SIZE + 1]; - bool force; - - txn_global = &S2C(session)->txn_global; - /* * Parsing will initialize the timestamp to zero even if * it is not configured. @@ -534,8 +439,8 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) __wt_readlock(session, &txn_global->rwlock); - __wt_timestamp_set(&last_oldest_ts, &txn_global->oldest_timestamp); - __wt_timestamp_set(&last_stable_ts, &txn_global->stable_timestamp); + last_oldest_ts = txn_global->oldest_timestamp; + last_stable_ts = txn_global->stable_timestamp; /* * First do error checking on the timestamp values. The @@ -545,35 +450,31 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) * setting both then compare the passed in values. */ if (!has_commit && txn_global->has_commit_timestamp) - __wt_timestamp_set(&commit_ts, &txn_global->commit_timestamp); + commit_ts = txn_global->commit_timestamp; if (!has_oldest && txn_global->has_oldest_timestamp) - __wt_timestamp_set(&oldest_ts, &last_oldest_ts); + oldest_ts = last_oldest_ts; if (!has_stable && txn_global->has_stable_timestamp) - __wt_timestamp_set(&stable_ts, &last_stable_ts); + stable_ts = last_stable_ts; /* * If a commit timestamp was supplied, check that it is no older than * either the stable timestamp or the oldest timestamp. */ - if (has_commit && (has_oldest || txn_global->has_oldest_timestamp) && - __wt_timestamp_cmp(&oldest_ts, &commit_ts) > 0) { + if (has_commit && (has_oldest || + txn_global->has_oldest_timestamp) && oldest_ts > commit_ts) { __wt_readunlock(session, &txn_global->rwlock); - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp[0], &oldest_ts)); - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp[1], &commit_ts)); + __wt_timestamp_to_hex_string(hex_timestamp[0], oldest_ts); + __wt_timestamp_to_hex_string(hex_timestamp[1], commit_ts); WT_RET_MSG(session, EINVAL, "set_timestamp: oldest timestamp %s must not be later than " "commit timestamp %s", hex_timestamp[0], hex_timestamp[1]); } - if (has_commit && (has_stable || txn_global->has_stable_timestamp) && - __wt_timestamp_cmp(&stable_ts, &commit_ts) > 0) { + if (has_commit && (has_stable || + txn_global->has_stable_timestamp) && stable_ts > commit_ts) { __wt_readunlock(session, &txn_global->rwlock); - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp[0], &stable_ts)); - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp[1], &commit_ts)); + __wt_timestamp_to_hex_string(hex_timestamp[0], stable_ts); + __wt_timestamp_to_hex_string(hex_timestamp[1], commit_ts); WT_RET_MSG(session, EINVAL, "set_timestamp: stable timestamp %s must not be later than " "commit timestamp %s", hex_timestamp[0], hex_timestamp[1]); @@ -585,13 +486,11 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) */ if ((has_oldest || has_stable) && (has_oldest || txn_global->has_oldest_timestamp) && - (has_stable || txn_global->has_stable_timestamp) && - __wt_timestamp_cmp(&oldest_ts, &stable_ts) > 0) { + (has_stable || + txn_global->has_stable_timestamp) && oldest_ts > stable_ts) { __wt_readunlock(session, &txn_global->rwlock); - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp[0], &oldest_ts)); - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp[1], &stable_ts)); + __wt_timestamp_to_hex_string(hex_timestamp[0], oldest_ts); + __wt_timestamp_to_hex_string(hex_timestamp[1], stable_ts); WT_RET_MSG(session, EINVAL, "set_timestamp: oldest timestamp %s must not be later than " "stable timestamp %s", hex_timestamp[0], hex_timestamp[1]); @@ -600,12 +499,12 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) __wt_readunlock(session, &txn_global->rwlock); /* Check if we are actually updating anything. */ - if (has_oldest && txn_global->has_oldest_timestamp && - __wt_timestamp_cmp(&oldest_ts, &last_oldest_ts) <= 0) + if (has_oldest && + txn_global->has_oldest_timestamp && oldest_ts <= last_oldest_ts) has_oldest = false; - if (has_stable && txn_global->has_stable_timestamp && - __wt_timestamp_cmp(&stable_ts, &last_stable_ts) <= 0) + if (has_stable && + txn_global->has_stable_timestamp && stable_ts <= last_stable_ts) has_stable = false; if (!has_commit && !has_oldest && !has_stable) @@ -623,47 +522,40 @@ set: __wt_writelock(session, &txn_global->rwlock); * assigned timestamps). */ if (has_commit) { - __wt_timestamp_set(&txn_global->commit_timestamp, &commit_ts); + txn_global->commit_timestamp = commit_ts; txn_global->has_commit_timestamp = true; WT_STAT_CONN_INCR(session, txn_set_ts_commit_upd); - __wt_verbose_timestamp(session, &commit_ts, + __wt_verbose_timestamp(session, commit_ts, "Updated global commit timestamp"); } - if (has_oldest && (!txn_global->has_oldest_timestamp || - force || __wt_timestamp_cmp( - &oldest_ts, &txn_global->oldest_timestamp) > 0)) { - __wt_timestamp_set(&txn_global->oldest_timestamp, &oldest_ts); + if (has_oldest && (!txn_global->has_oldest_timestamp || force || + oldest_ts > txn_global->oldest_timestamp)) { + txn_global->oldest_timestamp = oldest_ts; WT_STAT_CONN_INCR(session, txn_set_ts_oldest_upd); txn_global->has_oldest_timestamp = true; txn_global->oldest_is_pinned = false; - __wt_verbose_timestamp(session, &oldest_ts, + __wt_verbose_timestamp(session, oldest_ts, "Updated global oldest timestamp"); } - if (has_stable && (!txn_global->has_stable_timestamp || - force || __wt_timestamp_cmp( - &stable_ts, &txn_global->stable_timestamp) > 0)) { - __wt_timestamp_set(&txn_global->stable_timestamp, &stable_ts); + if (has_stable && (!txn_global->has_stable_timestamp || force || + stable_ts > txn_global->stable_timestamp)) { + txn_global->stable_timestamp = stable_ts; WT_STAT_CONN_INCR(session, txn_set_ts_stable_upd); txn_global->has_stable_timestamp = true; txn_global->stable_is_pinned = false; - __wt_verbose_timestamp(session, &stable_ts, + __wt_verbose_timestamp(session, stable_ts, "Updated global stable timestamp"); } __wt_writeunlock(session, &txn_global->rwlock); if (has_oldest || has_stable) WT_RET(__wt_txn_update_pinned_timestamp(session, force)); - } + return (0); -#else - WT_RET_MSG(session, ENOTSUP, "set_timestamp requires a " - "version of WiredTiger built with timestamp support"); -#endif } -#ifdef HAVE_TIMESTAMPS /* * __wt_timestamp_validate -- * Validate a timestamp to be not older than the global oldest and global @@ -672,39 +564,37 @@ set: __wt_writelock(session, &txn_global->rwlock); */ int __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, - wt_timestamp_t *ts, WT_CONFIG_ITEM *cval) + wt_timestamp_t ts, WT_CONFIG_ITEM *cval) { WT_TXN *txn = &session->txn; WT_TXN_GLOBAL *txn_global = &S2C(session)->txn_global; wt_timestamp_t oldest_ts, stable_ts; - char hex_timestamp[2 * WT_TIMESTAMP_SIZE + 1]; + char hex_timestamp[WT_TS_HEX_SIZE]; bool has_oldest_ts, has_stable_ts; /* * Added this redundant initialization to circumvent build failure. */ - __wt_timestamp_set_zero(&oldest_ts); - __wt_timestamp_set_zero(&stable_ts); + oldest_ts = stable_ts = 0; /* * Compare against the oldest and the stable timestamp. Return an error * if the given timestamp is older than oldest and/or stable timestamp. */ - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - if ((has_oldest_ts = txn_global->has_oldest_timestamp)) - __wt_timestamp_set(&oldest_ts, &txn_global->oldest_timestamp); - if ((has_stable_ts = txn_global->has_stable_timestamp)) - __wt_timestamp_set(&stable_ts, &txn_global->stable_timestamp)); - - if (has_oldest_ts && __wt_timestamp_cmp(ts, &oldest_ts) < 0) { - WT_RET(__wt_timestamp_to_hex_string(session, hex_timestamp, - &oldest_ts)); + has_oldest_ts = txn_global->has_oldest_timestamp; + if (has_oldest_ts) + oldest_ts = txn_global->oldest_timestamp; + has_stable_ts = txn_global->has_stable_timestamp; + if (has_stable_ts) + stable_ts = txn_global->stable_timestamp; + + if (has_oldest_ts && ts < oldest_ts) { + __wt_timestamp_to_hex_string(hex_timestamp, oldest_ts); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than oldest timestamp %s", name, (int)cval->len, cval->str, hex_timestamp); } - if (has_stable_ts && __wt_timestamp_cmp(ts, &stable_ts) < 0) { - WT_RET(__wt_timestamp_to_hex_string(session, hex_timestamp, - &stable_ts)); + if (has_stable_ts && ts < stable_ts) { + __wt_timestamp_to_hex_string(hex_timestamp, stable_ts); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than stable timestamp %s", name, (int)cval->len, cval->str, hex_timestamp); @@ -716,9 +606,9 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, * commit timestamp. */ if (F_ISSET(txn, WT_TXN_HAS_TS_COMMIT) && - __wt_timestamp_cmp(ts, &txn->first_commit_timestamp) < 0) { - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp, &txn->first_commit_timestamp)); + ts < txn->first_commit_timestamp) { + __wt_timestamp_to_hex_string( + hex_timestamp, txn->first_commit_timestamp); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than the first " "commit timestamp %s for this transaction", @@ -730,10 +620,9 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, * Return an error if the given timestamp is older than the prepare * timestamp. */ - if (F_ISSET(txn, WT_TXN_PREPARE) && - __wt_timestamp_cmp(ts, &txn->prepare_timestamp) < 0) { - WT_RET(__wt_timestamp_to_hex_string( - session, hex_timestamp, &txn->prepare_timestamp)); + if (F_ISSET(txn, WT_TXN_PREPARE) && ts < txn->prepare_timestamp) { + __wt_timestamp_to_hex_string( + hex_timestamp, txn->prepare_timestamp); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than the prepare timestamp %s " "for this transaction", @@ -742,7 +631,6 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, return (0); } -#endif /* * __wt_txn_set_timestamp -- @@ -753,24 +641,20 @@ __wt_txn_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) { WT_CONFIG_ITEM cval; WT_DECL_RET; + WT_TXN *txn; + wt_timestamp_t ts; + + txn = &session->txn; /* Look for a commit timestamp. */ ret = __wt_config_gets_def(session, cfg, "commit_timestamp", 0, &cval); WT_RET_NOTFOUND_OK(ret); if (ret == 0 && cval.len != 0) { -#ifdef HAVE_TIMESTAMPS - WT_TXN *txn = &session->txn; - wt_timestamp_t ts; - WT_TRET(__wt_txn_context_check(session, true)); WT_RET(__wt_txn_parse_timestamp(session, "commit", &ts, &cval)); - WT_RET(__wt_timestamp_validate(session, "commit", &ts, &cval)); - __wt_timestamp_set(&txn->commit_timestamp, &ts); + WT_RET(__wt_timestamp_validate(session, "commit", ts, &cval)); + txn->commit_timestamp = ts; __wt_txn_set_commit_timestamp(session); -#else - WT_RET_MSG(session, ENOTSUP, "commit_timestamp requires a " - "version of WiredTiger built with timestamp support"); -#endif } else /* * We allow setting the commit timestamp after a prepare @@ -793,18 +677,16 @@ __wt_txn_parse_prepare_timestamp( WT_SESSION_IMPL *session, const char *cfg[], wt_timestamp_t *timestamp) { WT_CONFIG_ITEM cval; + WT_TXN *prev; + WT_TXN_GLOBAL *txn_global; + wt_timestamp_t oldest_ts; + char hex_timestamp[WT_TS_HEX_SIZE]; + + txn_global = &S2C(session)->txn_global; WT_RET(__wt_config_gets_def(session, cfg, "prepare_timestamp", 0, &cval)); if (cval.len > 0) { -#ifdef HAVE_TIMESTAMPS - WT_TXN *prev; - WT_TXN_GLOBAL *txn_global; - wt_timestamp_t oldest_ts; - char hex_timestamp[2 * WT_TIMESTAMP_SIZE + 1]; - - txn_global = &S2C(session)->txn_global; - if (F_ISSET(&session->txn, WT_TXN_HAS_TS_COMMIT)) WT_RET_MSG(session, EINVAL, "commit timestamp should not have been set before " @@ -829,12 +711,11 @@ __wt_txn_parse_prepare_timestamp( prev, __wt_txn_rts_qh, read_timestampq); continue; } - if (__wt_timestamp_cmp( - &prev->read_timestamp, timestamp) >= 0) { + if (prev->read_timestamp >= *timestamp) { __wt_readunlock(session, &txn_global->read_timestamp_rwlock); - WT_RET(__wt_timestamp_to_hex_string(session, - hex_timestamp, &prev->read_timestamp)); + __wt_timestamp_to_hex_string( + hex_timestamp, prev->read_timestamp); WT_RET_MSG(session, EINVAL, "prepare timestamp %.*s not later than " "an active read timestamp %s ", @@ -849,24 +730,17 @@ __wt_txn_parse_prepare_timestamp( * be older than oldest timestamp. */ if (prev == NULL) { - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - __wt_timestamp_set(&oldest_ts, - &txn_global->oldest_timestamp)); + oldest_ts = txn_global->oldest_timestamp; - if (__wt_timestamp_cmp(timestamp, &oldest_ts) < 0) { - WT_RET(__wt_timestamp_to_hex_string(session, - hex_timestamp, &oldest_ts)); + if (*timestamp < oldest_ts) { + __wt_timestamp_to_hex_string( + hex_timestamp, oldest_ts); WT_RET_MSG(session, EINVAL, "prepare timestamp %.*s is older than the " "oldest timestamp %s ", (int)cval.len, cval.str, hex_timestamp); } } -#else - WT_UNUSED(timestamp); - WT_RET_MSG(session, EINVAL, "prepare_timestamp requires a " - "version of WiredTiger built with timestamp support"); -#endif } else WT_RET_MSG(session, EINVAL, "prepare timestamp is required"); @@ -881,17 +755,15 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) { WT_CONFIG_ITEM cval; WT_TXN *txn; + WT_TXN_GLOBAL *txn_global; + wt_timestamp_t ts; + char hex_timestamp[2][WT_TS_HEX_SIZE]; + bool round_to_oldest; txn = &session->txn; WT_RET(__wt_config_gets_def(session, cfg, "read_timestamp", 0, &cval)); if (cval.len > 0) { -#ifdef HAVE_TIMESTAMPS - wt_timestamp_t ts; - WT_TXN_GLOBAL *txn_global; - char hex_timestamp[2][2 * WT_TIMESTAMP_SIZE + 1]; - bool round_to_oldest; - txn_global = &S2C(session)->txn_global; WT_RET(__wt_txn_parse_timestamp(session, "read", &ts, &cval)); @@ -920,21 +792,19 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) * avoid a race between checking and setting transaction * timestamp. */ - WT_RET(__wt_timestamp_to_hex_string(session, - hex_timestamp[0], &ts)); + __wt_timestamp_to_hex_string(hex_timestamp[0], ts); __wt_readlock(session, &txn_global->rwlock); - if (__wt_timestamp_cmp( - &ts, &txn_global->oldest_timestamp) < 0) { - WT_RET(__wt_timestamp_to_hex_string(session, - hex_timestamp[1], &txn_global->oldest_timestamp)); + if (ts < txn_global->oldest_timestamp) { + __wt_timestamp_to_hex_string( + hex_timestamp[1], txn_global->oldest_timestamp); /* * If given read timestamp is earlier than oldest * timestamp then round the read timestamp to * oldest timestamp. */ if (round_to_oldest) - __wt_timestamp_set(&txn->read_timestamp, - &txn_global->oldest_timestamp); + txn->read_timestamp = + txn_global->oldest_timestamp; else { __wt_readunlock(session, &txn_global->rwlock); WT_RET_MSG(session, EINVAL, "read timestamp " @@ -942,7 +812,7 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) hex_timestamp[0], hex_timestamp[1]); } } else { - __wt_timestamp_set(&txn->read_timestamp, &ts); + txn->read_timestamp = ts; /* * Reset to avoid a verbose message as read * timestamp is not rounded to oldest timestamp. @@ -969,18 +839,11 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) */ if (F_ISSET(txn, WT_TXN_RUNNING)) __wt_txn_get_snapshot(session); - -#else - WT_UNUSED(txn); - WT_RET_MSG(session, EINVAL, "read_timestamp requires a " - "version of WiredTiger built with timestamp support"); -#endif } return (0); } -#ifdef HAVE_TIMESTAMPS /* * __wt_txn_set_commit_timestamp -- * Publish a transaction's commit timestamp. @@ -1004,7 +867,7 @@ __wt_txn_set_commit_timestamp(WT_SESSION_IMPL *session) * transaction is running) into the first_commit_timestamp, which is * fixed. */ - __wt_timestamp_set(&ts, &txn->commit_timestamp); + ts = txn->commit_timestamp; __wt_writelock(session, &txn_global->commit_timestamp_rwlock); /* @@ -1052,8 +915,7 @@ __wt_txn_set_commit_timestamp(WT_SESSION_IMPL *session) */ qtxn = TAILQ_LAST( &txn_global->commit_timestamph, __wt_txn_cts_qh); - while (qtxn != NULL && __wt_timestamp_cmp( - &qtxn->first_commit_timestamp, &ts) > 0) { + while (qtxn != NULL && qtxn->first_commit_timestamp > ts) { ++walked; qtxn = TAILQ_PREV( qtxn, __wt_txn_cts_qh, commit_timestampq); @@ -1067,7 +929,7 @@ __wt_txn_set_commit_timestamp(WT_SESSION_IMPL *session) qtxn, txn, commit_timestampq); WT_STAT_CONN_INCRV(session, txn_commit_queue_walked, walked); } - __wt_timestamp_set(&txn->first_commit_timestamp, &ts); + txn->first_commit_timestamp = ts; ++txn_global->commit_timestampq_len; WT_STAT_CONN_INCR(session, txn_commit_queue_inserts); txn->clear_commit_q = false; @@ -1162,8 +1024,7 @@ __wt_txn_set_read_timestamp(WT_SESSION_IMPL *session) qtxn = TAILQ_LAST( &txn_global->read_timestamph, __wt_txn_rts_qh); while (qtxn != NULL && - __wt_timestamp_cmp(&qtxn->read_timestamp, - &txn->read_timestamp) > 0) { + qtxn->read_timestamp > txn->read_timestamp) { ++walked; qtxn = TAILQ_PREV( qtxn, __wt_txn_rts_qh, read_timestampq); @@ -1209,10 +1070,8 @@ __wt_txn_clear_read_timestamp(WT_SESSION_IMPL *session) wt_timestamp_t pinned_ts; txn_global = &S2C(session)->txn_global; - WT_WITH_TIMESTAMP_READLOCK(session, &txn_global->rwlock, - __wt_timestamp_set(&pinned_ts, &txn_global->pinned_timestamp)); - WT_ASSERT(session, - __wt_timestamp_cmp(&txn->read_timestamp, &pinned_ts) >= 0); + pinned_ts = txn_global->pinned_timestamp; + WT_ASSERT(session, txn->read_timestamp >= pinned_ts); } #endif flags = txn->flags; @@ -1226,7 +1085,6 @@ __wt_txn_clear_read_timestamp(WT_SESSION_IMPL *session) WT_PUBLISH(txn->clear_read_q, true); WT_PUBLISH(txn->flags, flags); } -#endif /* * __wt_txn_clear_timestamp_queues -- |