void TimeTable::init(uint64_t thd_id, uint64_t key) { uint64_t idx = hash(key); uint64_t mtx_wait_starttime = get_sys_clock(); pthread_mutex_lock(&table[idx].mtx); INC_STATS(thd_id,mtx[34],get_sys_clock() - mtx_wait_starttime); TimeTableEntry* entry = find(key); if(!entry) { DEBUG_M("TimeTable::init entry alloc\n"); entry = (TimeTableEntry*) mem_allocator.alloc(sizeof(TimeTableEntry)); entry->init(key); LIST_PUT_TAIL(table[idx].head,table[idx].tail,entry); } pthread_mutex_unlock(&table[idx].mtx); }
void Row_mvcc::insert_history( ts_t ts, row_t * row) { MVHisEntry * new_entry = get_his_entry(); new_entry->ts = ts; new_entry->row = row; if (row != NULL) whis_len ++; else rhis_len ++; MVHisEntry ** queue = (row == NULL)? &(readhis) : &(writehis); MVHisEntry ** tail = (row == NULL)? &(readhistail) : &(writehistail); MVHisEntry * his = *queue; while (his != NULL && ts < his->ts) { his = his->next; } if (his) { LIST_INSERT_BEFORE(his, new_entry,(*queue)); //if (his == *queue) // *queue = new_entry; } else LIST_PUT_TAIL((*queue), (*tail), new_entry); }
TxnManager * TxnTable::get_transaction_manager(uint64_t thd_id, uint64_t txn_id,uint64_t batch_id){ DEBUG("TxnTable::get_txn_manager %ld / %ld\n",txn_id,pool_size); uint64_t starttime = get_sys_clock(); uint64_t pool_id = txn_id % pool_size; uint64_t mtx_starttime = starttime; // set modify bit for this pool: txn_id % pool_size while(!ATOM_CAS(pool[pool_id]->modify,false,true)) { }; INC_STATS(thd_id,mtx[7],get_sys_clock()-mtx_starttime); txn_node_t t_node = pool[pool_id]->head; TxnManager * txn_man = NULL; uint64_t prof_starttime = get_sys_clock(); while (t_node != NULL) { if(is_matching_txn_node(t_node,txn_id,batch_id)) { txn_man = t_node->txn_man; break; } t_node = t_node->next; } INC_STATS(thd_id,mtx[20],get_sys_clock()-prof_starttime); if(!txn_man) { prof_starttime = get_sys_clock(); txn_table_pool.get(thd_id,t_node); INC_STATS(thd_id,mtx[21],get_sys_clock()-prof_starttime); prof_starttime = get_sys_clock(); txn_man_pool.get(thd_id,txn_man); INC_STATS(thd_id,mtx[22],get_sys_clock()-prof_starttime); prof_starttime = get_sys_clock(); txn_man->set_txn_id(txn_id); txn_man->set_batch_id(batch_id); t_node->txn_man = txn_man; txn_man->txn_stats.starttime = get_sys_clock(); txn_man->txn_stats.restart_starttime = txn_man->txn_stats.starttime; LIST_PUT_TAIL(pool[pool_id]->head,pool[pool_id]->tail,t_node); INC_STATS(thd_id,mtx[23],get_sys_clock()-prof_starttime); prof_starttime = get_sys_clock(); ++pool[pool_id]->cnt; if(pool[pool_id]->cnt > 1) { INC_STATS(thd_id,txn_table_cflt_cnt,1); INC_STATS(thd_id,txn_table_cflt_size,pool[pool_id]->cnt-1); } INC_STATS(thd_id,txn_table_new_cnt,1); INC_STATS(thd_id,mtx[24],get_sys_clock()-prof_starttime); } #if CC_ALG == MVCC if(txn_man->get_timestamp() < pool[pool_id]->min_ts) pool[pool_id]->min_ts = txn_man->get_timestamp(); #endif // unset modify bit for this pool: txn_id % pool_size ATOM_CAS(pool[pool_id]->modify,true,false); INC_STATS(thd_id,txn_table_get_time,get_sys_clock() - starttime); INC_STATS(thd_id,txn_table_get_cnt,1); return txn_man; }