diff --git a/src/stasis/logger/inMemoryLog.c b/src/stasis/logger/inMemoryLog.c index 6992f37..e54a7a7 100644 --- a/src/stasis/logger/inMemoryLog.c +++ b/src/stasis/logger/inMemoryLog.c @@ -2,6 +2,9 @@ #include #include #include +/** + @todo remove static fields from inMemoryLog +*/ static rwl * flushedLSN_lock; static lsn_t nextAvailableLSN; static lsn_t globalOffset; @@ -9,6 +12,15 @@ static rwl * globalOffset_lock; static LogEntry ** buffer; static lsn_t bufferLen; +static lsn_t nextAvailableLSN_InMemoryLog(stasis_log_t * log) { + writelock(flushedLSN_lock,0); + writelock(globalOffset_lock,0); + lsn_t ret = nextAvailableLSN; + unlock(globalOffset_lock); + unlock(flushedLSN_lock); + return ret; +} + static int writeLogEntry_InMemoryLog(stasis_log_t * log, LogEntry *e) { writelock(flushedLSN_lock, 0); lsn_t bufferOffset; @@ -136,6 +148,7 @@ stasis_log_t* open_InMemoryLog() { readLSNEntry_InMemoryLog, // read_entry nextEntry_InMemoryLog,// next_entry flushedLSN_InMemoryLog, // first_unstable_lsn + nextAvailableLSN_InMemoryLog, // next_available_lsn syncLog_InMemoryLog, // force_tail truncateLog_InMemoryLog, // truncate firstLogEntry_InMemoryLog,// truncation_point diff --git a/src/stasis/logger/safeWrites.c b/src/stasis/logger/safeWrites.c index 923b4ee..9511b4e 100644 --- a/src/stasis/logger/safeWrites.c +++ b/src/stasis/logger/safeWrites.c @@ -299,7 +299,6 @@ static inline lsn_t log_crc_next_lsn(stasis_log_t* log, lsn_t ret) { LSN encountered so far to the end of the log. */ - static int writeLogEntryUnlocked(stasis_log_t* log, LogEntry * e) { stasis_log_safe_writes_state* sw = log->impl; @@ -426,6 +425,14 @@ static void syncLog_LogWriter(stasis_log_t * log, writeunlock(sw->flushedLSN_latch); } +static lsn_t nextAvailableLSN_LogWriter(stasis_log_t * log) { + stasis_log_safe_writes_state* sw = log->impl; + pthread_mutex_lock(&sw->nextAvailableLSN_mutex); + lsn_t ret = sw->nextAvailableLSN; + pthread_mutex_unlock(&sw->nextAvailableLSN_mutex); + return ret; +} + static lsn_t flushedLSN_LogWriter(stasis_log_t* log, stasis_log_force_mode_t mode) { stasis_log_safe_writes_state* sw = log->impl; @@ -746,6 +753,7 @@ stasis_log_t* stasis_log_safe_writes_open(const char * filename, readLSNEntry_LogWriter, // read_entry nextEntry_LogWriter,// next_entry flushedLSN_LogWriter, // first_unstable_lsn + nextAvailableLSN_LogWriter, // newt_available_lsn syncLog_LogWriter, // force_tail truncateLog_LogWriter, // truncate firstLogEntry_LogWriter,// truncation_point diff --git a/stasis/logger/logger2.h b/stasis/logger/logger2.h index 71fc322..7235026 100644 --- a/stasis/logger/logger2.h +++ b/stasis/logger/logger2.h @@ -132,7 +132,13 @@ struct stasis_log_t { */ lsn_t (*first_unstable_lsn)(struct stasis_log_t* log, stasis_log_force_mode_t mode); - + /** + This function returns the LSN of the next log entry passed to + write_entry. This shouldn't be used to determine which entry a + particular call will assign; rather it is used to provide a lower + bound on the LSN of newly-loaded LSN-free pages. + */ + lsn_t (*next_available_lsn)(struct stasis_log_t* log); /** Force any enqueued, unwritten entries to disk */ diff --git a/test/stasis/check_logWriter.c b/test/stasis/check_logWriter.c index 87ac859..d3623f3 100644 --- a/test/stasis/check_logWriter.c +++ b/test/stasis/check_logWriter.c @@ -85,9 +85,13 @@ static void setup_log() { rid.slot = 0; rid.size = sizeof(unsigned long); + lsn_t test = stasis_log_file->next_available_lsn(stasis_log_file); + stasis_log_file->write_entry(stasis_log_file,e); prevLSN = e->LSN; + assert(test <= e->LSN); + if(first) { first = 0; firstLSN = prevLSN;