From dc8a3e5d6011f039a3fa550263a9f5fe521cfaaf Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Fri, 16 Jun 2006 00:05:44 +0000 Subject: [PATCH] Eliminated slottedPreRalloc --- src/lladd/operations/alloc.c | 3 +- src/lladd/page/slotted.c | 80 ++++++++++++++++++-------------- src/lladd/page/slotted.h | 2 +- test/lladd/check_bufferManager.c | 10 +--- test/lladd/check_operations.c | 3 +- 5 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/lladd/operations/alloc.c b/src/lladd/operations/alloc.c index d0f9fc2..cd9b494 100644 --- a/src/lladd/operations/alloc.c +++ b/src/lladd/operations/alloc.c @@ -193,7 +193,8 @@ compensated_function recordid Talloc(int xid, long size) { slottedPageInitialize(p); } - rid = slottedPreRalloc(xid, size, &p); + // rid = slottedPreRalloc(xid, size, &p); + rid = slottedRawRalloc(p, size); Tupdate(xid, rid, NULL, OPERATION_ALLOC); /** @todo does releasePage do the correct error checking? <- Why is this comment here?*/ releasePage(p); diff --git a/src/lladd/page/slotted.c b/src/lladd/page/slotted.c index 68bc559..888fe58 100644 --- a/src/lladd/page/slotted.c +++ b/src/lladd/page/slotted.c @@ -2,7 +2,7 @@ #include "../page.h" -#include "../blobManager.h" /** So that we can call sizeof(blob_record_t) */ +//#include "../blobManager.h" /** So that we can call sizeof(blob_record_t) */ #include "slotted.h" #include @@ -192,57 +192,69 @@ size_t slottedFreespace(Page * page) { @todo need to obtain (transaction-level) write locks _before_ writing log entries. Otherwise, we can deadlock at recovery. */ -compensated_function recordid slottedPreRalloc(int xid, unsigned long size, Page ** pp) { +/*compensated_function recordid slottedPreRalloc(int xid, unsigned long size, Page ** pp) { recordid ret; - int isBlob = 0; - if(size == BLOB_SLOT) { - isBlob = 1; - size = sizeof(blob_record_t); - } - assert(size < BLOB_THRESHOLD_SIZE); + // int isBlob = 0; + //if(size == BLOB_SLOT) { + // isBlob = 1; + // size = sizeof(blob_record_t); + // } + // assert(size < BLOB_THRESHOLD_SIZE); - assert(*page_type_ptr(*pp) == SLOTTED_PAGE); + // assert(*page_type_ptr(*pp) == SLOTTED_PAGE); ret = slottedRawRalloc(*pp, size); - assert(ret.size == size); + // assert(ret.size == size); - if(isBlob) { - *slot_length_ptr(*pp, ret.slot) = BLOB_SLOT; - } + // if(isBlob) { + // *slot_length_ptr(*pp, ret.slot) = BLOB_SLOT; + // } DEBUG("alloced rid = {%d, %d, %ld}\n", ret.page, ret.slot, ret.size); return ret; -} +}*/ recordid slottedRawRalloc(Page * page, int size) { - writelock(page->rwlatch, 342); + int type = size; + if(type >= SLOT_TYPE_BASE) { + assert(type < SLOT_TYPE_END); + size = SLOT_TYPE_LENGTHS[type-SLOT_TYPE_BASE]; + } + assert(type != INVALID_SLOT); + assert(size < SLOT_TYPE_BASE && size >= 0); - recordid rid; + writelock(page->rwlatch, 342); + assert(*page_type_ptr(page) == SLOTTED_PAGE); - rid.page = page->id; - rid.slot = *numslots_ptr(page); - rid.size = size; + recordid rid; + + rid.page = page->id; + rid.slot = *numslots_ptr(page); + rid.size = size; + + /* The freelist_ptr points to the first free slot number, which + is the head of a linked list of free slot numbers.*/ + if(*freelist_ptr(page) != INVALID_SLOT) { + rid.slot = *freelist_ptr(page); + *freelist_ptr(page) = *slot_length_ptr(page, rid.slot); + *slot_length_ptr(page, rid.slot) = 0; + } + + really_do_ralloc(page, rid); - /* The freelist_ptr points to the first free slot number, which - is the head of a linked list of free slot numbers.*/ - if(*freelist_ptr(page) != INVALID_SLOT) { - rid.slot = *freelist_ptr(page); - *freelist_ptr(page) = *slot_length_ptr(page, rid.slot); - *slot_length_ptr(page, rid.slot) = 0; - } - - really_do_ralloc(page, rid); + assert(size == *slot_length_ptr(page, rid.slot)); - /* DEBUG("slot: %d freespace: %d\n", rid.slot, freeSpace); */ + *slot_length_ptr(page, rid.slot) = type; + + /* DEBUG("slot: %d freespace: %d\n", rid.slot, freeSpace); */ + + assert(slottedFreespaceUnlocked(page) >= 0); - assert(slottedFreespaceUnlocked(page) >= 0); + writeunlock(page->rwlatch); - writeunlock(page->rwlatch); - - - return rid; + return rid; } /** diff --git a/src/lladd/page/slotted.h b/src/lladd/page/slotted.h index 445fd96..8c23e90 100644 --- a/src/lladd/page/slotted.h +++ b/src/lladd/page/slotted.h @@ -96,7 +96,7 @@ void slottedPageInitialize(Page * p); * @see postRallocSlot the implementation of the second phase. * */ -compensated_function recordid slottedPreRalloc(int xid, unsigned long size, Page**p); +//compensated_function recordid slottedPreRalloc(int xid, unsigned long size, Page**p); /** * The second phase of slot allocation. Called after the log entry diff --git a/test/lladd/check_bufferManager.c b/test/lladd/check_bufferManager.c index daacdd3..12e71ee 100644 --- a/test/lladd/check_bufferManager.c +++ b/test/lladd/check_bufferManager.c @@ -87,15 +87,7 @@ void * workerThreadWriting(void * q) { int offset = *(int*)q; recordid rids[RECORDS_PER_THREAD]; for(int i = 0 ; i < RECORDS_PER_THREAD; i++) { - /* Page * tmp; - pthread_mutex_lock(&ralloc_mutex); - rids[i] = slottedPreRalloc(1, sizeof(int), &tmp); - slottedPostRalloc(-1, tmp, 1, rids[i]); - tmp->LSN = 0; - *lsn_ptr(tmp) = 0; - releasePage(tmp); - pthread_mutex_unlock(&ralloc_mutex); - */ + rids[i] = Talloc(-1, sizeof(int)); /* printf("\nRID:\t%d,%d\n", rids[i].page, rids[i].slot); */ /* fflush(NULL); */ diff --git a/test/lladd/check_operations.c b/test/lladd/check_operations.c index c8ddb80..cf58d75 100644 --- a/test/lladd/check_operations.c +++ b/test/lladd/check_operations.c @@ -76,7 +76,8 @@ START_TEST(operation_physical_do_undo) { xid = -1; Page * p = loadPage(xid, TpageAlloc(xid)); slottedPageInitialize(p); - rid = slottedPreRalloc(xid, sizeof(int), &p); + // rid = slottedPreRalloc(xid, sizeof(int), &p); + rid = slottedRawRalloc(p, sizeof(int)); releasePage(p); //rid = Talloc(xid, sizeof(int)); buf = 1;