From 8f3d503ea83a95e0b8acd0f2226d0e05b0e9b668 Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Wed, 7 Mar 2007 06:45:28 +0000 Subject: [PATCH] Added TdurabilityLevel(). Test cases now pass with LOG_TO_MEMORY and BUFFER_MANAGER_MEM_ARRAY --- lladd/bufferManager.h | 8 +++++++- lladd/constants.h | 4 ++++ lladd/transactional.h | 11 +++++++++++ src/lladd/bufferManager.c | 19 ++++++++++++------- src/lladd/bufferManager/pageArray.c | 3 ++- src/lladd/transactional2.c | 9 +++++++++ test/lladd/check_header.c | 2 ++ test/lladd/check_linearHash.c | 1 + test/lladd/check_operations.c | 3 ++- test/lladd/check_page.c | 13 ++++++++++--- test/lladd/check_regions.c | 2 ++ 11 files changed, 62 insertions(+), 13 deletions(-) diff --git a/lladd/bufferManager.h b/lladd/bufferManager.h index d39f85f..a09c411 100644 --- a/lladd/bufferManager.h +++ b/lladd/bufferManager.h @@ -115,7 +115,13 @@ extern int bufferManagerType; * @param pageid ID of the page you want to load * @return fully formed Page type */ -extern Page * (*loadPage)(int xid, int pageid); +Page * loadPage(int xid, int pageid); + +/** + This is the function pointer that bufInit sets in order to + override loadPage. +*/ +extern Page * (*loadPageImpl)(int xid, int pageid); /** loadPage aquires a lock when it is called, effectively pinning it in memory. releasePage releases this lock. diff --git a/lladd/constants.h b/lladd/constants.h index 6cc40f7..265d385 100644 --- a/lladd/constants.h +++ b/lladd/constants.h @@ -98,6 +98,10 @@ terms specified in this license. #define LOG_TO_FILE 0 #define LOG_TO_MEMORY 1 +#define VOLATILE 0 +#define PERSISTENT 1 +#define DURABLE 2 + #define MAX_TRANSACTIONS 1000 /** Operation types */ diff --git a/lladd/transactional.h b/lladd/transactional.h index c49a362..f97a04b 100644 --- a/lladd/transactional.h +++ b/lladd/transactional.h @@ -435,6 +435,17 @@ int TisActiveTransaction(int xid); */ lsn_t transactions_minRecLSN(); + +/** + Report Stasis' current durablity guarantees. + + @return VOLATILE if the data will be lost after Tdeinit(), or a + crash, PERSISTENT if the data will be written back to disk after + Tdeinit(), but may be corrupted at crash, or DURABLE if Stasis will + apply committed transactions, and roll back active transactions + after a crash. +*/ +int TdurabilityLevel(); END_C_DECLS #endif diff --git a/src/lladd/bufferManager.c b/src/lladd/bufferManager.c index d8b983e..fb42e99 100644 --- a/src/lladd/bufferManager.c +++ b/src/lladd/bufferManager.c @@ -122,7 +122,7 @@ static void bufManSimulateBufferManagerCrash(); static int bufManBufInit() { releasePage = bufManReleasePage; - loadPage = bufManLoadPage; + loadPageImpl = bufManLoadPage; writeBackPage = pageWrite; forcePages = forcePageFile; bufDeinit = bufManBufDeinit; @@ -469,11 +469,6 @@ compensated_function void __profile_releasePage(Page * p) { static compensated_function Page *bufManLoadPage(int xid, int pageid) { - try_ret(NULL) { - if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } - } end_ret(NULL); - - Page * ret = pthread_getspecific(lastPage); if(ret && ret->id == pageid) { @@ -503,13 +498,23 @@ static compensated_function Page *bufManLoadPage(int xid, int pageid) { return ret; } -Page * (*loadPage)(int xid, int pageid) = 0; +Page * (*loadPageImpl)(int xid, int pageid) = 0; void (*releasePage)(Page * p) = 0; void (*writeBackPage)(Page * p) = 0; void (*forcePages)() = 0; void (*bufDeinit)() = 0; void (*simulateBufferManagerCrash)() = 0; +Page * loadPage(int xid, int pageid) { + try_ret(NULL) { + // This lock is released at Tcommit() + if(globalLockManager.readLockPage) { globalLockManager.readLockPage(xid, pageid); } + } end_ret(NULL); + + return loadPageImpl(xid, pageid); + +} + int bufInit(int type) { bufferManagerType = type; static int lastType = 0; diff --git a/src/lladd/bufferManager/pageArray.c b/src/lladd/bufferManager/pageArray.c index 9462fda..77eeaee 100644 --- a/src/lladd/bufferManager/pageArray.c +++ b/src/lladd/bufferManager/pageArray.c @@ -12,6 +12,7 @@ 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*)); @@ -58,7 +59,7 @@ static void paBufDeinit() { void paBufInit () { releasePage = paReleasePage; - loadPage = paLoadPage; + loadPageImpl = paLoadPage; writeBackPage = paWriteBackPage; forcePages = paForcePages; bufDeinit = paBufDeinit; diff --git a/src/lladd/transactional2.c b/src/lladd/transactional2.c index 0833533..9bb3e1d 100644 --- a/src/lladd/transactional2.c +++ b/src/lladd/transactional2.c @@ -378,3 +378,12 @@ int TisActiveTransaction(int xid) { return ret; } +int TdurabilityLevel() { + if(bufferManagerType == BUFFER_MANAGER_MEM_ARRAY) { + return VOLATILE; + } else if(loggerType == LOG_TO_MEMORY) { + return PERSISTENT; + } else { + return DURABLE; + } +} diff --git a/test/lladd/check_header.c b/test/lladd/check_header.c index 31380f3..4eb810b 100644 --- a/test/lladd/check_header.c +++ b/test/lladd/check_header.c @@ -69,6 +69,8 @@ START_TEST (header_test) { Tdeinit(); + if(TdurabilityLevel() == VOLATILE) { return ; } + Tinit(); xid = Tbegin(); diff --git a/test/lladd/check_linearHash.c b/test/lladd/check_linearHash.c index a98363f..641ef26 100644 --- a/test/lladd/check_linearHash.c +++ b/test/lladd/check_linearHash.c @@ -238,6 +238,7 @@ START_TEST(transactionalLinearHashTest) Tabort(xid); Tdeinit(); + if(TdurabilityLevel() == VOLATILE) return; Tinit(); xid = Tbegin(); ThashOpen(xid, hashRoot, sizeof(int), sizeof(recordid)); diff --git a/test/lladd/check_operations.c b/test/lladd/check_operations.c index 20fe2f5..7210ebf 100644 --- a/test/lladd/check_operations.c +++ b/test/lladd/check_operations.c @@ -424,9 +424,10 @@ START_TEST(operation_instant_set) { Tread(xid, rid, &three); assert(two == three); Tcommit(xid); - Tdeinit(); + if(TdurabilityLevel() == VOLATILE) { return; } + Tinit(); xid = Tbegin(); diff --git a/test/lladd/check_page.c b/test/lladd/check_page.c index 85074a1..43dc7ab 100644 --- a/test/lladd/check_page.c +++ b/test/lladd/check_page.c @@ -202,8 +202,6 @@ static void* worker_thread(void * arg_ptr) { START_TEST(pageNoThreadTest) { Page * p; - /* p->id = 0;*/ - pthread_mutex_init(&lsn_mutex, NULL); @@ -214,12 +212,15 @@ START_TEST(pageNoThreadTest) slottedPageInitialize(p); worker_thread(p); - unlock(p->loadlatch); p->LSN = 0; *lsn_ptr(p) = p->LSN; + releasePage(p); + Tdeinit(); + pthread_mutex_destroy(&lsn_mutex); + } END_TEST @@ -316,6 +317,7 @@ START_TEST(pageNoThreadMultPageTest) Tdeinit(); + pthread_mutex_destroy(&lsn_mutex); } END_TEST @@ -357,6 +359,9 @@ START_TEST(pageThreadTest) { Tdeinit(); + pthread_mutex_destroy(&lsn_mutex); + pthread_mutex_destroy(&random_mutex); + } END_TEST @@ -384,6 +389,8 @@ START_TEST(fixedPageThreadTest) { *lsn_ptr(p) = p->LSN; releasePage(p); Tdeinit(); + pthread_mutex_destroy(&lsn_mutex); + pthread_mutex_destroy(&random_mutex); } END_TEST START_TEST(pageCheckSlotTypeTest) { diff --git a/test/lladd/check_regions.c b/test/lladd/check_regions.c index ebc376c..93f4c4b 100644 --- a/test/lladd/check_regions.c +++ b/test/lladd/check_regions.c @@ -329,6 +329,8 @@ START_TEST(regions_recoveryTest) { Tdeinit(); + if(TdurabilityLevel() == VOLATILE) { return; } + Tinit(); int xid = Tbegin();