2010-01-23 02:13:59 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2010-01-26 00:50:01 +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-01-26 03:37:07 +00:00
|
|
|
#include "check_util.h"
|
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
#undef begin
|
|
|
|
#undef end
|
|
|
|
|
|
|
|
template class DataPage<datatuple>;
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
sync();
|
|
|
|
|
2010-02-19 00:59:14 +00:00
|
|
|
diskTreeComponent::init_stasis();
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
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-02-15 23:02:01 +00:00
|
|
|
DataPage<datatuple>::RegionAllocator * alloc
|
2010-02-18 23:31:57 +00:00
|
|
|
= new DataPage<datatuple>::RegionAllocator(xid, 10000); // ~ 10 datapages per region.
|
2010-02-15 23:02:01 +00:00
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
recordid alloc_state = Talloc(xid,sizeof(RegionAllocConf_t));
|
|
|
|
|
2010-02-19 00:59:14 +00:00
|
|
|
Tset(xid,alloc_state, &diskTreeComponent::REGION_ALLOC_STATIC_INITIALIZER);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
printf("Stage 1: Writing %d keys\n", NUM_ENTRIES);
|
|
|
|
|
2010-02-11 20:04:42 +00:00
|
|
|
int pcount = 1000;
|
2010-01-23 02:13:59 +00:00
|
|
|
int dpages = 0;
|
|
|
|
DataPage<datatuple> *dp=0;
|
|
|
|
int64_t datasize = 0;
|
|
|
|
std::vector<pageid_t> dsp;
|
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
|
|
|
|
2010-02-10 21:49:50 +00:00
|
|
|
datasize += newtuple->byte_length();
|
2010-02-15 23:02:01 +00:00
|
|
|
if(dp==NULL || !dp->append(newtuple))
|
2010-01-23 02:13:59 +00:00
|
|
|
{
|
|
|
|
dpages++;
|
|
|
|
if(dp)
|
|
|
|
delete dp;
|
2010-02-25 20:17:04 +00:00
|
|
|
|
2010-02-15 23:02:01 +00:00
|
|
|
dp = new DataPage<datatuple>(xid, pcount, alloc);
|
2010-02-11 20:04:42 +00:00
|
|
|
|
2010-02-15 23:02:01 +00:00
|
|
|
bool succ = dp->append(newtuple);
|
2010-02-11 20:04:42 +00:00
|
|
|
assert(succ);
|
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
dsp.push_back(dp->get_start_pid());
|
|
|
|
}
|
2010-02-25 20:17:04 +00:00
|
|
|
}
|
|
|
|
if(dp) {
|
|
|
|
delete dp;
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 23:34:33 +00:00
|
|
|
printf("Total data set length: %lld\n", (long long)datasize);
|
2010-01-23 02:13:59 +00:00
|
|
|
printf("Storage utilization: %.2f\n", (datasize+.0) / (PAGE_SIZE * pcount * dpages));
|
|
|
|
printf("Number of datapages: %d\n", dpages);
|
|
|
|
printf("Writes complete.\n");
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
|
|
|
|
printf("Stage 2: Reading %d tuples\n", NUM_ENTRIES);
|
|
|
|
|
|
|
|
|
|
|
|
int tuplenum = 0;
|
|
|
|
for(int i = 0; i < dpages ; i++)
|
|
|
|
{
|
|
|
|
DataPage<datatuple> dp(xid, dsp[i]);
|
2010-03-09 00:14:24 +00:00
|
|
|
DataPage<datatuple>::iterator itr = dp.begin();
|
2010-01-23 02:13:59 +00:00
|
|
|
datatuple *dt=0;
|
2010-02-15 23:02:01 +00:00
|
|
|
while( (dt=itr.getnext()) != 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Reads completed.\n");
|
|
|
|
|
2010-02-10 21:49:50 +00:00
|
|
|
Tcommit(xid);
|
2010-02-15 23:02:01 +00:00
|
|
|
|
2010-02-19 00:59:14 +00:00
|
|
|
diskTreeComponent::deinit_stasis();
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test
|
|
|
|
*/
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
insertProbeIter(10000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|