pull memcpy out of allocUpdateEntry()

This commit is contained in:
Sears Russell 2009-12-31 19:30:40 +00:00
parent 32e40c949d
commit 9aa1d9d652
10 changed files with 31 additions and 31 deletions

View file

@ -96,8 +96,8 @@ int main(int argc, char ** argv) {
lsn_t prevLSN = -1; lsn_t prevLSN = -1;
byte * arg = calloc(PAGE_SIZE, 1); byte * arg = calloc(PAGE_SIZE, 1);
LogEntry * e = allocUpdateLogEntry(prevLSN, -1, OPERATION_NOOP, LogEntry * e = allocUpdateLogEntry(prevLSN, -1, OPERATION_NOOP,
0, 0, PAGE_SIZE);
arg, PAGE_SIZE); memcpy(getUpdateArgs(e), arg, PAGE_SIZE);
stasis_log_t * l = stasis_log(); stasis_log_t * l = stasis_log();
for(long i = 0; i < page_count; i++) { for(long i = 0; i < page_count; i++) {
void * h; void * h;

View file

@ -63,7 +63,7 @@ LogEntry * allocPrepareLogEntry(lsn_t prevLSN, int xid, lsn_t recLSN) {
*(lsn_t*)(((struct __raw_log_entry*)ret)+1)=recLSN; *(lsn_t*)(((struct __raw_log_entry*)ret)+1)=recLSN;
return ret; return ret;
} }
const void * getUpdateArgs(const LogEntry * ret) { void * getUpdateArgs(LogEntry * ret) {
assert(ret->type == UPDATELOG || assert(ret->type == UPDATELOG ||
ret->type == CLRLOG); ret->type == CLRLOG);
if(ret->update.arg_size == 0) { if(ret->update.arg_size == 0) {
@ -84,7 +84,7 @@ lsn_t getPrepareRecLSN(const LogEntry *e) {
LogEntry * allocUpdateLogEntry(lsn_t prevLSN, int xid, LogEntry * allocUpdateLogEntry(lsn_t prevLSN, int xid,
unsigned int op, pageid_t page, unsigned int op, pageid_t page,
const byte * args, unsigned int arg_size) { unsigned int arg_size) {
/** Use calloc since the struct might not be packed in memory; /** Use calloc since the struct might not be packed in memory;
otherwise, we'd leak uninitialized bytes to the log. */ otherwise, we'd leak uninitialized bytes to the log. */
@ -100,10 +100,6 @@ LogEntry * allocUpdateLogEntry(lsn_t prevLSN, int xid,
ret->update.page = page; ret->update.page = page;
ret->update.arg_size = arg_size; ret->update.arg_size = arg_size;
if(arg_size) {
memcpy((void*)getUpdateArgs(ret), args, arg_size);
}
return ret; return ret;
} }

View file

@ -101,8 +101,8 @@ LogEntry * stasis_log_write_update(stasis_log_t* log, stasis_transaction_table_e
const byte * arg, size_t arg_size) { const byte * arg, size_t arg_size) {
LogEntry * e = allocUpdateLogEntry(l->prevLSN, l->xid, op, LogEntry * e = allocUpdateLogEntry(l->prevLSN, l->xid, op,
page, page, arg_size);
arg, arg_size); memcpy(getUpdateArgs(e), arg, arg_size);
log->write_entry(log, e); log->write_entry(log, e);
DEBUG("Log Update %d, LSN: %ld type: %ld (prevLSN %ld) (arg_size %ld)\n", e->xid, DEBUG("Log Update %d, LSN: %ld type: %ld (prevLSN %ld) (arg_size %ld)\n", e->xid,
(long int)e->LSN, (long int)e->type, (long int)e->prevLSN, (long int) arg_size); (long int)e->LSN, (long int)e->type, (long int)e->prevLSN, (long int) arg_size);
@ -115,7 +115,8 @@ LogEntry * stasis_log_write_update(stasis_log_t* log, stasis_transaction_table_e
LogEntry * stasis_log_begin_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, unsigned int op, LogEntry * stasis_log_begin_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, unsigned int op,
const byte * arg, size_t arg_size) { const byte * arg, size_t arg_size) {
LogEntry * e = allocUpdateLogEntry(l->prevLSN, l->xid, op, INVALID_PAGE, arg, arg_size); LogEntry * e = allocUpdateLogEntry(l->prevLSN, l->xid, op, INVALID_PAGE, arg_size);
memcpy(getUpdateArgs(e), arg, arg_size);
return e; return e;
} }
lsn_t stasis_log_end_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, LogEntry * e) { lsn_t stasis_log_end_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, LogEntry * e) {
@ -143,7 +144,7 @@ lsn_t stasis_log_write_clr(stasis_log_t* log, const LogEntry * old_e) {
lsn_t stasis_log_write_dummy_clr(stasis_log_t* log, int xid, lsn_t prevLSN) { lsn_t stasis_log_write_dummy_clr(stasis_log_t* log, int xid, lsn_t prevLSN) {
// XXX waste of log bandwidth. // XXX waste of log bandwidth.
const LogEntry * e = allocUpdateLogEntry(prevLSN, xid, OPERATION_NOOP, const LogEntry * e = allocUpdateLogEntry(prevLSN, xid, OPERATION_NOOP,
INVALID_PAGE, NULL, 0); INVALID_PAGE, 0);
lsn_t ret = stasis_log_write_clr(log, e); lsn_t ret = stasis_log_write_clr(log, e);
freeLogEntry(e); freeLogEntry(e);
return ret; return ret;

View file

@ -156,7 +156,8 @@ void regionsInit() {
// hack; allocate a fake log entry; pass it into ourselves. // hack; allocate a fake log entry; pass it into ourselves.
LogEntry * e = allocUpdateLogEntry(0,0,OPERATION_ALLOC_BOUNDARY_TAG, LogEntry * e = allocUpdateLogEntry(0,0,OPERATION_ALLOC_BOUNDARY_TAG,
p->id, (const byte*)&t, sizeof(boundary_tag)); p->id, sizeof(boundary_tag));
memcpy(getUpdateArgs(e), &t, sizeof(boundary_tag));
writelock(p->rwlatch,0); writelock(p->rwlatch,0);
op_alloc_boundary_tag(e,p); op_alloc_boundary_tag(e,p);
unlock(p->rwlatch); unlock(p->rwlatch);

View file

@ -181,8 +181,9 @@ void TreorderableUpdate(int xid, void * hp, pageid_t page,
pthread_mutex_lock(&h->mut); pthread_mutex_lock(&h->mut);
LogEntry * e = allocUpdateLogEntry(-1, h->l->xid, op, LogEntry * e = allocUpdateLogEntry(-1, h->l->xid, op,
p->id, p->id, datlen);
dat, datlen);
memcpy(getUpdateArgs(e), dat, datlen);
stasis_log_reordering_handle_append(h, p, op, dat, datlen, sizeofLogEntry(0, e)); stasis_log_reordering_handle_append(h, p, op, dat, datlen, sizeofLogEntry(0, e));
@ -196,7 +197,9 @@ void TreorderableUpdate(int xid, void * hp, pageid_t page,
} }
lsn_t TwritebackUpdate(int xid, pageid_t page, lsn_t TwritebackUpdate(int xid, pageid_t page,
const void *dat, size_t datlen, int op) { const void *dat, size_t datlen, int op) {
LogEntry * e = allocUpdateLogEntry(-1, xid, op, page, dat, datlen); LogEntry * e = allocUpdateLogEntry(-1, xid, op, page, datlen);
memcpy(getUpdateArgs(e), dat, datlen);
stasis_transaction_table_entry_t* l = stasis_transaction_table_get(stasis_transaction_table, xid); stasis_transaction_table_entry_t* l = stasis_transaction_table_get(stasis_transaction_table, xid);
stasis_log_file->write_entry(stasis_log_file, e); stasis_log_file->write_entry(stasis_log_file, e);
@ -215,7 +218,8 @@ void TreorderableWritebackUpdate(int xid, void* hp,
stasis_log_reordering_handle_t* h = hp; stasis_log_reordering_handle_t* h = hp;
assert(stasis_transaction_table_is_active(stasis_transaction_table, xid)); assert(stasis_transaction_table_is_active(stasis_transaction_table, xid));
pthread_mutex_lock(&h->mut); pthread_mutex_lock(&h->mut);
LogEntry * e = allocUpdateLogEntry(-1, xid, op, page, dat, datlen); LogEntry * e = allocUpdateLogEntry(-1, xid, op, page, datlen);
memcpy(getUpdateArgs(e), dat, datlen);
stasis_log_reordering_handle_append(h, 0, op, dat, datlen, sizeofLogEntry(0, e)); stasis_log_reordering_handle_append(h, 0, op, dat, datlen, sizeofLogEntry(0, e));
pthread_mutex_unlock(&h->mut); pthread_mutex_unlock(&h->mut);
} }

View file

@ -105,8 +105,7 @@ LogEntry * allocPrepareLogEntry(lsn_t prevLSN, int xid, lsn_t recLSN);
*/ */
LogEntry * allocUpdateLogEntry(lsn_t prevLSN, int xid, LogEntry * allocUpdateLogEntry(lsn_t prevLSN, int xid,
unsigned int op, pageid_t page, unsigned int op, pageid_t page, unsigned int arg_size);
const byte * arg, unsigned int arg_size);
/** /**
Allocate a CLR entry. These are written during recovery as log Allocate a CLR entry. These are written during recovery as log
@ -131,7 +130,7 @@ lsn_t sizeofLogEntry(stasis_log_t * lh, const LogEntry * e);
@todo Remove explicit casts from getUpdateArgs calls (so we don't accidentally strip the const). @todo Remove explicit casts from getUpdateArgs calls (so we don't accidentally strip the const).
@return the operation's arguments. @return the operation's arguments.
*/ */
const void * getUpdateArgs(const LogEntry * e); void * getUpdateArgs(LogEntry * e);
/** /**
@return a copy of the log entry that this CLR compensated. @return a copy of the log entry that this CLR compensated.

View file

@ -76,8 +76,8 @@ START_TEST(updateLogEntryAlloc)
Tinit(); /* Needed because it sets up the operations table. */ Tinit(); /* Needed because it sets up the operations table. */
log = allocUpdateLogEntry(200, 1, OPERATION_SET, log = allocUpdateLogEntry(200, 1, OPERATION_SET,
rid.page, rid.page, 3*sizeof(char));
(const byte*)args, 3*sizeof(char)); memcpy(getUpdateArgs(log), args, 3*sizeof(char));
assert(log->LSN == -1); assert(log->LSN == -1);
assert(log->prevLSN == 200); assert(log->prevLSN == 200);
assert(log->xid == 1); assert(log->xid == 1);
@ -107,8 +107,7 @@ START_TEST(updateLogEntryAllocNoExtras)
recordid rid = { 3 , 4, sizeof(int)*3 }; recordid rid = { 3 , 4, sizeof(int)*3 };
LogEntry * log = allocUpdateLogEntry(200, 1, OPERATION_SET, LogEntry * log = allocUpdateLogEntry(200, 1, OPERATION_SET,
rid.page, rid.page, 0);
(byte*)args, 0);
assert(log->LSN == -1); assert(log->LSN == -1);
assert(log->prevLSN == 200); assert(log->prevLSN == 200);
assert(log->xid == 1); assert(log->xid == 1);

View file

@ -103,8 +103,8 @@ static stasis_log_t * setup_log() {
freeLogEntry(e); freeLogEntry(e);
freeLogEntry(f); freeLogEntry(f);
e = allocUpdateLogEntry(prevLSN, xid, 1, rid.page, args, args_size); e = allocUpdateLogEntry(prevLSN, xid, 1, rid.page, args_size);
memcpy(getUpdateArgs(e), args, args_size);
stasis_log_file->write_entry(stasis_log_file,e); stasis_log_file->write_entry(stasis_log_file,e);
prevLSN = e->prevLSN; prevLSN = e->prevLSN;

View file

@ -180,8 +180,9 @@ START_TEST(multiplexTest) {
for(i = 0; i < NUM_INSERTS; i++) { for(i = 0; i < NUM_INSERTS; i++) {
(*(lsn_t*)(arg+1)) = i; (*(lsn_t*)(arg+1)) = i;
LogEntry * e = allocUpdateLogEntry(-1, -1, OPERATION_LINEAR_HASH_INSERT, INVALID_PAGE, (byte*)arg, LogEntry * e = allocUpdateLogEntry(-1, -1, OPERATION_LINEAR_HASH_INSERT, INVALID_PAGE,
sizeof(linearHash_remove_arg) + sizeof(lsn_t) + sizeof(char)); sizeof(linearHash_remove_arg) + sizeof(lsn_t) + sizeof(char));
memcpy(getUpdateArgs(e), arg, sizeof(linearHash_remove_arg) + sizeof(lsn_t) + sizeof(char));
ThashInsert(xid, hash, (byte*)&i, sizeof(lsn_t), (byte*)e, sizeofLogEntry(0, e)); ThashInsert(xid, hash, (byte*)&i, sizeof(lsn_t), (byte*)e, sizeofLogEntry(0, e));

View file

@ -89,9 +89,8 @@ START_TEST(operation_physical_do_undo) {
// XXX fails; set log format has changed // XXX fails; set log format has changed
setToTwo = allocUpdateLogEntry(-1, xid, OPERATION_SET, rid.page, setToTwo = allocUpdateLogEntry(-1, xid, OPERATION_SET, rid.page,
(void*)arg, sizeof(slotid_t) + sizeof(int64_t) + 2 * sizeof(int)); sizeof(slotid_t) + sizeof(int64_t) + 2 * sizeof(int));
memcpy(getUpdateArgs(setToTwo), arg, sizeof(slotid_t) + sizeof(int64_t) + 2 * sizeof(int));
/* Do, undo and redo operation without updating the LSN field of the page. */ /* Do, undo and redo operation without updating the LSN field of the page. */