regions now make use of nested top actions, so they're almost correct. (Still need to lock freed regions until end of transaction.)

This commit is contained in:
Sears Russell 2006-07-25 00:56:50 +00:00
parent 86fab6a22b
commit 0f45b97eda
4 changed files with 91 additions and 31 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 4006 //#define MAX_BUFFER_SIZE 4006
/* #define MAX_BUFFER_SIZE 71 */ /* #define MAX_BUFFER_SIZE 71 */
/*#define MAX_BUFFER_SIZE 7 */ /*#define MAX_BUFFER_SIZE 7 */
@ -137,6 +137,9 @@ terms specified in this license.
#define OPERATION_FIXED_PAGE_ALLOC 36 #define OPERATION_FIXED_PAGE_ALLOC 36
#define OPERATION_ALLOC_REGION 37
#define OPERATION_DEALLOC_REGION 38
// these operations are specific to OASYS // these operations are specific to OASYS
#define OPERATION_OASYS_DIFF_DO 75 #define OPERATION_OASYS_DIFF_DO 75
#define OPERATION_OASYS_DIFF_REDO 76 #define OPERATION_OASYS_DIFF_REDO 76

View file

@ -34,7 +34,7 @@ void TregionFindNthActive(int xid, unsigned int n, unsigned int * firstPage, uns
Operation getAllocBoundaryTag(); Operation getAllocBoundaryTag();
Operation getRegionAlloc(); Operation getAllocRegion();
Operation getRegionFree(); Operation getDeallocRegion();
// XXX need callbacks to handle transaction commit/abort. // XXX need callbacks to handle transaction commit/abort.

View file

@ -5,8 +5,18 @@
#define INVALID_XID (-1) #define INVALID_XID (-1)
typedef struct regionAllocLogArg{
int startPage;
unsigned int pageCount;
int allocationManager;
} regionAllocArg;
#define boundary_tag_ptr(p) (((byte*)end_of_usable_space_ptr((p)))-sizeof(boundary_tag_t)) #define boundary_tag_ptr(p) (((byte*)end_of_usable_space_ptr((p)))-sizeof(boundary_tag_t))
pthread_mutex_t region_mutex = PTHREAD_MUTEX_INITIALIZER;
static void TregionAllocHelper(int xid, unsigned int pageid, unsigned int pageCount, int allocationManager);
static int operate_alloc_boundary_tag(int xid, Page * p, lsn_t lsn, recordid rid, const void * dat) { static int operate_alloc_boundary_tag(int xid, Page * p, lsn_t lsn, recordid rid, const void * dat) {
slottedPageInitialize(p); slottedPageInitialize(p);
@ -16,6 +26,22 @@ static int operate_alloc_boundary_tag(int xid, Page * p, lsn_t lsn, recordid rid
return 0; return 0;
} }
static int operate_alloc_region(int xid, Page * p, lsn_t lsn, recordid rid, const void * datP) {
pthread_mutex_lock(&region_mutex);
assert(!p);
regionAllocArg *dat = (regionAllocArg*)datP;
TregionAllocHelper(xid, dat->startPage, dat->pageCount, dat->allocationManager);
pthread_mutex_unlock(&region_mutex);
return 0;
}
static int operate_dealloc_region(int xid, Page * p, lsn_t lsn, recordid rid, const void * datP) {
regionAllocArg *dat = (regionAllocArg*)datP;
assert(!p);
TregionDealloc(xid, dat->startPage+1);
return 0;
}
// TODO: Implement these four functions. // TODO: Implement these four functions.
static void TallocBoundaryTag(int xid, unsigned int page, boundary_tag* tag) { static void TallocBoundaryTag(int xid, unsigned int page, boundary_tag* tag) {
// printf("Alloc boundary tag at %d\n", page); // printf("Alloc boundary tag at %d\n", page);
@ -27,13 +53,8 @@ static void TdeallocBoundaryTag(int xid, unsigned int page) {
} }
static void TreadBoundaryTag(int xid, unsigned int page, boundary_tag* tag) { static void TreadBoundaryTag(int xid, unsigned int page, boundary_tag* tag) {
// printf("Reading boundary tag at %d\n", page);
recordid rid = { page, 0, sizeof(boundary_tag) }; recordid rid = { page, 0, sizeof(boundary_tag) };
Tread(xid, rid, tag); Tread(xid, rid, tag);
// Page * p = loadPage(xid, page);
// printf("regions.c: %d\n", *page_type_ptr(p)); fflush(NULL);
// assert(*page_type_ptr(p) == BOUNDARY_TAG_PAGE);
// releasePage(p);
} }
static void TsetBoundaryTag(int xid, unsigned int page, boundary_tag* tag) { static void TsetBoundaryTag(int xid, unsigned int page, boundary_tag* tag) {
// printf("Writing boundary tag at %d\n", page); // printf("Writing boundary tag at %d\n", page);
@ -65,30 +86,10 @@ void regionsInit() {
releasePage(p); releasePage(p);
} }
pthread_mutex_t region_mutex = PTHREAD_MUTEX_INITIALIZER; static void TregionAllocHelper(int xid, unsigned int pageid, unsigned int pageCount, int allocationManager) {
unsigned int TregionAlloc(int xid, unsigned int pageCount, int allocationManager) {
// Initial implementation. Naive first fit.
pthread_mutex_lock(&region_mutex);
unsigned int pageid = 0;
boundary_tag t; boundary_tag t;
unsigned int prev_size = UINT32_MAX; TreadBoundaryTag(xid, pageid, &t);
TreadBoundaryTag(xid, pageid, &t); // XXX need to check if there is a boundary tag there or not!
while(t.status != REGION_VACANT || t.size < pageCount) { // TODO: This while loop and the boundary tag manipulation below should be factored into two submodules.
// printf("t.status = %d, REGION_VACANT = %d, t.size = %d, pageCount = %d\n", t.status, REGION_VACANT, t.size, pageCount);
assert(t.prev_size == prev_size);
prev_size = t.size;
pageid += ( t.size + 1 );
TreadBoundaryTag(xid, pageid, &t);
}
// printf("page = %d, t.status = %d, REGION_VACANT = %d, t.size = %d, pageCount = %d (alloced)\n", pageid, t.status, REGION_VACANT, t.size, pageCount);
assert(t.prev_size == prev_size);
if(t.size != pageCount) { if(t.size != pageCount) {
// need to split region // need to split region
// allocate new boundary tag. // allocate new boundary tag.
@ -131,6 +132,39 @@ unsigned int TregionAlloc(int xid, unsigned int pageCount, int allocationManager
TsetBoundaryTag(xid, pageid, &t); TsetBoundaryTag(xid, pageid, &t);
}
unsigned int TregionAlloc(int xid, unsigned int pageCount, int allocationManager) {
// Initial implementation. Naive first fit.
pthread_mutex_lock(&region_mutex);
unsigned int pageid = 0;
boundary_tag t;
unsigned int prev_size = UINT32_MAX;
TreadBoundaryTag(xid, pageid, &t); // XXX need to check if there is a boundary tag there or not!
while(t.status != REGION_VACANT || t.size < pageCount) { // TODO: This while loop and the boundary tag manipulation below should be factored into two submodules.
// printf("t.status = %d, REGION_VACANT = %d, t.size = %d, pageCount = %d\n", t.status, REGION_VACANT, t.size, pageCount);
assert(t.prev_size == prev_size);
prev_size = t.size;
pageid += ( t.size + 1 );
TreadBoundaryTag(xid, pageid, &t);
}
// printf("page = %d, t.status = %d, REGION_VACANT = %d, t.size = %d, pageCount = %d (alloced)\n", pageid, t.status, REGION_VACANT, t.size, pageCount);
assert(t.prev_size == prev_size);
regionAllocArg arg = { pageid, pageCount, allocationManager };
void * ntaHandle = TbeginNestedTopAction(xid, OPERATION_ALLOC_REGION, (const byte*)&arg, sizeof(regionAllocArg));
TregionAllocHelper(xid, pageid, pageCount, allocationManager);
TendNestedTopAction(xid, ntaHandle);
pthread_mutex_unlock(&region_mutex); pthread_mutex_unlock(&region_mutex);
return pageid+1; return pageid+1;
@ -238,6 +272,26 @@ Operation getAllocBoundaryTag() {
return o; return o;
} }
Operation getAllocRegion() {
Operation o = {
OPERATION_ALLOC_REGION,
sizeof(regionAllocArg),
OPERATION_DEALLOC_REGION,
&operate_alloc_region
};
return o;
}
Operation getDeallocRegion() {
Operation o = {
OPERATION_DEALLOC_REGION,
sizeof(regionAllocArg),
OPERATION_ALLOC_REGION,
&operate_dealloc_region
};
return o;
}
void TregionFindNthActive(int xid, unsigned int regionNumber, unsigned int * firstPage, unsigned int * size) { void TregionFindNthActive(int xid, unsigned int regionNumber, unsigned int * firstPage, unsigned int * size) {
boundary_tag t; boundary_tag t;
recordid rid = {0, 0, sizeof(boundary_tag)}; recordid rid = {0, 0, sizeof(boundary_tag)};

View file

@ -86,6 +86,9 @@ void setupOperationsTable() {
operationsTable[OPERATION_FIXED_PAGE_ALLOC] = getFixedPageAlloc(); operationsTable[OPERATION_FIXED_PAGE_ALLOC] = getFixedPageAlloc();
operationsTable[OPERATION_ALLOC_REGION] = getAllocRegion();
operationsTable[OPERATION_DEALLOC_REGION] = getDeallocRegion();
/* /*
int i; int i;