expose nextAvailableLSN for lsn-free pages

This commit is contained in:
Sears Russell 2009-03-15 02:43:09 +00:00
parent 1a1268ac36
commit bd2015443f
4 changed files with 33 additions and 2 deletions

View file

@ -2,6 +2,9 @@
#include <stasis/latches.h> #include <stasis/latches.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
/**
@todo remove static fields from inMemoryLog
*/
static rwl * flushedLSN_lock; static rwl * flushedLSN_lock;
static lsn_t nextAvailableLSN; static lsn_t nextAvailableLSN;
static lsn_t globalOffset; static lsn_t globalOffset;
@ -9,6 +12,15 @@ static rwl * globalOffset_lock;
static LogEntry ** buffer; static LogEntry ** buffer;
static lsn_t bufferLen; 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) { static int writeLogEntry_InMemoryLog(stasis_log_t * log, LogEntry *e) {
writelock(flushedLSN_lock, 0); writelock(flushedLSN_lock, 0);
lsn_t bufferOffset; lsn_t bufferOffset;
@ -136,6 +148,7 @@ stasis_log_t* open_InMemoryLog() {
readLSNEntry_InMemoryLog, // read_entry readLSNEntry_InMemoryLog, // read_entry
nextEntry_InMemoryLog,// next_entry nextEntry_InMemoryLog,// next_entry
flushedLSN_InMemoryLog, // first_unstable_lsn flushedLSN_InMemoryLog, // first_unstable_lsn
nextAvailableLSN_InMemoryLog, // next_available_lsn
syncLog_InMemoryLog, // force_tail syncLog_InMemoryLog, // force_tail
truncateLog_InMemoryLog, // truncate truncateLog_InMemoryLog, // truncate
firstLogEntry_InMemoryLog,// truncation_point firstLogEntry_InMemoryLog,// truncation_point

View file

@ -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. LSN encountered so far to the end of the log.
*/ */
static int writeLogEntryUnlocked(stasis_log_t* log, LogEntry * e) { static int writeLogEntryUnlocked(stasis_log_t* log, LogEntry * e) {
stasis_log_safe_writes_state* sw = log->impl; stasis_log_safe_writes_state* sw = log->impl;
@ -426,6 +425,14 @@ static void syncLog_LogWriter(stasis_log_t * log,
writeunlock(sw->flushedLSN_latch); 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, static lsn_t flushedLSN_LogWriter(stasis_log_t* log,
stasis_log_force_mode_t mode) { stasis_log_force_mode_t mode) {
stasis_log_safe_writes_state* sw = log->impl; 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 readLSNEntry_LogWriter, // read_entry
nextEntry_LogWriter,// next_entry nextEntry_LogWriter,// next_entry
flushedLSN_LogWriter, // first_unstable_lsn flushedLSN_LogWriter, // first_unstable_lsn
nextAvailableLSN_LogWriter, // newt_available_lsn
syncLog_LogWriter, // force_tail syncLog_LogWriter, // force_tail
truncateLog_LogWriter, // truncate truncateLog_LogWriter, // truncate
firstLogEntry_LogWriter,// truncation_point firstLogEntry_LogWriter,// truncation_point

View file

@ -132,7 +132,13 @@ struct stasis_log_t {
*/ */
lsn_t (*first_unstable_lsn)(struct stasis_log_t* log, lsn_t (*first_unstable_lsn)(struct stasis_log_t* log,
stasis_log_force_mode_t mode); 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 Force any enqueued, unwritten entries to disk
*/ */

View file

@ -85,9 +85,13 @@ static void setup_log() {
rid.slot = 0; rid.slot = 0;
rid.size = sizeof(unsigned long); 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); stasis_log_file->write_entry(stasis_log_file,e);
prevLSN = e->LSN; prevLSN = e->LSN;
assert(test <= e->LSN);
if(first) { if(first) {
first = 0; first = 0;
firstLSN = prevLSN; firstLSN = prevLSN;