static void stasis_alloc_reserve_new_region(stasis_alloc_t* alloc, int xid) { void* nta = TbeginNestedTopAction(xid, OPERATION_NOOP, 0,0); pageid_t firstPage = TregionAlloc(xid, TALLOC_REGION_SIZE, STORAGE_MANAGER_TALLOC); int initialFreespace = -1; for(pageid_t i = 0; i < TALLOC_REGION_SIZE; i++) { TinitializeSlottedPage(xid, firstPage + i); if(initialFreespace == -1) { Page * p = loadPage(xid, firstPage); readlock(p->rwlatch,0); initialFreespace = stasis_record_freespace(xid, p); unlock(p->rwlatch); releasePage(p); } stasis_allocation_policy_register_new_page(alloc->allocPolicy, firstPage + i, initialFreespace); } TendNestedTopAction(xid, nta); }
int TlinkedListRemove(int xid, recordid list, const byte * key, int keySize) { byte * value; int valueSize; pthread_mutex_lock(&stasis_linked_list_mutex); int ret; ret = TlinkedListFind(xid, list, key, keySize, &value); if(ret != -1) { valueSize = ret; } else { pthread_mutex_unlock(&stasis_linked_list_mutex); return 0; } int entrySize = sizeof(stasis_linked_list_remove_log) + keySize + valueSize; stasis_linked_list_remove_log * undoLog = (stasis_linked_list_remove_log *)malloc(entrySize); undoLog->list = list; undoLog->keySize = keySize; undoLog->valueSize = valueSize; memcpy(undoLog+1, key, keySize); memcpy(((byte*)(undoLog+1))+keySize, value, valueSize); // printf("entry size %d sizeof(remove_log)%d keysize %d valuesize %d sizeof(rid) %d key %d value {%d %d %ld}\n", // entrySize, sizeof(stasis_linked_list_remove_log), keySize, valueSize, sizeof(recordid), key, value->page, value->slot, value->size); void * handle = TbeginNestedTopAction(xid, OPERATION_LINKED_LIST_REMOVE, (byte*)undoLog, entrySize); free(value); free(undoLog); stasis_linked_list_remove_helper(xid, list, key, keySize); TendNestedTopAction(xid, handle); pthread_mutex_unlock(&stasis_linked_list_mutex); return 1; }
int TlinkedListInsert(int xid, recordid list, const byte * key, int keySize, const byte * value, int valueSize) { int ret = 0; /* try_ret(compensation_error()) { ret = TlinkedListRemove(xid, list, key, keySize); } end_ret(compensation_error()); */ stasis_linked_list_insert_log * undoLog = stasis_malloc_trailing_array(stasis_linked_list_insert_log, keySize); undoLog->list = list; undoLog->keySize = keySize; memcpy(undoLog+1, key, keySize); pthread_mutex_lock(&stasis_linked_list_mutex); void * handle = TbeginNestedTopAction(xid, OPERATION_LINKED_LIST_INSERT, (byte*)undoLog, sizeof(stasis_linked_list_insert_log) + keySize); free(undoLog); stasis_linked_list_insert_helper(xid, list, key, keySize, value, valueSize); TendNestedTopAction(xid, handle); pthread_mutex_unlock(&stasis_linked_list_mutex); return ret; }