mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-10-31 15:38:57 +08:00 
			
		
		
		
	test: canary fetch/update for jitter testcase.
Change-Id: I8402328f880addb1170e8e778b64aa4f12d18718
This commit is contained in:
		| @@ -31,27 +31,29 @@ bool testcase_jitter::run() { | |||||||
|     if (flipcoin()) { |     if (flipcoin()) { | ||||||
|       jitter_delay(); |       jitter_delay(); | ||||||
|       txn_begin(true); |       txn_begin(true); | ||||||
|  |       fetch_canary(); | ||||||
|       jitter_delay(); |       jitter_delay(); | ||||||
|       txn_end(false); |       txn_end(flipcoin()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     jitter_delay(); |     jitter_delay(); | ||||||
|     txn_begin(mode_readonly()); |     txn_begin(mode_readonly()); | ||||||
|     jitter_delay(); |     jitter_delay(); | ||||||
|     if (!mode_readonly()) { |     if (!mode_readonly()) { | ||||||
|  |       fetch_canary(); | ||||||
|  |       update_canary(1); | ||||||
|       /* TODO: |       /* TODO: | ||||||
|        *  - db_sequence() |  | ||||||
|        *  - db_setsize() |        *  - db_setsize() | ||||||
|        *  ... |        *  ... | ||||||
|        */ |        */ | ||||||
|     } |     } | ||||||
|     txn_end(false); |     txn_end(flipcoin()); | ||||||
|  |  | ||||||
|     if (flipcoin()) { |     if (flipcoin()) { | ||||||
|       jitter_delay(); |       jitter_delay(); | ||||||
|       txn_begin(true); |       txn_begin(true); | ||||||
|       jitter_delay(); |       jitter_delay(); | ||||||
|       txn_end(false); |       txn_end(flipcoin()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     jitter_delay(); |     jitter_delay(); | ||||||
|   | |||||||
							
								
								
									
										37
									
								
								test/test.cc
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								test/test.cc
									
									
									
									
									
								
							| @@ -252,6 +252,43 @@ bool testcase::should_continue() const { | |||||||
|   return result; |   return result; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void testcase::fetch_canary() { | ||||||
|  |   mdbx_canary canary_now; | ||||||
|  |   log_trace(">> fetch_canary"); | ||||||
|  |  | ||||||
|  |   int rc = mdbx_canary_get(txn_guard.get(), &canary_now); | ||||||
|  |   if (rc != MDB_SUCCESS) | ||||||
|  |     failure_perror("mdbx_canary_get()", rc); | ||||||
|  |  | ||||||
|  |   if (canary_now.v < last.canary.v) | ||||||
|  |     failure("fetch_canary: %" PRIu64 " canary-now.v) < %" PRIu64 | ||||||
|  |             "(canary-last.v)", | ||||||
|  |             canary_now.v, last.canary.v); | ||||||
|  |   if (canary_now.y < last.canary.y) | ||||||
|  |     failure("fetch_canary: %" PRIu64 "(canary-now.y) < %" PRIu64 | ||||||
|  |             "(canary-last.y)", | ||||||
|  |             canary_now.y, last.canary.y); | ||||||
|  |  | ||||||
|  |   last.canary = canary_now; | ||||||
|  |   log_trace("<< fetch_canary: db-sequence %" PRIu64 | ||||||
|  |             ", db-sequence.txnid %" PRIu64, | ||||||
|  |             last.canary.y, last.canary.v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void testcase::update_canary(uint64_t increment) { | ||||||
|  |   mdbx_canary canary_now = last.canary; | ||||||
|  |  | ||||||
|  |   log_trace(">> update_canary: sequence %" PRIu64 " += %" PRIu64, canary_now.y, | ||||||
|  |             increment); | ||||||
|  |   canary_now.y += increment; | ||||||
|  |  | ||||||
|  |   int rc = mdbx_canary_put(txn_guard.get(), &canary_now); | ||||||
|  |   if (rc != MDB_SUCCESS) | ||||||
|  |     failure_perror("mdbx_canary_put()", rc); | ||||||
|  |  | ||||||
|  |   log_trace(">> update_canary: sequence = %" PRIu64, canary_now.y); | ||||||
|  | } | ||||||
|  |  | ||||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||||
|  |  | ||||||
| bool test_execute(const actor_config &config) { | bool test_execute(const actor_config &config) { | ||||||
|   | |||||||
| @@ -88,11 +88,17 @@ protected: | |||||||
|   size_t nops_completed; |   size_t nops_completed; | ||||||
|   chrono::time start_timestamp; |   chrono::time start_timestamp; | ||||||
|  |  | ||||||
|  |   struct { | ||||||
|  |     mdbx_canary canary; | ||||||
|  |   } last; | ||||||
|  |  | ||||||
|   void db_prepare(); |   void db_prepare(); | ||||||
|   void db_open(); |   void db_open(); | ||||||
|   void db_close(); |   void db_close(); | ||||||
|   void txn_begin(bool readonly); |   void txn_begin(bool readonly); | ||||||
|   void txn_end(bool abort); |   void txn_end(bool abort); | ||||||
|  |   void fetch_canary(); | ||||||
|  |   void update_canary(uint64_t increment); | ||||||
|  |  | ||||||
|   bool wait4start(); |   bool wait4start(); | ||||||
|   void report(size_t nops_done); |   void report(size_t nops_done); | ||||||
| @@ -107,6 +113,7 @@ public: | |||||||
|   testcase(const actor_config &config, const mdbx_pid_t pid) |   testcase(const actor_config &config, const mdbx_pid_t pid) | ||||||
|       : config(config), pid(pid), nops_completed(0) { |       : config(config), pid(pid), nops_completed(0) { | ||||||
|     start_timestamp.reset(); |     start_timestamp.reset(); | ||||||
|  |     memset(&last, 0, sizeof(last)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   virtual bool setup(); |   virtual bool setup(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user