more tests / bugfixes for buffermanager.
This commit is contained in:
parent
d88aef1520
commit
15e77da1d4
6 changed files with 158 additions and 5 deletions
|
@ -90,6 +90,7 @@ static void * writeBackWorker(void * ignored) {
|
|||
Page * old = LH_ENTRY(remove)(cachedPages, &(victim->id), sizeof(int));
|
||||
assert(old == victim);
|
||||
|
||||
// printf("Write(%ld)\n", (long)victim->id);
|
||||
pageWrite(victim);
|
||||
|
||||
freeList[freeCount] = victim;
|
||||
|
|
|
@ -74,7 +74,9 @@ void pageRead(Page *ret) {
|
|||
dirty page table can be kept up to date. */
|
||||
void pageWrite(Page * ret) {
|
||||
/** If the page is clean, there's no reason to write it out. */
|
||||
if(!dirtyPages_isDirty(ret)) {
|
||||
assert(ret->dirty == dirtyPages_isDirty(ret));
|
||||
if(!ret->dirty) {
|
||||
// if(!dirtyPages_isDirty(ret)) {
|
||||
DEBUG(" =^)~ ");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ static void * lruGetStale(replacementPolicy* r) {
|
|||
lru * l = r->impl;
|
||||
entry * e = (entry * ) RB_ENTRY(min)(l->lru);
|
||||
pthread_mutex_unlock(&mut);
|
||||
return e->value;
|
||||
return e ? e->value : 0;
|
||||
}
|
||||
static void* lruRemove(replacementPolicy* r, int id) {
|
||||
pthread_mutex_lock(&mut);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
if HAVE_LIBCHECK
|
||||
## Had to disable check_lht because lht needs to be rewritten.
|
||||
TESTS = check_lhtable check_logEntry check_logWriter check_page check_operations check_transactional2 check_recovery check_blobRecovery check_bufferManager check_indirect check_pageOperations check_linearHash check_logicalLinearHash check_header check_linkedListNTA check_linearHashNTA check_pageOrientedList check_lockManager check_compensations check_errorHandling check_ringbuffer check_iterator check_multiplexer check_bTree check_regions check_allocationPolicy check_io check_rangeTracker
|
||||
TESTS = check_lhtable check_logEntry check_logWriter check_page check_operations check_transactional2 check_recovery check_blobRecovery check_bufferManager check_indirect check_pageOperations check_linearHash check_logicalLinearHash check_header check_linkedListNTA check_linearHashNTA check_pageOrientedList check_lockManager check_compensations check_errorHandling check_ringbuffer check_iterator check_multiplexer check_bTree check_regions check_allocationPolicy check_io check_rangeTracker check_replacementPolicy
|
||||
#check_lladdhash
|
||||
else
|
||||
TESTS =
|
||||
|
|
|
@ -36,6 +36,14 @@
|
|||
|
||||
#define MAX_TRANS_LENGTH 100 // Number of writes per transaction. Keeping this low allows truncation.
|
||||
|
||||
long myrandom(long x) {
|
||||
double xx = x;
|
||||
double r = random();
|
||||
double max = ((uint64_t)RAND_MAX)+1;
|
||||
max /= xx;
|
||||
return (long)((r/max));
|
||||
}
|
||||
|
||||
void initializePages() {
|
||||
|
||||
int i;
|
||||
|
@ -253,16 +261,53 @@ START_TEST(pageThreadedWritersTest) {
|
|||
Tdeinit();
|
||||
}END_TEST
|
||||
|
||||
//#define PINNED_PAGE_COUNT (MAX_BUFFER_SIZE - 1)
|
||||
#define PINNED_PAGE_COUNT 2
|
||||
#define MAX_PAGE_ID (MAX_BUFFER_SIZE * 10)
|
||||
|
||||
START_TEST(pageBlindRandomTest) {
|
||||
Tinit();
|
||||
// logInit(loggerType);
|
||||
// bufInit(bufferManagerType);
|
||||
|
||||
int * pageids = malloc(PINNED_PAGE_COUNT * sizeof(int));
|
||||
Page ** pages = calloc(PINNED_PAGE_COUNT, sizeof(Page*));
|
||||
|
||||
for(int i = 0; i < PINNED_PAGE_COUNT; i++) {
|
||||
pageids[i] = -1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 1000000000; i ++) {
|
||||
int j = myrandom(PINNED_PAGE_COUNT);
|
||||
if(pageids[j] == -1) {
|
||||
pageids[j] = myrandom(MAX_PAGE_ID);
|
||||
pages[j] = loadPage(-1, pageids[j]);
|
||||
assert(pages[j]->id == pageids[j]);
|
||||
} else {
|
||||
dirtyPages_add(pages[j]);
|
||||
releasePage(pages[j]);
|
||||
pageids[j] = -1;
|
||||
pages[j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// bufDeinit();
|
||||
// logDenit(loggerType);
|
||||
Tdeinit();
|
||||
} END_TEST
|
||||
|
||||
Suite * check_suite(void) {
|
||||
Suite *s = suite_create("bufferManager");
|
||||
/* Begin a new test */
|
||||
TCase *tc = tcase_create("multithreaded");
|
||||
tcase_set_timeout(tc, 1200); // twenty minute timeout
|
||||
/* Sub tests are added, one per line, here */
|
||||
tcase_add_test(tc, pageSingleThreadTest);
|
||||
/* tcase_add_test(tc, pageSingleThreadTest);
|
||||
tcase_add_test(tc, pageSingleThreadWriterTest);
|
||||
tcase_add_test(tc, pageLoadTest);
|
||||
tcase_add_test(tc, pageThreadedWritersTest);
|
||||
tcase_add_test(tc, pageThreadedWritersTest); */
|
||||
tcase_add_test(tc, pageBlindRandomTest);
|
||||
|
||||
|
||||
|
||||
/* --------------------------------------------- */
|
||||
|
|
105
test/lladd/check_replacementPolicy.c
Normal file
105
test/lladd/check_replacementPolicy.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
#include <check.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <lladd/transactional.h>
|
||||
#include <lladd/replacementPolicy.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include "../check_includes.h"
|
||||
|
||||
#define LOG_NAME "check_replacementPolicy.log"
|
||||
|
||||
long myrandom(long x) {
|
||||
double xx = x;
|
||||
double r = random();
|
||||
double max = ((uint64_t)RAND_MAX)+1;
|
||||
max /= xx;
|
||||
return (long)((r/max));
|
||||
}
|
||||
|
||||
#define OBJECT_COUNT 1000
|
||||
#define OP_COUNT 10000000
|
||||
|
||||
typedef struct tracker {
|
||||
long key;
|
||||
int inCache;
|
||||
} tracker;
|
||||
START_TEST(replacementPolicyRandomTest) {
|
||||
time_t seed = time(0);
|
||||
printf("\nSeed = %ld\n", seed);
|
||||
srandom(seed);
|
||||
|
||||
replacementPolicy * lru = lruInit();
|
||||
int cachedCount = 0;
|
||||
|
||||
tracker * t = calloc(OBJECT_COUNT, sizeof(tracker));
|
||||
for(int i = 0; i < OBJECT_COUNT; i++) {
|
||||
t[i].key = i;
|
||||
}
|
||||
for(unsigned long j = 0; j < 100000000UL; j++) {
|
||||
int op = myrandom(100);
|
||||
|
||||
int i = myrandom(OBJECT_COUNT);
|
||||
if(op < 10) {
|
||||
// TOGGLE IN CACHE
|
||||
if(!t[i].inCache) {
|
||||
lru->insert(lru, t[i].key, &t[i]);
|
||||
t[i].inCache = 1;
|
||||
cachedCount ++;
|
||||
} else {
|
||||
void * v = lru->remove(lru, t[i].key);
|
||||
assert(v == &t[i]);
|
||||
t[i].inCache = 0;
|
||||
cachedCount --;
|
||||
}
|
||||
} else if(op < 30) {
|
||||
// Get stale + remove
|
||||
tracker * tr = lru->getStale(lru);
|
||||
if( tr ) {
|
||||
assert(tr->inCache);
|
||||
assert(tr == &t[tr->key]);
|
||||
tr = lru->remove(lru, tr->key);
|
||||
assert(tr == &t[tr->key]);
|
||||
tr->inCache = 0;
|
||||
assert(cachedCount != 0);
|
||||
cachedCount --;
|
||||
} else {
|
||||
assert(cachedCount == 0);
|
||||
}
|
||||
} else if(op < 50) {
|
||||
// Get stale
|
||||
tracker * tr = lru->getStale(lru);
|
||||
if(tr) {
|
||||
assert(tr->inCache);
|
||||
assert(tr == &t[tr->key]);
|
||||
assert(cachedCount != 0);
|
||||
} else {
|
||||
assert(cachedCount == 0);
|
||||
}
|
||||
} else {
|
||||
// Hit
|
||||
if(t[i].inCache) lru->hit(lru, t[i].key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} END_TEST
|
||||
|
||||
Suite * check_suite(void) {
|
||||
Suite *s = suite_create("replacemenPolicy");
|
||||
/* Begin a new test */
|
||||
TCase *tc = tcase_create("multithreaded");
|
||||
tcase_set_timeout(tc, 1200); // twenty minute timeout
|
||||
/* Sub tests are added, one per line, here */
|
||||
tcase_add_test(tc, replacementPolicyRandomTest);
|
||||
|
||||
/* --------------------------------------------- */
|
||||
|
||||
tcase_add_checked_fixture(tc, setup, teardown);
|
||||
|
||||
|
||||
suite_add_tcase(s, tc);
|
||||
return s;
|
||||
}
|
||||
|
||||
#include "../check_setup.h"
|
Loading…
Reference in a new issue