2010-01-23 02:13:59 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2010-10-02 12:52:41 +00:00
|
|
|
#include <algorithm>
|
2010-01-23 02:13:59 +00:00
|
|
|
#include "logstore.h"
|
2010-01-27 23:15:47 +00:00
|
|
|
#include "datapage.h"
|
2010-01-23 02:13:59 +00:00
|
|
|
#include "merger.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2010-03-17 21:51:26 +00:00
|
|
|
#include <stasis/transactional.h>
|
2010-01-23 02:13:59 +00:00
|
|
|
#undef begin
|
|
|
|
#undef end
|
|
|
|
|
2010-01-26 03:37:07 +00:00
|
|
|
#include "check_util.h"
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2010-01-27 23:34:33 +00:00
|
|
|
void insertProbeIter(size_t NUM_ENTRIES)
|
2010-01-23 02:13:59 +00:00
|
|
|
{
|
|
|
|
srand(1000);
|
|
|
|
unlink("storefile.txt");
|
|
|
|
unlink("logfile.txt");
|
2011-04-20 21:51:04 +00:00
|
|
|
system("rm -rf stasis_log/");
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2011-06-09 01:16:55 +00:00
|
|
|
logtable::init_stasis();
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
//data generation
|
|
|
|
std::vector<std::string> * data_arr = new std::vector<std::string>;
|
|
|
|
std::vector<std::string> * key_arr = new std::vector<std::string>;
|
|
|
|
|
2010-01-26 03:37:07 +00:00
|
|
|
preprandstr(NUM_ENTRIES, data_arr, 10*8192, true);
|
|
|
|
preprandstr(NUM_ENTRIES+200, key_arr, 100, true);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
std::sort(key_arr->begin(), key_arr->end(), &mycmp);
|
|
|
|
|
|
|
|
removeduplicates(key_arr);
|
2010-08-23 23:28:29 +00:00
|
|
|
scramble(key_arr);
|
|
|
|
|
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
if(key_arr->size() > NUM_ENTRIES)
|
|
|
|
key_arr->erase(key_arr->begin()+NUM_ENTRIES, key_arr->end());
|
|
|
|
|
|
|
|
NUM_ENTRIES=key_arr->size();
|
|
|
|
|
|
|
|
if(data_arr->size() > NUM_ENTRIES)
|
|
|
|
data_arr->erase(data_arr->begin()+NUM_ENTRIES, data_arr->end());
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
2011-06-09 01:16:55 +00:00
|
|
|
logtable * ltable = new logtable(10 * 1024 * 1024, 1000, 10000, 5);
|
2010-12-11 00:51:19 +00:00
|
|
|
merge_scheduler mscheduler(ltable);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2010-12-11 00:51:19 +00:00
|
|
|
recordid table_root = ltable->allocTable(xid);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
2010-12-11 00:51:19 +00:00
|
|
|
mscheduler.start();
|
2010-05-19 23:42:06 +00:00
|
|
|
|
2010-07-16 21:43:21 +00:00
|
|
|
printf("Stage 1: Writing %llu keys\n", (unsigned long long)NUM_ENTRIES);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
struct timeval start_tv, stop_tv, ti_st, ti_end;
|
|
|
|
double insert_time = 0;
|
|
|
|
int64_t datasize = 0;
|
|
|
|
std::vector<pageid_t> dsp;
|
|
|
|
gettimeofday(&start_tv,0);
|
2010-01-27 23:34:33 +00:00
|
|
|
for(size_t i = 0; i < NUM_ENTRIES; i++)
|
2010-01-23 02:13:59 +00:00
|
|
|
{
|
|
|
|
//prepare the key
|
2010-02-10 21:49:50 +00:00
|
|
|
datatuple *newtuple = datatuple::create((*key_arr)[i].c_str(), (*key_arr)[i].length()+1,(*data_arr)[i].c_str(), (*data_arr)[i].length()+1);
|
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
/*
|
|
|
|
printf("key: \t, keylen: %u\ndata: datalen: %u\n",
|
|
|
|
//newtuple.key,
|
|
|
|
*newtuple.keylen,
|
|
|
|
//newtuple.data,
|
|
|
|
*newtuple.datalen);
|
|
|
|
*/
|
|
|
|
|
2010-02-10 21:49:50 +00:00
|
|
|
datasize += newtuple->byte_length();
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
gettimeofday(&ti_st,0);
|
2010-12-11 00:51:19 +00:00
|
|
|
ltable->insertTuple(newtuple);
|
2010-01-23 02:13:59 +00:00
|
|
|
gettimeofday(&ti_end,0);
|
|
|
|
insert_time += tv_to_double(ti_end) - tv_to_double(ti_st);
|
|
|
|
|
2010-02-10 21:49:50 +00:00
|
|
|
datatuple::freetuple(newtuple);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
gettimeofday(&stop_tv,0);
|
|
|
|
printf("insert time: %6.1f\n", insert_time);
|
|
|
|
printf("insert time: %6.1f\n", (tv_to_double(stop_tv) - tv_to_double(start_tv)));
|
|
|
|
|
|
|
|
printf("\nTREE STRUCTURE\n");
|
|
|
|
//ltable.get_tree_c1()->print_tree(xid);
|
2010-01-27 23:34:33 +00:00
|
|
|
printf("datasize: %lld\n", (long long)datasize);
|
2010-01-23 02:13:59 +00:00
|
|
|
//sleep(20);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
|
2010-07-16 21:43:21 +00:00
|
|
|
printf("Stage 2: Looking up %llu keys:\n", (unsigned long long)NUM_ENTRIES);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
int found_tuples=0;
|
|
|
|
for(int i=NUM_ENTRIES-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
int ri = i;
|
|
|
|
//printf("key index%d\n", i);
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
//get the key
|
|
|
|
uint32_t keylen = (*key_arr)[ri].length()+1;
|
|
|
|
datatuple::key_t rkey = (datatuple::key_t) malloc(keylen);
|
|
|
|
memcpy((byte*)rkey, (*key_arr)[ri].c_str(), keylen);
|
|
|
|
//for(int j=0; j<keylen-1; j++)
|
|
|
|
//rkey[j] = (*key_arr)[ri][j];
|
|
|
|
//rkey[keylen-1]='\0';
|
|
|
|
|
|
|
|
//find the key with the given tuple
|
2010-12-11 00:51:19 +00:00
|
|
|
datatuple *dt = ltable->findTuple(xid, rkey, keylen);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
assert(dt!=0);
|
|
|
|
//if(dt!=0)
|
|
|
|
{
|
2010-02-10 21:49:50 +00:00
|
|
|
found_tuples++;
|
2011-04-22 22:54:49 +00:00
|
|
|
assert(dt->rawkeylen() == (*key_arr)[ri].length()+1);
|
2010-02-10 21:49:50 +00:00
|
|
|
assert(dt->datalen() == (*data_arr)[ri].length()+1);
|
|
|
|
datatuple::freetuple(dt);
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
dt = 0;
|
|
|
|
free(rkey);
|
|
|
|
}
|
|
|
|
printf("found %d\n", found_tuples);
|
|
|
|
|
|
|
|
key_arr->clear();
|
|
|
|
data_arr->clear();
|
|
|
|
delete key_arr;
|
|
|
|
delete data_arr;
|
|
|
|
|
|
|
|
mscheduler.shutdown();
|
|
|
|
printf("merge threads finished.\n");
|
|
|
|
gettimeofday(&stop_tv,0);
|
|
|
|
printf("run time: %6.1f\n", (tv_to_double(stop_tv) - tv_to_double(start_tv)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tcommit(xid);
|
2010-12-11 00:51:19 +00:00
|
|
|
delete ltable;
|
2011-06-09 01:16:55 +00:00
|
|
|
logtable::deinit_stasis();
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @test
|
|
|
|
*/
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
insertProbeIter(5000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|