2004-06-30 01:09:57 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-08-22 00:01:02 +00:00
|
|
|
#include <assert.h>
|
2004-06-30 01:09:57 +00:00
|
|
|
|
2009-08-22 00:01:02 +00:00
|
|
|
#include <stasis/operations.h>
|
2008-04-13 04:02:57 +00:00
|
|
|
#include <stasis/logger/logHandle.h>
|
2008-12-29 20:01:37 +00:00
|
|
|
#include <stasis/logger/logger2.h>
|
|
|
|
#include <stasis/logger/safeWrites.h>
|
2009-08-22 00:01:02 +00:00
|
|
|
#include <stasis/flags.h>
|
2004-06-30 01:09:57 +00:00
|
|
|
|
2006-04-11 02:20:21 +00:00
|
|
|
static char * logEntryToString(const LogEntry * le) {
|
2004-06-30 01:09:57 +00:00
|
|
|
char * ret = NULL;
|
2008-11-11 01:15:25 +00:00
|
|
|
int err;
|
2004-06-30 01:09:57 +00:00
|
|
|
switch(le->type) {
|
|
|
|
case UPDATELOG:
|
|
|
|
{
|
2008-09-28 03:11:24 +00:00
|
|
|
|
2009-04-22 22:03:38 +00:00
|
|
|
err = asprintf(&ret, "UPDATE\tlsn=%9lld\tprevlsn=%9lld\txid=%4d\tpage={%8lld}\tfuncId=%3d\targSize=%9lld\n", le->LSN, le->prevLSN, le->xid,
|
2008-09-28 03:11:24 +00:00
|
|
|
le->update.page, le->update.funcID, (long long)le->update.arg_size );
|
2004-06-30 01:09:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XBEGIN:
|
|
|
|
{
|
2008-11-11 01:15:25 +00:00
|
|
|
err = asprintf(&ret, "BEGIN\tlsn=%9lld\tprevlsn=%9lld\txid=%4d\n", le->LSN, le->prevLSN, le->xid);
|
2004-06-30 01:09:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XCOMMIT:
|
|
|
|
{
|
2008-11-11 01:15:25 +00:00
|
|
|
err = asprintf(&ret, "COMMIT\tlsn=%9lld\tprevlsn=%9lld\txid=%4d\n", le->LSN, le->prevLSN, le->xid);
|
2004-06-30 01:09:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XABORT:
|
|
|
|
{
|
2008-11-11 01:15:25 +00:00
|
|
|
err = asprintf(&ret, "ABORT\tlsn=%9lld\tprevlsn=%9lld\txid=%4d\n", le->LSN, le->prevLSN, le->xid);
|
2004-06-30 01:09:57 +00:00
|
|
|
|
2008-09-24 03:10:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XPREPARE:
|
|
|
|
{
|
2008-11-11 01:15:25 +00:00
|
|
|
err = asprintf(&ret, "PREPARE\tlsn=%9lld\tprevlsn=%9lld\txid=%4d,reclsn=%9lld\n", le->LSN, le->prevLSN, le->xid, getPrepareRecLSN(le));
|
2008-09-24 03:10:49 +00:00
|
|
|
|
2004-06-30 01:09:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XEND:
|
|
|
|
{
|
2008-11-11 01:15:25 +00:00
|
|
|
err = asprintf(&ret, "END \tlsn=%9lld\tprevlsn=%9lld\txid=%4d\n", le->LSN, le->prevLSN, le->xid);
|
2004-06-30 01:09:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLRLOG:
|
|
|
|
{
|
2009-04-22 22:03:38 +00:00
|
|
|
err = asprintf(&ret, "CLR \tlsn=%9lld\tprevlsn=%9lld\txid=%4d\tcompensates={%8lld}\n", le->LSN, le->prevLSN, le->xid,
|
|
|
|
(((const LogEntry*)((const struct __raw_log_entry*)le)+1))->LSN); //((CLRLogEntry*)le)->clr.compensated_lsn);
|
2004-06-30 01:09:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-11-11 01:15:25 +00:00
|
|
|
assert(err != -1);
|
2004-06-30 01:09:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2008-12-01 19:48:59 +00:00
|
|
|
LogHandle* lh;
|
2006-04-11 02:20:21 +00:00
|
|
|
const LogEntry * le;
|
2004-06-30 01:09:57 +00:00
|
|
|
|
2009-03-31 05:02:54 +00:00
|
|
|
stasis_operation_table_init();
|
2008-12-01 19:48:59 +00:00
|
|
|
stasis_log_t* log;
|
2008-12-29 19:46:51 +00:00
|
|
|
if(NULL == (log = 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))){
|
2004-06-30 01:09:57 +00:00
|
|
|
printf("Couldn't open log.\n");
|
|
|
|
}
|
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
lh = getLogHandle(log);
|
2004-06-30 01:09:57 +00:00
|
|
|
|
2008-12-01 19:48:59 +00:00
|
|
|
while((le = nextInLog(lh))) {
|
2004-06-30 01:09:57 +00:00
|
|
|
|
|
|
|
char * s = logEntryToString(le);
|
|
|
|
if(s) {
|
|
|
|
printf("%s", s);
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
2008-12-01 19:48:59 +00:00
|
|
|
freeLogHandle(lh);
|
2004-06-30 01:09:57 +00:00
|
|
|
|
|
|
|
}
|