32 #define strlen(s1) ((int) strlen(s1)) 34 #define NOPS_SNAPSHOT 1000000 35 #define NOPS_COMPLPETE 1000000 36 #define NOPS_OLDEST 2000000 39 #define MVCC_BITAREA_ELEMENT_BITS 64 40 #define MVCC_BITAREA_ELEMENT_ALL_COMMITTED 0xffffffffffffffffULL 41 #define MVCC_BITAREA_BIT_COMMITTED 1 42 #define MVCC_BITAREA_BIT_ACTIVE 0 45 #define MVCC_BITAREA_ELEMENTS_AFTER_FULL_CLEANUP 16 48 #define MVCC_BITAREA_MAXIMUM_ELEMENTS 500 51 #define MVCC_BITAREA_MAXIMUM_BITS 32000 53 #define MVCC_BITAREA_BITS_TO_ELEMENTS(count_bits) (((count_bits) + 63) >> 6) 54 #define MVCC_BITAREA_BITS_TO_BYTES(count_bits) ((((count_bits) + 63) >> 6) << 3) 55 #define MVCC_BITAREA_ELEMENTS_TO_BYTES(count_elements) ((count_elements) << 3) 56 #define MVCC_BITAREA_ELEMENTS_TO_BITS(count_elements) ((count_elements) << 6) 67 printf (
"Testing %s", test_name);
82 struct timeval end_time;
83 long long int elapsed_msec = 0;
85 gettimeofday (&end_time,
NULL);
87 elapsed_msec = (end_time.tv_usec -
start_time.tv_usec) / 1000;
88 elapsed_msec += (end_time.tv_sec -
start_time.tv_sec) * 1000;
90 printf (
" %s [%9.3f sec]\n",
"OK", (
float) elapsed_msec / 1000.0f);
123 memset (tdes, 0,
sizeof (
LOG_TDES));
138 size_t size, area_size;
144 if (num_threads == 0 || thread_array ==
NULL)
154 if (*thread_array ==
NULL)
159 memset (*thread_array, 0, size);
160 for (i = 0; i < num_threads; i++)
162 thread_p = *thread_array +
i;
165 thread_p->tran_index = i + 1;
190 for (i = 0; i < num_threads; i++)
246 if (thread_array && *thread_array)
273 unsigned int local_count_snapshots = 0;
284 local_count_snapshots++;
289 curr_mvcc_info->
reset ();
293 fprintf (stdout,
"snapshot worker thread (%p) is leaving\n", thread_p);
310 unsigned int local_count_complete = 0;
311 bool committed =
true;
327 committed = !committed;
330 local_count_complete++;
336 fprintf (stdout,
"complete worker thread (%p) is leaving\n", thread_p);
351 unsigned int local_count_oldest = 0;
360 prev_oldest = curr_oldest;
368 local_count_oldest++;
373 fprintf (stdout,
"get_oldest thread (%p) is leaving\n", thread_p);
389 #define MAX_THREADS 100 391 int idx_thread_entry;
394 numthreads = num_snapshot_threads + num_complete_threads + num_oldest_mvccid_threads;
395 sprintf (msg,
"test_mvcc_operations (%d snapshot threads, %d complete threads, %d oldest threads)",
396 num_snapshot_threads, num_complete_threads, num_oldest_mvccid_threads);
399 if (num_snapshot_threads < 0 || num_complete_threads < 0 || num_oldest_mvccid_threads < 0)
401 printf (
" %s: %s\n",
"FAILED",
"negative number of threads not allowed");
407 printf (
" %s: %s\n",
"FAILED",
"too many threads");
412 idx_thread_entry = 0;
413 for (i = 0; i < num_snapshot_threads; i++, idx_thread_entry++)
416 (
void *) (thread_array + idx_thread_entry)) !=
NO_ERROR)
418 printf (
" %s: %s\n",
"FAILED",
"thread create error");
423 for (i = 0; i < num_complete_threads; i++, idx_thread_entry++)
426 (
void *) (thread_array + idx_thread_entry)) !=
NO_ERROR)
428 printf (
" %s: %s\n",
"FAILED",
"thread create error");
433 for (i = 0; i < num_oldest_mvccid_threads; i++, idx_thread_entry++)
436 (
void *) (thread_array + idx_thread_entry)) !=
NO_ERROR)
438 printf (
" %s: %s\n",
"FAILED",
"thread create error");
443 for (i = 0; i < numthreads; i++)
447 pthread_join (threads[i], &retval);
450 printf (
" %s: %s\n",
"FAILED",
"thread proc error");
457 printf (
"snapshot count fail (%llu != %llu)",
458 (
unsigned long long)
count_snapshots, (
unsigned long long) num_snapshot_threads * NOPS_SNAPSHOT);
464 printf (
"complete count fail (%llu != %llu)",
465 (
unsigned long long)
count_complete, (
unsigned long long) num_complete_threads * NOPS_COMPLPETE);
471 printf (
"oldest count fail (%llu != %llu)",
472 (
unsigned long long)
count_oldest, (
unsigned long long) num_oldest_mvccid_threads * NOPS_OLDEST);
485 #define MAX_SNAPSHOT_THREADS 10 486 #define MAX_COMPLETE_THREADS 10 487 #define MAX_OLDEST_THREADS 1 489 int num_snapshot_threads, num_complete_threads, num_oldest_threads;
494 for (num_oldest_threads = 1; num_oldest_threads <=
MAX_OLDEST_THREADS; num_oldest_threads++)
496 for (num_complete_threads = 1; num_complete_threads <=
MAX_COMPLETE_THREADS; num_complete_threads++)
498 for (num_snapshot_threads = 1; num_snapshot_threads <=
MAX_SNAPSHOT_THREADS; num_snapshot_threads++)
514 printf (
"Unit tests failed!\n");
517 #undef MAX_SNAPSHOT_THREADS 518 #undef MAX_COMPLETE_THREADS 519 #undef MAX_OLDEST_THREADS
static unsigned int logtb_tran_btid_hash_func(const void *key, const unsigned int ht_size)
#define MAX_COMPLETE_THREADS
THREAD_RET_T THREAD_CALLING_CONVENTION test_mvcc_get_snapshot(void *param)
#define MAX_OLDEST_THREADS
MVCC_SNAPSHOT * logtb_get_mvcc_snapshot(THREAD_ENTRY *thread_p)
void logtb_complete_mvcc(THREAD_ENTRY *thread_p, LOG_TDES *tdes, bool committed)
MHT_TABLE * unique_stats_hash
static void logtb_initialize_mvcctable(void)
THREAD_RET_T THREAD_CALLING_CONVENTION test_mvcc_get_oldest(void *param)
LOG_TRAN_UPDATE_STATS log_upd_stats
struct log_addr_tdesarea LOG_ADDR_TDESAREA
static void logtb_finalize_mvcctable()
void clear_thread_local_entry(void)
void set_thread_local_entry(entry &tl_entry)
static int fail(const char *message)
LOG_TDES * LOG_FIND_TDES(int tran_index)
static int test_mvcc_operations(int num_snapshot_threads, int num_complete_threads, int num_oldest_mvccid_threads, THREAD_ENTRY *thread_array)
static UINT64 count_complete
void mht_destroy(MHT_TABLE *ht)
static int logtb_initialize_mvcc_testing(int num_threads, THREAD_ENTRY **thread_array)
#define ER_OUT_OF_VIRTUAL_MEMORY
static void logtb_initialize_tdes_for_mvcc_testing(LOG_TDES *tdes, int tran_index)
mvcc_active_tran m_active_mvccs
MHT_TABLE * mht_create(const char *name, int est_size, unsigned int(*hash_func)(const void *key, unsigned int ht_size), int(*cmp_func)(const void *key1, const void *key2))
#define MVCC_ID_PRECEDES(id1, id2)
#define MAX_SNAPSHOT_THREADS
MVCCID logtb_get_current_mvccid(THREAD_ENTRY *thread_p)
static void error(const char *msg)
static struct timeval start_time
MVCCID get_global_oldest_visible() const
static void logtb_finalize_mvcc_testing(THREAD_ENTRY **thread_array)
#define LOG_FIND_THREAD_TRAN_INDEX(thrd)
static void begin(char *test_name)
#define free_and_init(ptr)
THREAD_RET_T THREAD_CALLING_CONVENTION test_new_mvcc_complete(void *param)
static UINT64 count_oldest
static int logtb_tran_btid_hash_cmp_func(const void *key1, const void *key2)
void reset_transaction_lowest_active(int tran_index)
static UINT64 count_snapshots
#define THREAD_CALLING_CONVENTION
int main(int argc, char **argv)