move inMemoryLog, to the new api
This commit is contained in:
parent
fa4e4fa980
commit
022136d3c3
4 changed files with 21 additions and 30 deletions
|
@ -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) {
|
static int stasis_log_impl_in_memory_write_entry(stasis_log_t * log, LogEntry *e) {
|
||||||
stasis_log_impl_in_memory * impl = log->impl;
|
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;
|
lsn_t bufferOffset;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int blockCount = 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;
|
e->LSN = impl->nextAvailableLSN;
|
||||||
|
|
||||||
LogEntry * cpy = malloc(sizeofLogEntry(log, e));
|
|
||||||
memcpy(cpy, e, sizeofLogEntry(log, e));
|
|
||||||
|
|
||||||
DEBUG("lsn: %ld\n", e->LSN);
|
DEBUG("lsn: %ld\n", e->LSN);
|
||||||
impl->buffer[bufferOffset] = cpy;
|
impl->buffer[bufferOffset] = e;
|
||||||
|
|
||||||
DEBUG("lsn: %ld type: %d\n", e->LSN, e->type);
|
DEBUG("lsn: %ld type: %d\n", e->LSN, e->type);
|
||||||
impl->nextAvailableLSN++;
|
impl->nextAvailableLSN++;
|
||||||
|
|
||||||
unlock(impl->globalOffset_lock);
|
return e;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int stasis_log_impl_in_memory_entry_done(struct stasis_log_t* log, LogEntry* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,16 +47,14 @@ terms specified in this license.
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
LogEntry * allocCommonLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, unsigned int type) {
|
LogEntry * allocCommonLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, unsigned int type) {
|
||||||
LogEntry * ret = calloc(1,sizeof(struct __raw_log_entry));
|
LogEntry * ret = log->reserve_entry(log,sizeof(struct __raw_log_entry));
|
||||||
ret->LSN = -1;
|
|
||||||
ret->prevLSN = prevLSN;
|
ret->prevLSN = prevLSN;
|
||||||
ret->xid = xid;
|
ret->xid = xid;
|
||||||
ret->type = type;
|
ret->type = type;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
LogEntry * allocPrepareLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid, lsn_t recLSN) {
|
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));
|
LogEntry * ret = log->reserve_entry(log,sizeof(struct __raw_log_entry)+sizeof(lsn_t));
|
||||||
ret->LSN = -1;
|
|
||||||
ret->prevLSN = prevLSN;
|
ret->prevLSN = prevLSN;
|
||||||
ret->xid = xid;
|
ret->xid = xid;
|
||||||
ret->type = XPREPARE;
|
ret->type = XPREPARE;
|
||||||
|
@ -89,14 +87,10 @@ lsn_t getPrepareRecLSN(const LogEntry *e) {
|
||||||
LogEntry * allocUpdateLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid,
|
LogEntry * allocUpdateLogEntry(stasis_log_t* log, lsn_t prevLSN, int xid,
|
||||||
unsigned int op, pageid_t page,
|
unsigned int op, pageid_t page,
|
||||||
unsigned int arg_size) {
|
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 =
|
size_t logentrysize =
|
||||||
sizeof(struct __raw_log_entry) + sizeof(UpdateLogEntry) + arg_size;
|
sizeof(struct __raw_log_entry) + sizeof(UpdateLogEntry) + arg_size;
|
||||||
|
|
||||||
LogEntry * ret = calloc(1,logentrysize);
|
LogEntry * ret = log->reserve_entry(log,logentrysize);
|
||||||
ret->LSN = -1;
|
|
||||||
ret->prevLSN = prevLSN;
|
ret->prevLSN = prevLSN;
|
||||||
ret->xid = xid;
|
ret->xid = xid;
|
||||||
ret->type = UPDATELOG;
|
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) {
|
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->prevLSN = old_e->prevLSN;
|
||||||
ret->xid = old_e->xid;
|
ret->xid = old_e->xid;
|
||||||
ret->type = CLRLOG;
|
ret->type = CLRLOG;
|
||||||
|
|
|
@ -52,7 +52,6 @@ START_TEST(rawLogEntryAlloc)
|
||||||
Tinit();
|
Tinit();
|
||||||
stasis_log_t *l = stasis_log();
|
stasis_log_t *l = stasis_log();
|
||||||
LogEntry * log = allocCommonLogEntry(l, 200, 1, XABORT);
|
LogEntry * log = allocCommonLogEntry(l, 200, 1, XABORT);
|
||||||
assert(log->LSN == -1);
|
|
||||||
assert(log->prevLSN == 200);
|
assert(log->prevLSN == 200);
|
||||||
assert(log->xid == 1);
|
assert(log->xid == 1);
|
||||||
assert(log->type == XABORT);
|
assert(log->type == XABORT);
|
||||||
|
@ -82,7 +81,6 @@ START_TEST(updateLogEntryAlloc)
|
||||||
log = allocUpdateLogEntry(l, 200, 1, OPERATION_SET,
|
log = allocUpdateLogEntry(l, 200, 1, OPERATION_SET,
|
||||||
rid.page, 3*sizeof(char));
|
rid.page, 3*sizeof(char));
|
||||||
memcpy(stasis_log_entry_update_args_ptr(log), args, 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->prevLSN == 200);
|
||||||
assert(log->xid == 1);
|
assert(log->xid == 1);
|
||||||
assert(log->type == UPDATELOG);
|
assert(log->type == UPDATELOG);
|
||||||
|
@ -114,7 +112,6 @@ START_TEST(updateLogEntryAllocNoExtras)
|
||||||
stasis_log_t *l = stasis_log();
|
stasis_log_t *l = stasis_log();
|
||||||
LogEntry * log = allocUpdateLogEntry(l, 200, 1, OPERATION_SET,
|
LogEntry * log = allocUpdateLogEntry(l, 200, 1, OPERATION_SET,
|
||||||
rid.page, 0);
|
rid.page, 0);
|
||||||
assert(log->LSN == -1);
|
|
||||||
assert(log->prevLSN == 200);
|
assert(log->prevLSN == 200);
|
||||||
assert(log->xid == 1);
|
assert(log->xid == 1);
|
||||||
assert(log->type == UPDATELOG);
|
assert(log->type == UPDATELOG);
|
||||||
|
|
|
@ -73,6 +73,8 @@ static stasis_log_t * setup_log() {
|
||||||
int first = 1;
|
int first = 1;
|
||||||
stasis_log_t * stasis_log_file = stasis_log();
|
stasis_log_t * stasis_log_file = stasis_log();
|
||||||
for(i = 0 ; i < 1000; i++) {
|
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);
|
LogEntry * e = allocCommonLogEntry(stasis_log_file, prevLSN, xid, XBEGIN);
|
||||||
const LogEntry * f;
|
const LogEntry * f;
|
||||||
recordid rid;
|
recordid rid;
|
||||||
|
@ -83,8 +85,6 @@ static stasis_log_t * 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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue