More steps toward factoring page allocation out of record allocation.

This commit is contained in:
Sears Russell 2006-06-15 05:31:20 +00:00
parent 59bd80a2a8
commit 50515ffd23
9 changed files with 55 additions and 68 deletions

View file

@ -80,11 +80,11 @@ terms specified in this license.
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
//#define MAX_BUFFER_SIZE 100003 #define MAX_BUFFER_SIZE 100003
/*#define MAX_BUFFER_SIZE 20029 */ /*#define MAX_BUFFER_SIZE 20029 */
//#define MAX_BUFFER_SIZE 10007 //#define MAX_BUFFER_SIZE 10007
//#define MAX_BUFFER_SIZE 5003 //#define MAX_BUFFER_SIZE 5003
#define MAX_BUFFER_SIZE 2003 //#define MAX_BUFFER_SIZE 2003
/* #define MAX_BUFFER_SIZE 71 */ /* #define MAX_BUFFER_SIZE 71 */
/*#define MAX_BUFFER_SIZE 7 */ /*#define MAX_BUFFER_SIZE 7 */

View file

@ -19,6 +19,8 @@ Operation getAlloc();
Operation getDealloc(); Operation getDealloc();
Operation getRealloc(); Operation getRealloc();
void TallocInit();
/** /**
Allocate a record. Allocate a record.

View file

@ -143,6 +143,12 @@ Operation getRealloc() {
return o; return o;
} }
static uint64_t lastFreepage;
void TallocInit() {
lastFreepage = UINT64_MAX;
}
compensated_function recordid Talloc(int xid, long size) { compensated_function recordid Talloc(int xid, long size) {
recordid rid; recordid rid;
@ -159,38 +165,43 @@ compensated_function recordid Talloc(int xid, long size) {
begin_action_ret(pthread_mutex_unlock, &talloc_mutex, NULLRID) { begin_action_ret(pthread_mutex_unlock, &talloc_mutex, NULLRID) {
pthread_mutex_lock(&talloc_mutex); pthread_mutex_lock(&talloc_mutex);
if(lastFreepage == UINT64_MAX) {
try_ret(NULLRID) {
lastFreepage = TpageAlloc(xid);
} end_ret(NULLRID);
try_ret(NULLRID) {
p = loadPage(xid, lastFreepage);
} end_ret(NULLRID);
assert(*page_type_ptr(p) == UNINITIALIZED_PAGE);
slottedPageInitialize(p);
} else {
try_ret(NULLRID) {
p = loadPage(xid, lastFreepage);
} end_ret(NULLRID);
}
if(slottedFreespace(p) < size ) {
releasePage(p);
try_ret(NULLRID) {
lastFreepage = TpageAlloc(xid);
} end_ret(NULLRID);
try_ret(NULLRID) {
p = loadPage(xid, lastFreepage);
} end_ret(NULLRID);
slottedPageInitialize(p);
}
rid = slottedPreRalloc(xid, size, &p); rid = slottedPreRalloc(xid, size, &p);
Tupdate(xid, rid, NULL, OPERATION_ALLOC); Tupdate(xid, rid, NULL, OPERATION_ALLOC);
/** @todo does releasePage do the correct error checking? */ /** @todo does releasePage do the correct error checking? <- Why is this comment here?*/
releasePage(p); releasePage(p);
} compensate_ret(NULLRID); } compensate_ret(NULLRID);
} }
return rid; return rid;
/* try_ret(NULL_RID) {
if(size >= BLOB_THRESHOLD_SIZE && size != BLOB_SLOT) {
///@todo is it OK that Talloc doesn't pin the page when a blob is alloced?
rid = pr eAllocBlob(xid, size);
} else {
pthread_mutex_lock(&talloc_mutex);
rid = slottedPreRalloc(xid, size, &p);
assert(p != NULL);
}
Tupdate(xid,rid, NULL, OPERATION_ALLOC);
if(p != NULL) {
/// release the page that preAllocBlob pinned for us.
/// @todo alloc.c pins multiple pages -> Will deadlock with small buffer sizes..
releasePage(p);
pthread_mutex_unlock(&talloc_mutex);
}
} end_ret(NULLRID);
return rid;*/
} }
compensated_function recordid TallocFromPage(int xid, long page, unsigned long size) { compensated_function recordid TallocFromPage(int xid, long page, unsigned long size) {

View file

@ -113,11 +113,11 @@ void slottedCompact(Page * page) {
/*static pthread_mutex_t lastFreepage_mutex; */ /*static pthread_mutex_t lastFreepage_mutex; */
static uint64_t lastFreepage = -10; // static uint64_t lastFreepage = -10;
void slottedPageInit() { void slottedPageInit() {
/*pthread_mutex_init(&lastFreepage_mutex , NULL); */ /*pthread_mutex_init(&lastFreepage_mutex , NULL); */
lastFreepage = UINT64_MAX; //lastFreepage = UINT64_MAX;
} }
void slottedPageDeInit() { void slottedPageDeInit() {
@ -201,35 +201,6 @@ compensated_function recordid slottedPreRalloc(int xid, unsigned long size, Page
} }
assert(size < BLOB_THRESHOLD_SIZE); assert(size < BLOB_THRESHOLD_SIZE);
/** @todo is ((unsigned int) foo) == -1 portable? Gotta love C.*/
if(lastFreepage == UINT64_MAX) {
try_ret(NULLRID) {
lastFreepage = TpageAlloc(xid);
} end_ret(NULLRID);
try_ret(NULLRID) {
*pp = loadPage(xid, lastFreepage);
} end_ret(NULLRID);
assert(*page_type_ptr(*pp) == UNINITIALIZED_PAGE);
slottedPageInitialize(*pp);
} else {
try_ret(NULLRID) {
*pp = loadPage(xid, lastFreepage);
} end_ret(NULLRID);
}
if(slottedFreespace(*pp) < size ) {
releasePage(*pp);
try_ret(NULLRID) {
lastFreepage = TpageAlloc(xid);
} end_ret(NULLRID);
try_ret(NULLRID) {
*pp = loadPage(xid, lastFreepage);
} end_ret(NULLRID);
slottedPageInitialize(*pp);
}
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);

View file

@ -8,7 +8,6 @@
#include <lladd/consumer.h> #include <lladd/consumer.h>
#include <lladd/lockManager.h> #include <lladd/lockManager.h>
#include <lladd/compensations.h> #include <lladd/compensations.h>
#include "page.h" #include "page.h"
#include <lladd/logger/logger2.h> #include <lladd/logger/logger2.h>
#include <lladd/truncation.h> #include <lladd/truncation.h>
@ -111,6 +110,7 @@ int Tinit() {
pageOperationsInit(); pageOperationsInit();
} end_ret(compensation_error()); } end_ret(compensation_error());
initNestedTopActions(); initNestedTopActions();
TallocInit();
ThashInit(); ThashInit();
LinearHashNTAInit(); LinearHashNTAInit();
LinkedListNTAInit(); LinkedListNTAInit();

View file

@ -87,7 +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; /* Page * tmp;
pthread_mutex_lock(&ralloc_mutex); pthread_mutex_lock(&ralloc_mutex);
rids[i] = slottedPreRalloc(1, sizeof(int), &tmp); rids[i] = slottedPreRalloc(1, sizeof(int), &tmp);
slottedPostRalloc(-1, tmp, 1, rids[i]); slottedPostRalloc(-1, tmp, 1, rids[i]);
@ -95,7 +95,8 @@ void * workerThreadWriting(void * q) {
*lsn_ptr(tmp) = 0; *lsn_ptr(tmp) = 0;
releasePage(tmp); releasePage(tmp);
pthread_mutex_unlock(&ralloc_mutex); pthread_mutex_unlock(&ralloc_mutex);
*/
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); */
@ -239,7 +240,7 @@ Suite * check_suite(void) {
Suite *s = suite_create("bufferManager"); Suite *s = suite_create("bufferManager");
/* Begin a new test */ /* Begin a new test */
TCase *tc = tcase_create("multithreaded"); TCase *tc = tcase_create("multithreaded");
tcase_set_timeout(tc, 0); // disable timeouts
/* Sub tests are added, one per line, here */ /* Sub tests are added, one per line, here */
tcase_add_test(tc, pageSingleThreadTest); tcase_add_test(tc, pageSingleThreadTest);

View file

@ -132,7 +132,7 @@ START_TEST(indirectAlloc) {
printf("{page = %d, slot = %d, size = %lld}\n", rid.page, rid.slot, rid.size); printf("{page = %d, slot = %d, size = %lld}\n", rid.page, rid.slot, (long long int)rid.size);
releasePage(p); releasePage(p);
@ -156,7 +156,7 @@ START_TEST(indirectAlloc) {
printf("{page = %d, slot = %d, size = %lld}\n", rid.page, rid.slot, rid.size); printf("{page = %d, slot = %d, size = %lld}\n", rid.page, rid.slot, (long long int)rid.size);
releasePage(p); releasePage(p);

View file

@ -71,12 +71,14 @@ START_TEST(operation_physical_do_undo) {
int buf; int buf;
int arg; int arg;
LogEntry * setToTwo; LogEntry * setToTwo;
Page * p;
Tinit(); Tinit();
xid = -1; xid = -1;
Page * p = loadPage(xid, TpageAlloc(xid));
slottedPageInitialize(p);
rid = slottedPreRalloc(xid, sizeof(int), &p); rid = slottedPreRalloc(xid, sizeof(int), &p);
releasePage(p); releasePage(p);
//rid = Talloc(xid, sizeof(int));
buf = 1; buf = 1;
arg = 2; arg = 2;
@ -530,8 +532,8 @@ START_TEST(operation_alloc_test) {
Tcommit(xid); Tcommit(xid);
printf("rid1={%d,%d,%lld} rid2={%d,%d,%lld}\n", printf("rid1={%d,%d,%lld} rid2={%d,%d,%lld}\n",
rid1.page, rid1.slot, rid1.size, rid1.page, rid1.slot, (long long int)rid1.size,
rid2.page, rid2.slot, rid2.size); rid2.page, rid2.slot, (long long int)rid2.size);

View file

@ -14,7 +14,7 @@ static char * logEntryToString(const LogEntry * le) {
{ {
recordid rid = le->contents.clr.rid; recordid rid = le->contents.clr.rid;
asprintf(&ret, "UPDATE\tlsn=%9ld\tprevlsn=%9ld\txid=%4d\trid={%8d %5d %5lld}\tfuncId=%3d\targSize=%9d\n", le->LSN, le->prevLSN, le->xid, asprintf(&ret, "UPDATE\tlsn=%9ld\tprevlsn=%9ld\txid=%4d\trid={%8d %5d %5lld}\tfuncId=%3d\targSize=%9d\n", le->LSN, le->prevLSN, le->xid,
rid.page, rid.slot, rid.size, le->contents.update.funcID, le->contents.update.argSize ); rid.page, rid.slot, (long long int)rid.size, le->contents.update.funcID, le->contents.update.argSize );
} }
break; break;
@ -44,7 +44,7 @@ static char * logEntryToString(const LogEntry * le) {
{ {
recordid rid = le->contents.clr.rid; recordid rid = le->contents.clr.rid;
asprintf(&ret, "CLR \tlsn=%9ld\tprevlsn=%9ld\txid=%4d\trid={%8d %5d %5lld}\tthisUpdateLSN=%9ld\tundoNextLSN=%9ld\n", le->LSN, le->prevLSN, le->xid, asprintf(&ret, "CLR \tlsn=%9ld\tprevlsn=%9ld\txid=%4d\trid={%8d %5d %5lld}\tthisUpdateLSN=%9ld\tundoNextLSN=%9ld\n", le->LSN, le->prevLSN, le->xid,
rid.page, rid.slot, rid.size, (long int)le->contents.clr.thisUpdateLSN, (long int)le->contents.clr.undoNextLSN ); rid.page, rid.slot, (long long int) rid.size, (long int)le->contents.clr.thisUpdateLSN, (long int)le->contents.clr.undoNextLSN );
} }
break; break;
} }