More thorough multithreading, and truncation, re-opening tests.

This commit is contained in:
Sears Russell 2006-10-04 04:21:53 +00:00
parent 20060a099c
commit 8d93f9d7a9

View file

@ -70,12 +70,6 @@ static void setup_log() {
lladd_enableAutoTruncation = 0; lladd_enableAutoTruncation = 0;
Tinit(); Tinit();
// LogDeinit();
//deleteLogWriter();
// openLogWriter();
// LogInit(logType);
for(i = 0 ; i < 1000; i++) { for(i = 0 ; i < 1000; i++) {
LogEntry * e = allocCommonLogEntry(prevLSN, xid, XBEGIN); LogEntry * e = allocCommonLogEntry(prevLSN, xid, XBEGIN);
const LogEntry * f; const LogEntry * f;
@ -140,24 +134,16 @@ START_TEST(loggerTest)
LogHandle h; LogHandle h;
int i = 0; int i = 0;
setup_log(); setup_log();
// syncLog();
//closeLogWriter();
// LogDeinit();
// openLogWriter();
// LogInit(logType);
h = getLogHandle(); h = getLogHandle();
/* LogReadLSN(sizeof(lsn_t)); */
while((e = nextInLog(&h))) { while((e = nextInLog(&h))) {
FreeLogEntry(e); FreeLogEntry(e);
i++; i++;
assert(i < 4000);
} }
assert(i == 3000);
fail_unless(i = 3000, "Wrong number of log entries!");
deleteLogWriter(); deleteLogWriter();
LogDeinit(); LogDeinit();
@ -260,7 +246,9 @@ START_TEST(loggerTruncate) {
FreeLogEntry(le3); FreeLogEntry(le3);
while((le = nextInLog(&lh))) { while((le = nextInLog(&lh))) {
i++; if(le->type != INTERNALLOG) {
i++;
}
FreeLogEntry(le); FreeLogEntry(le);
} }
@ -331,8 +319,11 @@ static void* worker_thread(void * arg) {
pthread_mutex_lock(&random_mutex); pthread_mutex_lock(&random_mutex);
if(lsns[entry] > truncated_to && entry < i) { if(lsns[entry] > truncated_to && entry < i) {
/*printf("X %d\n", (LogReadLSN(lsns[entry])->xid == entry+key)); fflush(stdout); */ /*printf("X %d\n", (LogReadLSN(lsns[entry])->xid == entry+key)); fflush(stdout); */
const LogEntry * e = LogReadLSN(lsns[entry]); lsn_t lsn = lsns[entry];
pthread_mutex_unlock(&random_mutex); pthread_mutex_unlock(&random_mutex);
const LogEntry * e = LogReadLSN(lsn);
assert(e->xid == entry+key); assert(e->xid == entry+key);
FreeLogEntry(e); FreeLogEntry(e);
/* fail_unless(LogReadLSN(lsns[entry])->xid == entry+key, NULL); */ /* fail_unless(LogReadLSN(lsns[entry])->xid == entry+key, NULL); */
@ -385,48 +376,116 @@ START_TEST(loggerCheckThreaded) {
} END_TEST } END_TEST
static void reopenLogWorkload() { void reopenLogWorkload(int truncating) {
Tinit();
int xid1 = Tbegin(); lladd_enableAutoTruncation = 0;
int xid2 = Tbegin();
for(int i = 0; i < 1000; i++) { const int ENTRY_COUNT = 1000;
Talloc(xid1, sizeof(int)); const int SYNC_POINT = 900;
Talloc(xid2, sizeof(int)); lladd_enableAutoTruncation = 0;
}
Tcommit(xid1);
truncationDeinit();
simulateBufferManagerCrash();
LogDeinit();
numActiveXactions = 0; numActiveXactions = 0;
dirtyPagesInit();
bufInit();
Tinit(); LogInit(loggerType);
int xid = 1;
TransactionLog l = LogTransBegin(xid);
lsn_t startLSN = 0;
int xid3 = Tbegin(); LogEntry * entries[ENTRY_COUNT];
for(int i = 0; i < 1000; i++) {
Talloc(xid3, sizeof(int)); for(int i = 0; i < ENTRY_COUNT; i++) {
entries[i] = LogUpdate(&l, NULL, NULLRID, OPERATION_NOOP, NULL);
if(i == SYNC_POINT) {
if(truncating) {
// printf("Called LogTruncate()");
// fflush(stdout);
LogTruncate(entries[i]->LSN);
startLSN = entries[i]->LSN;
}
}
} }
Tcommit(xid3); LogDeinit(loggerType);
Tdeinit(); LogInit(loggerType);
LogHandle h;
int i;
if(truncating) {
h = getLogHandle(); //getLSNHandle(startLSN);
i = SYNC_POINT;
} else {
h = getLogHandle();
i = 0;
}
const LogEntry * e;
while((e = nextInLog(&h))) {
if(e->type != INTERNALLOG) {
assert(sizeofLogEntry(e) == sizeofLogEntry(entries[i]));
assert(!memcmp(e, entries[i], sizeofLogEntry(entries[i])));
assert(i < ENTRY_COUNT);
i++;
}
}
assert(i == (ENTRY_COUNT));
LogEntry * entries2[ENTRY_COUNT];
for(int i = 0; i < ENTRY_COUNT; i++) {
entries2[i] = LogUpdate(&l, NULL, NULLRID, OPERATION_NOOP, NULL);
if(i == SYNC_POINT) {
syncLog_LogWriter();
}
}
if(truncating) {
h = getLSNHandle(startLSN);
i = SYNC_POINT;
} else {
h = getLogHandle();
i = 0;
}
while((e = nextInLog(&h))) {
if(e->type != INTERNALLOG) {
if( i < ENTRY_COUNT) {
assert(sizeofLogEntry(e) == sizeofLogEntry(entries[i]));
assert(!memcmp(e, entries[i], sizeofLogEntry(entries[i])));
} else {
assert(i < ENTRY_COUNT * 2);
assert(sizeofLogEntry(e) == sizeofLogEntry(entries2[i-ENTRY_COUNT]));
assert(!memcmp(e, entries2[i-ENTRY_COUNT], sizeofLogEntry(entries2[i-ENTRY_COUNT])));
}
i++;
}
}
assert(i == (ENTRY_COUNT * 2));
lladd_enableAutoTruncation = 1;
Tinit();
Tdeinit();
} }
START_TEST(loggerReopenTest) { START_TEST(loggerReopenTest) {
lladd_enableAutoTruncation = 0;
reopenLogWorkload(); reopenLogWorkload(0);
lladd_enableAutoTruncation = 1;
} END_TEST } END_TEST
START_TEST(loggerTruncateReopenTest) { START_TEST(loggerTruncateReopenTest) {
reopenLogWorkload(); deleteLogWriter();
reopenLogWorkload(1);
/* reopenLogWorkload();
Tinit(); Tinit();
truncateNow(); truncateNow();
Tdeinit(); Tdeinit();
Tinit(); Tinit();
Tdeinit(); Tdeinit(); */
} END_TEST } END_TEST
Suite * check_suite(void) { Suite * check_suite(void) {
@ -441,7 +500,6 @@ Suite * check_suite(void) {
tcase_add_test(tc, loggerTruncate); tcase_add_test(tc, loggerTruncate);
tcase_add_test(tc, loggerCheckWorker); tcase_add_test(tc, loggerCheckWorker);
tcase_add_test(tc, loggerCheckThreaded); tcase_add_test(tc, loggerCheckThreaded);
if(loggerType != LOG_TO_MEMORY) { if(loggerType != LOG_TO_MEMORY) {
tcase_add_test(tc, loggerReopenTest); tcase_add_test(tc, loggerReopenTest);
tcase_add_test(tc, loggerTruncateReopenTest); tcase_add_test(tc, loggerTruncateReopenTest);