2004-06-24 21:10:31 +00:00
|
|
|
/*---
|
|
|
|
This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
/**
|
2007-04-20 07:14:19 +00:00
|
|
|
@file check_logWriter
|
2009-04-11 17:17:42 +00:00
|
|
|
|
|
|
|
Tests logWriter.
|
2007-04-20 07:14:19 +00:00
|
|
|
|
2007-06-01 21:06:18 +00:00
|
|
|
@todo Get rid of include for logWriter.h (stop calling deleteLogWriter, syncLog_logWriter...)
|
2007-04-20 07:14:19 +00:00
|
|
|
*/
|
2009-04-14 20:21:05 +00:00
|
|
|
#include "../check_includes.h"
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/transactional.h>
|
2008-04-13 04:02:57 +00:00
|
|
|
#include <stasis/logger/logHandle.h>
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/logger/logger2.h>
|
2008-12-29 20:01:37 +00:00
|
|
|
#include <stasis/logger/safeWrites.h>
|
2008-12-01 19:48:59 +00:00
|
|
|
#include <stasis/logger/inMemoryLog.h>
|
2009-04-14 20:21:05 +00:00
|
|
|
#include <stasis/truncation.h>
|
2008-04-13 04:02:57 +00:00
|
|
|
#include <stasis/latches.h>
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-06 01:22:18 +00:00
|
|
|
#include <sched.h>
|
2004-07-04 00:46:49 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
#define LOG_NAME "check_logWriter.log"
|
|
|
|
|
2009-05-13 18:04:53 +00:00
|
|
|
static stasis_log_t * setup_log() {
|
2004-06-24 21:10:31 +00:00
|
|
|
int i;
|
|
|
|
lsn_t prevLSN = -1;
|
2006-04-07 03:40:40 +00:00
|
|
|
int xid = 42;
|
2008-12-29 19:46:51 +00:00
|
|
|
stasis_log_safe_writes_delete(stasis_log_file_name);
|
2007-10-23 23:16:58 +00:00
|
|
|
stasis_truncation_automatic = 0;
|
2004-07-14 20:49:18 +00:00
|
|
|
Tinit();
|
2007-04-21 20:35:37 +00:00
|
|
|
lsn_t firstLSN = -1;
|
2007-04-20 07:14:19 +00:00
|
|
|
int first = 1;
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_t * stasis_log_file = stasis_log();
|
2004-06-24 21:10:31 +00:00
|
|
|
for(i = 0 ; i < 1000; i++) {
|
2010-01-11 22:55:55 +00:00
|
|
|
lsn_t test = stasis_log_file->next_available_lsn(stasis_log_file);
|
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
LogEntry * e = allocCommonLogEntry(stasis_log_file, prevLSN, xid, XBEGIN);
|
2006-04-11 02:20:21 +00:00
|
|
|
const LogEntry * f;
|
2004-06-24 21:10:31 +00:00
|
|
|
recordid rid;
|
|
|
|
byte * args = (byte*)"Test 123.";
|
2004-07-06 01:22:18 +00:00
|
|
|
long args_size = 10; /* Including null */
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
rid.page = 0;
|
|
|
|
rid.slot = 0;
|
|
|
|
rid.size = sizeof(unsigned long);
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->write_entry(stasis_log_file,e);
|
2004-06-24 21:10:31 +00:00
|
|
|
prevLSN = e->LSN;
|
2006-04-07 03:40:40 +00:00
|
|
|
|
2009-03-15 02:43:09 +00:00
|
|
|
assert(test <= e->LSN);
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(first) {
|
2007-04-20 07:14:19 +00:00
|
|
|
first = 0;
|
|
|
|
firstLSN = prevLSN;
|
|
|
|
}
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
f = stasis_log_file->read_entry(stasis_log_file, prevLSN);
|
2006-04-07 03:40:40 +00:00
|
|
|
|
2009-05-13 18:04:53 +00:00
|
|
|
fail_unless(sizeofLogEntry(0, e) == sizeofLogEntry(0, f), "Log entry changed size!!");
|
|
|
|
fail_unless(0 == memcmp(e,f,sizeofLogEntry(0, e)), "Log entries did not agree!!");
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2010-01-11 20:41:59 +00:00
|
|
|
stasis_log_file->write_entry_done(stasis_log_file, e);
|
2009-12-31 23:25:56 +00:00
|
|
|
stasis_log_file->read_entry_done(stasis_log_file, f);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
e = allocUpdateLogEntry(stasis_log_file, prevLSN, xid, 1, rid.page, args_size);
|
2009-12-31 20:20:47 +00:00
|
|
|
memcpy(stasis_log_entry_update_args_ptr(e), args, args_size);
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->write_entry(stasis_log_file,e);
|
2004-06-24 21:10:31 +00:00
|
|
|
prevLSN = e->prevLSN;
|
|
|
|
|
2007-04-03 09:18:45 +00:00
|
|
|
// LogEntry * g = allocCLRLogEntry(100, 1, 200, rid, 0); //prevLSN);
|
2009-12-31 23:01:37 +00:00
|
|
|
LogEntry * g = allocCLRLogEntry(stasis_log_file, e); // XXX will probably break
|
2007-04-20 07:14:19 +00:00
|
|
|
g->prevLSN = firstLSN;
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->write_entry(stasis_log_file,g);
|
2006-04-11 02:20:21 +00:00
|
|
|
assert (g->type == CLRLOG);
|
2008-12-01 19:48:59 +00:00
|
|
|
prevLSN = g->LSN;
|
|
|
|
|
2010-01-11 20:41:59 +00:00
|
|
|
stasis_log_file->write_entry_done(stasis_log_file, e);
|
|
|
|
stasis_log_file->write_entry_done(stasis_log_file, g);
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
2009-05-13 18:04:53 +00:00
|
|
|
return stasis_log_file;
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
|
|
|
/**
|
2009-04-11 17:17:42 +00:00
|
|
|
@test
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
Quick test of log writer and log handler. Not very extensive.
|
|
|
|
Just writes out 3000 log entries, checks that 1000 of them make
|
|
|
|
sense, and then closes, opens and iterates over the resulting log
|
|
|
|
file to make sure that it contains 3000 entries, and none of its
|
|
|
|
builtin assertions fail.
|
|
|
|
|
|
|
|
In particular, logWriter checks to make sure that each log entry's
|
|
|
|
size matches the size that it recorded before the logEntry. Also,
|
|
|
|
when checking the 1000 of 3000 entries, this test uses
|
2008-12-01 19:48:59 +00:00
|
|
|
log->read_entry, which tests the logWriter's ability to succesfully
|
2004-06-24 21:10:31 +00:00
|
|
|
manipulate LSN's.
|
|
|
|
|
|
|
|
@todo Test logHandle more thoroughly. (Still need to test the guard mechanism.)
|
|
|
|
|
|
|
|
*/
|
2009-04-11 17:17:42 +00:00
|
|
|
static void loggerTest(int logType) {
|
|
|
|
|
|
|
|
stasis_log_type = logType;
|
2006-04-11 02:20:21 +00:00
|
|
|
const LogEntry * e;
|
2008-12-01 19:48:59 +00:00
|
|
|
LogHandle* h;
|
2004-06-24 21:10:31 +00:00
|
|
|
int i = 0;
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_t * stasis_log_file = setup_log();
|
2008-12-01 19:48:59 +00:00
|
|
|
h = getLogHandle(stasis_log_file);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
while((e = nextInLog(h))) {
|
2004-06-24 21:10:31 +00:00
|
|
|
i++;
|
2006-10-04 04:21:53 +00:00
|
|
|
assert(i < 4000);
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(h);
|
|
|
|
|
2006-10-04 04:21:53 +00:00
|
|
|
assert(i == 3000);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2008-12-29 19:46:51 +00:00
|
|
|
stasis_log_safe_writes_delete(stasis_log_file_name);
|
2007-03-08 07:48:42 +00:00
|
|
|
Tdeinit();
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
START_TEST(loggerFileTest) {
|
|
|
|
loggerTest(LOG_TO_FILE);
|
|
|
|
} END_TEST
|
|
|
|
START_TEST(loggerMemTest) {
|
|
|
|
loggerTest(LOG_TO_MEMORY);
|
|
|
|
} END_TEST
|
|
|
|
/**
|
2004-06-24 21:10:31 +00:00
|
|
|
@test
|
|
|
|
Checks for a bug ecountered during devlopment. What happens when
|
|
|
|
previousInTransaction is called immediately after the handle is
|
|
|
|
allocated? */
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
static void logHandleColdReverseIterator(int logType) {
|
2006-04-11 02:20:21 +00:00
|
|
|
const LogEntry * e;
|
2009-04-11 17:17:42 +00:00
|
|
|
stasis_log_type = logType;
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_t * stasis_log_file = setup_log();
|
2008-12-01 19:48:59 +00:00
|
|
|
LogHandle* lh = getLogHandle(stasis_log_file);
|
2004-06-24 21:10:31 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
while(((e = nextInLog(lh)) && (i < 100)) ) {
|
2004-06-24 21:10:31 +00:00
|
|
|
i++;
|
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
lsn_t lsn = e->LSN;
|
|
|
|
|
|
|
|
freeLogHandle(lh);
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
i = 0;
|
2009-12-31 23:01:37 +00:00
|
|
|
lh = getLSNHandle(stasis_log_file, lsn);
|
2008-12-01 19:48:59 +00:00
|
|
|
while((e = previousInTransaction(lh))) {
|
2004-06-24 21:10:31 +00:00
|
|
|
i++;
|
|
|
|
}
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(lh);
|
2007-04-20 07:14:19 +00:00
|
|
|
assert(i <= 4); /* We should almost immediately hit a clr that goes to the beginning of the log... */
|
2007-03-08 07:48:42 +00:00
|
|
|
Tdeinit();
|
2004-06-24 21:10:31 +00:00
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
START_TEST(logHandleFileColdReverseIterator) {
|
|
|
|
logHandleColdReverseIterator(LOG_TO_FILE);
|
|
|
|
} END_TEST
|
|
|
|
START_TEST(logHandleMemColdReverseIterator) {
|
|
|
|
logHandleColdReverseIterator(LOG_TO_MEMORY);
|
|
|
|
} END_TEST
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
/**
|
2004-07-01 00:53:36 +00:00
|
|
|
@test
|
|
|
|
|
|
|
|
Build a simple log, truncate it, and then test the logWriter routines against it.
|
|
|
|
*/
|
2009-04-11 17:17:42 +00:00
|
|
|
static void loggerTruncate(int logType) {
|
|
|
|
stasis_log_type = logType;
|
2006-04-11 02:20:21 +00:00
|
|
|
const LogEntry * le;
|
|
|
|
const LogEntry * le2;
|
|
|
|
const LogEntry * le3 = NULL;
|
|
|
|
const LogEntry * tmp;
|
2009-05-13 18:04:53 +00:00
|
|
|
|
|
|
|
stasis_log_t * stasis_log_file = setup_log();
|
2004-07-01 00:53:36 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
LogHandle* lh = getLogHandle(stasis_log_file);
|
2004-07-01 00:53:36 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while(i < 234) {
|
|
|
|
i++;
|
2008-12-01 19:48:59 +00:00
|
|
|
le = nextInLog(lh);
|
2004-07-01 00:53:36 +00:00
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
LogEntry * copy = malloc(sizeofLogEntry(stasis_log_file, le));
|
|
|
|
memcpy(copy, le, sizeofLogEntry(stasis_log_file, le));
|
|
|
|
le = copy;
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
le2 = nextInLog(lh);
|
2009-12-31 23:01:37 +00:00
|
|
|
|
|
|
|
copy = malloc(sizeofLogEntry(stasis_log_file, le2));
|
|
|
|
memcpy(copy, le2, sizeofLogEntry(stasis_log_file, le2));
|
|
|
|
le2 = copy;
|
|
|
|
|
2004-07-01 00:53:36 +00:00
|
|
|
i = 0;
|
|
|
|
while(i < 23) {
|
|
|
|
i++;
|
2008-12-01 19:48:59 +00:00
|
|
|
le3 = nextInLog(lh);
|
2004-07-01 00:53:36 +00:00
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
copy = malloc(sizeofLogEntry(stasis_log_file, le3));
|
|
|
|
memcpy(copy, le3, sizeofLogEntry(stasis_log_file, le3));
|
|
|
|
le3 = copy;
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->truncate(stasis_log_file, le->LSN);
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
tmp = stasis_log_file->read_entry(stasis_log_file, le->LSN);
|
2004-07-01 00:53:36 +00:00
|
|
|
|
|
|
|
fail_unless(NULL != tmp, NULL);
|
|
|
|
fail_unless(tmp->LSN == le->LSN, NULL);
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2009-12-31 23:25:56 +00:00
|
|
|
stasis_log_file->read_entry_done(stasis_log_file, tmp);
|
2008-12-01 19:48:59 +00:00
|
|
|
tmp = stasis_log_file->read_entry(stasis_log_file, le2->LSN);
|
2004-07-01 00:53:36 +00:00
|
|
|
|
|
|
|
fail_unless(NULL != tmp, NULL);
|
|
|
|
fail_unless(tmp->LSN == le2->LSN, NULL);
|
|
|
|
|
2009-12-31 23:25:56 +00:00
|
|
|
stasis_log_file->read_entry_done(stasis_log_file, tmp);
|
2008-12-01 19:48:59 +00:00
|
|
|
tmp = stasis_log_file->read_entry(stasis_log_file, le3->LSN);
|
2004-07-01 00:53:36 +00:00
|
|
|
|
|
|
|
fail_unless(NULL != tmp, NULL);
|
|
|
|
fail_unless(tmp->LSN == le3->LSN, NULL);
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2009-12-31 23:25:56 +00:00
|
|
|
stasis_log_file->read_entry_done(stasis_log_file, tmp);
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(lh);
|
|
|
|
lh = getLogHandle(stasis_log_file);
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2004-07-01 00:53:36 +00:00
|
|
|
i = 0;
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
free((void*)le);
|
|
|
|
free((void*)le2);
|
|
|
|
free((void*)le3);
|
2004-07-01 00:53:36 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
while((le = nextInLog(lh))) {
|
2009-04-11 17:17:42 +00:00
|
|
|
if(le->type != INTERNALLOG) {
|
2006-10-04 04:21:53 +00:00
|
|
|
i++;
|
|
|
|
}
|
2004-07-01 00:53:36 +00:00
|
|
|
}
|
2006-04-07 03:40:40 +00:00
|
|
|
assert(i == (3000 - 234 + 1));
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(lh);
|
2007-03-08 07:48:42 +00:00
|
|
|
Tdeinit();
|
2009-04-11 17:17:42 +00:00
|
|
|
}
|
|
|
|
START_TEST(loggerFileTruncate) {
|
|
|
|
loggerTruncate(LOG_TO_FILE);
|
|
|
|
} END_TEST
|
|
|
|
START_TEST(loggerMemTruncate) {
|
|
|
|
loggerTruncate(LOG_TO_MEMORY);
|
2004-07-01 00:53:36 +00:00
|
|
|
} END_TEST
|
|
|
|
|
2006-04-14 03:45:26 +00:00
|
|
|
#define ENTRIES_PER_THREAD 200
|
2004-07-04 00:46:49 +00:00
|
|
|
|
|
|
|
pthread_mutex_t random_mutex;
|
|
|
|
|
2006-04-14 03:45:26 +00:00
|
|
|
lsn_t truncated_to = 4;
|
|
|
|
|
2007-04-20 07:14:19 +00:00
|
|
|
#undef NO_CONCURRENCY
|
2006-11-10 19:32:44 +00:00
|
|
|
#ifdef NO_CONCURRENCY
|
|
|
|
pthread_mutex_t big = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
2004-07-04 00:46:49 +00:00
|
|
|
static void* worker_thread(void * arg) {
|
2006-03-20 23:11:46 +00:00
|
|
|
long key = *(int*)arg;
|
|
|
|
long i = 0;
|
2004-07-04 00:46:49 +00:00
|
|
|
|
2006-04-14 03:45:26 +00:00
|
|
|
lsn_t lsns[ENTRIES_PER_THREAD];
|
2004-07-04 00:46:49 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
for(i = 0; i < ENTRIES_PER_THREAD; i++) {
|
2007-04-20 07:14:19 +00:00
|
|
|
lsns[i] = 0;
|
|
|
|
}
|
|
|
|
i = 0;
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_t * stasis_log_file = stasis_log();
|
2004-07-04 00:46:49 +00:00
|
|
|
|
|
|
|
while(i < ENTRIES_PER_THREAD) {
|
2009-12-31 23:01:37 +00:00
|
|
|
LogEntry * le = allocCommonLogEntry(stasis_log_file, -1, -1, XBEGIN);
|
2004-07-04 00:46:49 +00:00
|
|
|
int threshold;
|
2006-03-20 23:11:46 +00:00
|
|
|
long entry;
|
|
|
|
int needToTruncate = 0;
|
2006-04-14 03:45:26 +00:00
|
|
|
lsn_t myTruncVal = 0;
|
2004-07-04 00:46:49 +00:00
|
|
|
pthread_mutex_lock(&random_mutex);
|
|
|
|
|
|
|
|
threshold = (int) (2000.0*random()/(RAND_MAX+1.0));
|
2006-03-20 23:11:46 +00:00
|
|
|
entry = (long) (ENTRIES_PER_THREAD*random()/(RAND_MAX+1.0));
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(threshold < 3) {
|
2006-03-20 23:11:46 +00:00
|
|
|
if(i > 10) {
|
2009-10-15 18:48:58 +00:00
|
|
|
needToTruncate = 1;
|
|
|
|
if(lsns[i - 10] > truncated_to) {
|
|
|
|
truncated_to = lsns[i - 10];
|
|
|
|
myTruncVal = truncated_to;
|
|
|
|
}
|
2006-03-20 23:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-04 00:46:49 +00:00
|
|
|
|
|
|
|
pthread_mutex_unlock(&random_mutex);
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(needToTruncate) {
|
|
|
|
#ifdef NO_CONCURRENCY
|
2006-11-10 19:32:44 +00:00
|
|
|
pthread_mutex_lock(&big);
|
|
|
|
#endif
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->truncate(stasis_log_file, myTruncVal);
|
2009-04-11 17:17:42 +00:00
|
|
|
#ifdef NO_CONCURRENCY
|
2006-11-10 19:32:44 +00:00
|
|
|
pthread_mutex_unlock(&big);
|
2009-04-11 17:17:42 +00:00
|
|
|
#endif
|
2008-12-01 19:48:59 +00:00
|
|
|
assert(stasis_log_file->truncation_point(stasis_log_file) >= myTruncVal);
|
2006-04-14 03:45:26 +00:00
|
|
|
}
|
2004-07-04 00:46:49 +00:00
|
|
|
|
|
|
|
if(threshold < 3) {
|
|
|
|
} else {
|
|
|
|
le->xid = i+key;
|
2009-04-11 17:17:42 +00:00
|
|
|
#ifdef NO_CONCURRENCY
|
2006-11-10 19:32:44 +00:00
|
|
|
pthread_mutex_lock(&big);
|
|
|
|
#endif
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->write_entry(stasis_log_file,le);
|
2009-04-11 17:17:42 +00:00
|
|
|
#ifdef NO_CONCURRENCY
|
2006-11-10 19:32:44 +00:00
|
|
|
pthread_mutex_unlock(&big);
|
|
|
|
#endif
|
2004-07-04 00:46:49 +00:00
|
|
|
lsns[i] = le->LSN;
|
|
|
|
i++;
|
|
|
|
}
|
2006-03-20 23:11:46 +00:00
|
|
|
pthread_mutex_lock(&random_mutex);
|
2009-04-11 17:17:42 +00:00
|
|
|
#ifdef NO_CONCURRENCY
|
2007-04-20 07:14:19 +00:00
|
|
|
pthread_mutex_lock(&big);
|
2006-11-10 19:32:44 +00:00
|
|
|
#endif
|
2006-03-20 23:11:46 +00:00
|
|
|
if(lsns[entry] > truncated_to && entry < i) {
|
2006-10-04 04:21:53 +00:00
|
|
|
lsn_t lsn = lsns[entry];
|
2006-04-14 03:45:26 +00:00
|
|
|
pthread_mutex_unlock(&random_mutex);
|
2006-10-04 04:21:53 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
const LogEntry * e = stasis_log_file->read_entry(stasis_log_file, lsn);
|
2009-10-15 18:48:58 +00:00
|
|
|
if(e == NULL) {
|
|
|
|
pthread_mutex_lock(&random_mutex);
|
|
|
|
assert(lsn < truncated_to);
|
|
|
|
pthread_mutex_unlock(&random_mutex);
|
|
|
|
} else {
|
|
|
|
assert(e->xid == entry+key);
|
2009-12-31 23:25:56 +00:00
|
|
|
stasis_log_file->read_entry_done(stasis_log_file, e);
|
2009-10-15 18:48:58 +00:00
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
} else {
|
2006-03-20 23:11:46 +00:00
|
|
|
pthread_mutex_unlock(&random_mutex);
|
2004-07-04 00:46:49 +00:00
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
#ifdef NO_CONCURRENCY
|
2007-04-20 07:14:19 +00:00
|
|
|
pthread_mutex_unlock(&big);
|
2006-11-10 19:32:44 +00:00
|
|
|
#endif
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2004-07-04 00:46:49 +00:00
|
|
|
/* Try to interleave requests as much as possible */
|
2004-07-06 01:22:18 +00:00
|
|
|
sched_yield();
|
2010-01-11 20:41:59 +00:00
|
|
|
stasis_log_file->write_entry_done(stasis_log_file, le);
|
2004-07-04 00:46:49 +00:00
|
|
|
}
|
|
|
|
|
2006-04-11 02:20:21 +00:00
|
|
|
|
2004-07-04 00:46:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
static void loggerCheckWorker(int logType) {
|
|
|
|
stasis_log_type = logType;
|
2004-07-04 00:46:49 +00:00
|
|
|
int four = 4;
|
|
|
|
|
|
|
|
pthread_mutex_init(&random_mutex, NULL);
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
worker_thread(&four);
|
|
|
|
Tdeinit();
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
}
|
|
|
|
START_TEST(loggerFileCheckWorker) {
|
|
|
|
loggerCheckWorker(LOG_TO_FILE);
|
|
|
|
} END_TEST
|
|
|
|
START_TEST(loggerMemCheckWorker) {
|
|
|
|
loggerCheckWorker(LOG_TO_MEMORY);
|
2004-07-04 00:46:49 +00:00
|
|
|
} END_TEST
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
static void loggerCheckThreaded(int logType) {
|
|
|
|
stasis_log_type = logType;
|
2004-07-13 23:48:20 +00:00
|
|
|
|
2004-10-04 05:24:12 +00:00
|
|
|
#define THREAD_COUNT 100
|
2004-07-04 00:46:49 +00:00
|
|
|
pthread_t workers[THREAD_COUNT];
|
|
|
|
int i;
|
|
|
|
pthread_mutex_init(&random_mutex, NULL);
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
2004-07-13 23:48:20 +00:00
|
|
|
pthread_create(&workers[i], NULL, worker_thread, &i);
|
2004-07-04 00:46:49 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(workers[i], NULL);
|
|
|
|
}
|
|
|
|
Tdeinit();
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(loggerFileCheckThreaded) {
|
|
|
|
loggerCheckThreaded(LOG_TO_FILE);
|
|
|
|
} END_TEST
|
|
|
|
START_TEST(loggerMemCheckThreaded) {
|
|
|
|
loggerCheckThreaded(LOG_TO_MEMORY);
|
2004-07-04 00:46:49 +00:00
|
|
|
} END_TEST
|
2009-03-31 05:02:54 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
void reopenLogWorkload(int truncating) {
|
2009-03-31 05:02:54 +00:00
|
|
|
stasis_operation_table_init();
|
2007-10-23 23:16:58 +00:00
|
|
|
stasis_truncation_automatic = 0;
|
|
|
|
|
2006-10-04 04:21:53 +00:00
|
|
|
const int ENTRY_COUNT = 1000;
|
|
|
|
const int SYNC_POINT = 900;
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_t * stasis_log_file = 0;
|
2006-10-03 01:51:14 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(LOG_TO_FILE == stasis_log_type) {
|
2008-12-29 19:46:51 +00:00
|
|
|
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
|
|
|
stasis_log_file_mode,
|
2009-09-12 16:20:13 +00:00
|
|
|
stasis_log_file_permissions,
|
|
|
|
stasis_log_softcommit);
|
2009-04-11 17:17:42 +00:00
|
|
|
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
|
|
|
stasis_log_file = stasis_log_impl_in_memory_open();
|
2008-12-01 19:48:59 +00:00
|
|
|
} else {
|
|
|
|
assert(stasis_log_file != NULL);
|
|
|
|
}
|
|
|
|
|
2006-10-04 04:21:53 +00:00
|
|
|
int xid = 1;
|
2009-10-14 21:22:50 +00:00
|
|
|
stasis_transaction_table_entry_t l;
|
2009-10-15 22:46:25 +00:00
|
|
|
// pthread_mutex_init(&l.mut,0);
|
2009-05-13 18:04:53 +00:00
|
|
|
stasis_log_begin_transaction(stasis_log_file, xid, &l);
|
2006-10-04 04:21:53 +00:00
|
|
|
lsn_t startLSN = 0;
|
|
|
|
|
|
|
|
LogEntry * entries[ENTRY_COUNT];
|
|
|
|
|
|
|
|
for(int i = 0; i < ENTRY_COUNT; i++) {
|
|
|
|
|
2009-05-13 18:04:53 +00:00
|
|
|
entries[i] = stasis_log_write_update(stasis_log_file,
|
2009-07-13 17:18:01 +00:00
|
|
|
&l, 0, OPERATION_NOOP, NULL, 0);
|
2006-10-03 01:51:14 +00:00
|
|
|
|
2006-10-04 04:21:53 +00:00
|
|
|
if(i == SYNC_POINT) {
|
2009-04-11 17:17:42 +00:00
|
|
|
if(truncating) {
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_file->truncate(stasis_log_file,entries[i]->LSN);
|
2006-10-04 04:21:53 +00:00
|
|
|
startLSN = entries[i]->LSN;
|
|
|
|
}
|
|
|
|
}
|
2006-10-03 01:51:14 +00:00
|
|
|
}
|
2007-04-21 02:27:54 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
stasis_log_file->close(stasis_log_file);
|
2008-12-01 19:48:59 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(LOG_TO_FILE == stasis_log_type) {
|
2008-12-29 19:46:51 +00:00
|
|
|
stasis_log_file = stasis_log_safe_writes_open(stasis_log_file_name,
|
|
|
|
stasis_log_file_mode,
|
2009-09-12 16:20:13 +00:00
|
|
|
stasis_log_file_permissions,
|
|
|
|
stasis_log_softcommit);
|
2009-04-11 17:17:42 +00:00
|
|
|
} else if(LOG_TO_MEMORY == stasis_log_type) {
|
|
|
|
stasis_log_file = stasis_log_impl_in_memory_open();
|
2008-12-01 19:48:59 +00:00
|
|
|
} else {
|
|
|
|
assert(stasis_log_file != NULL);
|
|
|
|
}
|
2007-04-21 02:27:54 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
LogHandle * h;
|
2006-10-04 04:21:53 +00:00
|
|
|
int i;
|
2006-10-03 01:51:14 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(truncating) {
|
2008-12-01 19:48:59 +00:00
|
|
|
h = getLogHandle(stasis_log_file);
|
2006-10-04 04:21:53 +00:00
|
|
|
i = SYNC_POINT;
|
2009-04-11 17:17:42 +00:00
|
|
|
} else {
|
2008-12-01 19:48:59 +00:00
|
|
|
h = getLogHandle(stasis_log_file);
|
2006-10-04 04:21:53 +00:00
|
|
|
i = 0;
|
2009-04-11 17:17:42 +00:00
|
|
|
}
|
2006-10-04 04:21:53 +00:00
|
|
|
|
|
|
|
const LogEntry * e;
|
2009-04-11 17:17:42 +00:00
|
|
|
while((e = nextInLog(h))) {
|
|
|
|
if(e->type != INTERNALLOG) {
|
2009-05-13 18:04:53 +00:00
|
|
|
assert(sizeofLogEntry(0, e) == sizeofLogEntry(0, entries[i]));
|
|
|
|
assert(!memcmp(e, entries[i], sizeofLogEntry(0, entries[i])));
|
2006-10-04 04:21:53 +00:00
|
|
|
assert(i < ENTRY_COUNT);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2006-10-04 04:21:53 +00:00
|
|
|
assert(i == (ENTRY_COUNT));
|
|
|
|
|
|
|
|
LogEntry * entries2[ENTRY_COUNT];
|
|
|
|
for(int i = 0; i < ENTRY_COUNT; i++) {
|
2009-07-13 17:18:01 +00:00
|
|
|
entries2[i] = stasis_log_write_update(stasis_log_file, &l, 0, OPERATION_NOOP,
|
2008-12-01 19:48:59 +00:00
|
|
|
NULL, 0);
|
2009-04-11 17:17:42 +00:00
|
|
|
if(i == SYNC_POINT) {
|
2008-12-01 22:45:32 +00:00
|
|
|
stasis_log_file->force_tail(stasis_log_file, LOG_FORCE_COMMIT);
|
2006-10-04 04:21:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(h);
|
2006-10-04 04:21:53 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
if(truncating) {
|
2008-12-01 19:48:59 +00:00
|
|
|
h = getLSNHandle(stasis_log_file, startLSN);
|
2006-10-04 04:21:53 +00:00
|
|
|
i = SYNC_POINT;
|
2009-04-11 17:17:42 +00:00
|
|
|
} else {
|
2008-12-01 19:48:59 +00:00
|
|
|
h = getLogHandle(stasis_log_file);
|
2006-10-04 04:21:53 +00:00
|
|
|
i = 0;
|
2009-04-11 17:17:42 +00:00
|
|
|
}
|
2006-10-04 04:21:53 +00:00
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
while((e = nextInLog(h))) {
|
|
|
|
if(e->type != INTERNALLOG) {
|
|
|
|
if( i < ENTRY_COUNT) {
|
2009-05-13 18:04:53 +00:00
|
|
|
assert(sizeofLogEntry(0, e) == sizeofLogEntry(0, entries[i]));
|
|
|
|
assert(!memcmp(e, entries[i], sizeofLogEntry(0, entries[i])));
|
2009-04-11 17:17:42 +00:00
|
|
|
} else {
|
2009-05-13 18:04:53 +00:00
|
|
|
assert(i < ENTRY_COUNT * 2);
|
|
|
|
assert(sizeofLogEntry(0, e) == sizeofLogEntry(0, entries2[i-ENTRY_COUNT]));
|
|
|
|
assert(!memcmp(e, entries2[i-ENTRY_COUNT], sizeofLogEntry(0, entries2[i-ENTRY_COUNT])));
|
2006-10-04 04:21:53 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(h);
|
2009-04-11 17:17:42 +00:00
|
|
|
assert(i == (ENTRY_COUNT * 2));
|
2006-10-04 04:21:53 +00:00
|
|
|
|
2009-12-31 23:01:37 +00:00
|
|
|
for(int i = 0; i < ENTRY_COUNT; i++) {
|
2010-01-11 20:41:59 +00:00
|
|
|
stasis_log_file->write_entry_done(stasis_log_file, entries[i]);
|
|
|
|
stasis_log_file->write_entry_done(stasis_log_file, entries2[i]);
|
2009-12-31 23:01:37 +00:00
|
|
|
}
|
|
|
|
|
2007-10-23 23:16:58 +00:00
|
|
|
stasis_truncation_automatic = 1;
|
2009-04-11 17:17:42 +00:00
|
|
|
stasis_log_file->close(stasis_log_file);
|
2006-10-03 01:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(loggerReopenTest) {
|
2009-04-11 17:17:42 +00:00
|
|
|
stasis_log_type = LOG_TO_FILE;
|
|
|
|
stasis_log_safe_writes_delete(stasis_log_file_name);
|
2006-10-04 04:21:53 +00:00
|
|
|
reopenLogWorkload(0);
|
|
|
|
|
2006-10-03 01:51:14 +00:00
|
|
|
} END_TEST
|
|
|
|
|
2009-04-11 17:17:42 +00:00
|
|
|
START_TEST(loggerTruncateReopenTest) {
|
|
|
|
stasis_log_type = LOG_TO_FILE;
|
2008-12-29 19:46:51 +00:00
|
|
|
stasis_log_safe_writes_delete(stasis_log_file_name);
|
2006-10-04 04:21:53 +00:00
|
|
|
reopenLogWorkload(1);
|
2006-10-03 01:51:14 +00:00
|
|
|
} END_TEST
|
2004-07-04 00:46:49 +00:00
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("logWriter");
|
|
|
|
/* Begin a new test */
|
|
|
|
TCase *tc = tcase_create("writeNew");
|
2005-03-10 03:19:04 +00:00
|
|
|
tcase_set_timeout(tc, 0);
|
2004-06-24 21:10:31 +00:00
|
|
|
/* Sub tests are added, one per line, here */
|
2009-04-11 17:17:42 +00:00
|
|
|
tcase_add_test(tc, loggerFileTest);
|
|
|
|
tcase_add_test(tc, loggerMemTest);
|
|
|
|
tcase_add_test(tc, logHandleFileColdReverseIterator);
|
|
|
|
tcase_add_test(tc, logHandleMemColdReverseIterator);
|
|
|
|
tcase_add_test(tc, loggerFileTruncate);
|
|
|
|
tcase_add_test(tc, loggerMemTruncate);
|
|
|
|
tcase_add_test(tc, loggerFileCheckWorker);
|
|
|
|
tcase_add_test(tc, loggerMemCheckWorker);
|
|
|
|
tcase_add_test(tc, loggerFileCheckThreaded);
|
|
|
|
tcase_add_test(tc, loggerMemCheckThreaded);
|
|
|
|
if(stasis_log_type != LOG_TO_MEMORY) {
|
2006-10-03 01:51:14 +00:00
|
|
|
tcase_add_test(tc, loggerReopenTest);
|
|
|
|
tcase_add_test(tc, loggerTruncateReopenTest);
|
2007-03-03 01:46:06 +00:00
|
|
|
}
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------- */
|
2009-04-11 17:17:42 +00:00
|
|
|
|
2004-07-01 00:53:36 +00:00
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|