From 7bed4b67ba53e54c661fcdbd12464178f0ecfaea Mon Sep 17 00:00:00 2001 From: sears Date: Fri, 16 Jul 2010 21:43:21 +0000 Subject: [PATCH] fix a bunch of 64-bit integer signedness bugs git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@940 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe --- datapage.cpp | 4 ++-- datapage.h | 4 ++-- diskTreeComponent.cpp | 2 +- diskTreeComponent.h | 2 +- logserver.cpp | 8 ++++---- mergeManager.cpp | 4 ++-- test/check_datapage.cpp | 6 +++--- test/check_logtable.cpp | 4 ++-- test/check_merge.cpp | 4 ++-- test/check_mergelarge.cpp | 4 ++-- test/check_mergetuple.cpp | 14 +++++++------- test/check_rbtree.cpp | 2 +- test/check_tcpclient.cpp | 22 +++++++++++----------- util/space_usage.cpp | 2 +- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/datapage.cpp b/datapage.cpp index b8981a8..4b0b5ab 100644 --- a/datapage.cpp +++ b/datapage.cpp @@ -133,7 +133,7 @@ void DataPage::initialize_page(pageid_t pageid) { releasePage(p); } template -size_t DataPage::write_bytes(const byte * buf, size_t remaining) { +size_t DataPage::write_bytes(const byte * buf, ssize_t remaining) { recordid chunk = calc_chunk_from_offset(write_offset_); if(chunk.size > remaining) { chunk.size = remaining; @@ -152,7 +152,7 @@ size_t DataPage::write_bytes(const byte * buf, size_t remaining) { return chunk.size; } template -size_t DataPage::read_bytes(byte * buf, off_t offset, size_t remaining) { +size_t DataPage::read_bytes(byte * buf, off_t offset, ssize_t remaining) { recordid chunk = calc_chunk_from_offset(offset); if(chunk.size > remaining) { chunk.size = remaining; diff --git a/datapage.h b/datapage.h index 407c81a..5c59678 100644 --- a/datapage.h +++ b/datapage.h @@ -128,8 +128,8 @@ private: assert(ret.size); return ret; } - size_t write_bytes(const byte * buf, size_t remaining); - size_t read_bytes(byte * buf, off_t offset, size_t remaining); + size_t write_bytes(const byte * buf, ssize_t remaining); + size_t read_bytes(byte * buf, off_t offset, ssize_t remaining); bool write_data(const byte * buf, size_t len, bool init_next = true); bool read_data(byte * buf, off_t offset, size_t len); bool initialize_next_page(); diff --git a/diskTreeComponent.cpp b/diskTreeComponent.cpp index af3e7af..09c34a2 100644 --- a/diskTreeComponent.cpp +++ b/diskTreeComponent.cpp @@ -28,7 +28,7 @@ const int64_t diskTreeComponent::internalNodes::DEPTH = 0; //in root this is the slot num where the DEPTH (of tree) is stored const int64_t diskTreeComponent::internalNodes::COMPARATOR = 1; //in root this is the slot num where the COMPARATOR id is stored const int64_t diskTreeComponent::internalNodes::FIRST_SLOT = 2; //this is the first unused slot in all index pages -const size_t diskTreeComponent::internalNodes::root_rec_size = sizeof(int64_t); +const ssize_t diskTreeComponent::internalNodes::root_rec_size = sizeof(int64_t); const int64_t diskTreeComponent::internalNodes::PREV_LEAF = 0; //pointer to prev leaf page const int64_t diskTreeComponent::internalNodes::NEXT_LEAF = 1; //pointer to next leaf page diff --git a/diskTreeComponent.h b/diskTreeComponent.h index 2b0d092..54c16a6 100644 --- a/diskTreeComponent.h +++ b/diskTreeComponent.h @@ -128,7 +128,7 @@ class diskTreeComponent { const static int64_t DEPTH; const static int64_t COMPARATOR; const static int64_t FIRST_SLOT; - const static size_t root_rec_size; + const static ssize_t root_rec_size; const static int64_t PREV_LEAF; const static int64_t NEXT_LEAF; pageid_t lastLeaf; diff --git a/logserver.cpp b/logserver.cpp index 98f63e7..8b2cf20 100644 --- a/logserver.cpp +++ b/logserver.cpp @@ -145,8 +145,8 @@ void logserver::stopserver() tot_threadwork_time += idle_th->data->work_time; num_reqs += idle_th->data->num_reqs; - printf("thread %d: work_time %.3f\t#calls %d\tavg req process time:\t%.3f\n", - i, + printf("thread %llu: work_time %.3f\t#calls %d\tavg req process time:\t%.3f\n", + (unsigned long long)i, idle_th->data->work_time, idle_th->data->num_reqs, (( idle_th->data->num_reqs == 0 ) ? 0 : idle_th->data->work_time / idle_th->data->num_reqs) @@ -899,8 +899,8 @@ void * thread_work_fn( void * args) if(err) { if(opcode != OP_DONE) { char *msg; - if(-1 != asprintf(&msg, "network error. conn closed. (%d, %d) ", - *(item->data->workitem), item->data->work_queue->size())) { + if(-1 != asprintf(&msg, "network error. conn closed. (%d, %llu) ", + *(item->data->workitem), (unsigned long long)item->data->work_queue->size())) { perror(msg); free(msg); } else { diff --git a/mergeManager.cpp b/mergeManager.cpp index b14a31b..fdfb1a6 100644 --- a/mergeManager.cpp +++ b/mergeManager.cpp @@ -231,7 +231,7 @@ void mergeManager::tick(mergeStats * s, bool block, bool force) { total_sleep += sleeptime; if((spin > 40) || (total_sleep > (max_sleep * 20.0))) { - printf("\nMerge thread %d Overshoot: raw=%lld, d=%lld eff=%lld Throttle min(1, %6f) spin %d, total_sleep %6.3f\n", s->merge_level, raw_overshoot, overshoot_fudge, overshoot, sleeptime, spin, total_sleep); + printf("\nMerge thread %d Overshoot: raw=%lld, d=%lld eff=%lld Throttle min(1, %6f) spin %d, total_sleep %6.3f\n", s->merge_level, (long long)raw_overshoot, (long long)overshoot_fudge, (long long)overshoot, sleeptime, spin, total_sleep); } struct timeval now; @@ -364,7 +364,7 @@ void mergeManager::pretty_print(FILE * out) { assert((!c2->active) || (c1_c2_progress >= -1 && c1_c2_progress < 102)); fprintf(out,"[merge progress MB/s window (lifetime)]: app [%s %6lldMB ~ %3.0f%% %6.1fsec %4.1f (%4.1f)] %s %s [%s %3.0f%% ~ %3.0f%% %4.1f (%4.1f)] %s %s [%s %3.0f%% %4.1f (%4.1f)] %s ", - c0->active ? "RUN" : "---", (uint64_t)(c0->lifetime_consumed / mb), c0_out_progress, c0->lifetime_elapsed, c0->bps/((double)mb), c0->lifetime_consumed/(((double)mb)*c0->lifetime_elapsed), + c0->active ? "RUN" : "---", (long long)(c0->lifetime_consumed / mb), c0_out_progress, c0->lifetime_elapsed, c0->bps/((double)mb), c0->lifetime_consumed/(((double)mb)*c0->lifetime_elapsed), have_c0 ? "C0" : "..", have_c0m ? "C0'" : "...", c1->active ? "RUN" : "---", c0_c1_in_progress, c0_c1_out_progress, c1->bps/((double)mb), c1->lifetime_consumed/(((double)mb)*c1->lifetime_elapsed), diff --git a/test/check_datapage.cpp b/test/check_datapage.cpp index 5b55f07..57eb9f5 100644 --- a/test/check_datapage.cpp +++ b/test/check_datapage.cpp @@ -52,7 +52,7 @@ void insertWithConcurrentReads(size_t NUM_ENTRIES) { RegionAllocator * alloc = new RegionAllocator(xid, 10000); // ~ 10 datapages per region. - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); int pcount = 1000; int dpages = 0; @@ -154,7 +154,7 @@ void insertProbeIter(size_t NUM_ENTRIES) RegionAllocator * alloc = new RegionAllocator(xid, 10000); // ~ 10 datapages per region. - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); int pcount = 1000; int dpages = 0; @@ -196,7 +196,7 @@ void insertProbeIter(size_t NUM_ENTRIES) xid = Tbegin(); - printf("Stage 2: Reading %d tuples\n", NUM_ENTRIES); + printf("Stage 2: Reading %llu tuples\n", (unsigned long long)NUM_ENTRIES); int tuplenum = 0; diff --git a/test/check_logtable.cpp b/test/check_logtable.cpp index 2278ca8..eb1aea2 100644 --- a/test/check_logtable.cpp +++ b/test/check_logtable.cpp @@ -55,7 +55,7 @@ void insertProbeIter(size_t NUM_ENTRIES) if(data_arr.size() > NUM_ENTRIES) data_arr.erase(data_arr.begin()+NUM_ENTRIES, data_arr.end()); - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); for(size_t i = 0; i < NUM_ENTRIES; i++) { @@ -75,7 +75,7 @@ void insertProbeIter(size_t NUM_ENTRIES) Tcommit(xid); xid = Tbegin(); - printf("Stage 2: Sequentially reading %d tuples\n", NUM_ENTRIES); + printf("Stage 2: Sequentially reading %llu tuples\n", (unsigned long long)NUM_ENTRIES); size_t tuplenum = 0; diskTreeComponent::iterator * tree_itr = ltable_c1->open_iterator(); diff --git a/test/check_merge.cpp b/test/check_merge.cpp index 26e8d1a..5f694e6 100644 --- a/test/check_merge.cpp +++ b/test/check_merge.cpp @@ -58,7 +58,7 @@ void insertProbeIter(size_t NUM_ENTRIES) mscheduler.startlogtable(lindex, 10 * 1024 * 1024); - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); struct timeval start_tv, stop_tv, ti_st, ti_end; double insert_time = 0; @@ -100,7 +100,7 @@ void insertProbeIter(size_t NUM_ENTRIES) xid = Tbegin(); - printf("Stage 2: Looking up %d keys:\n", NUM_ENTRIES); + printf("Stage 2: Looking up %llu keys:\n", (unsigned long long)NUM_ENTRIES); int found_tuples=0; for(int i=NUM_ENTRIES-1; i>=0; i--) diff --git a/test/check_mergelarge.cpp b/test/check_mergelarge.cpp index 250c6c8..a9dffa0 100644 --- a/test/check_mergelarge.cpp +++ b/test/check_mergelarge.cpp @@ -57,7 +57,7 @@ void insertProbeIter(size_t NUM_ENTRIES) mscheduler.startlogtable(lindex, 10 * 1024 * 1024); - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); struct timeval start_tv, stop_tv, ti_st, ti_end; double insert_time = 0; @@ -88,7 +88,7 @@ void insertProbeIter(size_t NUM_ENTRIES) printf("\nTREE STRUCTURE\n"); //ltable.get_tree_c1()->print_tree(xid); - printf("datasize: %lld\n", datasize); + printf("datasize: %llu\n", (unsigned long long)datasize); mscheduler.shutdown(); printf("merge threads finished.\n"); diff --git a/test/check_mergetuple.cpp b/test/check_mergetuple.cpp index 5d71e11..3e552d8 100644 --- a/test/check_mergetuple.cpp +++ b/test/check_mergetuple.cpp @@ -47,7 +47,7 @@ void insertProbeIter(size_t NUM_ENTRIES) std::sort(key_arr->begin(), key_arr->end(), &mycmp); key_v_list->push_back(key_arr); - printf("size partition %d is %d\n", i+1, key_arr->size()); + printf("size partition %llu is %llu\n", (unsigned long long)i+1, (unsigned long long)key_arr->size()); } key_v_t * key_arr = new key_v_t; @@ -58,7 +58,7 @@ void insertProbeIter(size_t NUM_ENTRIES) iters.push_back(new key_v_t::iterator((*key_v_list)[i]->begin())); } - int lc = 0; + size_t lc = 0; while(true) { int list_index = -1; @@ -80,7 +80,7 @@ void insertProbeIter(size_t NUM_ENTRIES) (*iters[list_index])++; lc++; if(lc % max_partition_size == 0) - printf("%d/%d completed.\n", lc, NUM_ENTRIES); + printf("%llu/%llu completed.\n", (unsigned long long)lc, (unsigned long long)NUM_ENTRIES); } for(int i=0; iclear(); delete key_v_list; - printf("key arr size: %d\n", key_arr->size()); + printf("key arr size: %llu\n", (unsigned long long)key_arr->size()); if(key_arr->size() > NUM_ENTRIES) key_arr->erase(key_arr->begin()+NUM_ENTRIES, key_arr->end()); @@ -112,7 +112,7 @@ void insertProbeIter(size_t NUM_ENTRIES) mscheduler.startlogtable(lindex, 10 * 1024 * 1024); - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); struct timeval start_tv, stop_tv, ti_st, ti_end; double insert_time = 0; @@ -187,13 +187,13 @@ void insertProbeIter(size_t NUM_ENTRIES) printf("#deletions: %d\n#updates: %d\n", delcount, upcount); printf("\nTREE STRUCTURE\n"); - printf("datasize: %lld\n", datasize); + printf("datasize: %llu\n", (unsigned long long)datasize); xid = Tbegin(); - printf("Stage 2: Looking up %d keys:\n", NUM_ENTRIES); + printf("Stage 2: Looking up %llu keys:\n", (unsigned long long)NUM_ENTRIES); int found_tuples=0; for(int i=NUM_ENTRIES-1; i>=0; i--) diff --git a/test/check_rbtree.cpp b/test/check_rbtree.cpp index 881085b..f2621d5 100644 --- a/test/check_rbtree.cpp +++ b/test/check_rbtree.cpp @@ -56,7 +56,7 @@ void insertProbeIter(size_t NUM_ENTRIES) //ltable.get_tree_c1()->print_tree(xid); printf("datasize: %lld\n", (long long)datasize); - printf("Stage 2: Looking up %d keys:\n", NUM_ENTRIES); + printf("Stage 2: Looking up %llu keys:\n", (unsigned long long)NUM_ENTRIES); int found_tuples=0; for(int i=NUM_ENTRIES-1; i>=0; i--) diff --git a/test/check_tcpclient.cpp b/test/check_tcpclient.cpp index a297e84..4f52f05 100644 --- a/test/check_tcpclient.cpp +++ b/test/check_tcpclient.cpp @@ -34,8 +34,8 @@ void insertProbeIter(size_t NUM_ENTRIES) const static size_t max_partition_size = 100000; int KEY_LEN = 100; std::vector *key_v_list = new std::vector; - int list_size = NUM_ENTRIES / max_partition_size + 1; - for(int i =0; ibegin(), key_arr->end(), &mycmp); key_v_list->push_back(key_arr); - printf("size partition %d is %d\n", i+1, key_arr->size()); + printf("size partition %llu is %llu\n", (unsigned long long)i+1, (unsigned long long)key_arr->size()); } @@ -53,7 +53,7 @@ void insertProbeIter(size_t NUM_ENTRIES) key_v_t * key_arr = new key_v_t; std::vector iters; - for(int i=0; ibegin())); } @@ -62,7 +62,7 @@ void insertProbeIter(size_t NUM_ENTRIES) while(true) { int list_index = -1; - for(int i=0; iend()) continue; @@ -80,10 +80,10 @@ void insertProbeIter(size_t NUM_ENTRIES) (*iters[list_index])++; lc++; if(lc % max_partition_size == 0) - printf("%d/%d completed.\n", lc, NUM_ENTRIES); + printf("%llu/%llu completed.\n", (unsigned long long)lc, (unsigned long long)NUM_ENTRIES); } - for(int i=0; iclear(); delete (*key_v_list)[i]; @@ -91,14 +91,14 @@ void insertProbeIter(size_t NUM_ENTRIES) } key_v_list->clear(); delete key_v_list; - printf("key arr size: %d\n", key_arr->size()); + printf("key arr size: %llu\n", (unsigned long long)key_arr->size()); if(key_arr->size() > NUM_ENTRIES) key_arr->erase(key_arr->begin()+NUM_ENTRIES, key_arr->end()); NUM_ENTRIES=key_arr->size(); - printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); + printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES); struct timeval start_tv, stop_tv, ti_st, ti_end; double insert_time = 0; @@ -134,7 +134,7 @@ void insertProbeIter(size_t NUM_ENTRIES) datatuple::freetuple(newtuple); if(i % 10000 == 0 && i > 0) - printf("%d / %d inserted.\n", i, NUM_ENTRIES); + printf("%llu / %llu inserted.\n", (unsigned long long)i, (unsigned long long)NUM_ENTRIES); } gettimeofday(&stop_tv,0); @@ -144,7 +144,7 @@ void insertProbeIter(size_t NUM_ENTRIES) - printf("Stage 2: Looking up %d keys:\n", NUM_ENTRIES); + printf("Stage 2: Looking up %llu keys:\n", (unsigned long long)NUM_ENTRIES); int found_tuples=0; diff --git a/util/space_usage.cpp b/util/space_usage.cpp index 880c1d7..0d961a5 100644 --- a/util/space_usage.cpp +++ b/util/space_usage.cpp @@ -25,7 +25,7 @@ int main(int argc, char * argv[]) { logstore_client_close(l); assert(ret->keylen() == sizeof(uint64_t)); assert(ret->datalen() == sizeof(uint64_t)); - printf("Tree is %lld MB Store file is %lld MB\n", (*(uint64_t*)ret->key()) / (1024*1024), (*(uint64_t*)ret->data()) / (1024*1024)); + printf("Tree is %llu MB Store file is %llu MB\n", (unsigned long long)(*(uint64_t*)ret->key()) / (1024*1024), (unsigned long long)(*(uint64_t*)ret->data()) / (1024*1024)); datatuple::freetuple(ret); ; return 0;