diff options
author | Luke Chen <luke.chen@mongodb.com> | 2019-01-21 12:51:15 +1100 |
---|---|---|
committer | Luke Chen <luke.chen@mongodb.com> | 2019-01-21 12:51:15 +1100 |
commit | 6efcd5e6021d8cbf60c579dd1fbe898d5573f522 (patch) | |
tree | 852b9abc7ddb963202c6df7a391f081bd761eef3 /src/third_party/wiredtiger/src/txn/txn_timestamp.c | |
parent | 9cf00022b936cdb3c2234235d5aaa6be7ef6146a (diff) | |
download | mongo-6efcd5e6021d8cbf60c579dd1fbe898d5573f522.tar.gz |
Import wiredtiger: 1e7f5178b3e28d1f22d3f23cb632ba45b56d0091 from branch mongodb-4.2
ref: 2183883231..1e7f5178b3
for: 4.1.8
WT-4491 Change WT data format to include timestamps in internal page address cells
WT-4520 Fix prepare transactions fallout during cursor navigation
WT-4528 Retry Windows functions on access denied
Diffstat (limited to 'src/third_party/wiredtiger/src/txn/txn_timestamp.c')
-rw-r--r-- | src/third_party/wiredtiger/src/txn/txn_timestamp.c | 118 |
1 files changed, 74 insertions, 44 deletions
diff --git a/src/third_party/wiredtiger/src/txn/txn_timestamp.c b/src/third_party/wiredtiger/src/txn/txn_timestamp.c index 3adac2dca63..66ec0536d2b 100644 --- a/src/third_party/wiredtiger/src/txn/txn_timestamp.c +++ b/src/third_party/wiredtiger/src/txn/txn_timestamp.c @@ -15,11 +15,23 @@ /* AUTOMATIC FLAG VALUE GENERATION STOP */ /* + * __wt_timestamp_to_string -- + * Convert a timestamp to the MongoDB string representation. + */ +void +__wt_timestamp_to_string(wt_timestamp_t ts, char *ts_string, size_t len) +{ + WT_IGNORE_RET(__wt_snprintf(ts_string, len, + "(%" PRIu32 ",%" PRIu32 ")", + (uint32_t)((ts >> 32) & 0xffffffff), (uint32_t)(ts & 0xffffffff))); +} + +/* * __wt_timestamp_to_hex_string -- * Convert a timestamp to hex string representation. */ void -__wt_timestamp_to_hex_string(char *hex_timestamp, wt_timestamp_t ts) +__wt_timestamp_to_hex_string(wt_timestamp_t ts, char *hex_timestamp) { char *p, v; @@ -28,6 +40,10 @@ __wt_timestamp_to_hex_string(char *hex_timestamp, wt_timestamp_t ts) hex_timestamp[1] = '\0'; return; } + if (ts == WT_TS_MAX) { + (void)strcpy(hex_timestamp, "ffffffffffffffff"); + return; + } for (p = hex_timestamp; ts != 0; ts >>= 4) *p++ = (char)__wt_hex((u_char)(ts & 0x0f)); @@ -49,14 +65,14 @@ void __wt_verbose_timestamp( WT_SESSION_IMPL *session, wt_timestamp_t ts, const char *msg) { - char timestamp_buf[WT_TS_HEX_SIZE]; + char ts_string[WT_TS_INT_STRING_SIZE]; if (!WT_VERBOSE_ISSET(session, WT_VERB_TIMESTAMP)) return; - __wt_timestamp_to_hex_string(timestamp_buf, ts); + __wt_timestamp_to_string(ts, ts_string, sizeof(ts_string)); __wt_verbose(session, - WT_VERB_TIMESTAMP, "Timestamp %s : %s", timestamp_buf, msg); + WT_VERB_TIMESTAMP, "Timestamp %s : %s", ts_string, msg); } /* @@ -316,7 +332,7 @@ __wt_txn_query_timestamp(WT_SESSION_IMPL *session, else WT_RET(__txn_query_timestamp(session, &ts, cfg)); - __wt_timestamp_to_hex_string(hex_timestamp, ts); + __wt_timestamp_to_hex_string(ts, hex_timestamp); return (0); } @@ -391,7 +407,7 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) 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]; + char ts_string[2][WT_TS_INT_STRING_SIZE]; bool force, has_commit, has_oldest, has_stable; txn_global = &S2C(session)->txn_global; @@ -463,21 +479,25 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) if (has_commit && (has_oldest || txn_global->has_oldest_timestamp) && oldest_ts > commit_ts) { __wt_readunlock(session, &txn_global->rwlock); - __wt_timestamp_to_hex_string(hex_timestamp[0], oldest_ts); - __wt_timestamp_to_hex_string(hex_timestamp[1], commit_ts); + __wt_timestamp_to_string( + oldest_ts, ts_string[0], sizeof(ts_string[0])); + __wt_timestamp_to_string( + commit_ts, ts_string[1], sizeof(ts_string[1])); WT_RET_MSG(session, EINVAL, "set_timestamp: oldest timestamp %s must not be later than " - "commit timestamp %s", hex_timestamp[0], hex_timestamp[1]); + "commit timestamp %s", ts_string[0], ts_string[1]); } if (has_commit && (has_stable || txn_global->has_stable_timestamp) && stable_ts > commit_ts) { __wt_readunlock(session, &txn_global->rwlock); - __wt_timestamp_to_hex_string(hex_timestamp[0], stable_ts); - __wt_timestamp_to_hex_string(hex_timestamp[1], commit_ts); + __wt_timestamp_to_string( + stable_ts, ts_string[0], sizeof(ts_string[0])); + __wt_timestamp_to_string( + commit_ts, ts_string[1], sizeof(ts_string[1])); WT_RET_MSG(session, EINVAL, "set_timestamp: stable timestamp %s must not be later than " - "commit timestamp %s", hex_timestamp[0], hex_timestamp[1]); + "commit timestamp %s", ts_string[0], ts_string[1]); } /* @@ -489,11 +509,13 @@ __wt_txn_global_set_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) (has_stable || txn_global->has_stable_timestamp) && oldest_ts > stable_ts) { __wt_readunlock(session, &txn_global->rwlock); - __wt_timestamp_to_hex_string(hex_timestamp[0], oldest_ts); - __wt_timestamp_to_hex_string(hex_timestamp[1], stable_ts); + __wt_timestamp_to_string( + oldest_ts, ts_string[0], sizeof(ts_string[0])); + __wt_timestamp_to_string( + stable_ts, ts_string[1], sizeof(ts_string[1])); WT_RET_MSG(session, EINVAL, "set_timestamp: oldest timestamp %s must not be later than " - "stable timestamp %s", hex_timestamp[0], hex_timestamp[1]); + "stable timestamp %s", ts_string[0], ts_string[1]); } __wt_readunlock(session, &txn_global->rwlock); @@ -569,7 +591,7 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, WT_TXN *txn = &session->txn; WT_TXN_GLOBAL *txn_global = &S2C(session)->txn_global; wt_timestamp_t oldest_ts, stable_ts; - char hex_timestamp[WT_TS_HEX_SIZE]; + char ts_string[WT_TS_INT_STRING_SIZE]; bool has_oldest_ts, has_stable_ts; /* @@ -588,16 +610,18 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, stable_ts = txn_global->stable_timestamp; if (has_oldest_ts && ts < oldest_ts) { - __wt_timestamp_to_hex_string(hex_timestamp, oldest_ts); + __wt_timestamp_to_string( + oldest_ts, ts_string, sizeof(ts_string)); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than oldest timestamp %s", - name, (int)cval->len, cval->str, hex_timestamp); + name, (int)cval->len, cval->str, ts_string); } if (compare_stable && has_stable_ts && ts < stable_ts) { - __wt_timestamp_to_hex_string(hex_timestamp, stable_ts); + __wt_timestamp_to_string( + stable_ts, ts_string, sizeof(ts_string)); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than stable timestamp %s", - name, (int)cval->len, cval->str, hex_timestamp); + name, (int)cval->len, cval->str, ts_string); } /* @@ -607,12 +631,12 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, */ if (F_ISSET(txn, WT_TXN_HAS_TS_COMMIT) && ts < txn->first_commit_timestamp) { - __wt_timestamp_to_hex_string( - hex_timestamp, txn->first_commit_timestamp); + __wt_timestamp_to_string( + txn->first_commit_timestamp, ts_string, sizeof(ts_string)); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than the first " "commit timestamp %s for this transaction", - name, (int)cval->len, cval->str, hex_timestamp); + name, (int)cval->len, cval->str, ts_string); } /* @@ -621,12 +645,12 @@ __wt_timestamp_validate(WT_SESSION_IMPL *session, const char *name, * timestamp. */ if (F_ISSET(txn, WT_TXN_PREPARE) && ts < txn->prepare_timestamp) { - __wt_timestamp_to_hex_string( - hex_timestamp, txn->prepare_timestamp); + __wt_timestamp_to_string( + txn->prepare_timestamp, ts_string, sizeof(ts_string)); WT_RET_MSG(session, EINVAL, "%s timestamp %.*s older than the prepare timestamp %s " "for this transaction", - name, (int)cval->len, cval->str, hex_timestamp); + name, (int)cval->len, cval->str, ts_string); } return (0); @@ -717,7 +741,7 @@ __wt_txn_parse_prepare_timestamp( WT_TXN *prev; WT_TXN_GLOBAL *txn_global; wt_timestamp_t oldest_ts; - char hex_timestamp[WT_TS_HEX_SIZE]; + char ts_string[WT_TS_INT_STRING_SIZE]; txn_global = &S2C(session)->txn_global; @@ -751,12 +775,12 @@ __wt_txn_parse_prepare_timestamp( if (prev->read_timestamp >= *timestamp) { __wt_readunlock(session, &txn_global->read_timestamp_rwlock); - __wt_timestamp_to_hex_string( - hex_timestamp, prev->read_timestamp); + __wt_timestamp_to_string(prev->read_timestamp, + ts_string, sizeof(ts_string)); WT_RET_MSG(session, EINVAL, "prepare timestamp %.*s not later than " "an active read timestamp %s ", - (int)cval.len, cval.str, hex_timestamp); + (int)cval.len, cval.str, ts_string); } break; } @@ -770,12 +794,12 @@ __wt_txn_parse_prepare_timestamp( oldest_ts = txn_global->oldest_timestamp; if (*timestamp < oldest_ts) { - __wt_timestamp_to_hex_string( - hex_timestamp, oldest_ts); + __wt_timestamp_to_string( + oldest_ts, ts_string, sizeof(ts_string)); WT_RET_MSG(session, EINVAL, "prepare timestamp %.*s is older than the " "oldest timestamp %s ", (int)cval.len, - cval.str, hex_timestamp); + cval.str, ts_string); } } } else @@ -794,8 +818,8 @@ __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]; + wt_timestamp_t ts, ts_oldest; + char ts_string[2][WT_TS_INT_STRING_SIZE]; bool round_to_oldest; txn = &session->txn; @@ -830,24 +854,25 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) * avoid a race between checking and setting transaction * timestamp. */ - __wt_timestamp_to_hex_string(hex_timestamp[0], ts); __wt_readlock(session, &txn_global->rwlock); - if (ts < txn_global->oldest_timestamp) { - __wt_timestamp_to_hex_string( - hex_timestamp[1], txn_global->oldest_timestamp); + ts_oldest = txn_global->oldest_timestamp; + if (ts < ts_oldest) { /* * If given read timestamp is earlier than oldest * timestamp then round the read timestamp to * oldest timestamp. */ if (round_to_oldest) - txn->read_timestamp = - txn_global->oldest_timestamp; + txn->read_timestamp = ts_oldest; else { __wt_readunlock(session, &txn_global->rwlock); + __wt_timestamp_to_string( + ts, ts_string[0], sizeof(ts_string[0])); + __wt_timestamp_to_string(ts_oldest, + ts_string[1], sizeof(ts_string[1])); WT_RET_MSG(session, EINVAL, "read timestamp " "%s older than oldest timestamp %s", - hex_timestamp[0], hex_timestamp[1]); + ts_string[0], ts_string[1]); } } else { txn->read_timestamp = ts; @@ -860,14 +885,19 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[]) __wt_txn_set_read_timestamp(session); __wt_readunlock(session, &txn_global->rwlock); - if (round_to_oldest) { + if (round_to_oldest && + WT_VERBOSE_ISSET(session, WT_VERB_TIMESTAMP)) { /* * This message is generated here to reduce the span of * critical section. */ + __wt_timestamp_to_string( + ts, ts_string[0], sizeof(ts_string[0])); + __wt_timestamp_to_string( + ts_oldest, ts_string[1], sizeof(ts_string[1])); __wt_verbose(session, WT_VERB_TIMESTAMP, "Read " "timestamp %s : Rounded to oldest timestamp %s", - hex_timestamp[0], hex_timestamp[1]); + ts_string[0], ts_string[1]); } /* |