Miscellaneous cleanups, slightly more conservative latching.
This commit is contained in:
parent
99bcf8acd9
commit
3b1135ea2f
2 changed files with 34 additions and 21 deletions
|
@ -56,7 +56,7 @@ terms specified in this license.
|
|||
#include <config.h>
|
||||
#include <lladd/common.h>
|
||||
|
||||
#include <lladd/transactional.h>
|
||||
//#include <lladd/transactional.h>
|
||||
#include <lladd/crc32.h>
|
||||
#include "logWriter.h"
|
||||
#include "logHandle.h"
|
||||
|
@ -163,7 +163,7 @@ int openLogWriter() {
|
|||
|
||||
int logFD;
|
||||
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 {
|
||||
fprintf(stderr, "\n**********\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;
|
||||
LogEntry * readLSNEntry_LogWriter(lsn_t LSN) {
|
||||
LogEntry * readLSNEntry_LogWriter(const lsn_t LSN) {
|
||||
LogEntry * ret;
|
||||
|
||||
pthread_mutex_lock(&nextAvailableLSN_mutex);
|
||||
|
@ -568,15 +568,15 @@ LogEntry * readLSNEntry_LogWriter(lsn_t LSN) {
|
|||
}
|
||||
pthread_mutex_unlock(&nextAvailableLSN_mutex);
|
||||
|
||||
pthread_mutex_lock(&log_read_mutex);
|
||||
|
||||
/** Because we use two file descriptors to access the log, we need
|
||||
to flush the log write buffer before concluding we're at EOF. */
|
||||
if(flushedLSNInternal() <= LSN) { // && LSN < nextAvailableLSN) {
|
||||
syncLogInternal();
|
||||
assert(flushedLSNInternal() > LSN);
|
||||
assert(flushedLSNInternal() > LSN); // @todo move up into if()
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&log_read_mutex);
|
||||
|
||||
assert(global_offset <= LSN);
|
||||
|
||||
debug_lsn = LSN;
|
||||
|
@ -647,8 +647,13 @@ int truncateLog_LogWriter(lsn_t LSN) {
|
|||
lh = getLSNHandle(LSN);
|
||||
lsn_t lengthOfCopiedLog = 0;
|
||||
int firstInternalEntry = 1;
|
||||
lsn_t nextLSN = 0;
|
||||
while((le = nextInLog(&lh))) {
|
||||
size = sizeofLogEntry(le);
|
||||
if(nextLSN) {
|
||||
assert(nextLSN == le->LSN);
|
||||
}
|
||||
nextLSN = nextEntry_LogWriter(le);
|
||||
|
||||
if(firstInternalEntry && le->type == INTERNALLOG) {
|
||||
LogEntry * firstCRC = malloc(size);
|
||||
|
|
|
@ -78,13 +78,12 @@ long LoggerSizeOfInternalLogEntry(const LogEntry * e) {
|
|||
void LogWrite(LogEntry * e) {
|
||||
if(loggerType == LOG_TO_FILE) {
|
||||
writeLogEntry(e);
|
||||
return;
|
||||
} else if (loggerType == LOG_TO_MEMORY) {
|
||||
writeLogEntry_InMemoryLog(e);
|
||||
return;
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int LogInit(int logType) {
|
||||
|
@ -115,7 +114,8 @@ int LogDeinit() {
|
|||
}
|
||||
|
||||
void LogForce(lsn_t lsn) {
|
||||
if(LogFlushedLSN() < lsn) {
|
||||
lsn_t flushedLSN = LogFlushedLSN();
|
||||
if(flushedLSN < lsn) {
|
||||
if(LOG_TO_FILE == loggerType) {
|
||||
syncLog_LogWriter();
|
||||
} else if (LOG_TO_MEMORY == loggerType) {
|
||||
|
@ -134,45 +134,53 @@ void LogTruncate(lsn_t lsn) {
|
|||
} else {
|
||||
abort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lsn_t LogFlushedLSN() {
|
||||
lsn_t ret;
|
||||
if(LOG_TO_FILE == loggerType) {
|
||||
return flushedLSN_LogWriter();
|
||||
ret = flushedLSN_LogWriter();
|
||||
} else if(LOG_TO_MEMORY == loggerType) {
|
||||
return flushedLSN_InMemoryLog();
|
||||
}
|
||||
ret = flushedLSN_InMemoryLog();
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
lsn_t LogTruncationPoint() {
|
||||
lsn_t ret;
|
||||
if(LOG_TO_FILE == loggerType) {
|
||||
return firstLogEntry();
|
||||
ret = firstLogEntry();
|
||||
} else if(LOG_TO_MEMORY == loggerType) {
|
||||
return firstLogEntry_InMemoryLog();
|
||||
ret = firstLogEntry_InMemoryLog();
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
const LogEntry * LogReadLSN(lsn_t lsn) {
|
||||
LogEntry * ret;
|
||||
if(LOG_TO_FILE == loggerType) {
|
||||
return readLSNEntry_LogWriter(lsn);
|
||||
ret = readLSNEntry_LogWriter(lsn);
|
||||
} else if(LOG_TO_MEMORY == loggerType) {
|
||||
return readLSNEntry_InMemoryLog(lsn);
|
||||
ret = readLSNEntry_InMemoryLog(lsn);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
lsn_t LogNextEntry(const LogEntry * e) {
|
||||
lsn_t ret;
|
||||
if(LOG_TO_FILE == loggerType) {
|
||||
return nextEntry_LogWriter(e);
|
||||
ret = nextEntry_LogWriter(e);
|
||||
} else if(LOG_TO_MEMORY == loggerType) {
|
||||
return nextEntry_InMemoryLog(e);
|
||||
ret = nextEntry_InMemoryLog(e);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FreeLogEntry(const LogEntry * e) {
|
||||
|
|
Loading…
Reference in a new issue