From 022136d3c31b65863c776240f4b3f907f3243c4e Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Mon, 11 Jan 2010 22:55:55 +0000 Subject: [PATCH] move inMemoryLog, to the new api --- src/stasis/logger/inMemoryLog.c | 29 +++++++++++++++-------------- src/stasis/logger/logEntry.c | 15 ++++----------- test/stasis/check_logEntry.c | 3 --- test/stasis/check_logWriter.c | 4 ++-- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/stasis/logger/inMemoryLog.c b/src/stasis/logger/inMemoryLog.c index 2f535c4..f27e02f 100644 --- a/src/stasis/logger/inMemoryLog.c +++ b/src/stasis/logger/inMemoryLog.c @@ -35,6 +35,19 @@ static lsn_t stasis_log_impl_in_memory_next_available_lsn(stasis_log_t * log) { static int stasis_log_impl_in_memory_write_entry(stasis_log_t * log, LogEntry *e) { stasis_log_impl_in_memory * impl = log->impl; + // XXX release these earlier? + unlock(impl->globalOffset_lock); + unlock(impl->flushedLSN_lock); + return 0; +} + +LogEntry* stasis_log_impl_in_memory_reserve_entry(struct stasis_log_t* log, size_t sz) { + stasis_log_impl_in_memory * impl = log->impl; + /** Use calloc since the entry might not be packed in memory; + otherwise, we'd leak uninitialized bytes to the log. */ + + LogEntry * e = calloc(1,sz); + lsn_t bufferOffset; int done = 0; int blockCount = 0; @@ -65,28 +78,16 @@ static int stasis_log_impl_in_memory_write_entry(stasis_log_t * log, LogEntry *e e->LSN = impl->nextAvailableLSN; - LogEntry * cpy = malloc(sizeofLogEntry(log, e)); - memcpy(cpy, e, sizeofLogEntry(log, e)); - DEBUG("lsn: %ld\n", e->LSN); - impl->buffer[bufferOffset] = cpy; + impl->buffer[bufferOffset] = e; DEBUG("lsn: %ld type: %d\n", e->LSN, e->type); impl->nextAvailableLSN++; - unlock(impl->globalOffset_lock); - unlock(impl->flushedLSN_lock); - return 0; -} - -LogEntry* stasis_log_impl_in_memory_reserve_entry(struct stasis_log_t* log, size_t sz) { - // XXX need to assign LSN here. - return malloc(sz); + return e; } int stasis_log_impl_in_memory_entry_done(struct stasis_log_t* log, LogEntry* e) { -// int ret = stasis_log_impl_in_memory_write_entry(log, e); - free(e); return 0; } diff --git a/src/stasis/logger/logEntry.c b/src/stasis/logger/logEntry.c index 48eb9f4..92d9032 100644 --- a/src/stasis/logger/logEntry.c +++ b/src/stasis/logger/logEntry.c @@ -47,16 +47,14 @@ terms specified in this license. #include LogEntry * allocCommonLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, unsigned int type) { - LogEntry * ret = calloc(1,sizeof(struct __raw_log_entry)); - ret->LSN = -1; + LogEntry * ret = log->reserve_entry(log,sizeof(struct __raw_log_entry)); ret->prevLSN = prevLSN; ret->xid = xid; ret->type = type; return ret; } LogEntry * allocPrepareLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, lsn_t recLSN) { - LogEntry * ret = calloc(1,sizeof(struct __raw_log_entry)+sizeof(lsn_t)); - ret->LSN = -1; + LogEntry * ret = log->reserve_entry(log,sizeof(struct __raw_log_entry)+sizeof(lsn_t)); ret->prevLSN = prevLSN; ret->xid = xid; ret->type = XPREPARE; @@ -89,14 +87,10 @@ lsn_t getPrepareRecLSN(const LogEntry *e) { LogEntry * allocUpdateLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, unsigned int op, pageid_t page, unsigned int arg_size) { - /** Use calloc since the struct might not be packed in memory; - otherwise, we'd leak uninitialized bytes to the log. */ - size_t logentrysize = sizeof(struct __raw_log_entry) + sizeof(UpdateLogEntry) + arg_size; - LogEntry * ret = calloc(1,logentrysize); - ret->LSN = -1; + LogEntry * ret = log->reserve_entry(log,logentrysize); ret->prevLSN = prevLSN; ret->xid = xid; ret->type = UPDATELOG; @@ -108,9 +102,8 @@ LogEntry * allocUpdateLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, } LogEntry * allocCLRLogEntry(stasis_log_t* log, const LogEntry * old_e) { - CLRLogEntry * ret = calloc(1,sizeof(struct __raw_log_entry)+sizeofLogEntry(0, old_e)); + CLRLogEntry * ret = log->reserve_entry(log,sizeof(struct __raw_log_entry)+sizeofLogEntry(0, old_e)); - ret->LSN = -1; ret->prevLSN = old_e->prevLSN; ret->xid = old_e->xid; ret->type = CLRLOG; diff --git a/test/stasis/check_logEntry.c b/test/stasis/check_logEntry.c index 7c1a692..89c14bb 100644 --- a/test/stasis/check_logEntry.c +++ b/test/stasis/check_logEntry.c @@ -52,7 +52,6 @@ START_TEST(rawLogEntryAlloc) Tinit(); stasis_log_t *l = stasis_log(); LogEntry * log = allocCommonLogEntry(l, 200, 1, XABORT); - assert(log->LSN == -1); assert(log->prevLSN == 200); assert(log->xid == 1); assert(log->type == XABORT); @@ -82,7 +81,6 @@ START_TEST(updateLogEntryAlloc) log = allocUpdateLogEntry(l, 200, 1, OPERATION_SET, rid.page, 3*sizeof(char)); memcpy(stasis_log_entry_update_args_ptr(log), args, 3*sizeof(char)); - assert(log->LSN == -1); assert(log->prevLSN == 200); assert(log->xid == 1); assert(log->type == UPDATELOG); @@ -114,7 +112,6 @@ START_TEST(updateLogEntryAllocNoExtras) stasis_log_t *l = stasis_log(); LogEntry * log = allocUpdateLogEntry(l, 200, 1, OPERATION_SET, rid.page, 0); - assert(log->LSN == -1); assert(log->prevLSN == 200); assert(log->xid == 1); assert(log->type == UPDATELOG); diff --git a/test/stasis/check_logWriter.c b/test/stasis/check_logWriter.c index 359fb59..df30ce5 100644 --- a/test/stasis/check_logWriter.c +++ b/test/stasis/check_logWriter.c @@ -73,6 +73,8 @@ static stasis_log_t * setup_log() { int first = 1; stasis_log_t * stasis_log_file = stasis_log(); for(i = 0 ; i < 1000; i++) { + lsn_t test = stasis_log_file->next_available_lsn(stasis_log_file); + LogEntry * e = allocCommonLogEntry(stasis_log_file, prevLSN, xid, XBEGIN); const LogEntry * f; recordid rid; @@ -83,8 +85,6 @@ static stasis_log_t * 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;