stasis-aries-wal/utilities/logfile_dump.c

90 lines
2.3 KiB
C
Raw Normal View History

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stasis/operations.h>
#include <stasis/logger/logHandle.h>
#include <stasis/logger/logger2.h>
#include <stasis/logger/safeWrites.h>
#include <stasis/flags.h>
static char * logEntryToString(const LogEntry * le) {
char * ret = NULL;
2008-11-11 01:15:25 +00:00
int err;
switch(le->type) {
case UPDATELOG:
{
err = asprintf(&ret, "UPDATE\tlsn=%9lld\tprevlsn=%9lld\txid=%4d\tpage={%8lld}\tfuncId=%3d\targSize=%9lld\n", le->LSN, le->prevLSN, le->xid,
le->update.page, le->update.funcID, (long long)le->update.arg_size );
}
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);
}
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);
}
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);
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
}
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);
}
break;
case CLRLOG:
{
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);
}
break;
}
2008-11-11 01:15:25 +00:00
assert(err != -1);
return ret;
}
int main() {
2008-12-01 19:48:59 +00:00
LogHandle* lh;
const LogEntry * le;
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,
stasis_log_file_permissions,
stasis_log_softcommit))){
printf("Couldn't open log.\n");
}
2008-12-01 19:48:59 +00:00
lh = getLogHandle(log);
2008-12-01 19:48:59 +00:00
while((le = nextInLog(lh))) {
char * s = logEntryToString(le);
if(s) {
printf("%s", s);
free(s);
}
2008-12-01 19:48:59 +00:00
freeLogEntry(le);
}
2008-12-01 19:48:59 +00:00
freeLogHandle(lh);
}