commit fd3bc03403b23c7c0661fdb3ae3c45b9d9f823e2
Author: nehakhatri5 <neha.khatri@mongodb.com>
Date:   Tue Sep 18 16:10:05 2018 +1000

    WT-4323 Add stress test to induce timestamp update race

diff --git a/dist/api_data.py b/dist/api_data.py
index 08a322a66..aacc8bed5 100644
--- a/dist/api_data.py
+++ b/dist/api_data.py
@@ -597,8 +597,9 @@ connection_runtime_config = [
         intended for use with internal stress testing of WiredTiger.''',
         type='list', undoc=True,
         choices=[
-        'checkpoint_slow', 'lookaside_sweep_race', 'split_1', 'split_2',
-        'split_3', 'split_4', 'split_5', 'split_6', 'split_7', 'split_8']),
+        'checkpoint_slow', 'lookaside_sweep_race', 'update_pinned_race',
+        'set_read_ts_race', 'split_1', 'split_2', 'split_3', 'split_4',
+        'split_5', 'split_6', 'split_7', 'split_8']),
     Config('verbose', '', r'''
         enable messages for various events. Options are given as a
         list, such as <code>"verbose=[evictserver,read]"</code>''',
diff --git a/src/config/config_def.c b/src/config/config_def.c
index 1bda9a62e..549b624f5 100644
--- a/src/config/config_def.c
+++ b/src/config/config_def.c
@@ -189,8 +189,9 @@ static const WT_CONFIG_CHECK confchk_WT_CONNECTION_reconfigure[] = {
 	    confchk_WT_CONNECTION_reconfigure_statistics_log_subconfigs, 5 },
 	{ "timing_stress_for_test", "list",
 	    NULL, "choices=[\"checkpoint_slow\",\"lookaside_sweep_race\","
-	    "\"split_1\",\"split_2\",\"split_3\",\"split_4\",\"split_5\","
-	    "\"split_6\",\"split_7\",\"split_8\"]",
+	    "\"update_pinned_race\",\"set_read_ts_race\",\"split_1\","
+	    "\"split_2\",\"split_3\",\"split_4\",\"split_5\",\"split_6\","
+	    "\"split_7\",\"split_8\"]",
 	    NULL, 0 },
 	{ "verbose", "list",
 	    NULL, "choices=[\"api\",\"block\",\"checkpoint\","
@@ -895,8 +896,9 @@ static const WT_CONFIG_CHECK confchk_wiredtiger_open[] = {
 	    confchk_wiredtiger_open_statistics_log_subconfigs, 6 },
 	{ "timing_stress_for_test", "list",
 	    NULL, "choices=[\"checkpoint_slow\",\"lookaside_sweep_race\","
-	    "\"split_1\",\"split_2\",\"split_3\",\"split_4\",\"split_5\","
-	    "\"split_6\",\"split_7\",\"split_8\"]",
+	    "\"update_pinned_race\",\"set_read_ts_race\",\"split_1\","
+	    "\"split_2\",\"split_3\",\"split_4\",\"split_5\",\"split_6\","
+	    "\"split_7\",\"split_8\"]",
 	    NULL, 0 },
 	{ "transaction_sync", "category",
 	    NULL, NULL,
@@ -1001,8 +1003,9 @@ static const WT_CONFIG_CHECK confchk_wiredtiger_open_all[] = {
 	    confchk_wiredtiger_open_statistics_log_subconfigs, 6 },
 	{ "timing_stress_for_test", "list",
 	    NULL, "choices=[\"checkpoint_slow\",\"lookaside_sweep_race\","
-	    "\"split_1\",\"split_2\",\"split_3\",\"split_4\",\"split_5\","
-	    "\"split_6\",\"split_7\",\"split_8\"]",
+	    "\"update_pinned_race\",\"set_read_ts_race\",\"split_1\","
+	    "\"split_2\",\"split_3\",\"split_4\",\"split_5\",\"split_6\","
+	    "\"split_7\",\"split_8\"]",
 	    NULL, 0 },
 	{ "transaction_sync", "category",
 	    NULL, NULL,
@@ -1104,8 +1107,9 @@ static const WT_CONFIG_CHECK confchk_wiredtiger_open_basecfg[] = {
 	    confchk_wiredtiger_open_statistics_log_subconfigs, 6 },
 	{ "timing_stress_for_test", "list",
 	    NULL, "choices=[\"checkpoint_slow\",\"lookaside_sweep_race\","
-	    "\"split_1\",\"split_2\",\"split_3\",\"split_4\",\"split_5\","
-	    "\"split_6\",\"split_7\",\"split_8\"]",
+	    "\"update_pinned_race\",\"set_read_ts_race\",\"split_1\","
+	    "\"split_2\",\"split_3\",\"split_4\",\"split_5\",\"split_6\","
+	    "\"split_7\",\"split_8\"]",
 	    NULL, 0 },
 	{ "transaction_sync", "category",
 	    NULL, NULL,
@@ -1205,8 +1209,9 @@ static const WT_CONFIG_CHECK confchk_wiredtiger_open_usercfg[] = {
 	    confchk_wiredtiger_open_statistics_log_subconfigs, 6 },
 	{ "timing_stress_for_test", "list",
 	    NULL, "choices=[\"checkpoint_slow\",\"lookaside_sweep_race\","
-	    "\"split_1\",\"split_2\",\"split_3\",\"split_4\",\"split_5\","
-	    "\"split_6\",\"split_7\",\"split_8\"]",
+	    "\"update_pinned_race\",\"set_read_ts_race\",\"split_1\","
+	    "\"split_2\",\"split_3\",\"split_4\",\"split_5\",\"split_6\","
+	    "\"split_7\",\"split_8\"]",
 	    NULL, 0 },
 	{ "transaction_sync", "category",
 	    NULL, NULL,
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index e98be368a..34e716b90 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -2018,6 +2018,8 @@ __wt_timing_stress_config(WT_SESSION_IMPL *session, const char *cfg[])
 	static const WT_NAME_FLAG stress_types[] = {
 		{ "checkpoint_slow",	WT_TIMING_STRESS_CHECKPOINT_SLOW },
 		{ "lookaside_sweep_race",WT_TIMING_STRESS_LOOKASIDE_SWEEP },
+		{ "update_pinned_race",	WT_TIMING_STRESS_UPDATE_PINNED },
+		{ "set_read_ts_race",	WT_TIMING_STRESS_SET_READ_TS },
 		{ "split_1",		WT_TIMING_STRESS_SPLIT_1 },
 		{ "split_2",		WT_TIMING_STRESS_SPLIT_2 },
 		{ "split_3",		WT_TIMING_STRESS_SPLIT_3 },
diff --git a/src/include/connection.h b/src/include/connection.h
index c3af948f9..9f3abc5f7 100644
--- a/src/include/connection.h
+++ b/src/include/connection.h
@@ -452,14 +452,16 @@ struct __wt_connection_impl {
 /* AUTOMATIC FLAG VALUE GENERATION START */
 #define	WT_TIMING_STRESS_CHECKPOINT_SLOW	0x001u
 #define	WT_TIMING_STRESS_LOOKASIDE_SWEEP	0x002u
-#define	WT_TIMING_STRESS_SPLIT_1		0x004u
-#define	WT_TIMING_STRESS_SPLIT_2		0x008u
-#define	WT_TIMING_STRESS_SPLIT_3		0x010u
-#define	WT_TIMING_STRESS_SPLIT_4		0x020u
-#define	WT_TIMING_STRESS_SPLIT_5		0x040u
-#define	WT_TIMING_STRESS_SPLIT_6		0x080u
-#define	WT_TIMING_STRESS_SPLIT_7		0x100u
-#define	WT_TIMING_STRESS_SPLIT_8		0x200u
+#define	WT_TIMING_STRESS_SET_READ_TS		0x004u
+#define	WT_TIMING_STRESS_SPLIT_1		0x008u
+#define	WT_TIMING_STRESS_SPLIT_2		0x010u
+#define	WT_TIMING_STRESS_SPLIT_3		0x020u
+#define	WT_TIMING_STRESS_SPLIT_4		0x040u
+#define	WT_TIMING_STRESS_SPLIT_5		0x080u
+#define	WT_TIMING_STRESS_SPLIT_6		0x100u
+#define	WT_TIMING_STRESS_SPLIT_7                0x200u
+#define	WT_TIMING_STRESS_SPLIT_8                0x400u
+#define	WT_TIMING_STRESS_UPDATE_PINNED		0x800u
 /* AUTOMATIC FLAG VALUE GENERATION STOP */
 	uint64_t timing_stress_flags;
 
diff --git a/src/txn/txn_timestamp.c b/src/txn/txn_timestamp.c
index 28f635f55..db0209060 100644
--- a/src/txn/txn_timestamp.c
+++ b/src/txn/txn_timestamp.c
@@ -437,6 +437,7 @@ __wt_txn_update_pinned_timestamp(WT_SESSION_IMPL *session, bool force)
 			return (0);
 	}
 
+	__wt_timing_stress(session, WT_TIMING_STRESS_UPDATE_PINNED);
 	__wt_writelock(session, &txn_global->rwlock);
 	if (!txn_global->has_pinned_timestamp || force || __wt_timestamp_cmp(
 	    &txn_global->pinned_timestamp, &pinned_timestamp) < 0) {
@@ -938,6 +939,7 @@ __wt_txn_parse_read_timestamp(WT_SESSION_IMPL *session, const char *cfg[])
 			round_to_oldest = false;
 		}
 
+		__wt_timing_stress(session, WT_TIMING_STRESS_SET_READ_TS);
 		__wt_txn_set_read_timestamp(session);
 		__wt_readunlock(session, &txn_global->rwlock);
 		if (round_to_oldest) {
diff --git a/test/format/config.h b/test/format/config.h
index 70e8165e9..743a74977 100644
--- a/test/format/config.h
+++ b/test/format/config.h
@@ -338,6 +338,14 @@ static CONFIG c[] = {
 	  "stress lookaside sweep",				/* 2% */
 	  C_BOOL, 2, 0, 0, &g.c_timing_stress_lookaside_sweep, NULL },
 
+	{ "timing_stress_update_pinned_ts",
+	  "stress pinned timestamp update",			/* 2% */
+	  C_BOOL, 2, 0, 0, &g.c_timing_stress_update_pinned_ts, NULL },
+
+	{ "timing_stress_set_read_ts",
+	  "stress set read timestamp",				/* 2% */
+	  C_BOOL, 2, 0, 0, &g.c_timing_stress_set_read_ts, NULL }
+,
 	{ "timing_stress_split_1",
 	  "stress splits (#1)",					/* 2% */
 	  C_BOOL, 2, 0, 0, &g.c_timing_stress_split_1, NULL },
diff --git a/test/format/format.h b/test/format/format.h
index a83aa0d2d..f335f5d1a 100644
--- a/test/format/format.h
+++ b/test/format/format.h
@@ -223,6 +223,8 @@ typedef struct {
 	uint32_t c_timer;
 	uint32_t c_timing_stress_checkpoint;
 	uint32_t c_timing_stress_lookaside_sweep;
+	uint32_t c_timing_stress_update_pinned_ts;
+	uint32_t c_timing_stress_set_read_ts;
 	uint32_t c_timing_stress_split_1;
 	uint32_t c_timing_stress_split_2;
 	uint32_t c_timing_stress_split_3;
diff --git a/test/format/wts.c b/test/format/wts.c
index 30b910435..05ce4b278 100644
--- a/test/format/wts.c
+++ b/test/format/wts.c
@@ -248,6 +248,10 @@ wts_open(const char *home, bool set_api, WT_CONNECTION **connp)
 		CONFIG_APPEND(p, ",checkpoint_slow");
 	if (g.c_timing_stress_lookaside_sweep)
 		CONFIG_APPEND(p, ",lookaside_sweep_race");
+	if (g.c_timing_stress_update_pinned_ts)
+		CONFIG_APPEND(p, ",update_pinned_race");
+	if (g.c_timing_stress_set_read_ts)
+		CONFIG_APPEND(p, ",set_read_ts_race");
 	if (g.c_timing_stress_split_1)
 		CONFIG_APPEND(p, ",split_1");
 	if (g.c_timing_stress_split_2)
