Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/obj_bencher.cc: fix verification crashing when there's no objects #5853

Merged
2 commits merged into from Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/common/obj_bencher.cc
Expand Up @@ -52,7 +52,7 @@ static std::string generate_object_name(int objnum, int pid = 0)
return oss.str();
}

static void sanitize_object_contents (bench_data *data, int length) {
static void sanitize_object_contents (bench_data *data, size_t length) {
memset(data->object_contents, 'z', length);
}

Expand Down Expand Up @@ -204,7 +204,7 @@ void *ObjBencher::status_printer(void *_bencher) {

int ObjBencher::aio_bench(
int operation, int secondsToRun,
int concurrentios, int object_size, bool cleanup, const std::string& run_name, bool no_verify) {
int concurrentios, size_t object_size, bool cleanup, const std::string& run_name, bool no_verify) {

if (concurrentios <= 0)
return -EINVAL;
Expand Down Expand Up @@ -322,11 +322,11 @@ static T vec_stddev(vector<T>& v)
return sqrt(stddev);
}

int ObjBencher::fetch_bench_metadata(const std::string& metadata_file, int* object_size, int* num_objects, int* prevPid) {
int ObjBencher::fetch_bench_metadata(const std::string& metadata_file, size_t* object_size, int* num_objects, int* prevPid) {
int r = 0;
bufferlist object_data;

r = sync_read(metadata_file, object_data, sizeof(int)*3);
r = sync_read(metadata_file, object_data, sizeof(int) * 2 + sizeof(size_t));
if (r <= 0) {
// treat an empty file as a file that does not exist
if (r == 0) {
Expand Down Expand Up @@ -666,7 +666,8 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre

if (!no_verify) {
snprintf(data.object_contents, data.object_size, "I'm the %16dth object!", current_index);
if (memcmp(data.object_contents, cur_contents->c_str(), data.object_size) != 0) {
if ( (cur_contents->length() != data.object_size) ||
(memcmp(data.object_contents, cur_contents->c_str(), data.object_size) != 0) ) {
cerr << name[slot] << " is not correct!" << std::endl;
++errors;
}
Expand All @@ -676,13 +677,13 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
index[slot] = data.started;
lock.Unlock();
completion_wait(slot);
lock.Lock();
r = completion_ret(slot);
if (r < 0) {
cerr << "read got " << r << std::endl;
lock.Unlock();
goto ERR;
}
lock.Lock();
total_latency += data.cur_latency;
if (data.cur_latency > data.max_latency) data.max_latency = data.cur_latency;
if (data.cur_latency < data.min_latency) data.min_latency = data.cur_latency;
Expand Down Expand Up @@ -728,7 +729,8 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
if (!no_verify) {
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) {
if ((contents[slot]->length() != data.object_size) ||
(memcmp(data.object_contents, contents[slot]->c_str(), data.object_size) != 0)) {
cerr << name[slot] << " is not correct!" << std::endl;
++errors;
}
Expand Down Expand Up @@ -899,7 +901,8 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr

if (!no_verify) {
snprintf(data.object_contents, data.object_size, "I'm the %16dth object!", current_index);
if (memcmp(data.object_contents, cur_contents->c_str(), data.object_size) != 0) {
if ((cur_contents->length() != data.object_size) ||
(memcmp(data.object_contents, cur_contents->c_str(), data.object_size) != 0)) {
cerr << name[slot] << " is not correct!" << std::endl;
++errors;
}
Expand Down Expand Up @@ -950,7 +953,8 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
if (!no_verify) {
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) {
if ((contents[slot]->length() != data.object_size) ||
(memcmp(data.object_contents, contents[slot]->c_str(), data.object_size) != 0)) {
cerr << name[slot] << " is not correct!" << std::endl;
++errors;
}
Expand Down Expand Up @@ -1010,7 +1014,7 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr

int ObjBencher::clean_up(const std::string& prefix, int concurrentios, const std::string& run_name) {
int r = 0;
int object_size;
size_t object_size;
int num_objects;
int prevPid;

Expand Down
6 changes: 3 additions & 3 deletions src/common/obj_bencher.h
Expand Up @@ -36,7 +36,7 @@ struct bench_history {

struct bench_data {
bool done; //is the benchmark is done
int object_size; //the size of the objects
size_t object_size; //the size of the objects
// same as object_size for write tests
int in_flight; //number of reads/writes being waited on
int started;
Expand Down Expand Up @@ -71,7 +71,7 @@ class ObjBencher {

struct bench_data data;

int fetch_bench_metadata(const std::string& metadata_file, int* object_size, int* num_objects, int* prevPid);
int fetch_bench_metadata(const std::string& metadata_file, size_t* object_size, int* num_objects, int* prevPid);

int write_bench(int secondsToRun, int concurrentios, const string& run_name_meta);
int seq_read_bench(int secondsToRun, int num_objects, int concurrentios, int writePid, bool no_verify=false);
Expand Down Expand Up @@ -107,7 +107,7 @@ class ObjBencher {
virtual ~ObjBencher() {}
int aio_bench(
int operation, int secondsToRun,
int concurrentios, int op_size, bool cleanup, const std::string& run_name, bool no_verify=false);
int concurrentios, size_t op_size, bool cleanup, const std::string& run_name, bool no_verify=false);
int clean_up(const std::string& prefix, int concurrentios, const std::string& run_name);

void set_show_time(bool dt) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/test_rados_tool.sh
Expand Up @@ -38,6 +38,12 @@ run_expect_succ() {
[ $? -ne 0 ] && die "expected success, but got failure! cmd: $@"
}

run_expect_nosignal() {
echo "RUN_EXPECT_NOSIGNAL: " "$@"
do_run "$@"
[ $? -ge 128 ] && die "expected succes or fail, but got signal! cmd: $@"
}

run() {
echo "RUN: " $@
do_run "$@"
Expand Down Expand Up @@ -225,6 +231,12 @@ run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --format json --no-cl
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 rand --format json
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 seq --format json

for i in $("$RADOS_TOOL" --pool "$POOL" ls | grep "benchmark_data"); do
"$RADOS_TOOL" --pool "$POOL" truncate $i 0
done

run_expect_nosignal "$RADOS_TOOL" --pool "$POOL" bench 1 rand
run_expect_nosignal "$RADOS_TOOL" --pool "$POOL" bench 1 seq

echo "SUCCESS!"
exit 0