move send_tuple into utils, fix warnings
git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@529 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
parent
2f562a175a
commit
616c028b17
3 changed files with 94 additions and 100 deletions
|
@ -18,10 +18,9 @@
|
|||
|
||||
#include "check_util.h"
|
||||
|
||||
//template class DataPage<datatuple>;
|
||||
template class treeIterator<datatuple>;
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
void insertProbeIter(size_t NUM_ENTRIES)
|
||||
{
|
||||
srand(1000);
|
||||
unlink("storefile.txt");
|
||||
|
@ -76,7 +75,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
DataPage<datatuple> *dp=0;
|
||||
int64_t datasize = 0;
|
||||
std::vector<pageid_t> dsp;
|
||||
for(int i = 0; i < NUM_ENTRIES; i++)
|
||||
for(size_t i = 0; i < NUM_ENTRIES; i++)
|
||||
{
|
||||
//prepare the key
|
||||
datatuple newtuple;
|
||||
|
@ -84,7 +83,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
newtuple.keylen = &keylen;
|
||||
|
||||
newtuple.key = (datatuple::key_t) malloc(keylen);
|
||||
for(int j=0; j<keylen-1; j++)
|
||||
for(size_t j=0; j<keylen-1; j++)
|
||||
newtuple.key[j] = key_arr[i][j];
|
||||
newtuple.key[keylen-1]='\0';
|
||||
|
||||
|
@ -93,7 +92,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
newtuple.datalen = &datalen;
|
||||
|
||||
newtuple.data = (datatuple::data_t) malloc(datalen);
|
||||
for(int j=0; j<datalen-1; j++)
|
||||
for(size_t j=0; j<datalen-1; j++)
|
||||
newtuple.data[j] = data_arr[i][j];
|
||||
newtuple.data[datalen-1]='\0';
|
||||
|
||||
|
@ -132,7 +131,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
printf("\nTREE STRUCTURE\n");
|
||||
lt->print_tree(xid);
|
||||
|
||||
printf("Total data set length: %d\n", datasize);
|
||||
printf("Total data set length: %lld\n", datasize);
|
||||
printf("Storage utilization: %.2f\n", (datasize+.0) / (PAGE_SIZE * npages));
|
||||
printf("Number of datapages: %d\n", dpages);
|
||||
printf("Writes complete.\n");
|
||||
|
@ -147,7 +146,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
printf("Stage 2: Sequentially reading %d tuples\n", NUM_ENTRIES);
|
||||
|
||||
|
||||
int tuplenum = 0;
|
||||
size_t tuplenum = 0;
|
||||
treeIterator<datatuple> tree_itr(tree_root);
|
||||
|
||||
|
||||
|
@ -177,7 +176,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
//get the key
|
||||
uint32_t keylen = key_arr[ri].length()+1;
|
||||
datatuple::key_t rkey = (datatuple::key_t) malloc(keylen);
|
||||
for(int j=0; j<keylen-1; j++)
|
||||
for(size_t j=0; j<keylen-1; j++)
|
||||
rkey[j] = key_arr[ri][j];
|
||||
rkey[keylen-1]='\0';
|
||||
|
||||
|
|
|
@ -10,100 +10,12 @@
|
|||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "check_util.h"
|
||||
|
||||
#undef begin
|
||||
#undef end
|
||||
|
||||
datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode, datatuple &tuple)
|
||||
{
|
||||
struct sockaddr_in serveraddr;
|
||||
struct hostent *server;
|
||||
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sockfd < 0)
|
||||
{
|
||||
printf("ERROR opening socket.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
server = gethostbyname(servername.c_str());
|
||||
if (server == NULL) {
|
||||
fprintf(stderr,"ERROR, no such host as %s\n", servername.c_str());
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* build the server's Internet address */
|
||||
bzero((char *) &serveraddr, sizeof(serveraddr));
|
||||
serveraddr.sin_family = AF_INET;
|
||||
bcopy((char *)server->h_addr,
|
||||
(char *)&serveraddr.sin_addr.s_addr, server->h_length);
|
||||
serveraddr.sin_port = htons(serverport);
|
||||
|
||||
/* connect: create a connection with the server */
|
||||
if (connect(sockfd, (sockaddr*) &serveraddr, sizeof(serveraddr)) < 0)
|
||||
{
|
||||
printf("ERROR connecting\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//send the opcode
|
||||
int n = write(sockfd, (byte*) &opcode, sizeof(uint8_t));
|
||||
assert(n == sizeof(uint8_t));
|
||||
|
||||
//send the tuple
|
||||
n = write(sockfd, (byte*) tuple.keylen, sizeof(uint32_t));
|
||||
assert( n == sizeof(uint32_t));
|
||||
|
||||
n = write(sockfd, (byte*) tuple.datalen, sizeof(uint32_t));
|
||||
assert( n == sizeof(uint32_t));
|
||||
|
||||
logserver::writetosocket(sockfd, (byte*) tuple.key, *tuple.keylen);
|
||||
if(!tuple.isDelete() && *tuple.datalen != 0)
|
||||
logserver::writetosocket(sockfd, (byte*) tuple.data, *tuple.datalen);
|
||||
|
||||
//read the reply code
|
||||
uint8_t rcode;
|
||||
n = read(sockfd, (byte*) &rcode, sizeof(uint8_t));
|
||||
|
||||
if(rcode == logserver::OP_SENDING_TUPLE)
|
||||
{
|
||||
datatuple *rcvdtuple = (datatuple*)malloc(sizeof(datatuple));
|
||||
//read the keylen
|
||||
rcvdtuple->keylen = (uint32_t*) malloc(sizeof(uint32_t));
|
||||
n = read(sockfd, (byte*) rcvdtuple->keylen, sizeof(uint32_t));
|
||||
assert(n == sizeof(uint32_t));
|
||||
//read the datalen
|
||||
rcvdtuple->datalen = (uint32_t*) malloc(sizeof(uint32_t));
|
||||
n = read(sockfd, (byte*) rcvdtuple->datalen, sizeof(uint32_t));
|
||||
assert(n == sizeof(uint32_t));
|
||||
//read key
|
||||
rcvdtuple->key = (byte*) malloc(*rcvdtuple->keylen);
|
||||
logserver::readfromsocket(sockfd, (byte*) rcvdtuple->key, *rcvdtuple->keylen);
|
||||
if(!rcvdtuple->isDelete())
|
||||
{
|
||||
//read key
|
||||
rcvdtuple->data = (byte*) malloc(*rcvdtuple->datalen);
|
||||
logserver::readfromsocket(sockfd, (byte*) rcvdtuple->data, *rcvdtuple->datalen);
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
return rcvdtuple;
|
||||
}
|
||||
else
|
||||
assert(rcode == logserver::OP_SUCCESS);
|
||||
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
{
|
||||
srand(1000);
|
||||
|
@ -291,10 +203,6 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
}
|
||||
printf("found %d\n", found_tuples);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
key_arr->clear();
|
||||
//data_arr->clear();
|
||||
delete key_arr;
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
#ifndef CHECK_UTIL_H_
|
||||
#define CHECK_UTIL_H_
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
|
@ -149,6 +153,89 @@ void preprandstr(int count, std::vector<std::string> &arr, int avg_len=50, bool
|
|||
|
||||
}
|
||||
|
||||
datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode, datatuple &tuple)
|
||||
{
|
||||
struct sockaddr_in serveraddr;
|
||||
struct hostent *server;
|
||||
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sockfd < 0)
|
||||
{
|
||||
printf("ERROR opening socket.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
server = gethostbyname(servername.c_str());
|
||||
if (server == NULL) {
|
||||
fprintf(stderr,"ERROR, no such host as %s\n", servername.c_str());
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* build the server's Internet address */
|
||||
bzero((char *) &serveraddr, sizeof(serveraddr));
|
||||
serveraddr.sin_family = AF_INET;
|
||||
bcopy((char *)server->h_addr,
|
||||
(char *)&serveraddr.sin_addr.s_addr, server->h_length);
|
||||
serveraddr.sin_port = htons(serverport);
|
||||
|
||||
/* connect: create a connection with the server */
|
||||
if (connect(sockfd, (sockaddr*) &serveraddr, sizeof(serveraddr)) < 0)
|
||||
{
|
||||
printf("ERROR connecting\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//send the opcode
|
||||
int n = write(sockfd, (byte*) &opcode, sizeof(uint8_t));
|
||||
assert(n == sizeof(uint8_t));
|
||||
|
||||
//send the tuple
|
||||
n = write(sockfd, (byte*) tuple.keylen, sizeof(uint32_t));
|
||||
assert( n == sizeof(uint32_t));
|
||||
|
||||
n = write(sockfd, (byte*) tuple.datalen, sizeof(uint32_t));
|
||||
assert( n == sizeof(uint32_t));
|
||||
|
||||
logserver::writetosocket(sockfd, (byte*) tuple.key, *tuple.keylen);
|
||||
if(!tuple.isDelete() && *tuple.datalen != 0)
|
||||
logserver::writetosocket(sockfd, (byte*) tuple.data, *tuple.datalen);
|
||||
|
||||
//read the reply code
|
||||
uint8_t rcode;
|
||||
n = read(sockfd, (byte*) &rcode, sizeof(uint8_t));
|
||||
|
||||
if(rcode == logserver::OP_SENDING_TUPLE)
|
||||
{
|
||||
datatuple *rcvdtuple = (datatuple*)malloc(sizeof(datatuple));
|
||||
//read the keylen
|
||||
rcvdtuple->keylen = (uint32_t*) malloc(sizeof(uint32_t));
|
||||
n = read(sockfd, (byte*) rcvdtuple->keylen, sizeof(uint32_t));
|
||||
assert(n == sizeof(uint32_t));
|
||||
//read the datalen
|
||||
rcvdtuple->datalen = (uint32_t*) malloc(sizeof(uint32_t));
|
||||
n = read(sockfd, (byte*) rcvdtuple->datalen, sizeof(uint32_t));
|
||||
assert(n == sizeof(uint32_t));
|
||||
//read key
|
||||
rcvdtuple->key = (byte*) malloc(*rcvdtuple->keylen);
|
||||
logserver::readfromsocket(sockfd, (byte*) rcvdtuple->key, *rcvdtuple->keylen);
|
||||
if(!rcvdtuple->isDelete())
|
||||
{
|
||||
//read key
|
||||
rcvdtuple->data = (byte*) malloc(*rcvdtuple->datalen);
|
||||
logserver::readfromsocket(sockfd, (byte*) rcvdtuple->data, *rcvdtuple->datalen);
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
return rcvdtuple;
|
||||
}
|
||||
else
|
||||
assert(rcode == logserver::OP_SUCCESS);
|
||||
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue