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:
parent
86fab6a22b
commit
0f45b97eda
4 changed files with 91 additions and 31 deletions
|
@ -80,11 +80,11 @@ terms specified in this license.
|
|||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#define MAX_BUFFER_SIZE 100003
|
||||
//#define MAX_BUFFER_SIZE 100003
|
||||
/*#define MAX_BUFFER_SIZE 20029 */
|
||||
//#define MAX_BUFFER_SIZE 10007
|
||||
//#define MAX_BUFFER_SIZE 5003
|
||||
//#define MAX_BUFFER_SIZE 2003
|
||||
#define MAX_BUFFER_SIZE 2003
|
||||
//#define MAX_BUFFER_SIZE 4006
|
||||
/* #define MAX_BUFFER_SIZE 71 */
|
||||
/*#define MAX_BUFFER_SIZE 7 */
|
||||
|
@ -137,6 +137,9 @@ terms specified in this license.
|
|||
|
||||
#define OPERATION_FIXED_PAGE_ALLOC 36
|
||||
|
||||
#define OPERATION_ALLOC_REGION 37
|
||||
#define OPERATION_DEALLOC_REGION 38
|
||||
|
||||
// these operations are specific to OASYS
|
||||
#define OPERATION_OASYS_DIFF_DO 75
|
||||
#define OPERATION_OASYS_DIFF_REDO 76
|
||||
|
|
|
@ -34,7 +34,7 @@ void TregionFindNthActive(int xid, unsigned int n, unsigned int * firstPage, uns
|
|||
|
||||
Operation getAllocBoundaryTag();
|
||||
|
||||
Operation getRegionAlloc();
|
||||
Operation getRegionFree();
|
||||
Operation getAllocRegion();
|
||||
Operation getDeallocRegion();
|
||||
|
||||
// XXX need callbacks to handle transaction commit/abort.
|
||||
|
|
|
@ -5,8 +5,18 @@
|
|||
|
||||
#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))
|
||||
|
||||
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) {
|
||||
slottedPageInitialize(p);
|
||||
|
@ -16,6 +26,22 @@ static int operate_alloc_boundary_tag(int xid, Page * p, lsn_t lsn, recordid rid
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int operate_alloc_region(int xid, Page * p, lsn_t lsn, recordid rid, const void * datP) {
|
||||
pthread_mutex_lock(®ion_mutex);
|
||||
assert(!p);
|
||||
regionAllocArg *dat = (regionAllocArg*)datP;
|
||||
TregionAllocHelper(xid, dat->startPage, dat->pageCount, dat->allocationManager);
|
||||
pthread_mutex_unlock(®ion_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.
|
||||
static void TallocBoundaryTag(int xid, unsigned int page, boundary_tag* tag) {
|
||||
// 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) {
|
||||
// printf("Reading boundary tag at %d\n", page);
|
||||
recordid rid = { page, 0, sizeof(boundary_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) {
|
||||
// printf("Writing boundary tag at %d\n", page);
|
||||
|
@ -65,30 +86,10 @@ void regionsInit() {
|
|||
releasePage(p);
|
||||
}
|
||||
|
||||
pthread_mutex_t region_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
unsigned int TregionAlloc(int xid, unsigned int pageCount, int allocationManager) {
|
||||
// Initial implementation. Naive first fit.
|
||||
|
||||
pthread_mutex_lock(®ion_mutex);
|
||||
|
||||
unsigned int pageid = 0;
|
||||
static void TregionAllocHelper(int xid, unsigned int pageid, unsigned int pageCount, int allocationManager) {
|
||||
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) {
|
||||
// need to split region
|
||||
// allocate new boundary tag.
|
||||
|
@ -131,6 +132,39 @@ unsigned int TregionAlloc(int xid, unsigned int pageCount, int allocationManager
|
|||
|
||||
TsetBoundaryTag(xid, pageid, &t);
|
||||
|
||||
}
|
||||
|
||||
unsigned int TregionAlloc(int xid, unsigned int pageCount, int allocationManager) {
|
||||
// Initial implementation. Naive first fit.
|
||||
|
||||
|
||||
pthread_mutex_lock(®ion_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(®ion_mutex);
|
||||
|
||||
return pageid+1;
|
||||
|
@ -238,6 +272,26 @@ Operation getAllocBoundaryTag() {
|
|||
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) {
|
||||
boundary_tag t;
|
||||
recordid rid = {0, 0, sizeof(boundary_tag)};
|
||||
|
|
|
@ -86,6 +86,9 @@ void setupOperationsTable() {
|
|||
|
||||
operationsTable[OPERATION_FIXED_PAGE_ALLOC] = getFixedPageAlloc();
|
||||
|
||||
operationsTable[OPERATION_ALLOC_REGION] = getAllocRegion();
|
||||
operationsTable[OPERATION_DEALLOC_REGION] = getDeallocRegion();
|
||||
|
||||
/*
|
||||
int i;
|
||||
|
||||
|
|
Loading…
Reference in a new issue