refactor getUpdateArgs; remove a bunch of casts, fix a bunch of warnings

This commit is contained in:
Sears Russell 2009-12-31 20:20:47 +00:00
parent 1c82f9e76e
commit a5788688c8
22 changed files with 56 additions and 53 deletions

View file

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

View file

@ -57,7 +57,7 @@ static int insert_node(int xid, recordid rid, tree_node* node) {
static int op_tree_insert(const LogEntry* e, Page* p) {
// TODO: Latching
assert(p == NULL);
const tree_op_args* a = getUpdateArgs(e);
const tree_op_args* a = stasis_log_entry_update_args_cptr(e);
recordid root_rid = { a->page, a->slot, sizeof(tree_root) };
tree_root root;
@ -154,7 +154,7 @@ static int remove_node(int xid, recordid rid, int val) {
static int op_tree_remove(const LogEntry* e, Page* p) {
// TODO: Latching
assert(p == NULL);
const tree_op_args* a = getUpdateArgs(e);
const tree_op_args* a = stasis_log_entry_update_args_cptr(e);
recordid root_rid = { a->page, a->slot, sizeof(tree_root) };
return remove_node(e->xid, root_rid, a->val);
}

View file

@ -63,7 +63,8 @@ LogEntry * allocPrepareLogEntry(lsn_t prevLSN, int xid, lsn_t recLSN) {
*(lsn_t*)(((struct __raw_log_entry*)ret)+1)=recLSN;
return ret;
}
void * getUpdateArgs(LogEntry * ret) {
const void * stasis_log_entry_update_args_cptr(const LogEntry * ret) {
assert(ret->type == UPDATELOG ||
ret->type == CLRLOG);
if(ret->update.arg_size == 0) {
@ -75,6 +76,9 @@ void * getUpdateArgs(LogEntry * ret) {
}
}
void * stasis_log_entry_update_args_ptr(LogEntry * ret) {
return (void*)stasis_log_entry_update_args_cptr(ret);
}
lsn_t getPrepareRecLSN(const LogEntry *e) {
lsn_t ret = *(lsn_t*)(((struct __raw_log_entry*)e)+1);

View file

@ -102,7 +102,7 @@ LogEntry * stasis_log_write_update(stasis_log_t* log, stasis_transaction_table_e
LogEntry * e = allocUpdateLogEntry(l->prevLSN, l->xid, op,
page, arg_size);
memcpy(getUpdateArgs(e), arg, arg_size);
memcpy(stasis_log_entry_update_args_ptr(e), arg, arg_size);
log->write_entry(log, e);
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);
@ -116,7 +116,7 @@ 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,
const byte * arg, size_t arg_size) {
LogEntry * e = allocUpdateLogEntry(l->prevLSN, l->xid, op, INVALID_PAGE, arg_size);
memcpy(getUpdateArgs(e), arg, arg_size);
memcpy(stasis_log_entry_update_args_ptr(e), arg, arg_size);
return e;
}
lsn_t stasis_log_end_nta(stasis_log_t* log, stasis_transaction_table_entry_t * l, LogEntry * e) {

View file

@ -128,7 +128,7 @@ void multiplexHashLogByKey(byte * key,
size_t * multiplexKeySize) {
// We don't care what the key is. It's probably an LSN.
const LogEntry * log = (const LogEntry*) value;
const byte * updateArgs = getUpdateArgs(log); // assume the log is a logical update entry.
const byte * updateArgs = stasis_log_entry_update_args_cptr(log); // assume the log is a logical update entry.
switch(log->update.funcID) {
// If you really want to know why insert takes

View file

@ -104,7 +104,7 @@ struct stasis_alloc_t {
static int op_alloc(const LogEntry* e, Page* p) {
assert(e->update.arg_size >= sizeof(alloc_arg));
const alloc_arg* arg = (const alloc_arg*)getUpdateArgs(e);
const alloc_arg* arg = stasis_log_entry_update_args_cptr(e);
recordid rid = {
p->id,
arg->slot,
@ -129,7 +129,7 @@ static int op_alloc(const LogEntry* e, Page* p) {
static int op_dealloc(const LogEntry* e, Page* p) {
assert(e->update.arg_size >= sizeof(alloc_arg));
const alloc_arg* arg = (const alloc_arg*)getUpdateArgs(e);
const alloc_arg* arg = stasis_log_entry_update_args_cptr(e);
recordid rid = {
p->id,
arg->slot,
@ -147,7 +147,7 @@ static int op_dealloc(const LogEntry* e, Page* p) {
static int op_realloc(const LogEntry* e, Page* p) {
assert(e->update.arg_size >= sizeof(alloc_arg));
const alloc_arg* arg = (const alloc_arg*)getUpdateArgs(e);
const alloc_arg* arg = stasis_log_entry_update_args_cptr(e);
recordid rid = {
p->id,

View file

@ -57,7 +57,7 @@ static int array_list_op_init_header(const LogEntry* e, Page* p) {
assert(e->update.arg_size == sizeof(array_list_parameter_t));
const array_list_parameter_t * alp
= (const array_list_parameter_t*)getUpdateArgs(e);
= stasis_log_entry_update_args_cptr(e);
stasis_fixed_initialize_page(p, sizeof(pageid_t),
stasis_fixed_records_per_page(sizeof(pageid_t)));

View file

@ -51,7 +51,7 @@ terms specified in this license.
static int op_decrement(const LogEntry* e, Page* p) {
int i;
assert(e->update.arg_size == sizeof(slotid_t));
recordid r = {p->id, *(slotid_t*)getUpdateArgs(e), sizeof(int)};
recordid r = {p->id, *(slotid_t*)stasis_log_entry_update_args_cptr(e), sizeof(int)};
stasis_record_read(e->xid, p, r, (byte*)&i);
i--;

View file

@ -52,7 +52,7 @@ static int op_increment(const LogEntry* e, Page* p) {
int i;
assert(e->update.arg_size == sizeof(slotid_t));
recordid r = {p->id, *(slotid_t*)getUpdateArgs(e), sizeof(int)};
recordid r = {p->id, *(const slotid_t*)stasis_log_entry_update_args_cptr(e), sizeof(int)};
stasis_record_read(e->xid, p, r, (byte*)&i);
i++;

View file

@ -133,7 +133,7 @@ typedef struct {
//compensated_function static int operateInsert(int xid, Page *p, lsn_t lsn, recordid rid, const void *dat) {
compensated_function static int op_linear_hash_insert(const LogEntry* e, Page* p) {
const linearHash_remove_arg * args = (const linearHash_remove_arg*)getUpdateArgs(e);
const linearHash_remove_arg * args = stasis_log_entry_update_args_cptr(e);
recordid hashHeader = args->hashHeader;
int keySize = args->keySize;
int valueSize = args->valueSize;
@ -149,7 +149,7 @@ compensated_function static int op_linear_hash_insert(const LogEntry* e, Page* p
return 0;
}
compensated_function static int op_linear_hash_remove(const LogEntry* e, Page* p) {
const linearHash_insert_arg * args = (const linearHash_insert_arg*) getUpdateArgs(e);
const linearHash_insert_arg * args = stasis_log_entry_update_args_cptr(e);
recordid hashHeader = args->hashHeader;
int keySize = args->keySize;

View file

@ -63,7 +63,7 @@ typedef struct {
compensated_function static int op_linked_list_nta_insert(const LogEntry* e, Page* p) {
assert(!p);
stasis_linked_list_remove_log * log = (stasis_linked_list_remove_log*)getUpdateArgs(e);;
const stasis_linked_list_remove_log * log = stasis_log_entry_update_args_cptr(e);;
byte * key;
byte * value;
@ -86,7 +86,7 @@ compensated_function static int op_linked_list_nta_insert(const LogEntry* e, Pag
}
compensated_function static int op_linked_list_nta_remove(const LogEntry *e, Page* p) {
assert(!p);
stasis_linked_list_remove_log * log = (stasis_linked_list_remove_log*)getUpdateArgs(e);
const stasis_linked_list_remove_log * log = stasis_log_entry_update_args_cptr(e);
byte * key;
int keySize;

View file

@ -10,7 +10,7 @@ static int op_lsn_free_set(const LogEntry *e, Page *p) {
assert(e->update.arg_size >= (sizeof(pageoff_t) * 2));
int size = e->update.arg_size;
size -= (2*sizeof(pageoff_t));
const pageoff_t * a = (const pageoff_t*)getUpdateArgs(e);
const pageoff_t * a = stasis_log_entry_update_args_cptr(e);
const byte* b = (const byte*)&(a[2]);
assertlocked(p->rwlatch);
memcpy(p->memAddr + a[0], b, a[1]);
@ -21,7 +21,7 @@ static int op_lsn_free_unset(const LogEntry *e, Page *p) {
assert(e->update.arg_size >= (sizeof(pageoff_t) * 2));
int size = e->update.arg_size;
size -= (2*sizeof(pageoff_t));
const pageoff_t * a = (const pageoff_t*)getUpdateArgs(e);
const pageoff_t * a = stasis_log_entry_update_args_cptr(e);
const byte* b = (const byte*)&(a[2]);
assertlocked(p->rwlatch);
memcpy(p->memAddr + a[0], b+a[1], a[1]);

View file

@ -11,24 +11,24 @@ static int op_page_set_range(const LogEntry* e, Page* p) {
assert(e->update.arg_size >= sizeof(int));
assert(!((e->update.arg_size - sizeof(int)) % 2));
int off = *(int*)getUpdateArgs(e);
int off = *(const int*)stasis_log_entry_update_args_cptr(e);
int len = (e->update.arg_size - sizeof(int)) >> 1;
assert(off+len <=PAGE_SIZE);
memcpy(p->memAddr + off, ((const byte*)getUpdateArgs(e))+sizeof(int), len);
memcpy(p->memAddr + off, ((const byte*)stasis_log_entry_update_args_cptr(e))+sizeof(int), len);
return 0;
}
static int op_page_set_range_inverse(const LogEntry* e, Page* p) {
assert(e->update.arg_size >= sizeof(int));
assert(!((e->update.arg_size - sizeof(int)) % 2));
int off = *(int*)getUpdateArgs(e);
int off = *(const int*)stasis_log_entry_update_args_cptr(e);
int len = (e->update.arg_size - sizeof(int)) >> 1;
assert(off+len <=PAGE_SIZE);
memcpy(p->memAddr + off, ((const byte*)getUpdateArgs(e))+sizeof(int)+len,
memcpy(p->memAddr + off, ((const byte*)stasis_log_entry_update_args_cptr(e))+sizeof(int)+len,
len);
return 0;
}
@ -198,7 +198,7 @@ void TinitializeFixedPage(int xid, pageid_t page, int slotLength) {
static int op_initialize_page(const LogEntry* e, Page* p) {
assert(e->update.arg_size == sizeof(page_init_arg));
const page_init_arg* arg = (const page_init_arg*)getUpdateArgs(e);
const page_init_arg* arg = stasis_log_entry_update_args_cptr(e);
switch(arg->slot) {
case SLOTTED_PAGE:

View file

@ -30,7 +30,7 @@ static int op_alloc_boundary_tag(const LogEntry* e, Page* p) {
p->pageType = BOUNDARY_TAG_PAGE;
stasis_record_alloc_done(e->xid, p, rid);
byte * buf = stasis_record_write_begin(e->xid, p, rid);
memcpy(buf, getUpdateArgs(e), stasis_record_length_read(e->xid, p, rid));
memcpy(buf, stasis_log_entry_update_args_cptr(e), stasis_record_length_read(e->xid, p, rid));
stasis_record_write_done(e->xid, p, rid, buf);
return 0;
}
@ -39,14 +39,14 @@ static int op_alloc_region(const LogEntry *e, Page* p) {
pthread_mutex_lock(&region_mutex);
assert(0 == holding_mutex);
holding_mutex = pthread_self();
regionAllocArg *dat = (regionAllocArg*)getUpdateArgs(e);
const regionAllocArg *dat = stasis_log_entry_update_args_cptr(e);
TregionAllocHelper(e->xid, dat->startPage, dat->pageCount, dat->allocationManager);
holding_mutex = 0;
pthread_mutex_unlock(&region_mutex);
return 0;
}
static int operate_dealloc_region_unlocked(int xid, regionAllocArg *dat) {
static int operate_dealloc_region_unlocked(int xid, const regionAllocArg *dat) {
pageid_t firstPage = dat->startPage + 1;
@ -70,7 +70,7 @@ static int op_dealloc_region(const LogEntry* e, Page* p) {
assert(0 == holding_mutex);
holding_mutex = pthread_self();
ret = operate_dealloc_region_unlocked(e->xid, (regionAllocArg*)getUpdateArgs(e));
ret = operate_dealloc_region_unlocked(e->xid, stasis_log_entry_update_args_cptr(e));
holding_mutex = 0;
pthread_mutex_unlock(&region_mutex);
@ -157,7 +157,7 @@ void regionsInit() {
// hack; allocate a fake log entry; pass it into ourselves.
LogEntry * e = allocUpdateLogEntry(0,0,OPERATION_ALLOC_BOUNDARY_TAG,
p->id, sizeof(boundary_tag));
memcpy(getUpdateArgs(e), &t, sizeof(boundary_tag));
memcpy(stasis_log_entry_update_args_ptr(e), &t, sizeof(boundary_tag));
writelock(p->rwlatch,0);
op_alloc_boundary_tag(e,p);
unlock(p->rwlatch);

View file

@ -112,7 +112,7 @@ ssize_t Tpwrite(int xid, const byte * buf, size_t count, off_t offset) {
static int op_segment_file_pwrite(const LogEntry* e, Page* p) {
assert(p == 0);
size_t count = (e->update.arg_size - sizeof(segment_file_arg_t)) / 2;
segment_file_arg_t * arg = (segment_file_arg_t*)getUpdateArgs(e);
const segment_file_arg_t * arg = stasis_log_entry_update_args_cptr(e);
off_t offset = arg->offset;
read_write_helper(0, e->xid, e->LSN, (byte*)(arg+1), count, offset);
return 0;
@ -121,7 +121,7 @@ static int op_segment_file_pwrite(const LogEntry* e, Page* p) {
static int op_segment_file_pwrite_inverse(const LogEntry* e, Page* p) {
assert(p == 0);
size_t count = (e->update.arg_size - sizeof(segment_file_arg_t)) / 2;
segment_file_arg_t * arg = (segment_file_arg_t*)getUpdateArgs(e);
const segment_file_arg_t * arg = stasis_log_entry_update_args_cptr(e);
off_t offset = arg->offset;
read_write_helper(0, e->xid, e->LSN, ((byte*)(arg+1))+count, count, offset);
return 0;

View file

@ -53,7 +53,7 @@ terms specified in this license.
#include <assert.h>
static int op_set(const LogEntry *e, Page *p) {
assert(e->update.arg_size >= sizeof(slotid_t) + sizeof(int64_t));
const byte * b = getUpdateArgs(e);
const byte * b = stasis_log_entry_update_args_cptr(e);
recordid rid;
rid.page = p->id;
@ -70,7 +70,7 @@ static int op_set(const LogEntry *e, Page *p) {
}
static int op_set_inverse(const LogEntry *e, Page *p) {
assert(e->update.arg_size >= sizeof(slotid_t) + sizeof(int64_t));
const byte * b = getUpdateArgs(e);
const byte * b = stasis_log_entry_update_args_cptr(e);
recordid rid;
rid.page = p->id;
@ -145,7 +145,7 @@ static int op_set_range(const LogEntry* e, Page* p) {
int diffLength = e->update.arg_size - sizeof(set_range_t);
assert(! (diffLength % 2));
diffLength >>= 1;
const set_range_t * range = (const set_range_t*)getUpdateArgs(e);
const set_range_t * range = stasis_log_entry_update_args_cptr(e);
recordid rid;
rid.page = p->id;
rid.slot = range->slot;
@ -167,7 +167,7 @@ static int op_set_range_inverse(const LogEntry* e, Page* p) {
int diffLength = e->update.arg_size - sizeof(set_range_t);
assert(! (diffLength % 2));
diffLength >>= 1;
const set_range_t * range = (const set_range_t*)getUpdateArgs(e);
const set_range_t * range = stasis_log_entry_update_args_cptr(e);
recordid rid;
rid.page = p->id;
rid.slot = range->slot;

View file

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

View file

@ -127,10 +127,10 @@ void freeLogEntry(const LogEntry * e);
*/
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).
@return the operation's arguments.
* @return the operation's arguments, or NULL if there are no arguments.
*/
void * getUpdateArgs(LogEntry * e);
void * stasis_log_entry_update_args_ptr(LogEntry * e);
const void * stasis_log_entry_update_args_cptr(const LogEntry * e);
/**
@return a copy of the log entry that this CLR compensated.

View file

@ -77,7 +77,7 @@ START_TEST(updateLogEntryAlloc)
log = allocUpdateLogEntry(200, 1, OPERATION_SET,
rid.page, 3*sizeof(char));
memcpy(getUpdateArgs(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->xid == 1);
@ -87,10 +87,10 @@ START_TEST(updateLogEntryAlloc)
assert(log->update.page == 3);
assert(log->update.arg_size == 3*sizeof(char));
assert(getUpdateArgs(log) != NULL);
assert(args[0] == ((char*)getUpdateArgs(log))[0]);
assert(args[1] == ((char*)getUpdateArgs(log))[1]);
assert(args[2] == ((char*)getUpdateArgs(log))[2]);
assert(stasis_log_entry_update_args_ptr(log) != NULL);
assert(args[0] == ((char*)stasis_log_entry_update_args_ptr(log))[0]);
assert(args[1] == ((char*)stasis_log_entry_update_args_ptr(log))[1]);
assert(args[2] == ((char*)stasis_log_entry_update_args_ptr(log))[2]);
// printf("sizes %d %d\n",sizeofLogEntry(log),(sizeof(struct __raw_log_entry) + sizeof(UpdateLogEntry) + (sizeof(char))));
@ -103,7 +103,6 @@ END_TEST
START_TEST(updateLogEntryAllocNoExtras)
{
char args[] = {'a', 'b', 'c'};
recordid rid = { 3 , 4, sizeof(int)*3 };
LogEntry * log = allocUpdateLogEntry(200, 1, OPERATION_SET,
@ -117,7 +116,7 @@ START_TEST(updateLogEntryAllocNoExtras)
assert(log->update.page == 3);
assert(log->update.arg_size == 0);
assert(getUpdateArgs(log) == NULL);
assert(stasis_log_entry_update_args_ptr(log) == NULL);
assert(sizeofLogEntry(0, log) == (sizeof(struct __raw_log_entry) + sizeof(UpdateLogEntry) + 0 * (sizeof(int)+sizeof(char))));
free(log);

View file

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

View file

@ -79,7 +79,7 @@ static void * go( void * arg) {
assert(keySize == sizeof(lsn_t));
LogEntry * e = (LogEntry*)value;
linearHash_remove_arg * arg = (linearHash_remove_arg*)getUpdateArgs(e);
linearHash_remove_arg * arg = (linearHash_remove_arg*)stasis_log_entry_update_args_ptr(e);
assert(arg->keySize == sizeof(lsn_t));
assert(arg->valueSize == sizeof(char));
@ -113,7 +113,7 @@ static void * trygo( void * arg) {
assert(keySize == sizeof(lsn_t));
LogEntry * e = (LogEntry*)value;
linearHash_remove_arg * arg = (linearHash_remove_arg*)getUpdateArgs(e);
linearHash_remove_arg * arg = (linearHash_remove_arg*)stasis_log_entry_update_args_ptr(e);
assert(arg->keySize == sizeof(lsn_t));
assert(arg->valueSize == sizeof(char));
@ -182,7 +182,7 @@ START_TEST(multiplexTest) {
(*(lsn_t*)(arg+1)) = i;
LogEntry * e = allocUpdateLogEntry(-1, -1, OPERATION_LINEAR_HASH_INSERT, INVALID_PAGE,
sizeof(linearHash_remove_arg) + sizeof(lsn_t) + sizeof(char));
memcpy(getUpdateArgs(e), arg, sizeof(linearHash_remove_arg) + sizeof(lsn_t) + sizeof(char));
memcpy(stasis_log_entry_update_args_ptr(e), arg, sizeof(linearHash_remove_arg) + sizeof(lsn_t) + sizeof(char));
ThashInsert(xid, hash, (byte*)&i, sizeof(lsn_t), (byte*)e, sizeofLogEntry(0, e));

View file

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