Skip to content

Commit

Permalink
obj_bencher: fix data encoding
Browse files Browse the repository at this point in the history
There was a bug when doing a read with multiple threads, when
one of the threads was left behind; when it returned the compared
data string might have been cluttered by newer strings that
were longer.

Signed-off-by: Yehuda Sadeh <[email protected]>
  • Loading branch information
Yehuda Sadeh authored and yehudasa committed May 4, 2012
1 parent 76a5c89 commit 9979132
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/common/obj_bencher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ static void generate_object_name(char *s, size_t size, int objnum, int pid = 0)
}

static void sanitize_object_contents (bench_data *data, int length) {
for (int i = 0; i < length; ++i) {
data->object_contents[i] = i % sizeof(char);
}
memset(data->object_contents, 'z', length);
}

void *ObjBencher::status_printer(void *_bencher) {
Expand Down Expand Up @@ -207,7 +205,7 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) {
name[i] = new char[128];
contents[i] = new bufferlist();
generate_object_name(name[i], 128, i);
snprintf(data.object_contents, data.object_size, "I'm the %dth object!", i);
snprintf(data.object_contents, data.object_size, "I'm the %16dth object!", i);
contents[i]->append(data.object_contents, data.object_size);
}

Expand Down Expand Up @@ -266,7 +264,7 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) {
newContents = new bufferlist();
newName = new char[128];
generate_object_name(newName, 128, data.started);
snprintf(data.object_contents, data.object_size, "I'm the %dth object!", data.started);
snprintf(data.object_contents, data.object_size, "I'm the %16dth object!", data.started);
newContents->append(data.object_contents, data.object_size);
completion_wait(slot);
lock.Lock();
Expand Down Expand Up @@ -382,8 +380,8 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
double total_latency = 0;
int r = 0;
utime_t runtime;
sanitize_object_contents(&data, 128); //clean it up once; subsequent
//changes will be safe because string length monotonically increases
sanitize_object_contents(&data, data.object_size); //clean it up once; subsequent
//changes will be safe because string length should remain the same

r = completions_init(concurrentios);
if (r < 0)
Expand Down Expand Up @@ -481,7 +479,7 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
lock.Lock();
++data.started;
++data.in_flight;
snprintf(data.object_contents, data.object_size, "I'm the %dth object!", current_index);
snprintf(data.object_contents, data.object_size, "I'm the %16dth object!", current_index);
lock.Unlock();
if (memcmp(data.object_contents, cur_contents->c_str(), data.object_size) != 0) {
cerr << name[slot] << " is not correct!" << std::endl;
Expand Down Expand Up @@ -511,7 +509,7 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
data.avg_latency = total_latency / data.finished;
--data.in_flight;
release_completion(slot);
snprintf(data.object_contents, data.object_size, "I'm the %dth object!", index[slot]);
snprintf(data.object_contents, data.object_size, "I'm the %16dth object!", index[slot]);
lock.Unlock();
if (memcmp(data.object_contents, contents[slot]->c_str(), data.object_size) != 0) {
cerr << name[slot] << " is not correct!" << std::endl;
Expand Down

0 comments on commit 9979132

Please sign in to comment.