Skip to content

Commit

Permalink
rbd-replay: Add --anonymize flag to rbd-replay-prep
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Crume <[email protected]>
  • Loading branch information
adamcrume committed Sep 11, 2014
1 parent 60d65da commit 3911354
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
6 changes: 5 additions & 1 deletion doc/man/8/rbd-replay-prep.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Synopsis
========

| **rbd-replay-prep** [ --window *seconds* ] *trace_dir* *replay_file*
| **rbd-replay-prep** [ --window *seconds* ] [ --anonymize ] *trace_dir* *replay_file*

Description
Expand All @@ -23,6 +23,10 @@ Options

Requests further apart than 'seconds' seconds are assumed to be independent.

.. option:: --anonymize

Anonymizes image and snap names.


Examples
========
Expand Down
9 changes: 7 additions & 2 deletions man/rbd-replay-prep.8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "RBD-REPLAY-PREP" "8" "August 11, 2014" "dev" "Ceph"
.TH "RBD-REPLAY-PREP" "8" "August 21, 2014" "dev" "Ceph"
.SH NAME
rbd-replay-prep \- prepare captured rados block device (RBD) workloads for replay
.
Expand Down Expand Up @@ -59,7 +59,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
..
.SH SYNOPSIS
.nf
\fBrbd\-replay\-prep\fP [ \-\-window \fIseconds\fP ] \fItrace_dir\fP \fIreplay_file\fP
\fBrbd\-replay\-prep\fP [ \-\-window \fIseconds\fP ] [ \-\-anonymize ] \fItrace_dir\fP \fIreplay_file\fP
.fi
.sp
.SH DESCRIPTION
Expand All @@ -71,6 +71,11 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.B \-\-window seconds
Requests further apart than \(aqseconds\(aq seconds are assumed to be independent.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-anonymize
Anonymizes image and snap names.
.UNINDENT
.SH EXAMPLES
.sp
To prepare workload1\-trace for replay:
Expand Down
61 changes: 57 additions & 4 deletions src/rbd_replay/rbd-replay-prep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,41 @@ class Thread {
uint64_t m_max_ts;
};

class AnonymizedImage {
public:
void init(string image_name, int index) {
assert(m_image_name == "");
m_image_name = image_name;
ostringstream oss;
oss << "image" << index;
m_anonymized_image_name = oss.str();
}

string image_name() const {
return m_image_name;
}

pair<string, string> anonymize(string snap_name) {
if (snap_name == "") {
return pair<string, string>(m_anonymized_image_name, "");
}
string& anonymized_snap_name(m_snaps[snap_name]);
if (anonymized_snap_name == "") {
ostringstream oss;
oss << "snap" << m_snaps.size();
anonymized_snap_name = oss.str();
}
return pair<string, string>(m_anonymized_image_name, anonymized_snap_name);
}

private:
string m_image_name;
string m_anonymized_image_name;
map<string, string> m_snaps;
};

static void usage(string prog) {
cout << "Usage: " << prog << " [ --window <seconds> ] <trace-input> <replay-output>" << endl;
cout << "Usage: " << prog << " [ --window <seconds> ] [ --anonymize ] <trace-input> <replay-output>" << endl;
}

__attribute__((noreturn)) static void usage_exit(string prog, string msg) {
Expand All @@ -104,7 +137,9 @@ class Processor {
m_recent_completions(io_set_t()),
m_open_images(set<imagectx_id_t>()),
m_ios(vector<IO::ptr>()),
m_pending_ios(map<uint64_t, IO::ptr>()) {
m_pending_ios(map<uint64_t, IO::ptr>()),
m_anonymize(false),
m_anonymized_images(map<string, AnonymizedImage>()) {
}

void run(vector<string> args) {
Expand All @@ -123,6 +158,8 @@ class Processor {
// TODO: test
printf("Arg: '%s'\n", arg.c_str() + sizeof("--window="));
m_window = (uint64_t)(1e9 * atof(arg.c_str() + sizeof("--window=")));
} else if (arg == "--anonymize") {
m_anonymize = true;
} else if (arg == "-h" || arg == "--help") {
usage(args[0]);
exit(0);
Expand Down Expand Up @@ -335,7 +372,8 @@ class Processor {
bool readonly = fields.int64("read_only");
imagectx_id_t imagectx = fields.uint64("imagectx");
action_id_t ionum = next_id();
IO::ptr io(new OpenImageIO(ionum, ts, threadID, thread->pending_io(), imagectx, name, snap_name, readonly));
pair<string, string> aname(map_image_snap(name, snap_name));
IO::ptr io(new OpenImageIO(ionum, ts, threadID, thread->pending_io(), imagectx, aname.first, aname.second, readonly));
io->add_dependencies(m_recent_completions);
thread->issued_io(io, m_threads);
m_ios.push_back(io);
Expand Down Expand Up @@ -443,6 +481,17 @@ class Processor {
m_recent_completions.insert(io);
}

pair<string, string> map_image_snap(string image_name, string snap_name) {
if (!m_anonymize) {
return pair<string, string>(image_name, snap_name);
}
AnonymizedImage& m(m_anonymized_images[image_name]);
if (m.image_name() == "") {
m.init(image_name, m_anonymized_images.size());
}
return m.anonymize(snap_name);
}

void require_image(uint64_t ts,
Thread::ptr thread,
imagectx_id_t imagectx,
Expand All @@ -454,7 +503,8 @@ class Processor {
return;
}
action_id_t ionum = next_id();
IO::ptr io(new OpenImageIO(ionum, ts - 2, thread->id(), thread->pending_io(), imagectx, name, snap_name, readonly));
pair<string, string> aname(map_image_snap(name, snap_name));
IO::ptr io(new OpenImageIO(ionum, ts - 2, thread->id(), thread->pending_io(), imagectx, aname.first, aname.second, readonly));
io->add_dependencies(m_recent_completions);
thread->issued_io(io, m_threads);
m_ios.push_back(io);
Expand All @@ -473,6 +523,9 @@ class Processor {

// keyed by completion
map<uint64_t, IO::ptr> m_pending_ios;

bool m_anonymize;
map<string, AnonymizedImage> m_anonymized_images;
};

int main(int argc, char** argv) {
Expand Down

0 comments on commit 3911354

Please sign in to comment.