You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/08/25 21:51:02 UTC
[1/5] kudu git commit: [c++-client] reduce in-flight-op partition key
lifetime
Repository: kudu
Updated Branches:
refs/heads/master 2976b2a2c -> 86afadc7f
[c++-client] reduce in-flight-op partition key lifetime
This commit changes the C++ MetaCache to take the lookup partition key
by value, and updates Batcher to pass the partition key by move when
calling the MetaCache. Additionally, the partition key is no longer
stored as a field in the InFlightOp. The effect is that the InFlightOp
is smaller by the size of a std::string, and the lifetime of the
partition key is reduced from when the InFlightOp is complete to when
the meta cache lookup is complete.
Change-Id: Ia949b65a9447979c9c5eff324448af307a1db1b7
Reviewed-on: http://gerrit.cloudera.org:8080/4114
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <as...@cloudera.com>
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/effcd2c9
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/effcd2c9
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/effcd2c9
Branch: refs/heads/master
Commit: effcd2c9624196bb5626cb853f0f19ce06d036c0
Parents: 2976b2a
Author: Dan Burkert <da...@cloudera.com>
Authored: Wed Aug 24 11:09:56 2016 -0700
Committer: Adar Dembo <ad...@cloudera.com>
Committed: Wed Aug 24 22:21:28 2016 +0000
----------------------------------------------------------------------
src/kudu/client/batcher.cc | 8 +++-----
src/kudu/client/meta_cache.cc | 8 ++++----
src/kudu/client/meta_cache.h | 4 ++--
3 files changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/effcd2c9/src/kudu/client/batcher.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/batcher.cc b/src/kudu/client/batcher.cc
index 0346119..fbdb2a9 100644
--- a/src/kudu/client/batcher.cc
+++ b/src/kudu/client/batcher.cc
@@ -166,8 +166,6 @@ struct InFlightOp {
// The actual operation.
gscoped_ptr<KuduWriteOperation> write_op;
- string partition_key;
-
// The tablet the operation is destined for.
// This is only filled in after passing through the kLookingUpTablet state.
scoped_refptr<RemoteTablet> tablet;
@@ -531,8 +529,8 @@ Status Batcher::Add(KuduWriteOperation* write_op) {
// As soon as we get the op, start looking up where it belongs,
// so that when the user calls Flush, we are ready to go.
gscoped_ptr<InFlightOp> op(new InFlightOp());
- RETURN_NOT_OK(write_op->table_->partition_schema()
- .EncodeKey(write_op->row(), &op->partition_key));
+ string partition_key;
+ RETURN_NOT_OK(write_op->table_->partition_schema().EncodeKey(write_op->row(), &partition_key));
op->write_op.reset(write_op);
op->state = InFlightOp::kLookingUpTablet;
@@ -547,7 +545,7 @@ Status Batcher::Add(KuduWriteOperation* write_op) {
base::RefCountInc(&outstanding_lookups_);
client_->data_->meta_cache_->LookupTabletByKey(
op->write_op->table(),
- op->partition_key,
+ std::move(partition_key),
deadline,
&op->tablet,
Bind(&Batcher::TabletLookupFinished, this, op.get()));
http://git-wip-us.apache.org/repos/asf/kudu/blob/effcd2c9/src/kudu/client/meta_cache.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/meta_cache.cc b/src/kudu/client/meta_cache.cc
index bc11ccf..9ae6714 100644
--- a/src/kudu/client/meta_cache.cc
+++ b/src/kudu/client/meta_cache.cc
@@ -947,14 +947,14 @@ void MetaCache::ClearCache() {
}
void MetaCache::LookupTabletByKey(const KuduTable* table,
- const string& partition_key,
+ string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback) {
LookupRpc* rpc = new LookupRpc(this,
callback,
table,
- partition_key,
+ std::move(partition_key),
remote_tablet,
deadline,
client_->data_->messenger_,
@@ -963,14 +963,14 @@ void MetaCache::LookupTabletByKey(const KuduTable* table,
}
void MetaCache::LookupTabletByKeyOrNext(const KuduTable* table,
- const string& partition_key,
+ string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback) {
LookupRpc* rpc = new LookupRpc(this,
callback,
table,
- partition_key,
+ std::move(partition_key),
remote_tablet,
deadline,
client_->data_->messenger_,
http://git-wip-us.apache.org/repos/asf/kudu/blob/effcd2c9/src/kudu/client/meta_cache.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/meta_cache.h b/src/kudu/client/meta_cache.h
index 1f93440..b621500 100644
--- a/src/kudu/client/meta_cache.h
+++ b/src/kudu/client/meta_cache.h
@@ -361,7 +361,7 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
// NOTE: the memory referenced by 'table' must remain valid until 'callback'
// is invoked.
void LookupTabletByKey(const KuduTable* table,
- const std::string& partition_key,
+ std::string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback);
@@ -369,7 +369,7 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
// Look up which tablet hosts the given partition key, or the next tablet if
// the key falls in a non-covered range partition.
void LookupTabletByKeyOrNext(const KuduTable* table,
- const std::string& partition_key,
+ std::string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback);
[2/5] kudu git commit: subprocess: allow Call() to read both stdout
and stderr
Posted by to...@apache.org.
subprocess: allow Call() to read both stdout and stderr
I'm going to use this in a new integration test for the tool.
Since the parent is now reading from two pipes, it needs to do so more
carefully. For example, if it read from stdout fully before looking at
stderr, both it and the child would deadlock if the child wrote 64k bytes
to the stderr pipe, hit the kernel limit, and got blocked.
I played around with an implementation based on poll(), but ultimately found
this one (based on libev) to be simpler.
Change-Id: If5f2be94c2e5cc0644a5bb2340adc4a71d844247
Reviewed-on: http://gerrit.cloudera.org:8080/4057
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/666ae1ed
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/666ae1ed
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/666ae1ed
Branch: refs/heads/master
Commit: 666ae1ed1f47fab7a67f0f53f48ccaeee7f11654
Parents: effcd2c
Author: Adar Dembo <ad...@cloudera.com>
Authored: Thu Aug 18 20:45:55 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Aug 25 05:32:48 2016 +0000
----------------------------------------------------------------------
src/kudu/util/CMakeLists.txt | 1 +
src/kudu/util/subprocess-test.cc | 26 ++++-
src/kudu/util/subprocess.cc | 181 ++++++++++++++++++++++++----------
src/kudu/util/subprocess.h | 13 +--
4 files changed, 160 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/666ae1ed/src/kudu/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/util/CMakeLists.txt b/src/kudu/util/CMakeLists.txt
index a4527b9..82e7b91 100644
--- a/src/kudu/util/CMakeLists.txt
+++ b/src/kudu/util/CMakeLists.txt
@@ -197,6 +197,7 @@ set(UTIL_LIBS
glog
gutil
histogram_proto
+ libev
maintenance_manager_proto
pb_util_proto
protobuf
http://git-wip-us.apache.org/repos/asf/kudu/blob/666ae1ed/src/kudu/util/subprocess-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/subprocess-test.cc b/src/kudu/util/subprocess-test.cc
index 6397f7c..31b47fa 100644
--- a/src/kudu/util/subprocess-test.cc
+++ b/src/kudu/util/subprocess-test.cc
@@ -15,11 +15,15 @@
// specific language governing permissions and limitations
// under the License.
-#include <vector>
+#include "kudu/util/subprocess.h"
+
+#include <unistd.h>
+
#include <string>
+#include <vector>
#include <gtest/gtest.h>
-#include "kudu/util/subprocess.h"
+
#include "kudu/util/test_util.h"
using std::string;
@@ -105,4 +109,22 @@ TEST_F(SubprocessTest, TestKill) {
ASSERT_EQ(SIGKILL, WTERMSIG(wait_status));
}
+// Writes enough bytes to stdout and stderr concurrently that if Call() were
+// fully reading them one at a time, the test would deadlock.
+TEST_F(SubprocessTest, TestReadFromStdoutAndStderr) {
+ // Set an alarm to break out of any potential deadlocks (if the implementation
+ // regresses).
+ alarm(60);
+
+ string stdout;
+ string stderr;
+ ASSERT_OK(Subprocess::Call({
+ "/bin/bash",
+ "-c",
+ "dd if=/dev/urandom of=/dev/stdout bs=512 count=2048 &"
+ "dd if=/dev/urandom of=/dev/stderr bs=512 count=2048 &"
+ "wait"
+ }, &stdout, &stderr));
+}
+
} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/666ae1ed/src/kudu/util/subprocess.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/subprocess.cc b/src/kudu/util/subprocess.cc
index a00b66c..01425a2 100644
--- a/src/kudu/util/subprocess.cc
+++ b/src/kudu/util/subprocess.cc
@@ -19,19 +19,21 @@
#include <dirent.h>
#include <fcntl.h>
-#include <glog/logging.h>
-#include <glog/stl_logging.h>
-#include <memory>
#include <signal.h>
-#include <string>
+#if defined(__linux__)
+#include <sys/prctl.h>
+#endif
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+
+#include <memory>
+#include <string>
#include <vector>
-#if defined(__linux__)
-#include <sys/prctl.h>
-#endif
+#include <ev++.h>
+#include <glog/logging.h>
+#include <glog/stl_logging.h>
#include "kudu/gutil/once.h"
#include "kudu/gutil/port.h"
@@ -43,6 +45,7 @@
#include "kudu/util/errno.h"
#include "kudu/util/status.h"
+using std::unique_ptr;
using std::shared_ptr;
using std::string;
using std::vector;
@@ -144,6 +147,98 @@ void CloseNonStandardFDs(DIR* fd_dir) {
}
}
+void RedirectToDevNull(int fd) {
+ // We must not close stderr or stdout, because then when a new file descriptor
+ // gets opened, it might get that fd number. (We always allocate the lowest
+ // available file descriptor number.) Instead, we reopen that fd as
+ // /dev/null.
+ int dev_null = open("/dev/null", O_WRONLY);
+ if (dev_null < 0) {
+ PLOG(WARNING) << "failed to open /dev/null";
+ } else {
+ PCHECK(dup2(dev_null, fd));
+ }
+}
+
+// Stateful libev watcher to help ReadFdsFully().
+class ReadFdsFullyHelper {
+ public:
+ ReadFdsFullyHelper(const string& progname, ev::dynamic_loop* loop, int fd)
+ : progname_(progname) {
+ // Bind the watcher to the provided loop, to this functor, and to the
+ // readable fd.
+ watcher_.set(*loop);
+ watcher_.set(this);
+ watcher_.set(fd, ev::READ);
+
+ // The watcher will now be polled when its loop is run.
+ watcher_.start();
+ }
+
+ void operator() (ev::io &w, int revents) {
+ DCHECK_EQ(ev::READ, revents);
+
+ char buf[1024];
+ ssize_t n = read(w.fd, buf, arraysize(buf));
+ if (n == 0) {
+ // EOF, stop watching.
+ w.stop();
+ } else if (n < 0) {
+ // Interrupted by a signal, do nothing.
+ if (errno == EINTR) return;
+
+ // A fatal error. Store it and stop watching.
+ status_ = Status::IOError("IO error reading from " + progname_,
+ ErrnoToString(errno), errno);
+ w.stop();
+ } else {
+ // Add our bytes and keep watching.
+ output_.append(buf, n);
+ }
+ }
+
+ const Status& status() const { return status_; }
+ const string& output() const { return output_; }
+
+ private:
+ const string progname_;
+
+ ev::io watcher_;
+ string output_;
+ Status status_;
+};
+
+// Reads from all descriptors in 'fds' until EOF on all of them. If any read
+// yields an error, it is returned. Otherwise, 'out' contains the bytes read
+// for each fd, in the same order as was in 'fds'.
+Status ReadFdsFully(const string& progname,
+ const vector<int>& fds,
+ vector<string>* out) {
+ ev::dynamic_loop loop;
+
+ // Set up a watcher for each fd.
+ vector<unique_ptr<ReadFdsFullyHelper>> helpers;
+ for (int fd : fds) {
+ helpers.emplace_back(new ReadFdsFullyHelper(progname, &loop, fd));
+ }
+
+ // This will read until all fds return EOF.
+ loop.run();
+
+ // Check for failures.
+ for (const auto& h : helpers) {
+ if (!h->status().ok()) {
+ return h->status();
+ }
+ }
+
+ // No failures; write the output to the caller.
+ for (const auto& h : helpers) {
+ out->push_back(h->output());
+ }
+ return Status::OK();
+}
+
} // anonymous namespace
Subprocess::Subprocess(string program, vector<string> argv)
@@ -194,19 +289,6 @@ void Subprocess::DisableStdout() {
fd_state_[STDOUT_FILENO] = DISABLED;
}
-static void RedirectToDevNull(int fd) {
- // We must not close stderr or stdout, because then when a new file descriptor
- // gets opened, it might get that fd number. (We always allocate the lowest
- // available file descriptor number.) Instead, we reopen that fd as
- // /dev/null.
- int dev_null = open("/dev/null", O_WRONLY);
- if (dev_null < 0) {
- PLOG(WARNING) << "failed to open /dev/null";
- } else {
- PCHECK(dup2(dev_null, fd));
- }
-}
-
#if defined(__APPLE__)
static int pipe2(int pipefd[2], int flags) {
DCHECK_EQ(O_CLOEXEC, flags);
@@ -369,50 +451,43 @@ Status Subprocess::Kill(int signal) {
Status Subprocess::Call(const string& arg_str) {
vector<string> argv = Split(arg_str, " ");
- return Call(argv);
+ return Call(argv, nullptr, nullptr);
}
-Status Subprocess::Call(const vector<string>& argv) {
+Status Subprocess::Call(const vector<string>& argv,
+ string* stdout_out,
+ string* stderr_out) {
VLOG(2) << "Invoking command: " << argv;
- Subprocess proc(argv[0], argv);
- RETURN_NOT_OK(proc.Start());
- int retcode;
- RETURN_NOT_OK(proc.Wait(&retcode));
+ Subprocess p(argv[0], argv);
- if (retcode == 0) {
- return Status::OK();
- } else {
- return Status::RuntimeError(Substitute(
- "Subprocess '$0' terminated with non-zero exit status $1",
- argv[0],
- retcode));
+ if (stdout_out) {
+ p.ShareParentStdout(false);
}
-}
-
-Status Subprocess::Call(const vector<string>& argv, string* stdout_out) {
- VLOG(2) << "Invoking command: " << argv;
- Subprocess p(argv[0], argv);
- p.ShareParentStdout(false);
- RETURN_NOT_OK_PREPEND(p.Start(), "Unable to fork " + argv[0]);
+ if (stderr_out) {
+ p.ShareParentStderr(false);
+ }
+ RETURN_NOT_OK_PREPEND(p.Start(),
+ "Unable to fork " + argv[0]);
int err = close(p.ReleaseChildStdinFd());
if (PREDICT_FALSE(err != 0)) {
return Status::IOError("Unable to close child process stdin", ErrnoToString(errno), errno);
}
- stdout_out->clear();
- char buf[1024];
- while (true) {
- ssize_t n = read(p.from_child_stdout_fd(), buf, arraysize(buf));
- if (n == 0) {
- // EOF
- break;
- }
- if (n < 0) {
- if (errno == EINTR) continue;
- return Status::IOError("IO error reading from " + argv[0], ErrnoToString(errno), errno);
- }
+ vector<int> fds;
+ if (stdout_out) {
+ fds.push_back(p.from_child_stdout_fd());
+ }
+ if (stderr_out) {
+ fds.push_back(p.from_child_stderr_fd());
+ }
+ vector<string> out;
+ RETURN_NOT_OK(ReadFdsFully(argv[0], fds, &out));
- stdout_out->append(buf, n);
+ if (stdout_out) {
+ *stdout_out = std::move(out[0]);
+ }
+ if (stderr_out) {
+ *stderr_out = std::move(out[1]);
}
int retcode;
http://git-wip-us.apache.org/repos/asf/kudu/blob/666ae1ed/src/kudu/util/subprocess.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/subprocess.h b/src/kudu/util/subprocess.h
index 6889b6a..1b70b1a 100644
--- a/src/kudu/util/subprocess.h
+++ b/src/kudu/util/subprocess.h
@@ -17,10 +17,11 @@
#ifndef KUDU_UTIL_SUBPROCESS_H
#define KUDU_UTIL_SUBPROCESS_H
-#include <glog/logging.h>
#include <string>
#include <vector>
+#include <glog/logging.h>
+
#include "kudu/gutil/macros.h"
#include "kudu/util/status.h"
@@ -97,12 +98,12 @@ class Subprocess {
// Same as above, but accepts a vector that includes the path to the
// executable as argv[0] and the arguments to the program in argv[1..n].
- static Status Call(const std::vector<std::string>& argv);
-
- // Same as above, but collects the output from the child process stdout into
- // 'stdout_out'.
+ //
+ // Also collects the output from the child process stdout and stderr into
+ // 'stdout_out' and 'stderr_out' respectively.
static Status Call(const std::vector<std::string>& argv,
- std::string* stdout_out);
+ std::string* stdout_out = nullptr,
+ std::string* stderr_out = nullptr);
// Return the pipe fd to the child's standard stream.
// Stream should not be disabled or shared.
[3/5] kudu git commit: Remove pessimizing std::move() in return
statement
Posted by to...@apache.org.
Remove pessimizing std::move() in return statement
This change fixes this Clang warning:
[334/463] Building CXX object src/kudu/consensus/CMakeFiles/raft_consensus_quorum-test.dir/raft_consensus_quorum-test.cc.o
../../src/kudu/consensus/raft_consensus_quorum-test.cc:534:12: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
return std::move(cmeta);
^
../../src/kudu/consensus/raft_consensus_quorum-test.cc:534:12: note: remove std::move call here
return std::move(cmeta);
^~~~~~~~~~ ~
1 warning generated.
Change-Id: Ida46588398ca5f5982cb86aa03825530565c0923
Reviewed-on: http://gerrit.cloudera.org:8080/4122
Reviewed-by: Todd Lipcon <to...@apache.org>
Tested-by: Kudu Jenkins
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a1e6b884
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a1e6b884
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a1e6b884
Branch: refs/heads/master
Commit: a1e6b884a681e33aa4755267cb14602cf97b4b97
Parents: 666ae1e
Author: Mike Percy <mp...@apache.org>
Authored: Wed Aug 24 22:54:03 2016 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Thu Aug 25 07:43:38 2016 +0000
----------------------------------------------------------------------
src/kudu/consensus/raft_consensus_quorum-test.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/a1e6b884/src/kudu/consensus/raft_consensus_quorum-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus_quorum-test.cc b/src/kudu/consensus/raft_consensus_quorum-test.cc
index d32f7fe..ee1a568 100644
--- a/src/kudu/consensus/raft_consensus_quorum-test.cc
+++ b/src/kudu/consensus/raft_consensus_quorum-test.cc
@@ -531,7 +531,7 @@ class RaftConsensusQuorumTest : public KuduTest {
string peer_uuid = Substitute("peer-$0", peer_index);
unique_ptr<ConsensusMetadata> cmeta;
CHECK_OK(ConsensusMetadata::Load(fs_managers_[peer_index], kTestTablet, peer_uuid, &cmeta));
- return std::move(cmeta);
+ return cmeta;
}
// Assert that the durable term == term and that the peer that got the vote == voted_for.
[5/5] kudu git commit: tool: add ksck
Posted by to...@apache.org.
tool: add ksck
This patch adds ksck functionality to the new CLI tool. ksck is still
available as a library used by several integration tests.
Change-Id: Iad9aaffa5c0c77080dcaeb2cdfa572dcbeeb1407
Reviewed-on: http://gerrit.cloudera.org:8080/4121
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/86afadc7
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/86afadc7
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/86afadc7
Branch: refs/heads/master
Commit: 86afadc7fc6f9274402edcb3599c243ec2de0ccb
Parents: 7321b38
Author: Adar Dembo <ad...@cloudera.com>
Authored: Wed Aug 24 20:24:08 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Aug 25 21:46:47 2016 +0000
----------------------------------------------------------------------
docs/release_notes.adoc | 3 +
src/kudu/tools/CMakeLists.txt | 7 +-
src/kudu/tools/kudu-ksck.cc | 151 -----------------------------
src/kudu/tools/kudu-tool-test.cc | 6 ++
src/kudu/tools/tool_action.h | 1 +
src/kudu/tools/tool_action_cluster.cc | 149 ++++++++++++++++++++++++++++
src/kudu/tools/tool_main.cc | 1 +
7 files changed, 162 insertions(+), 156 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/docs/release_notes.adoc
----------------------------------------------------------------------
diff --git a/docs/release_notes.adoc b/docs/release_notes.adoc
index 38c3d7a..b629a2f 100644
--- a/docs/release_notes.adoc
+++ b/docs/release_notes.adoc
@@ -43,6 +43,9 @@ detailed below.
- The `kudu-pbc-dump` tool has been removed. The same functionality is now
implemented as `kudu pbc dump`.
+- The `kudu-ksck` tool has been removed. The same functionality is now
+ implemented as `kudu cluster ksck`.
+
- KuduSession methods in the C++ library are no longer advertised as thread-safe
to have one set of semantics for both C++ and Java Kudu client libraries.
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/src/kudu/tools/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/tools/CMakeLists.txt b/src/kudu/tools/CMakeLists.txt
index ce361f0..614bf11 100644
--- a/src/kudu/tools/CMakeLists.txt
+++ b/src/kudu/tools/CMakeLists.txt
@@ -82,13 +82,9 @@ target_link_libraries(ksck
${KUDU_BASE_LIBS}
)
-add_executable(kudu-ksck kudu-ksck.cc)
-target_link_libraries(kudu-ksck
- ksck
-)
-
add_executable(kudu
tool_action.cc
+ tool_action_cluster.cc
tool_action_fs.cc
tool_action_pbc.cc
tool_action_tablet.cc
@@ -100,6 +96,7 @@ target_link_libraries(kudu
kudu_common
kudu_fs
kudu_util
+ ksck
master
tserver
${KUDU_BASE_LIBS}
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/src/kudu/tools/kudu-ksck.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-ksck.cc b/src/kudu/tools/kudu-ksck.cc
deleted file mode 100644
index 70a6ce1..0000000
--- a/src/kudu/tools/kudu-ksck.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// Command line tool to run Ksck against a cluster. Defaults to running against a local Master
-// on the default RPC port. It verifies that all the reported Tablet Servers are running and that
-// the tablets are in a consistent state.
-
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-#include <iostream>
-
-#include "kudu/gutil/strings/split.h"
-#include "kudu/gutil/strings/substitute.h"
-#include "kudu/tools/ksck_remote.h"
-#include "kudu/util/flags.h"
-#include "kudu/util/logging.h"
-
-#define PUSH_PREPEND_NOT_OK(s, statuses, msg) do { \
- ::kudu::Status _s = (s); \
- if (PREDICT_FALSE(!_s.ok())) { \
- statuses->push_back(string(msg) + ": " + _s.ToString()); \
- } \
-} while (0);
-
-using std::cerr;
-using std::cout;
-using std::endl;
-using std::shared_ptr;
-using std::vector;
-using strings::Substitute;
-
-DEFINE_string(master_address, "",
- "Address of master server to run against.");
-
-DEFINE_bool(checksum_scan, false,
- "Perform a checksum scan on data in the cluster.");
-
-DEFINE_string(tables, "",
- "Tables to check (comma-separated list of names). "
- "If not specified, checks all tables.");
-
-DEFINE_string(tablets, "",
- "Tablets to check (comma-separated list of IDs) "
- "If not specified, checks all tablets.");
-
-namespace kudu {
-namespace tools {
-
-static string GetKsckUsage(const char* progname) {
- string msg = Substitute("Usage: $0 --master_address=<addr> <flags>\n\n", progname);
- msg += "Check the health of a Kudu cluster.\n\n"
- "By default, ksck checks that master and tablet server processes are running,\n"
- "and that table metadata is consistent. Use the 'checksum' flag to check that\n"
- "tablet data is consistent (also see the 'tables' and 'tablets' flags below).\n"
- "Use the 'checksum_snapshot' along with 'checksum' if the table or tablets are\n"
- "actively receiving inserts or updates.";
- return msg;
-}
-
-// Run ksck.
-// Error information is appended to the provided vector.
-// If the vector is empty upon completion, ksck ran successfully.
-static void RunKsck(vector<string>* error_messages) {
- vector<Sockaddr> master_addrs;
- PUSH_PREPEND_NOT_OK(ParseAddressList(FLAGS_master_address,
- master::Master::kDefaultPort,
- &master_addrs),
- error_messages, "Unable to parse master address");
- // return early if the addresses could not be resolved
- if (!error_messages->empty()) return;
-
- shared_ptr<KsckMaster> master;
- PUSH_PREPEND_NOT_OK(RemoteKsckMaster::Build(master_addrs[0], &master),
- error_messages, "Unable to build KsckMaster");
- if (!error_messages->empty()) return;
- shared_ptr<KsckCluster> cluster(new KsckCluster(master));
- shared_ptr<Ksck> ksck(new Ksck(cluster));
-
- ksck->set_table_filters(strings::Split(FLAGS_tables, ",", strings::SkipEmpty()));
- ksck->set_tablet_id_filters(strings::Split(FLAGS_tablets, ",", strings::SkipEmpty()));
-
- // This is required for everything below.
- PUSH_PREPEND_NOT_OK(ksck->CheckMasterRunning(), error_messages,
- "Master aliveness check error");
- if (!error_messages->empty()) return;
-
- // This is also required for everything below.
- PUSH_PREPEND_NOT_OK(ksck->FetchTableAndTabletInfo(), error_messages,
- "Error fetching the cluster metadata from the Master server");
- if (!error_messages->empty()) return;
-
- PUSH_PREPEND_NOT_OK(ksck->FetchInfoFromTabletServers(), error_messages,
- "Error fetching info from tablet servers");
-
- // TODO: Add support for tables / tablets filter in the consistency check.
- PUSH_PREPEND_NOT_OK(ksck->CheckTablesConsistency(), error_messages,
- "Table consistency check error");
-
- if (FLAGS_checksum_scan) {
- PUSH_PREPEND_NOT_OK(ksck->ChecksumData(ChecksumOptions()),
- error_messages, "Checksum scan error");
- }
-}
-
-} // namespace tools
-} // namespace kudu
-
-int main(int argc, char** argv) {
- google::SetUsageMessage(kudu::tools::GetKsckUsage(argv[0]));
- if (argc < 2) {
- google::ShowUsageWithFlagsRestrict(argv[0], __FILE__);
- exit(1);
- }
- kudu::ParseCommandLineFlags(&argc, &argv, true);
- FLAGS_logtostderr = true;
- kudu::InitGoogleLoggingSafe(argv[0]);
-
- vector<string> error_messages;
- kudu::tools::RunKsck(&error_messages);
-
- // All good.
- if (error_messages.empty()) {
- cout << "OK" << endl;
- return 0;
- }
-
- // Something went wrong.
- cerr << "==================" << endl;
- cerr << "Errors:" << endl;
- cerr << "==================" << endl;
- for (const string& s : error_messages) {
- cerr << s << endl;
- }
- cerr << endl;
- cerr << "FAILED" << endl;
- return 1;
-}
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 2700fb1..ba748aa 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -137,6 +137,12 @@ TEST_F(ToolTest, TestModeHelp) {
};
NO_FATALS(RunTestHelp("tablet cmeta", kCmetaModeRegexes));
}
+ {
+ const vector<string> kClusterModeRegexes = {
+ "ksck.*Check the health of a Kudu cluster",
+ };
+ NO_FATALS(RunTestHelp("cluster", kClusterModeRegexes));
+ }
}
TEST_F(ToolTest, TestActionHelp) {
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/src/kudu/tools/tool_action.h
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action.h b/src/kudu/tools/tool_action.h
index da5d1e9..7d79a4f 100644
--- a/src/kudu/tools/tool_action.h
+++ b/src/kudu/tools/tool_action.h
@@ -247,6 +247,7 @@ class Action {
};
// Returns new nodes for each major mode.
+std::unique_ptr<Mode> BuildClusterMode();
std::unique_ptr<Mode> BuildFsMode();
std::unique_ptr<Mode> BuildPbcMode();
std::unique_ptr<Mode> BuildTabletMode();
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/src/kudu/tools/tool_action_cluster.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_cluster.cc b/src/kudu/tools/tool_action_cluster.cc
new file mode 100644
index 0000000..d198a9b
--- /dev/null
+++ b/src/kudu/tools/tool_action_cluster.cc
@@ -0,0 +1,149 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/tools/tool_action.h"
+
+#include <iostream>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include <gflags/gflags.h>
+
+#include "kudu/gutil/map-util.h"
+#include "kudu/gutil/strings/split.h"
+#include "kudu/master/master.h"
+#include "kudu/tools/ksck.h"
+#include "kudu/tools/ksck_remote.h"
+#include "kudu/util/net/net_util.h"
+#include "kudu/util/status.h"
+
+#define PUSH_PREPEND_NOT_OK(s, statuses, msg) do { \
+ ::kudu::Status _s = (s); \
+ if (PREDICT_FALSE(!_s.ok())) { \
+ statuses.push_back(string(msg) + ": " + _s.ToString()); \
+ } \
+} while (0);
+
+
+DEFINE_bool(checksum_scan, false,
+ "Perform a checksum scan on data in the cluster.");
+
+DEFINE_string(tables, "",
+ "Tables to check (comma-separated list of names). "
+ "If not specified, checks all tables.");
+
+DEFINE_string(tablets, "",
+ "Tablets to check (comma-separated list of IDs) "
+ "If not specified, checks all tablets.");
+
+using std::cerr;
+using std::cout;
+using std::endl;
+using std::shared_ptr;
+using std::string;
+using std::unique_ptr;
+using std::vector;
+
+namespace kudu {
+namespace tools {
+
+namespace {
+
+Status RunKsck(const RunnerContext& context) {
+ vector<Sockaddr> master_addrs;
+ string master_address = FindOrDie(context.required_args, "master_address");
+ RETURN_NOT_OK_PREPEND(ParseAddressList(master_address,
+ master::Master::kDefaultPort,
+ &master_addrs),
+ "unable to parse master address");
+
+ shared_ptr<KsckMaster> master;
+ RETURN_NOT_OK_PREPEND(RemoteKsckMaster::Build(master_addrs[0], &master),
+ "unable to build KsckMaster");
+
+ shared_ptr<KsckCluster> cluster(new KsckCluster(master));
+ shared_ptr<Ksck> ksck(new Ksck(cluster));
+
+ ksck->set_table_filters(strings::Split(
+ FLAGS_tables, ",", strings::SkipEmpty()));
+ ksck->set_tablet_id_filters(strings::Split(
+ FLAGS_tablets, ",", strings::SkipEmpty()));
+
+ RETURN_NOT_OK_PREPEND(ksck->CheckMasterRunning(),
+ "master liveness check error");
+ RETURN_NOT_OK_PREPEND(ksck->FetchTableAndTabletInfo(),
+ "error fetching the cluster metadata from the Master server");
+
+ vector<string> error_messages;
+ PUSH_PREPEND_NOT_OK(ksck->FetchInfoFromTabletServers(), error_messages,
+ "error fetching info from tablet servers");
+
+ // TODO: Add support for tables / tablets filter in the consistency check.
+ PUSH_PREPEND_NOT_OK(ksck->CheckTablesConsistency(), error_messages,
+ "table consistency check error");
+
+ if (FLAGS_checksum_scan) {
+ PUSH_PREPEND_NOT_OK(ksck->ChecksumData(ChecksumOptions()),
+ error_messages, "checksum scan error");
+ }
+
+ // All good.
+ if (error_messages.empty()) {
+ cout << "OK" << endl;
+ return Status::OK();
+ }
+
+ // Something went wrong.
+ cerr << "==================" << endl;
+ cerr << "Errors:" << endl;
+ cerr << "==================" << endl;
+ for (const auto& s : error_messages) {
+ cerr << s << endl;
+ }
+ cerr << endl;
+ cerr << "FAILED" << endl;
+ return Status::RuntimeError("ksck discovered errors");
+}
+
+} // anonymous namespace
+
+unique_ptr<Mode> BuildClusterMode() {
+ // TODO: the long description looks pretty horrible, need to fix.
+ string desc = "Check the health of a Kudu cluster. By default, ksck checks "
+ "that master and tablet server processes are running, and that table "
+ "metadata is consistent. Use the 'checksum' flag to check that tablet "
+ "data is consistent (also see the 'tables' and 'tablets' flags). Use the "
+ "'checksum_snapshot' along with 'checksum' if the table or tablets are "
+ "actively receiving inserts or updates.";
+ unique_ptr<Action> ksck = ActionBuilder(
+ { "ksck", desc }, &RunKsck)
+ .AddRequiredParameter({ "master_address", "Kudu Master RPC address of form hostname:port" })
+ .AddOptionalParameter("checksum_scan")
+ .AddOptionalParameter("checksum_snapshot")
+ .AddOptionalParameter("tables")
+ .AddOptionalParameter("tablets")
+ .Build();
+
+ return ModeBuilder({ "cluster", "Operate on a Kudu cluster" })
+ .AddAction(std::move(ksck))
+ .Build();
+}
+
+} // namespace tools
+} // namespace kudu
+
http://git-wip-us.apache.org/repos/asf/kudu/blob/86afadc7/src/kudu/tools/tool_main.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_main.cc b/src/kudu/tools/tool_main.cc
index 18137a1..70fdfc0 100644
--- a/src/kudu/tools/tool_main.cc
+++ b/src/kudu/tools/tool_main.cc
@@ -111,6 +111,7 @@ int DispatchCommand(const vector<Mode*>& chain,
int RunTool(int argc, char** argv, bool show_help) {
unique_ptr<Mode> root =
ModeBuilder({ argv[0], "" }) // root mode description isn't printed
+ .AddMode(BuildClusterMode())
.AddMode(BuildFsMode())
.AddMode(BuildPbcMode())
.AddMode(BuildTabletMode())
[4/5] kudu git commit: tool: basic integration test
Posted by to...@apache.org.
tool: basic integration test
So far all it does is spot check some help pages, but in the future we
should augment it to test functionality too. For now that's not a big deal
because every tool function is covered in either master_migration-itest or
master_failover-itest.
Change-Id: Ib386882c1874e987d5824cfe742cc86627cd9eaa
Reviewed-on: http://gerrit.cloudera.org:8080/4058
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/7321b38b
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/7321b38b
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/7321b38b
Branch: refs/heads/master
Commit: 7321b38be0303876fcc71b5c73e3e6eddbbdf012
Parents: a1e6b88
Author: Adar Dembo <ad...@cloudera.com>
Authored: Thu Aug 18 20:50:39 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Aug 25 21:46:35 2016 +0000
----------------------------------------------------------------------
build-support/dist_test.py | 13 ++-
src/kudu/tools/CMakeLists.txt | 3 +
src/kudu/tools/kudu-tool-test.cc | 154 ++++++++++++++++++++++++++++++++++
src/kudu/util/test_macros.h | 21 ++++-
4 files changed, 188 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/7321b38b/build-support/dist_test.py
----------------------------------------------------------------------
diff --git a/build-support/dist_test.py b/build-support/dist_test.py
index f56513f..d391cf4 100755
--- a/build-support/dist_test.py
+++ b/build-support/dist_test.py
@@ -182,7 +182,10 @@ def ldd_deps(exe):
If the provided 'exe' is not a binary executable, returns
an empty list.
"""
- if exe.endswith(".sh"):
+ if (exe.endswith(".pl") or
+ exe.endswith(".py") or
+ exe.endswith(".sh") or
+ exe.endswith(".txt")):
return []
p = subprocess.Popen(["ldd", exe], stdout=subprocess.PIPE)
out, err = p.communicate()
@@ -243,7 +246,13 @@ def create_archive_input(staging, argv,
if os.path.isdir(d):
d += "/"
deps.append(d)
- for d in deps:
+ # DEPS_FOR_ALL may include binaries whose dependencies are not dependencies
+ # of the test executable. We must include those dependencies in the archive
+ # for the binaries to be usable.
+ deps.extend(ldd_deps(d))
+
+ # Deduplicate dependencies included via DEPS_FOR_ALL.
+ for d in set(deps):
# System libraries will end up being relative paths out
# of the build tree. We need to copy those into the build
# tree somewhere.
http://git-wip-us.apache.org/repos/asf/kudu/blob/7321b38b/src/kudu/tools/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/tools/CMakeLists.txt b/src/kudu/tools/CMakeLists.txt
index c66b314..ce361f0 100644
--- a/src/kudu/tools/CMakeLists.txt
+++ b/src/kudu/tools/CMakeLists.txt
@@ -115,6 +115,9 @@ ADD_KUDU_TEST(ksck_remote-test)
ADD_KUDU_TEST(kudu-admin-test)
ADD_KUDU_TEST_DEPENDENCIES(kudu-admin-test
kudu-admin)
+ADD_KUDU_TEST(kudu-tool-test)
+ADD_KUDU_TEST_DEPENDENCIES(kudu-tool-test
+ kudu)
ADD_KUDU_TEST(kudu-ts-cli-test)
ADD_KUDU_TEST_DEPENDENCIES(kudu-ts-cli-test
kudu-ts-cli)
http://git-wip-us.apache.org/repos/asf/kudu/blob/7321b38b/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
new file mode 100644
index 0000000..2700fb1
--- /dev/null
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -0,0 +1,154 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+#include <glog/stl_logging.h>
+
+#include "kudu/gutil/strings/split.h"
+#include "kudu/gutil/strings/substitute.h"
+#include "kudu/util/env.h"
+#include "kudu/util/path_util.h"
+#include "kudu/util/subprocess.h"
+#include "kudu/util/test_macros.h"
+#include "kudu/util/test_util.h"
+
+namespace kudu {
+namespace tools {
+
+using std::string;
+using std::vector;
+
+class ToolTest : public KuduTest {
+ public:
+ ToolTest() {
+ string exe;
+ CHECK_OK(env_->GetExecutablePath(&exe));
+ string bin_root = DirName(exe);
+ string tool_path = JoinPathSegments(bin_root, "kudu");
+ CHECK(env_->FileExists(tool_path)) << "kudu tool not found at " << tool_path;
+ tool_path_ = tool_path;
+ }
+
+ Status RunTool(const string& arg_str,
+ vector<string>* stdout_lines,
+ vector<string>* stderr_lines) const {
+ vector<string> args = { tool_path_ };
+ vector<string> more_args = strings::Split(arg_str, " ",
+ strings::SkipEmpty());
+ args.insert(args.end(), more_args.begin(), more_args.end());
+
+ string stdout;
+ string stderr;
+ Status s = Subprocess::Call(args, &stdout, &stderr);
+ StripWhiteSpace(&stdout);
+ StripWhiteSpace(&stderr);
+ *stdout_lines = strings::Split(stdout, "\n", strings::SkipEmpty());
+ *stderr_lines = strings::Split(stderr, "\n", strings::SkipEmpty());
+ return s;
+
+ }
+
+ void RunTestHelp(const string& arg_str,
+ const vector<string>& regexes,
+ const Status& expected_status = Status::OK()) const {
+ vector<string> stdout;
+ vector<string> stderr;
+ Status s = RunTool(arg_str, &stdout, &stderr);
+ SCOPED_TRACE(stdout);
+ SCOPED_TRACE(stderr);
+
+ // These are always true for showing help.
+ ASSERT_TRUE(s.IsRuntimeError());
+ ASSERT_TRUE(stdout.empty());
+ ASSERT_FALSE(stderr.empty());
+
+ // If it was an invalid command, the usage string is on the second line.
+ int usage_idx = 0;
+ if (!expected_status.ok()) {
+ ASSERT_EQ(expected_status.ToString(), stderr[0]);
+ usage_idx = 1;
+ }
+ ASSERT_EQ(0, stderr[usage_idx].find("Usage: "));
+
+ // Strip away everything up to the usage string to test for regexes.
+ vector<string> remaining_lines;
+ for (int i = usage_idx + 1; i < stderr.size(); i++) {
+ remaining_lines.push_back(stderr[i]);
+ }
+ for (const auto& r : regexes) {
+ ASSERT_STRINGS_ANY_MATCH(remaining_lines, r);
+ }
+ }
+
+ private:
+ string tool_path_;
+};
+
+TEST_F(ToolTest, TestTopLevelHelp) {
+ const vector<string> kTopLevelRegexes = {
+ "fs.*Kudu filesystem",
+ "pbc.*protobuf container",
+ "tablet.*Kudu replica"
+ };
+ NO_FATALS(RunTestHelp("", kTopLevelRegexes));
+ NO_FATALS(RunTestHelp("--help", kTopLevelRegexes));
+ NO_FATALS(RunTestHelp("not_a_mode", kTopLevelRegexes,
+ Status::InvalidArgument("unknown command 'not_a_mode'")));
+}
+
+TEST_F(ToolTest, TestModeHelp) {
+ {
+ const vector<string> kFsModeRegexes = {
+ "format.*new Kudu filesystem",
+ "print_uuid.*UUID of a Kudu filesystem"
+ };
+ NO_FATALS(RunTestHelp("fs", kFsModeRegexes));
+ NO_FATALS(RunTestHelp("fs not_a_mode", kFsModeRegexes,
+ Status::InvalidArgument("unknown command 'not_a_mode'")));
+ }
+ {
+ const vector<string> kTabletModeRegexes = {
+ "cmeta.*consensus metadata file",
+ "copy.*Copy a replica"
+ };
+ NO_FATALS(RunTestHelp("tablet", kTabletModeRegexes));
+ }
+ {
+ const vector<string> kCmetaModeRegexes = {
+ "print_replica_uuids.*Print all replica UUIDs",
+ "rewrite_raft_config.*Rewrite a replica"
+ };
+ NO_FATALS(RunTestHelp("tablet cmeta", kCmetaModeRegexes));
+ }
+}
+
+TEST_F(ToolTest, TestActionHelp) {
+ const vector<string> kFormatActionRegexes = {
+ "-fs_wal_dir \\(Directory",
+ "-fs_data_dirs \\(Comma-separated list",
+ "-uuid \\(The uuid"
+ };
+ NO_FATALS(RunTestHelp("fs format --help", kFormatActionRegexes));
+ NO_FATALS(RunTestHelp("fs format extra_arg", kFormatActionRegexes,
+ Status::InvalidArgument("too many arguments: 'extra_arg'")));
+}
+
+} // namespace tools
+} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/7321b38b/src/kudu/util/test_macros.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/test_macros.h b/src/kudu/util/test_macros.h
index e7950a9..a5f151f 100644
--- a/src/kudu/util/test_macros.h
+++ b/src/kudu/util/test_macros.h
@@ -63,7 +63,9 @@
ASSERT_THAT(str, testing::ContainsRegex(pattern))
// Batched substring regular expressions in extended regex (POSIX) syntax.
-#define ASSERT_STRINGS_MATCH(strings, pattern) do { \
+//
+// All strings must match the pattern.
+#define ASSERT_STRINGS_ALL_MATCH(strings, pattern) do { \
const auto& _strings = (strings); \
const auto& _pattern = (pattern); \
int _str_idx = 0; \
@@ -75,6 +77,23 @@
} \
} while (0)
+// Batched substring regular expressions in extended regex (POSIX) syntax.
+//
+// At least one string must match the pattern.
+#define ASSERT_STRINGS_ANY_MATCH(strings, pattern) do { \
+ const auto& _strings = (strings); \
+ const auto& _pattern = (pattern); \
+ bool matched = false; \
+ for (const auto& str : _strings) { \
+ if (testing::internal::RE::PartialMatch(str, testing::internal::RE(_pattern))) { \
+ matched = true; \
+ break; \
+ } \
+ } \
+ ASSERT_TRUE(matched) \
+ << "not one string matched pattern " << _pattern; \
+} while (0)
+
#define ASSERT_FILE_EXISTS(env, path) do { \
std::string _s = path; \
ASSERT_TRUE(env->FileExists(_s)) \