Eliminated slottedPreRalloc

This commit is contained in:
Sears Russell 2006-06-16 00:05:44 +00:00
parent ffac2d6362
commit dc8a3e5d60
5 changed files with 52 additions and 46 deletions

View file

@ -193,7 +193,8 @@ compensated_function recordid Talloc(int xid, long size) {
slottedPageInitialize(p); slottedPageInitialize(p);
} }
rid = slottedPreRalloc(xid, size, &p); // rid = slottedPreRalloc(xid, size, &p);
rid = slottedRawRalloc(p, size);
Tupdate(xid, rid, NULL, OPERATION_ALLOC); Tupdate(xid, rid, NULL, OPERATION_ALLOC);
/** @todo does releasePage do the correct error checking? <- Why is this comment here?*/ /** @todo does releasePage do the correct error checking? <- Why is this comment here?*/
releasePage(p); releasePage(p);

View file

@ -2,7 +2,7 @@
#include "../page.h" #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 "slotted.h"
#include <assert.h> #include <assert.h>
@ -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. @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; recordid ret;
int isBlob = 0; // int isBlob = 0;
if(size == BLOB_SLOT) { //if(size == BLOB_SLOT) {
isBlob = 1; // isBlob = 1;
size = sizeof(blob_record_t); // size = sizeof(blob_record_t);
} // }
assert(size < BLOB_THRESHOLD_SIZE); // assert(size < BLOB_THRESHOLD_SIZE);
assert(*page_type_ptr(*pp) == SLOTTED_PAGE); // assert(*page_type_ptr(*pp) == SLOTTED_PAGE);
ret = slottedRawRalloc(*pp, size); ret = slottedRawRalloc(*pp, size);
assert(ret.size == size); // assert(ret.size == size);
if(isBlob) { // if(isBlob) {
*slot_length_ptr(*pp, ret.slot) = BLOB_SLOT; // *slot_length_ptr(*pp, ret.slot) = BLOB_SLOT;
} // }
DEBUG("alloced rid = {%d, %d, %ld}\n", ret.page, ret.slot, ret.size); DEBUG("alloced rid = {%d, %d, %ld}\n", ret.page, ret.slot, ret.size);
return ret; return ret;
} }*/
recordid slottedRawRalloc(Page * page, int size) { 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; recordid rid;
rid.slot = *numslots_ptr(page);
rid.size = size;
/* The freelist_ptr points to the first free slot number, which rid.page = page->id;
is the head of a linked list of free slot numbers.*/ rid.slot = *numslots_ptr(page);
if(*freelist_ptr(page) != INVALID_SLOT) { rid.size = size;
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;
}
/* DEBUG("slot: %d freespace: %d\n", rid.slot, freeSpace); */ really_do_ralloc(page, rid);
assert(slottedFreespaceUnlocked(page) >= 0); assert(size == *slot_length_ptr(page, rid.slot));
writeunlock(page->rwlatch); *slot_length_ptr(page, rid.slot) = type;
/* DEBUG("slot: %d freespace: %d\n", rid.slot, freeSpace); */
return rid; assert(slottedFreespaceUnlocked(page) >= 0);
writeunlock(page->rwlatch);
return rid;
} }
/** /**

View file

@ -96,7 +96,7 @@ void slottedPageInitialize(Page * p);
* @see postRallocSlot the implementation of the second phase. * @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 * The second phase of slot allocation. Called after the log entry

View file

@ -87,15 +87,7 @@ void * workerThreadWriting(void * q) {
int offset = *(int*)q; int offset = *(int*)q;
recordid rids[RECORDS_PER_THREAD]; recordid rids[RECORDS_PER_THREAD];
for(int i = 0 ; i < RECORDS_PER_THREAD; i++) { 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)); rids[i] = Talloc(-1, sizeof(int));
/* printf("\nRID:\t%d,%d\n", rids[i].page, rids[i].slot); */ /* printf("\nRID:\t%d,%d\n", rids[i].page, rids[i].slot); */
/* fflush(NULL); */ /* fflush(NULL); */

View file

@ -76,7 +76,8 @@ START_TEST(operation_physical_do_undo) {
xid = -1; xid = -1;
Page * p = loadPage(xid, TpageAlloc(xid)); Page * p = loadPage(xid, TpageAlloc(xid));
slottedPageInitialize(p); slottedPageInitialize(p);
rid = slottedPreRalloc(xid, sizeof(int), &p); // rid = slottedPreRalloc(xid, sizeof(int), &p);
rid = slottedRawRalloc(p, sizeof(int));
releasePage(p); releasePage(p);
//rid = Talloc(xid, sizeof(int)); //rid = Talloc(xid, sizeof(int));
buf = 1; buf = 1;