From 73788eb910d1d595e55e44474c1e9210a400f677 Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Sat, 3 Mar 2007 01:52:03 +0000 Subject: [PATCH] Reworked intialization code, includes to isolate bufferManager implementation from the rest of Stasis. --- lladd/bufferManager.h | 27 ++++++++++++++++----------- lladd/constants.h | 2 ++ src/lladd/blobManager.c | 8 -------- src/lladd/blobManager.h | 2 -- src/lladd/bufferManager.c | 36 ++++++++++++++++++++++-------------- src/lladd/page.c | 4 +--- src/lladd/page.h | 3 +-- src/lladd/recovery2.c | 5 +---- 8 files changed, 43 insertions(+), 44 deletions(-) diff --git a/lladd/bufferManager.h b/lladd/bufferManager.h index ad96c5a..b741613 100644 --- a/lladd/bufferManager.h +++ b/lladd/bufferManager.h @@ -43,10 +43,10 @@ terms specified in this license. * @file * Manages the page buffer - pageManager - Provides cached page handling, delegates to blob + bufferManager - Provides cached page handling, delegates to blob manager when necessary. Doesn't implement an eviction policy. That is left to a cacheManager. (Multiple cacheManagers could be - used with a single page manager.) + used with a single bufferManager.) @todo Allow error checking! @@ -60,7 +60,7 @@ terms specified in this license. Operations, Predicates. - LLADD already has operations and transactions, and these can be + Stasis already has operations and transactions, and these can be relatively unchanged. Predicates are read only operations that return a set of tuples. Tread() is the simplest predicate. Index scans provide a motivating example. @@ -90,27 +90,29 @@ BEGIN_C_DECLS an abstraction barrier between page.h and the rest of the system. If you need to muck with page internals, first consider the - implications that doing so has on locking. In particular, rwlatch + implications that doing so has on latching. In particular, rwlatch is currently entirely handled in page.c. */ typedef struct Page_s Page_s; typedef struct Page_s Page; +extern Page * (*loadPage)(int xid, int pageid); +extern void (*releasePage)(Page * p); +extern int (*bufInit)(); +extern void (*bufDeinit)(); + /** * @param xid The transaction that is pinning the page (used by page-level locking implementations.) * @param pageid ID of the page you want to load * @return fully formed Page type */ -compensated_function Page * loadPage(int xid, int pageid); +compensated_function Page * bufManLoadPage(int xid, int pageid); /** loadPage aquires a lock when it is called, effectively pinning it in memory. releasePage releases this lock. */ -void releasePage(Page * p); - -//#define loadPage(xid, pageid) loadPage(xid, pageid); printf("%s %d: thread=%d loadPage(%d, %d)\n", __FILE__, __LINE__, pthread_self(), (xid), (pageid)); -//#define releasePage(pageid) releasePage(pageid); printf("%s,%d: thread=%d releasePage()\n", __FILE__, __LINE__, pthread_self()); +void bufManReleasePage(Page * p); #ifdef PROFILE_LATCHES_WRITE_ONLY #define loadPage(x,y) __profile_loadPage((x), (y), __FILE__, __LINE__) @@ -125,13 +127,16 @@ compensated_function Page * __profile_loadPage(int xid, int pageid, char * file, * @return 0 on success * @return error code on failure */ -int bufInit(); +int bufManBufInit(); /** * will write out any dirty pages, assumes that there are no running * transactions */ -void bufDeinit(); +void bufManBufDeinit(); + +void setBufferManager(int i); + END_C_DECLS diff --git a/lladd/constants.h b/lladd/constants.h index 2ba62ad..7c353e9 100644 --- a/lladd/constants.h +++ b/lladd/constants.h @@ -91,6 +91,8 @@ terms specified in this license. /*#define MAX_BUFFER_SIZE 7 */ #endif +#define BUFFER_MANAGER_HASH 0 + #define MAX_TRANSACTIONS 1000 /** Operation types */ diff --git a/src/lladd/blobManager.c b/src/lladd/blobManager.c index ee65422..ba863a2 100644 --- a/src/lladd/blobManager.c +++ b/src/lladd/blobManager.c @@ -18,14 +18,6 @@ void allocBlob(int xid, recordid rid) { // printf("rid = {%d %d %d}\n", rid.page, rid.slot, rid.size); } -void openBlobStore() { - -} - -void closeBlobStore() { - -} - void readBlob(int xid, Page * p2, recordid rid, byte * buf) { int chunk; recordid rawRid = rid; diff --git a/src/lladd/blobManager.h b/src/lladd/blobManager.h index a6d6578..11fb8da 100644 --- a/src/lladd/blobManager.h +++ b/src/lladd/blobManager.h @@ -69,8 +69,6 @@ compensated_function recordid preAllocBlobFromPage(int xid, long page, long blob */ void allocBlob(int xid, recordid rid); -void openBlobStore(); -void closeBlobStore(); END_C_DECLS diff --git a/src/lladd/bufferManager.c b/src/lladd/bufferManager.c index 09b2f45..a02bd36 100644 --- a/src/lladd/bufferManager.c +++ b/src/lladd/bufferManager.c @@ -64,8 +64,6 @@ terms specified in this license. #include #include -#include "page.h" -#include "blobManager.h" #include #include "pageFile.h" @@ -109,9 +107,10 @@ static Page * dummy_page; pthread_key_t lastPage; -int bufInit() { +int bufManBufInit() { + + bufferPoolInit(); - pageInit(); openPageFile(); @@ -126,8 +125,6 @@ int bufInit() { pageFree(first, 0); LH_ENTRY(insert)(activePages, &first->id, sizeof(int), first); - openBlobStore(); - pageCacheInit(first); int err = pthread_key_create(&lastPage, 0); @@ -141,9 +138,7 @@ int bufInit() { return 0; } -void bufDeinit() { - - closeBlobStore(); +void bufManBufDeinit() { DEBUG("pageCacheDeinit()"); @@ -155,15 +150,16 @@ void bufDeinit() { pageWrite((Page*)next->value); DEBUG("+"); } - + LH_ENTRY(destroy)(activePages); pthread_mutex_destroy(&loadPagePtr_mutex); pageCacheDeinit(); closePageFile(); + + bufferPoolDeInit(); - pageDeInit(); #ifdef PIN_COUNT if(pinCount != 0) { printf("WARNING: At exit, %d pages were still pinned!\n", pinCount); @@ -176,14 +172,13 @@ void bufDeinit() { testing.) */ void simulateBufferManagerCrash() { - closeBlobStore(); closePageFile(); #ifdef PIN_COUNT pinCount = 0; #endif } -void releasePage (Page * p) { +void bufManReleasePage (Page * p) { unlock(p->loadlatch); #ifdef PIN_COUNT pthread_mutex_lock(&pinCount_mutex); @@ -453,7 +448,7 @@ compensated_function void __profile_releasePage(Page * p) { #endif -compensated_function Page *loadPage(int xid, int pageid) { +compensated_function Page *bufManLoadPage(int xid, int pageid) { try_ret(NULL) { if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } @@ -489,3 +484,16 @@ compensated_function Page *loadPage(int xid, int pageid) { return ret; } +Page * (*loadPage)(int xid, int pageid) = 0; +void (*releasePage)(Page * p) = 0; +int (*bufInit)() = 0; +void (*bufDeinit)() = 0; + +void setBufferManager(int i ) { + if(i == BUFFER_MANAGER_HASH) { + releasePage = bufManReleasePage; + bufInit = bufManBufInit; + loadPage = bufManLoadPage; + bufDeinit = bufManBufDeinit; + } +} diff --git a/src/lladd/page.c b/src/lladd/page.c index fe26f94..73bb1de 100644 --- a/src/lladd/page.c +++ b/src/lladd/page.c @@ -122,12 +122,10 @@ lsn_t pageReadLSN(const Page * page) { * all the functions dealing with pages. */ void pageInit() { - bufferPoolInit(); slottedPageInit(); } -void pageDeInit() { - bufferPoolDeInit(); +void pageDeinit() { slottedPageDeInit(); } diff --git a/src/lladd/page.h b/src/lladd/page.h index da3adef..8b761bc 100644 --- a/src/lladd/page.h +++ b/src/lladd/page.h @@ -84,7 +84,6 @@ terms specified in this license. /** @todo page.h includes things that it shouldn't, and page.h should eventually be an installed header. */ #include -#include BEGIN_C_DECLS @@ -192,7 +191,7 @@ void pageInit(); /** * releases all resources held by the page sub-system. */ -void pageDeInit(); +void pageDeinit(); /** * assumes that the page is already loaded in memory. It takes as a diff --git a/src/lladd/recovery2.c b/src/lladd/recovery2.c index a6b6420..cce2620 100644 --- a/src/lladd/recovery2.c +++ b/src/lladd/recovery2.c @@ -18,10 +18,7 @@ #include #include -/** @todo recovery2.c shouldn't include pageCache.h once refactoring is done. */ -#include -/** @todo questionable include? */ -#include "page.h" +#include "page.h" // Needed for pageReadLSN. #include