New buffer manager implementation (very simple; just stores pages in memory, addressed via an array of pointers)

This commit is contained in:
Sears Russell 2007-03-04 02:46:23 +00:00
parent d2e3aea23e
commit c1bf2ba7ac
5 changed files with 90 additions and 7 deletions

View file

@ -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

View file

@ -60,6 +60,7 @@ terms specified in this license.
#include <assert.h>
#include <lladd/bufferManager.h>
#include "bufferManager/pageArray.h"
#include <lladd/bufferPool.h>
@ -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();

View file

@ -0,0 +1,70 @@
#include <stdlib.h>
#include <config.h>
#include <lladd/transactional.h>
#include <lladd/bufferManager.h>
#include <lladd/bufferPool.h>
#include <lladd/truncation.h>
#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;
}

View file

@ -0,0 +1 @@
void paBufInit();

View file

@ -113,6 +113,7 @@ int Tinit() {
LogInit(loggerType);
pageInit();
bufInit(BUFFER_MANAGER_HASH);
//bufInit(BUFFER_MANAGER_MEM_ARRAY);
pageOperationsInit();
initNestedTopActions();
TallocInit();