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 <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 22:29:12 +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
|
|
|
|
|
|
|
sync();
|
|
|
|
|
2010-04-28 19:21:25 +00:00
|
|
|
logtable<datatuple>::init_stasis();
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
Tcommit(xid);
|
2010-04-29 00:57:48 +00:00
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
xid = Tbegin();
|
2010-04-29 00:57:48 +00:00
|
|
|
|
2010-05-19 23:42:06 +00:00
|
|
|
mergeManager merge_mgr(0);
|
2010-05-26 00:58:17 +00:00
|
|
|
mergeStats * stats = merge_mgr.get_merge_stats(1);
|
2010-04-29 23:13:04 +00:00
|
|
|
|
|
|
|
diskTreeComponent *ltable_c1 = new diskTreeComponent(xid, 1000, 10000, 5, stats);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
std::vector<std::string> data_arr;
|
|
|
|
std::vector<std::string> key_arr;
|
|
|
|
preprandstr(NUM_ENTRIES, data_arr, 5*4096, true);
|
|
|
|
preprandstr(NUM_ENTRIES+200, key_arr, 50, true);//well i can handle upto 200
|
|
|
|
|
|
|
|
std::sort(key_arr.begin(), key_arr.end(), &mycmp);
|
|
|
|
|
|
|
|
removeduplicates(key_arr);
|
|
|
|
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());
|
|
|
|
|
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
|
|
|
|
2010-01-27 22:29:12 +00:00
|
|
|
for(size_t i = 0; i < NUM_ENTRIES; i++)
|
2010-01-23 02:13:59 +00:00
|
|
|
{
|
2010-02-10 21:49:50 +00:00
|
|
|
//prepare the tuple
|
|
|
|
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-04-29 00:57:48 +00:00
|
|
|
ltable_c1->insertTuple(xid, newtuple);
|
2010-02-10 21:49:50 +00:00
|
|
|
datatuple::freetuple(newtuple);
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
printf("\nTREE STRUCTURE\n");
|
2010-02-16 01:01:52 +00:00
|
|
|
ltable_c1->print_tree(xid);
|
2010-03-13 00:05:06 +00:00
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
printf("Writes complete.\n");
|
2010-03-13 00:05:06 +00:00
|
|
|
|
|
|
|
ltable_c1->writes_done();
|
2010-02-27 00:33:12 +00:00
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
|
2010-07-16 21:43:21 +00:00
|
|
|
printf("Stage 2: Sequentially reading %llu tuples\n", (unsigned long long)NUM_ENTRIES);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2010-01-27 22:29:12 +00:00
|
|
|
size_t tuplenum = 0;
|
2010-03-17 21:51:26 +00:00
|
|
|
diskTreeComponent::iterator * tree_itr = ltable_c1->open_iterator();
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
datatuple *dt=0;
|
2010-03-13 00:05:06 +00:00
|
|
|
while( (dt=tree_itr->next_callerFrees()) != NULL)
|
2010-01-23 02:13:59 +00:00
|
|
|
{
|
2010-02-10 21:49:50 +00:00
|
|
|
assert(dt->keylen() == key_arr[tuplenum].length()+1);
|
|
|
|
assert(dt->datalen() == data_arr[tuplenum].length()+1);
|
2010-01-23 02:13:59 +00:00
|
|
|
tuplenum++;
|
2010-02-10 21:49:50 +00:00
|
|
|
datatuple::freetuple(dt);
|
2010-01-23 02:13:59 +00:00
|
|
|
dt = 0;
|
|
|
|
}
|
2010-03-13 00:05:06 +00:00
|
|
|
delete(tree_itr);
|
2010-01-23 02:13:59 +00:00
|
|
|
assert(tuplenum == key_arr.size());
|
|
|
|
|
|
|
|
printf("Sequential Reads completed.\n");
|
|
|
|
|
|
|
|
int rrsize=key_arr.size() / 3;
|
|
|
|
printf("Stage 3: Randomly reading %d tuples by key\n", rrsize);
|
|
|
|
|
|
|
|
for(int i=0; i<rrsize; i++)
|
|
|
|
{
|
|
|
|
//randomly pick a key
|
|
|
|
int ri = rand()%key_arr.size();
|
|
|
|
|
2010-03-13 00:05:06 +00:00
|
|
|
datatuple *dt = ltable_c1->findTuple(xid, (const datatuple::key_t) key_arr[ri].c_str(), (size_t)key_arr[ri].length()+1);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
assert(dt!=0);
|
2010-02-10 21:49:50 +00:00
|
|
|
assert(dt->keylen() == key_arr[ri].length()+1);
|
|
|
|
assert(dt->datalen() == data_arr[ri].length()+1);
|
|
|
|
datatuple::freetuple(dt);
|
2010-01-23 02:13:59 +00:00
|
|
|
dt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Random Reads completed.\n");
|
|
|
|
Tcommit(xid);
|
2010-04-28 19:21:25 +00:00
|
|
|
logtable<datatuple>::deinit_stasis();
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test
|
|
|
|
*/
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
insertProbeIter(15000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|