int SyntheticClient::read_random(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes
{
uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize;
-
int fd = client->open(fn.c_str(), O_RDWR);
dout(5) << "reading from " << fn << " fd " << fd << dendl;
-
- // dout(0) << "READING FROM " << fn << " fd " << fd << dendl;
-
- // dout(0) << "filename " << fn << " size:" << size << " read size|" << rdsize << "|" << "\ chunks: |" << chunks <<"|" << dendl;
if (fd < 0) return fd;
int offset = 0;
// use rand instead ??
double x = drand48();
- //dout(0) << "RANDOM NUMBER RETURN |" << x << "|" << dendl;
-
// cleanup before call 'new'
if (buf != NULL) {
delete[] buf;
buf = NULL;
}
- if ( x < 0.5)
- {
- //dout(0) << "DECIDED TO READ " << x << dendl;
+ if (x < 0.5) {
buf = new char[rdsize];
memset(buf, 1, rdsize);
read=true;
- }
- else
- {
- // dout(0) << "DECIDED TO WRITE " << x << dendl;
+ } else {
buf = new char[rdsize+100]; // 1 MB
memset(buf, 7, rdsize);
}
-
- //double y = drand48() ;
-
- //dout(0) << "OFFSET is |" << offset << "| chunks |" << chunks<< dendl;
- if ( read)
- {
+ if (read) {
offset=(rand())%(chunks+1);
dout(2) << "reading block " << offset << "/" << chunks << dendl;
- int r = client->read(fd, buf, rdsize,
- offset*rdsize);
+ int r = client->read(fd, buf, rdsize, offset*rdsize);
if (r < rdsize) {
- dout(1) << "read_file got r = " << r << ", probably end of file" << dendl;
- }
- }
- else
- {
- dout(2) << "writing block " << offset << "/" << chunks << dendl;
-
- // fill buf with a 16 byte fingerprint
- // 64 bits : file offset
- // 64 bits : client id
- // = 128 bits (16 bytes)
-
- //if (true )
- //{
- //int count = rand()%10;
+ dout(1) << "read_file got r = " << r << ", probably end of file" << dendl;
+ }
+ } else {
+ dout(2) << "writing block " << offset << "/" << chunks << dendl;
- //for ( int j=0;j<count; j++ )
- //{
+ // fill buf with a 16 byte fingerprint
+ // 64 bits : file offset
+ // 64 bits : client id
+ // = 128 bits (16 bytes)
offset=(rand())%(chunks+1);
- uint64_t *p = (uint64_t*)buf;
- while ((char*)p < buf + rdsize) {
- *p = offset*rdsize + (char*)p - buf;
- p++;
- *p = client->get_nodeid().v;
- p++;
- }
+ uint64_t *p = (uint64_t*)buf;
+ while ((char*)p < buf + rdsize) {
+ *p = offset*rdsize + (char*)p - buf;
+ p++;
+ *p = client->get_nodeid().v;
+ p++;
+ }
client->write(fd, buf, rdsize,
offset*rdsize);
- //}
- //}
}
// verify fingerprint
- if ( read )
- {
- int bad = 0;
- int64_t *p = (int64_t*)buf;
- int64_t readoff, readclient;
- while ((char*)p + 32 < buf + rdsize) {
- readoff = *p;
- int64_t wantoff = offset*rdsize + (int64_t)((char*)p - buf);
- p++;
- readclient = *p;
- p++;
- if (readoff != wantoff ||
- readclient != client->get_nodeid()) {
- if (!bad)
- dout(0) << "WARNING: wrong data from OSD, block says fileoffset=" << readoff << " client=" << readclient
- << ", should be offset " << wantoff << " clietn " << client->get_nodeid()
- << dendl;
- bad++;
+ if (read) {
+ int bad = 0;
+ int64_t *p = (int64_t*)buf;
+ int64_t readoff, readclient;
+ while ((char*)p + 32 < buf + rdsize) {
+ readoff = *p;
+ int64_t wantoff = offset*rdsize + (int64_t)((char*)p - buf);
+ p++;
+ readclient = *p;
+ p++;
+ if (readoff != wantoff || readclient != client->get_nodeid()) {
+ if (!bad)
+ dout(0) << "WARNING: wrong data from OSD, block says fileoffset=" << readoff << " client=" << readclient
+ << ", should be offset " << wantoff << " clietn " << client->get_nodeid()
+ << dendl;
+ bad++;
+ }
}
+ if (bad)
+ dout(0) << " + " << (bad-1) << " other bad 16-byte bits in this block" << dendl;
}
- if (bad)
- dout(0) << " + " << (bad-1) << " other bad 16-byte bits in this block" << dendl;
- }
}
client->close(fd);
return 0;
}
-
-//#include<stdio.h>
-//#include<stdlib.h>
-
-int normdist(int min, int max, int stdev) /* specifies input values */;
-//main()
-//{
- // for ( int i=0; i < 10; i++ )
- // normdist ( 0 , 10, 1 );
-
-//}
-
-
int normdist(int min, int max, int stdev) /* specifies input values */
{
/* min: Minimum value; max: Maximum value; stdev: degree of deviation */
int SyntheticClient::read_random_ex(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes
{
uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize;
-
int fd = client->open(fn.c_str(), O_RDWR);
dout(5) << "reading from " << fn << " fd " << fd << dendl;
- // dout(0) << "READING FROM " << fn << " fd " << fd << dendl;
-
- // dout(0) << "filename " << fn << " size:" << size << " read size|" << rdsize << "|" << "\ chunks: |" << chunks <<"|" << dendl;
-
if (fd < 0) return fd;
int offset = 0;
char * buf = NULL;
// use rand instead ??
double x = drand48();
- //dout(0) << "RANDOM NUMBER RETURN |" << x << "|" << dendl;
-
// cleanup before call 'new'
if (buf != NULL) {
- delete[] buf;
- buf = NULL;
+ delete[] buf;
+ buf = NULL;
+ }
+ if (x < 0.5) {
+ buf = new char[rdsize];
+ memset(buf, 1, rdsize);
+ read=true;
+ } else {
+ buf = new char[rdsize+100]; // 1 MB
+ memset(buf, 7, rdsize);
}
- if ( x < 0.5)
- {
- //dout(0) << "DECIDED TO READ " << x << dendl;
- buf = new char[rdsize];
- memset(buf, 1, rdsize);
- read=true;
- }
- else
- {
- // dout(0) << "DECIDED TO WRITE " << x << dendl;
- buf = new char[rdsize+100]; // 1 MB
- memset(buf, 7, rdsize);
- }
-
- //double y = drand48() ;
-
- //dout(0) << "OFFSET is |" << offset << "| chunks |" << chunks<< dendl;
- if ( read)
- {
- //offset=(rand())%(chunks+1);
+ if (read) {
+ dout(2) << "reading block " << offset << "/" << chunks << dendl;
- /* if ( chunks > 10000 )
- offset= normdist( 0 , chunks/1000 , 5 )*1000;
- else if ( chunks > 1000 )
- offset= normdist( 0 , chunks/100 , 5 )*100;
- else if ( chunks > 100 )
- offset= normdist( 0 , chunks/20 , 5 )*20;*/
-
-
- dout(2) << "reading block " << offset << "/" << chunks << dendl;
-
- int r = client->read(fd, buf, rdsize,
+ int r = client->read(fd, buf, rdsize,
offset*rdsize);
- if (r < rdsize) {
- dout(1) << "read_file got r = " << r << ", probably end of file" << dendl;
- }
+ if (r < rdsize) {
+ dout(1) << "read_file got r = " << r << ", probably end of file" << dendl;
}
- else
- {
+ } else {
dout(2) << "writing block " << offset << "/" << chunks << dendl;
// fill buf with a 16 byte fingerprint
// 64 bits : client id
// = 128 bits (16 bytes)
- //if (true )
- //{
int count = rand()%10;
- for ( int j=0;j<count; j++ )
- {
-
- offset=(rand())%(chunks+1);
- uint64_t *p = (uint64_t*)buf;
- while ((char*)p < buf + rdsize) {
- *p = offset*rdsize + (char*)p - buf;
- p++;
- *p = client->get_nodeid().v;
- p++;
- }
-
- client->write(fd, buf, rdsize,
- offset*rdsize);
+ for ( int j=0;j<count; j++ ) {
+ offset=(rand())%(chunks+1);
+ uint64_t *p = (uint64_t*)buf;
+ while ((char*)p < buf + rdsize) {
+ *p = offset*rdsize + (char*)p - buf;
+ p++;
+ *p = client->get_nodeid().v;
+ p++;
}
- //}
- }
+
+ client->write(fd, buf, rdsize, offset*rdsize);
+ }
+ }
// verify fingerprint
- if ( read )
- {
- int bad = 0;
- int64_t *p = (int64_t*)buf;
- int64_t readoff, readclient;
- while ((char*)p + 32 < buf + rdsize) {
- readoff = *p;
- int64_t wantoff = offset*rdsize + (int64_t)((char*)p - buf);
- p++;
- readclient = *p;
- p++;
- if (readoff != wantoff ||
- readclient != client->get_nodeid()) {
- if (!bad)
- dout(0) << "WARNING: wrong data from OSD, block says fileoffset=" << readoff << " client=" << readclient
- << ", should be offset " << wantoff << " clietn " << client->get_nodeid()
- << dendl;
- bad++;
- }
+ if (read) {
+ int bad = 0;
+ int64_t *p = (int64_t*)buf;
+ int64_t readoff, readclient;
+ while ((char*)p + 32 < buf + rdsize) {
+ readoff = *p;
+ int64_t wantoff = offset*rdsize + (int64_t)((char*)p - buf);
+ p++;
+ readclient = *p;
+ p++;
+ if (readoff != wantoff || readclient != client->get_nodeid()) {
+ if (!bad)
+ dout(0) << "WARNING: wrong data from OSD, block says fileoffset=" << readoff << " client=" << readclient
+ << ", should be offset " << wantoff << " clietn " << client->get_nodeid()
+ << dendl;
+ bad++;
}
- if (bad)
- dout(0) << " + " << (bad-1) << " other bad 16-byte bits in this block" << dendl;
}
+ if (bad)
+ dout(0) << " + " << (bad-1) << " other bad 16-byte bits in this block" << dendl;
+ }
}
client->close(fd);