Miscellaneous cleanups, slightly more conservative latching.

This commit is contained in:
Sears Russell 2007-01-30 18:26:59 +00:00
parent 99bcf8acd9
commit 3b1135ea2f
2 changed files with 34 additions and 21 deletions

View file

@ -56,7 +56,7 @@ terms specified in this license.
#include <config.h> #include <config.h>
#include <lladd/common.h> #include <lladd/common.h>
#include <lladd/transactional.h> //#include <lladd/transactional.h>
#include <lladd/crc32.h> #include <lladd/crc32.h>
#include "logWriter.h" #include "logWriter.h"
#include "logHandle.h" #include "logHandle.h"
@ -163,7 +163,7 @@ int openLogWriter() {
int logFD; int logFD;
if(logWriter_isDurable) { if(logWriter_isDurable) {
logFD = open(LOG_FILE, O_CREAT | O_RDWR | O_SYNC, FILE_PERM); //, S_IRWXU | S_IRWXG | S_IRWXO); logFD = open(LOG_FILE, LOG_MODE, FILE_PERM); //, S_IRWXU | S_IRWXG | S_IRWXO);
} else { } else {
fprintf(stderr, "\n**********\n"); fprintf(stderr, "\n**********\n");
fprintf (stderr, "logWriter.c: logWriter_isDurable==0; the logger will not force writes to disk.\n"); fprintf (stderr, "logWriter.c: logWriter_isDurable==0; the logger will not force writes to disk.\n");
@ -557,7 +557,7 @@ static LogEntry * readLogEntry() {
} }
//static lsn_t lastPosition_readLSNEntry = -1; //static lsn_t lastPosition_readLSNEntry = -1;
LogEntry * readLSNEntry_LogWriter(lsn_t LSN) { LogEntry * readLSNEntry_LogWriter(const lsn_t LSN) {
LogEntry * ret; LogEntry * ret;
pthread_mutex_lock(&nextAvailableLSN_mutex); pthread_mutex_lock(&nextAvailableLSN_mutex);
@ -568,15 +568,15 @@ LogEntry * readLSNEntry_LogWriter(lsn_t LSN) {
} }
pthread_mutex_unlock(&nextAvailableLSN_mutex); pthread_mutex_unlock(&nextAvailableLSN_mutex);
pthread_mutex_lock(&log_read_mutex);
/** Because we use two file descriptors to access the log, we need /** Because we use two file descriptors to access the log, we need
to flush the log write buffer before concluding we're at EOF. */ to flush the log write buffer before concluding we're at EOF. */
if(flushedLSNInternal() <= LSN) { // && LSN < nextAvailableLSN) { if(flushedLSNInternal() <= LSN) { // && LSN < nextAvailableLSN) {
syncLogInternal(); syncLogInternal();
assert(flushedLSNInternal() > LSN); assert(flushedLSNInternal() > LSN); // @todo move up into if()
} }
pthread_mutex_lock(&log_read_mutex);
assert(global_offset <= LSN); assert(global_offset <= LSN);
debug_lsn = LSN; debug_lsn = LSN;
@ -647,8 +647,13 @@ int truncateLog_LogWriter(lsn_t LSN) {
lh = getLSNHandle(LSN); lh = getLSNHandle(LSN);
lsn_t lengthOfCopiedLog = 0; lsn_t lengthOfCopiedLog = 0;
int firstInternalEntry = 1; int firstInternalEntry = 1;
lsn_t nextLSN = 0;
while((le = nextInLog(&lh))) { while((le = nextInLog(&lh))) {
size = sizeofLogEntry(le); size = sizeofLogEntry(le);
if(nextLSN) {
assert(nextLSN == le->LSN);
}
nextLSN = nextEntry_LogWriter(le);
if(firstInternalEntry && le->type == INTERNALLOG) { if(firstInternalEntry && le->type == INTERNALLOG) {
LogEntry * firstCRC = malloc(size); LogEntry * firstCRC = malloc(size);

View file

@ -78,13 +78,12 @@ long LoggerSizeOfInternalLogEntry(const LogEntry * e) {
void LogWrite(LogEntry * e) { void LogWrite(LogEntry * e) {
if(loggerType == LOG_TO_FILE) { if(loggerType == LOG_TO_FILE) {
writeLogEntry(e); writeLogEntry(e);
return;
} else if (loggerType == LOG_TO_MEMORY) { } else if (loggerType == LOG_TO_MEMORY) {
writeLogEntry_InMemoryLog(e); writeLogEntry_InMemoryLog(e);
return;
} else { } else {
abort(); abort();
} }
return;
} }
int LogInit(int logType) { int LogInit(int logType) {
@ -115,7 +114,8 @@ int LogDeinit() {
} }
void LogForce(lsn_t lsn) { void LogForce(lsn_t lsn) {
if(LogFlushedLSN() < lsn) { lsn_t flushedLSN = LogFlushedLSN();
if(flushedLSN < lsn) {
if(LOG_TO_FILE == loggerType) { if(LOG_TO_FILE == loggerType) {
syncLog_LogWriter(); syncLog_LogWriter();
} else if (LOG_TO_MEMORY == loggerType) { } else if (LOG_TO_MEMORY == loggerType) {
@ -134,45 +134,53 @@ void LogTruncate(lsn_t lsn) {
} else { } else {
abort(); abort();
} }
} }
lsn_t LogFlushedLSN() { lsn_t LogFlushedLSN() {
lsn_t ret;
if(LOG_TO_FILE == loggerType) { if(LOG_TO_FILE == loggerType) {
return flushedLSN_LogWriter(); ret = flushedLSN_LogWriter();
} else if(LOG_TO_MEMORY == loggerType) { } else if(LOG_TO_MEMORY == loggerType) {
return flushedLSN_InMemoryLog(); ret = flushedLSN_InMemoryLog();
} } else {
abort(); abort();
}
return ret;
} }
lsn_t LogTruncationPoint() { lsn_t LogTruncationPoint() {
lsn_t ret;
if(LOG_TO_FILE == loggerType) { if(LOG_TO_FILE == loggerType) {
return firstLogEntry(); ret = firstLogEntry();
} else if(LOG_TO_MEMORY == loggerType) { } else if(LOG_TO_MEMORY == loggerType) {
return firstLogEntry_InMemoryLog(); ret = firstLogEntry_InMemoryLog();
} else { } else {
abort(); abort();
} }
return ret;
} }
const LogEntry * LogReadLSN(lsn_t lsn) { const LogEntry * LogReadLSN(lsn_t lsn) {
LogEntry * ret;
if(LOG_TO_FILE == loggerType) { if(LOG_TO_FILE == loggerType) {
return readLSNEntry_LogWriter(lsn); ret = readLSNEntry_LogWriter(lsn);
} else if(LOG_TO_MEMORY == loggerType) { } else if(LOG_TO_MEMORY == loggerType) {
return readLSNEntry_InMemoryLog(lsn); ret = readLSNEntry_InMemoryLog(lsn);
} else { } else {
abort(); abort();
} }
return ret;
} }
lsn_t LogNextEntry(const LogEntry * e) { lsn_t LogNextEntry(const LogEntry * e) {
lsn_t ret;
if(LOG_TO_FILE == loggerType) { if(LOG_TO_FILE == loggerType) {
return nextEntry_LogWriter(e); ret = nextEntry_LogWriter(e);
} else if(LOG_TO_MEMORY == loggerType) { } else if(LOG_TO_MEMORY == loggerType) {
return nextEntry_InMemoryLog(e); ret = nextEntry_InMemoryLog(e);
} else { } else {
abort(); abort();
} }
return ret;
} }
void FreeLogEntry(const LogEntry * e) { void FreeLogEntry(const LogEntry * e) {