Fixed broken min_rec_lsn() semantics; before, if there were not outstanding transactions / writes,

then these calls would return flushedLSN().  The problem was that flushedLSN wasn't guaranteed to
return a pointed to the beginning of a log entry.
This commit is contained in:
Sears Russell 2006-06-12 21:50:21 +00:00
parent 7bb0ce0d17
commit e0b34633ec
5 changed files with 27 additions and 10 deletions

View file

@ -64,7 +64,6 @@ terms specified in this license.
#ifndef __lladd_common_h
#define __lladd_common_h
#ifdef __cplusplus
# define BEGIN_C_DECLS extern "C" {
# define END_C_DECLS }
@ -73,6 +72,8 @@ terms specified in this license.
# define END_C_DECLS
#endif /* __cplusplus */
#include <limits.h>
/* Should be included by the .c files only. :( */
/*#if HAVE_CONFIG_H
# include "config.h"
@ -99,7 +100,7 @@ extern int errno;
#define byte unsigned char
#define lsn_t long
#define LSN_T_MAX (LONG_MAX)
/*#define DEBUGGING */
/*#define PROFILE_LATCHES*/

View file

@ -95,6 +95,10 @@ int LogDeinit();
void LogForce(lsn_t lsn);
void LogTruncate(lsn_t lsn);
/** This function is guaranteed to return the LSN of the most recent
log entry that has not been flushed to disk. (If the entire log
is flushed, this function returns the LSN of the entry that will
be allocated the next time the log is appended to. */
lsn_t LogFlushedLSN();

View file

@ -316,7 +316,7 @@ void syncLog() {
pthread_mutex_lock(&log_read_mutex);
// newFlushedLSN = ftell(log) + global_offset;
newFlushedLSN = nextAvailableLSN -1;
newFlushedLSN = nextAvailableLSN;
pthread_mutex_unlock(&log_read_mutex);
// Wait to set the static variable until after the flush returns.

View file

@ -15,6 +15,7 @@
#include <stdio.h>
#include <assert.h>
#include "page/indirect.h"
#include <limits.h>
TransactionLog XactionTable[MAX_TRANSACTIONS];
int numActiveXactions = 0;
@ -370,7 +371,7 @@ void TsetXIDCount(int xid) {
}
lsn_t transactions_minRecLSN() {
lsn_t minRecLSN = LogFlushedLSN();
lsn_t minRecLSN = LSN_T_MAX; // LogFlushedLSN()
pthread_mutex_lock(&transactional_2_mutex);
for(int i = 0; i < MAX_TRANSACTIONS; i++) {
if(XactionTable[i].xid != INVALID_XTABLE_XID) {

View file

@ -1,3 +1,4 @@
#include <limits.h>
#include <lladd/truncation.h>
#include <pbl/pbl.h>
#include <lladd/logger/logger2.h>
@ -53,7 +54,7 @@ int dirtyPages_isDirty(Page * p) {
}
static lsn_t dirtyPages_minRecLSN() {
lsn_t lsn = LogFlushedLSN ();
lsn_t lsn = LSN_T_MAX; // LogFlushedLSN ();
int* pageid;
pthread_mutex_lock(&dirtyPages_mutex);
@ -149,9 +150,21 @@ void autoTruncate() {
int truncateNow() {
// *_minRecLSN() used to return the same value as flushed if
//there were no outstanding transactions, but flushed might
//not point to the front of a log entry... now, both return
//LSN_T_MAX if there are no outstanding transactions / no
//dirty pages.
lsn_t page_rec_lsn = dirtyPages_minRecLSN();
lsn_t xact_rec_lsn = transactions_minRecLSN();
lsn_t flushed_lsn = LogFlushedLSN();
lsn_t rec_lsn = page_rec_lsn < xact_rec_lsn ? page_rec_lsn : xact_rec_lsn;
rec_lsn = (rec_lsn < flushed_lsn) ? rec_lsn : flushed_lsn;
lsn_t log_trunc = LogTruncationPoint();
if((xact_rec_lsn - log_trunc) > MIN_INCREMENTAL_TRUNCATION) {
//printf("xact = %ld \t log = %ld\n", xact_rec_lsn, log_trunc);
@ -168,16 +181,14 @@ int truncateNow() {
page_rec_lsn = dirtyPages_minRecLSN();
rec_lsn = page_rec_lsn < xact_rec_lsn ? page_rec_lsn : xact_rec_lsn;
rec_lsn = (rec_lsn < flushed_lsn) ? rec_lsn : flushed_lsn;
printf("Truncating to rec_lsn = %ld\n", rec_lsn);
fflush(stdout);
// What was this check for?!?
//if(rec_lsn != flushed) {
LogTruncate(rec_lsn);
return 1;
// } else {
// return 0;
// }
} else {
return 0;
}