diff --git a/lladd/bufferManager.h b/lladd/bufferManager.h index b741613..7b9e0fd 100644 --- a/lladd/bufferManager.h +++ b/lladd/bufferManager.h @@ -96,23 +96,49 @@ BEGIN_C_DECLS 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 * bufManLoadPage(int xid, int pageid); - +extern Page * (*loadPage)(int xid, int pageid); /** loadPage aquires a lock when it is called, effectively pinning it in memory. releasePage releases this lock. */ -void bufManReleasePage(Page * p); +extern void (*releasePage)(Page * p); +/** + * initialize buffer manager + * @return 0 on success + * @return error code on failure + */ +/** + This is used by truncation to move dirty pages from Stasis cache + into the operating system cache. Once writeBackPage(p) returns, + calling forcePages() will synchronously force page number p to + disk. + + (Not all buffer managers support synchronous writes to stable + storage. For compatibility, such buffer managers should ignore + this call.) +*/ +extern void (*writeBackPage)(Page * p); +/** + Force any written back pages to disk. + + @see writeBackPage for more information. + + If the buffer manager doesn't support stable storage, this call is + a no-op. +*/ +extern void (*forcePages)(); + +int bufInit(int type); +/** + * will write out any dirty pages, assumes that there are no running + * transactions + */ +extern void (*bufDeinit)(); #ifdef PROFILE_LATCHES_WRITE_ONLY #define loadPage(x,y) __profile_loadPage((x), (y), __FILE__, __LINE__) @@ -122,20 +148,15 @@ compensated_function Page * __profile_loadPage(int xid, int pageid, char * file, #endif -/** - * initialize buffer manager - * @return 0 on success - * @return error code on failure - */ +/*compensated_function Page * bufManLoadPage(int xid, int pageid); + +void bufManReleasePage(Page * p); + int bufManBufInit(); -/** - * will write out any dirty pages, assumes that there are no running - * transactions - */ void bufManBufDeinit(); -void setBufferManager(int i); +void setBufferManager(int i); */ END_C_DECLS diff --git a/lladd/constants.h b/lladd/constants.h index 7c353e9..2e6648b 100644 --- a/lladd/constants.h +++ b/lladd/constants.h @@ -91,7 +91,8 @@ terms specified in this license. /*#define MAX_BUFFER_SIZE 7 */ #endif -#define BUFFER_MANAGER_HASH 0 +#define BUFFER_MANAGER_REOPEN 0 +#define BUFFER_MANAGER_HASH 1 #define MAX_TRANSACTIONS 1000 diff --git a/src/lladd/bufferManager.c b/src/lladd/bufferManager.c index a02bd36..51e23d7 100644 --- a/src/lladd/bufferManager.c +++ b/src/lladd/bufferManager.c @@ -105,9 +105,9 @@ static pthread_mutex_t loadPagePtr_mutex; static Page * dummy_page; -pthread_key_t lastPage; +static pthread_key_t lastPage; -int bufManBufInit() { +static int bufManBufInit() { bufferPoolInit(); @@ -138,7 +138,7 @@ int bufManBufInit() { return 0; } -void bufManBufDeinit() { +static void bufManBufDeinit() { DEBUG("pageCacheDeinit()"); @@ -178,7 +178,7 @@ void simulateBufferManagerCrash() { #endif } -void bufManReleasePage (Page * p) { +static void bufManReleasePage (Page * p) { unlock(p->loadlatch); #ifdef PIN_COUNT pthread_mutex_lock(&pinCount_mutex); @@ -448,7 +448,7 @@ compensated_function void __profile_releasePage(Page * p) { #endif -compensated_function Page *bufManLoadPage(int xid, int pageid) { +static compensated_function Page *bufManLoadPage(int xid, int pageid) { try_ret(NULL) { if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } @@ -486,14 +486,26 @@ compensated_function Page *bufManLoadPage(int xid, int pageid) { Page * (*loadPage)(int xid, int pageid) = 0; void (*releasePage)(Page * p) = 0; -int (*bufInit)() = 0; -void (*bufDeinit)() = 0; +void (*writeBackPage)(Page * p) = 0; +void (*forcePages)() = 0; -void setBufferManager(int i ) { - if(i == BUFFER_MANAGER_HASH) { +void (*bufDeinit)() = 0; +int bufInit(int type) { + static int lastType = 0; + if(type == BUFFER_MANAGER_REOPEN) { + type = lastType; + } + lastType = type; + if(type == BUFFER_MANAGER_HASH) { releasePage = bufManReleasePage; - bufInit = bufManBufInit; loadPage = bufManLoadPage; + writeBackPage = pageWrite; + forcePages = forcePageFile; bufDeinit = bufManBufDeinit; - } + bufManBufInit(); + return 0; + } else { + // XXX error handling + abort(); + } } diff --git a/src/lladd/transactional2.c b/src/lladd/transactional2.c index 3bc6851..4a65147 100644 --- a/src/lladd/transactional2.c +++ b/src/lladd/transactional2.c @@ -103,8 +103,6 @@ void setupOperationsTable() { int Tinit() { - setBufferManager(BUFFER_MANAGER_HASH); - pthread_mutex_init(&transactional_2_mutex, NULL); numActiveXactions = 0; @@ -114,10 +112,8 @@ int Tinit() { dirtyPagesInit(); LogInit(loggerType); pageInit(); - bufInit(); - // try_ret(compensation_error()) { + bufInit(BUFFER_MANAGER_HASH); pageOperationsInit(); - // } end_ret(compensation_error()); initNestedTopActions(); TallocInit(); ThashInit(); diff --git a/src/lladd/truncation.c b/src/lladd/truncation.c index 3890d95..a41b363 100644 --- a/src/lladd/truncation.c +++ b/src/lladd/truncation.c @@ -4,8 +4,6 @@ #include #include "page.h" #include -/** @todo truncation.c is too dependent on the bufferManager implementation. */ -#include "pageFile.h" static volatile int initialized = 0; static int automaticallyTuncating = 0; @@ -100,7 +98,7 @@ static void dirtyPages_flush() { for(i = 0; i < MAX_BUFFER_SIZE && staleDirtyPages[i] != -1; i++) { p = loadPage(-1, staleDirtyPages[i]); - pageWrite(p); + writeBackPage(p); releasePage(p); } free(staleDirtyPages); @@ -183,7 +181,7 @@ int truncateNow() { if((rec_lsn - log_trunc) > MIN_INCREMENTAL_TRUNCATION) { // fprintf(stderr, "Truncating now. rec_lsn = %ld, log_trunc = %ld\n", rec_lsn, log_trunc); // fprintf(stderr, "Truncating to rec_lsn = %ld\n", rec_lsn); - forcePageFile(); + forcePages(); LogTruncate(rec_lsn); return 1; } else { @@ -198,7 +196,7 @@ int truncateNow() { //fprintf(stderr, "Flushed Dirty Buffers. Truncating to rec_lsn = %ld\n", rec_lsn); - forcePageFile(); + forcePages(); LogTruncate(rec_lsn); return 1; diff --git a/test/lladd/check_logWriter.c b/test/lladd/check_logWriter.c index 17af920..a78b2e1 100644 --- a/test/lladd/check_logWriter.c +++ b/test/lladd/check_logWriter.c @@ -405,7 +405,7 @@ void reopenLogWorkload(int truncating) { numActiveXactions = 0; dirtyPagesInit(); - bufInit(); + bufInit(BUFFER_MANAGER_REOPEN); LogInit(loggerType); int xid = 1;