diff --git a/src/lladd/Makefile.am b/src/lladd/Makefile.am index fc44642..65bf01f 100644 --- a/src/lladd/Makefile.am +++ b/src/lladd/Makefile.am @@ -18,7 +18,8 @@ liblladd_a_SOURCES=crc32.c redblack.c lhtable.c common.c stats.c io.c bufferMana operations/linearHashNTA.c operations/linkedListNTA.c \ operations/pageOrientedListNTA.c operations/bTree.c \ operations/regions.c \ - io/rangeTracker.c io/memory.c io/file.c io/non_blocking.c io/debug.c + io/rangeTracker.c io/memory.c io/file.c io/non_blocking.c io/debug.c \ + bufferManager/pageArray.c # page/header.c logger/logMemory.c \ ringbuffer.c \ asdfas #operations/lladdhash.c #AM_CFLAGS= -g -Wall -pedantic -std=gnu99 diff --git a/src/lladd/bufferManager.c b/src/lladd/bufferManager.c index 51e23d7..db3952f 100644 --- a/src/lladd/bufferManager.c +++ b/src/lladd/bufferManager.c @@ -60,6 +60,7 @@ terms specified in this license. #include #include +#include "bufferManager/pageArray.h" #include @@ -107,8 +108,19 @@ static Page * dummy_page; static pthread_key_t lastPage; +static void bufManBufDeinit(); +static compensated_function Page *bufManLoadPage(int xid, int pageid); +static void bufManReleasePage (Page * p); + static int bufManBufInit() { + releasePage = bufManReleasePage; + loadPage = bufManLoadPage; + writeBackPage = pageWrite; + forcePages = forcePageFile; + bufDeinit = bufManBufDeinit; + + bufferPoolInit(); openPageFile(); @@ -488,8 +500,8 @@ Page * (*loadPage)(int xid, int pageid) = 0; void (*releasePage)(Page * p) = 0; void (*writeBackPage)(Page * p) = 0; void (*forcePages)() = 0; - void (*bufDeinit)() = 0; + int bufInit(int type) { static int lastType = 0; if(type == BUFFER_MANAGER_REOPEN) { @@ -497,13 +509,11 @@ int bufInit(int type) { } lastType = type; if(type == BUFFER_MANAGER_HASH) { - releasePage = bufManReleasePage; - loadPage = bufManLoadPage; - writeBackPage = pageWrite; - forcePages = forcePageFile; - bufDeinit = bufManBufDeinit; bufManBufInit(); return 0; + } else if (type == BUFFER_MANAGER_MEM_ARRAY) { + paBufInit(); + return 0; } else { // XXX error handling abort(); diff --git a/src/lladd/bufferManager/pageArray.c b/src/lladd/bufferManager/pageArray.c new file mode 100644 index 0000000..f13cc78 --- /dev/null +++ b/src/lladd/bufferManager/pageArray.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include "latches.h" +#include "bufferManager/pageArray.h" + +static Page ** pageMap; +static int pageCount; +static pthread_mutex_t pageArray_mut = PTHREAD_MUTEX_INITIALIZER; + +static Page * paLoadPage(int xid, int pageid) { + pthread_mutex_lock(&pageArray_mut); + if(pageid >= pageCount) { + pageMap = realloc(pageMap, (1+pageid) * sizeof(Page*)); + for(int i = pageCount; i <= pageid; i++) { + pageMap[i] = 0; + } + pageCount = pageid + 1; + } + + if(!pageMap[pageid]) { + pageMap[pageid] = malloc(sizeof(Page)); + pageMap[pageid]->id = pageid; + pageMap[pageid]->LSN = 0; + pageMap[pageid]->dirty = 0; + pageMap[pageid]->next = 0; + pageMap[pageid]->prev = 0; + pageMap[pageid]->queue = 0; + pageMap[pageid]->inCache = 1; + pageMap[pageid]->rwlatch = initlock(); + pageMap[pageid]->loadlatch = initlock(); + pageMap[pageid]->memAddr= calloc(PAGE_SIZE, sizeof(byte)); + } + pthread_mutex_unlock(&pageArray_mut); + return pageMap[pageid]; +} + +static void paReleasePage(Page * p) { + /* no-op */ +} + +static void paWriteBackPage(Page * p) { + dirtyPages_remove(p); +} +static void paForcePages() { /* no-op */ } + +static void paBufDeinit() { + for(int i =0; i < pageCount; i++) { + if(pageMap[i]) { + deletelock(pageMap[i]->rwlatch); + deletelock(pageMap[i]->loadlatch); + free(pageMap[i]); + } + } +} +void paBufInit () { + + releasePage = paReleasePage; + loadPage = paLoadPage; + writeBackPage = paWriteBackPage; + forcePages = paForcePages; + bufDeinit = paBufDeinit; + + pageCount = 0; + pageMap = 0; +} + diff --git a/src/lladd/bufferManager/pageArray.h b/src/lladd/bufferManager/pageArray.h new file mode 100644 index 0000000..95f7a2d --- /dev/null +++ b/src/lladd/bufferManager/pageArray.h @@ -0,0 +1 @@ +void paBufInit(); diff --git a/src/lladd/transactional2.c b/src/lladd/transactional2.c index 4a65147..1dedbfd 100644 --- a/src/lladd/transactional2.c +++ b/src/lladd/transactional2.c @@ -113,6 +113,7 @@ int Tinit() { LogInit(loggerType); pageInit(); bufInit(BUFFER_MANAGER_HASH); + //bufInit(BUFFER_MANAGER_MEM_ARRAY); pageOperationsInit(); initNestedTopActions(); TallocInit();