Factored logWriter.h out of the rest of the system. The only file that directly depends on it is logger2.c, which can

now dispatch requests to different (hardcoded) log implementations.
This commit is contained in:
Sears Russell 2006-04-06 03:22:57 +00:00
parent 10e7434d32
commit 1c979f3052
11 changed files with 106 additions and 40 deletions

View file

@ -83,6 +83,18 @@ typedef struct {
LogHandle lh;
} TransactionLog;
#define LOG_TO_FILE 0
#define LOG_TO_MEMORY 1
int LogInit(int logType);
int LogDeinit();
void LogForce(lsn_t lsn);
lsn_t LogTruncationPoint();
LogEntry * LogReadLSN(lsn_t lsn);
/**
Inform the logging layer that a new transaction has begun.
@ -118,7 +130,8 @@ LogEntry * LogUpdate(TransactionLog * l, Page * p, recordid rid, int operation,
(Needed so that the lsn slot of the page in question can be
updated.)
*/
lsn_t LogCLR (LogEntry * undone);
//lsn_t LogCLR (LogEntry * undone);
lsn_t LogCLR(int xid, lsn_t LSN, recordid rid, lsn_t prevLSN);
/**
Write a end transaction record @see XEND

View file

@ -41,7 +41,6 @@ terms specified in this license.
---*/
#include "logHandle.h"
#include "logWriter.h"
#include <config.h>
#include <stdlib.h>
@ -56,7 +55,7 @@ static void set_offsets(LogHandle * h, LogEntry * e, lsn_t lastRead);
LogHandle getLogHandle() {
lsn_t lsn = firstLogEntry();
lsn_t lsn = LogTruncationPoint();
return getGuardedHandle(lsn, NULL, NULL);
}
@ -75,7 +74,7 @@ LogHandle getGuardedHandle(lsn_t lsn, guard_fcn_t * guard, void * guard_state) {
}
LogEntry * nextInLog(LogHandle * h) {
LogEntry * ret = readLSNEntry(h->next_offset);
LogEntry * ret = LogReadLSN(h->next_offset);
if(ret != NULL) {
set_offsets(h, ret, h->next_offset);
}
@ -95,7 +94,7 @@ LogEntry * previousInTransaction(LogHandle * h) {
LogEntry * ret = NULL;
if(h->prev_offset > 0) {
/* printf("A"); fflush(NULL); */
ret = readLSNEntry(h->prev_offset);
ret = LogReadLSN(h->prev_offset);
set_offsets(h, ret, h->prev_offset);
/*printf("B"); fflush(NULL); */

View file

@ -41,8 +41,6 @@ terms specified in this license.
---*/
#include <lladd/logger/logger2.h>
/*#include "logEntry.h"
#include "logWriter.h" */
#ifndef __LOGHANDLE_H
#define __LOGHANDLE_H

View file

@ -70,7 +70,6 @@ terms specified in this license.
#ifndef __LOGWRITER_H__
#define __LOGWRITER_H__
/*#include "logEntry.h"*/
#include <lladd/constants.h>
#include <lladd/common.h>

View file

@ -49,6 +49,58 @@ terms specified in this license.
/*#include <lladd/bufferManager.h>*/
#include <stdio.h>
#include <assert.h>
static int loggerType = -1;
static void genericLogWrite(LogEntry * e) {
assert(loggerType != -1); // Otherwise, we haven't been initialized.
if(loggerType == LOG_TO_FILE) {
writeLogEntry(e);
}
}
int LogInit(int logType) {
if(LOG_TO_FILE == logType) {
openLogWriter();
} else {
return -1;
}
loggerType = logType;
return 0;
}
int LogDeinit() {
assert(loggerType != -1);
if(LOG_TO_FILE == loggerType) {
closeLogWriter();
}
return 0;
}
void LogForce(lsn_t lsn) {
assert(loggerType != -1);
if(LOG_TO_FILE == loggerType) {
if(flushedLSN() < lsn) {
syncLog();
}
}
}
lsn_t LogTruncationPoint() {
assert(loggerType != -1);
if(LOG_TO_FILE == loggerType) {
return firstLogEntry();
}
abort();
}
LogEntry * LogReadLSN(lsn_t lsn) {
assert(loggerType != -1);
if(LOG_TO_FILE == loggerType) {
return readLSNEntry(lsn);
}
abort();
}
TransactionLog LogTransBegin(int xid) {
TransactionLog tl;
tl.xid = xid;
@ -62,7 +114,8 @@ static lsn_t LogTransCommon(TransactionLog * l, int type) {
LogEntry * e = allocCommonLogEntry(l->prevLSN, l->xid, type);
lsn_t ret;
writeLogEntry(e);
genericLogWrite(e);
l->prevLSN = e->LSN;
DEBUG("Log Common %d, LSN: %ld type: %ld (prevLSN %ld)\n", e->xid,
(long int)e->LSN, (long int)e->type, (long int)e->prevLSN);
@ -76,7 +129,10 @@ static lsn_t LogTransCommon(TransactionLog * l, int type) {
}
extern int numActiveXactions;
lsn_t LogTransCommit(TransactionLog * l) {
/**
@todo This belongs in logWriter.c and needs a new name.
*/
static lsn_t LogTransBundledCommit(TransactionLog * l) {
static pthread_mutex_t check_commit = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t tooFewXacts = PTHREAD_COND_INITIALIZER;
static int pendingCommits = 0;
@ -130,6 +186,14 @@ lsn_t LogTransCommit(TransactionLog * l) {
return ret;
}
lsn_t LogTransCommit(TransactionLog * l) {
assert(loggerType != -1);
if(LOG_TO_FILE == loggerType) {
return LogTransBundledCommit(l);
}
abort();
}
lsn_t LogTransAbort(TransactionLog * l) {
return LogTransCommon(l, XABORT);
}
@ -165,7 +229,8 @@ LogEntry * LogUpdate(TransactionLog * l, Page * p, recordid rid, int operation,
e = allocUpdateLogEntry(l->prevLSN, l->xid, operation, rid, args, argSize, preImage);
writeLogEntry(e);
// writeLogEntry(e);
genericLogWrite(e);
DEBUG("Log Common %d, LSN: %ld type: %ld (prevLSN %ld) (argSize %ld)\n", e->xid,
(long int)e->LSN, (long int)e->type, (long int)e->prevLSN, (long int) argSize);
@ -177,13 +242,13 @@ LogEntry * LogUpdate(TransactionLog * l, Page * p, recordid rid, int operation,
return e;
}
lsn_t LogCLR(LogEntry * undone) {
lsn_t LogCLR(int xid, lsn_t LSN, recordid rid, lsn_t prevLSN) {
lsn_t ret;
LogEntry * e = allocCLRLogEntry(-1, undone->xid, undone->LSN, undone->contents.update.rid, undone->prevLSN);
writeLogEntry(e);
LogEntry * e = allocCLRLogEntry(-1, xid, LSN, rid, prevLSN);
genericLogWrite(e);
DEBUG("Log CLR %d, LSN: %ld type: %ld (undoing: %ld, next to undo: %ld)\n", e->xid,
(long int)e->LSN, (long int)e->type, (long int)undone->LSN, (long int)undone->prevLSN);
DEBUG("Log CLR %d, LSN: %ld (undoing: %ld, next to undo: %ld)\n", xid,
e->LSN, LSN, prevLSN);
ret = e->LSN;
free(e);

View file

@ -41,7 +41,7 @@ terms specified in this license.
---*/
#include <lladd/operations.h>
#include "logger/logWriter.h"
#include <lladd/logger/logger2.h>
#include <lladd/bufferManager.h>
#include <assert.h>
#include <string.h>
@ -85,7 +85,7 @@ void redoUpdate(const LogEntry * e) {
releasePage(p);
} else if(e->type == CLRLOG) {
LogEntry * f = readLSNEntry(e->contents.clr.thisUpdateLSN);
LogEntry * f = LogReadLSN(e->contents.clr.thisUpdateLSN);
recordid rid = f->contents.update.rid;
Page * p = NULL;
@ -99,7 +99,7 @@ void redoUpdate(const LogEntry * e) {
/* See if the page contains the result of the undo that this CLR is supposed to perform. If it
doesn't, then undo the original operation. */
/* if(f->LSN > pageReadLSN(e->contents.update.rid.page)) { */
if(isNullRid || f->LSN > pageReadLSN(p)) {
DEBUG("OPERATION Undoing for clr, %ld {%d %d %ld}\n", f->LSN, rid.page, rid.slot, rid.size);

View file

@ -48,7 +48,6 @@ terms specified in this license.
#include <lladd/common.h>
#include <lladd/operations/nestedTopActions.h>
#include <lladd/logger/logger2.h>
#include "../logger/logWriter.h"
#include <pbl/pbl.h>
#include <string.h>
#include <stdlib.h>
@ -114,19 +113,16 @@ lsn_t TendNestedTopAction(int xid, void * handle) {
recordid undoneRID = NULLRID; // Not correct, but this field is unused anyway. ;)
// Write a CLR.
LogEntry * e = allocCLRLogEntry(-1, xid, undoneLSN, undoneRID, *prevLSN);
writeLogEntry(e);
lsn_t clrLSN = LogCLR(xid, undoneLSN, undoneRID, *prevLSN);
// Ensure that the next action in this transaction points to the CLR.
XactionTable[xid % MAX_TRANSACTIONS].prevLSN = e->LSN;
XactionTable[xid % MAX_TRANSACTIONS].prevLSN = clrLSN;
DEBUG("NestedTopAction CLR %d, LSN: %ld type: %ld (undoing: %ld, next to undo: %ld)\n", e->xid,
(long int)e->LSN, (long int)e->type, (long int)undone->LSN, (long int)undone->prevLSN);
clrLSN, undoneLSN, *prevLSN);
lsn_t ret = e->LSN;
free(e);
free(prevLSN);
pthread_mutex_unlock(&transactional_2_mutex);
return ret;
return clrLSN;
}

View file

@ -47,13 +47,13 @@ terms specified in this license.
**********************************************/
#include <lladd/operations.h>
#include "../logger/logWriter.h"
#include <lladd/logger/logger2.h>
#include <stdlib.h>
#include <assert.h>
recordid prepare_bogus_rec = { 0, 0, 0};
static int operate(int xid, Page * p, lsn_t lsn, recordid rid, const void *dat) {
syncLog();
LogForce(lsn);
return 0;
}

View file

@ -8,7 +8,7 @@
#include "pageFile.h"
#include <assert.h>
#include "logger/logWriter.h"
#include <lladd/logger/logger2.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -85,10 +85,8 @@ void pageWrite(Page * ret) {
/* assert(ret->pending == 0); */
if(flushedLSN() < pageReadLSN(ret)) {
DEBUG("pageWrite is calling syncLog()!\n");
syncLog();
}
// If necessary, force the log to disk so that ret's LSN will be stable.
LogForce(pageReadLSN(ret));
pthread_mutex_lock(&stable_mutex);

View file

@ -15,7 +15,6 @@
#include <pbl/pbl.h>
#include "linkedlist.h"
#include "logger/logHandle.h"
#include "logger/logWriter.h"
#include <lladd/bufferManager.h>
#include <lladd/lockManager.h>
@ -230,7 +229,7 @@ static void Undo(int recovery) {
/* Need to log a clr here. */
clr_lsn = LogCLR(e);
clr_lsn = LogCLR(e->xid, e->LSN, e->contents.update.rid, e->prevLSN);
/* Undo update is a no-op if the page does not reflect this
update, but it will write the new clr_lsn if necessary. */
@ -242,7 +241,7 @@ static void Undo(int recovery) {
} else {
// The log entry is not associated with a particular page.
// (Therefore, it must be an idempotent logical log entry.)
clr_lsn = LogCLR(e);
clr_lsn = LogCLR(e->xid, e->LSN, e->contents.update.rid, e->prevLSN);
undoUpdate(e, NULL, clr_lsn);
}
break;

View file

@ -4,7 +4,6 @@
#include <lladd/transactional.h>
#include <lladd/recovery.h>
#include "logger/logWriter.h"
#include <lladd/bufferManager.h>
#include <lladd/consumer.h>
#include <lladd/lockManager.h>
@ -100,7 +99,7 @@ int Tinit() {
bufInit();
openLogWriter();
LogInit(LOG_TO_FILE);
try_ret(compensation_error()) {
pageOperationsInit();
@ -354,7 +353,7 @@ int Tdeinit() {
assert( numActiveXactions == 0 );
ThashDeinit();
bufDeinit();
closeLogWriter();
LogDeinit();
return 0;
}