📄 tstrx.c
字号:
ulinttest2(/*==*/ void* arg){ ulint tm, oldtm; sess_t* sess; com_endpoint_t* com_endpoint; mem_heap_t* heap; que_fork_t* fork; dict_table_t* table; que_thr_t* thr; trx_t* trx; ulint i; ulint rnd; dtuple_t* row; byte buf[100]; ulint count = 0; ins_node_t* node; printf("-------------------------------------------------\n"); printf("TEST 2. MASSIVE INSERT\n"); heap = mem_heap_create(512); com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL value */ mutex_enter(&kernel_mutex); sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6); trx = sess->trx; mutex_exit(&kernel_mutex);loop: ut_a(trx_start(trx, ULINT_UNDEFINED)); /*-------------------------------------*/ /* MASSIVE INSERT */ fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); table = dict_table_get("TS_TABLE1", trx); row = dtuple_create(heap, 3 + DATA_N_SYS_COLS); dict_table_copy_types(row, table); node = ins_node_create(fork, thr, row, table, heap); thr->child = node; row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap); row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx); node->init_all_sys_fields = FALSE; mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; mutex_exit(&kernel_mutex); rnd = 0; mem_print_info(); oldtm = ut_clock(); for (i = 0; i < *((ulint*)arg); i++) { rnd = (rnd + 1) % 200000; dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf); mutex_enter(&kernel_mutex); ut_a( thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); que_run_threads(thr); } tm = ut_clock(); printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm); mem_print_info();/* dict_table_print_by_name("TS_TABLE1"); */ /*-------------------------------------*/ /* ROLLBACK */#ifdef notdefined fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); thr->child = roll_node_create(fork, thr, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); oldtm = ut_clock(); que_run_threads(thr); tm = ut_clock(); printf("Wall time for rollback of %lu inserts %lu milliseconds\n", i, tm - oldtm); /*-------------------------------------*/#endif /* COMMIT */ fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); thr->child = commit_node_create(fork, thr, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); oldtm = ut_clock(); que_run_threads(thr); tm = ut_clock(); printf("Wall time for commit %lu milliseconds\n", tm - oldtm); /*-------------------------------------*/ count++; if (count < 1) { goto loop; } return(0);}/*********************************************************************Test for updates. */ulinttest3(/*==*/ void* arg){ ulint tm, oldtm; sess_t* sess; com_endpoint_t* com_endpoint; mem_heap_t* heap; que_fork_t* fork; dict_table_t* table; que_thr_t* thr; trx_t* trx; ulint i; ulint rnd; dtuple_t* row; dtuple_t* entry; byte buf[100]; ulint count = 0; btr_pcur_t pcur; upd_t* update; upd_field_t* ufield; dict_tree_t* tree; dict_index_t* index; mtr_t mtr; upd_node_t* node; byte* ptr; ulint len; ulint err; UT_NOT_USED(arg); printf("-------------------------------------------------\n"); printf("TEST 3. UPDATES\n"); heap = mem_heap_create(512); com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL value */ mutex_enter(&kernel_mutex); sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6); trx = sess->trx; mutex_exit(&kernel_mutex);loop: ut_a(trx_start(trx, ULINT_UNDEFINED)); /*-------------------------------------*/ /* INSERT */ fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); table = dict_table_get("TS_TABLE1", trx); row = dtuple_create(heap, 3 + DATA_N_SYS_COLS); dict_table_copy_types(row, table); thr->child = ins_node_create(fork, thr, row, table, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; mutex_exit(&kernel_mutex); rnd = 0; oldtm = ut_clock(); for (i = 0; i < 3; i++) { dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf); mutex_enter(&kernel_mutex); ut_a( thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); que_run_threads(thr); } tm = ut_clock(); printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm); /*-------------------------------------*/ /* COMMIT */ fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); thr->child = commit_node_create(fork, thr, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); oldtm = ut_clock(); que_run_threads(thr); tm = ut_clock(); printf("Wall time for commit %lu milliseconds\n", tm - oldtm); dict_table_print_by_name("TS_TABLE1"); /*-------------------------------------*/ /* UPDATE ROWS */ ut_a(trx_start(trx, ULINT_UNDEFINED)); fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); table = dict_table_get("TS_TABLE1", trx); row = dtuple_create(heap, 3 + DATA_N_SYS_COLS); dict_table_copy_types(row, table); update = upd_create(1, heap); node = upd_node_create(fork, thr, table, &pcur, update, heap); thr->child = node; node->cmpl_info = 0; mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; mutex_exit(&kernel_mutex); dtuple_gen_test_tuple3(row, 1, DTUPLE_TEST_FIXED30, buf); entry = dtuple_create(heap, 2); dfield_copy(dtuple_get_nth_field(entry, 0), dtuple_get_nth_field(row, 0)); dfield_copy(dtuple_get_nth_field(entry, 1), dtuple_get_nth_field(row, 1)); index = dict_table_get_first_index(table); tree = dict_index_get_tree(index); btr_pcur_set_mtr(&pcur, &mtr); mtr_start(&mtr); btr_pcur_open(tree, entry, PAGE_CUR_G, BTR_SEARCH_LEAF, &pcur, &mtr); btr_pcur_store_position(&pcur, &mtr); err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur), index, LOCK_X, thr); ut_a(err == DB_SUCCESS); btr_pcur_commit(&pcur); ufield = upd_get_nth_field(update, 0); ufield->col_no = 2; dfield_set_data(&(ufield->new_val), "updated field", 14); mutex_enter(&kernel_mutex); ut_a( thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); que_run_threads(thr); mtr_start(&mtr); ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr)); ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len); ut_a(ut_memcmp(ptr, "updated field", 14) == 0); btr_pcur_commit(&pcur); dict_table_print_by_name("TS_TABLE1"); ufield = upd_get_nth_field(update, 0); ufield->col_no = 0; dfield_set_data(&(ufield->new_val), "31415926", 9); mutex_enter(&kernel_mutex); ut_a( thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); que_run_threads(thr); dict_table_print_by_name("TS_TABLE1"); /*-------------------------------------*/ /* ROLLBACK */#ifdef notdefined fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); thr->child = roll_node_create(fork, thr, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); oldtm = ut_clock(); que_run_threads(thr); tm = ut_clock(); printf("Wall time for rollback of %lu updates %lu milliseconds\n", i, tm - oldtm); /*-------------------------------------*/ /* COMMIT */ fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); thr->child = commit_node_create(fork, thr, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); oldtm = ut_clock(); que_run_threads(thr); tm = ut_clock(); printf("Wall time for commit %lu milliseconds\n", tm - oldtm); /*-------------------------------------*/#endif dict_table_print_by_name("TS_TABLE1"); count++; if (count < 1) { goto loop; } return(0);}/*********************************************************************Test for massive updates. */ulinttest4(/*==*/ void* arg){ ulint tm, oldtm; sess_t* sess; com_endpoint_t* com_endpoint; mem_heap_t* heap; que_fork_t* fork; dict_table_t* table; que_thr_t* thr; trx_t* trx; ulint i; ulint j; ulint rnd; dtuple_t* row; dtuple_t* entry; byte buf[100]; ulint count = 0; btr_pcur_t pcur; upd_t* update; upd_field_t* ufield; dict_tree_t* tree; dict_index_t* index; mtr_t mtr; upd_node_t* node; byte* ptr; ulint len; ulint err; printf("-------------------------------------------------\n"); printf("TEST 4. MASSIVE UPDATES\n"); heap = mem_heap_create(512); com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL value */ mutex_enter(&kernel_mutex); sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6); trx = sess->trx; mutex_exit(&kernel_mutex);loop: ut_a(trx_start(trx, ULINT_UNDEFINED)); /*-------------------------------------*/ /* INSERT */ fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); table = dict_table_get("TS_TABLE1", trx); row = dtuple_create(heap, 3 + DATA_N_SYS_COLS); dict_table_copy_types(row, table); thr->child = ins_node_create(fork, thr, row, table, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; mutex_exit(&kernel_mutex); rnd = 0; oldtm = ut_clock(); for (i = 0; i < *((ulint*)arg); i++) { dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf); mutex_enter(&kernel_mutex); ut_a( thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0)); mutex_exit(&kernel_mutex); que_run_threads(thr); } tm = ut_clock(); printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);#ifdef notdefined /*-------------------------------------*/ /* COMMIT */ fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap); fork->trx = trx; thr = que_thr_create(fork, fork, heap); thr->child = commit_node_create(fork, thr, heap); mutex_enter(&kernel_mutex); que_graph_publish(fork, trx->sess); trx->graph = fork; ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -