kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [3/5] kudu git commit: client/sample.cc: fixed a couple of crashes
Date Sat, 13 Aug 2016 02:08:48 GMT
client/sample.cc: fixed a couple of crashes

Fixed 'pure virtual method called' error with subsequent SIGABRT
termination due to attempt to access destroyed log callback object
while logging some messages from terminating reactor threads.

Fixed issue with an attempt to access non-existing element
of pending errors array with subsequent SIGSEGV termination.

Change-Id: Ic5fa3b812e6402a113bf5e432a3a451dc4cc3735
Reviewed-on: http://gerrit.cloudera.org:8080/3685
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <todd@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/883785c6
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/883785c6
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/883785c6

Branch: refs/heads/master
Commit: 883785c6ad27a7cbcf0cf92cce7864bdb5e7cf80
Parents: 9532197
Author: Alexey Serbin <aserbin@cloudera.com>
Authored: Wed Jul 20 00:02:35 2016 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Fri Aug 12 20:06:37 2016 +0000

----------------------------------------------------------------------
 src/kudu/client/samples/sample.cc | 67 ++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/883785c6/src/kudu/client/samples/sample.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/samples/sample.cc b/src/kudu/client/samples/sample.cc
index 4367822..94084e6 100644
--- a/src/kudu/client/samples/sample.cc
+++ b/src/kudu/client/samples/sample.cc
@@ -154,11 +154,13 @@ static Status InsertRows(const shared_ptr<KuduTable>& table,
int num_rows) {
   vector<KuduError*> errors;
   bool overflow;
   session->GetPendingErrors(&errors, &overflow);
-  s = overflow ? Status::IOError("Overflowed pending errors in session") :
-      errors.front()->status();
-  while (!errors.empty()) {
-    delete errors.back();
-    errors.pop_back();
+  if (!errors.empty()) {
+    s = overflow ? Status::IOError("Overflowed pending errors in session") :
+        errors.front()->status();
+    while (!errors.empty()) {
+      delete errors.back();
+      errors.pop_back();
+    }
   }
   KUDU_RETURN_NOT_OK(s);
 
@@ -216,23 +218,39 @@ static Status ScanRows(const shared_ptr<KuduTable>& table)
{
   return Status::OK();
 }
 
-static void LogCb(void* unused,
-                  kudu::client::KuduLogSeverity severity,
-                  const char* filename,
-                  int line_number,
-                  const struct ::tm* time,
-                  const char* message,
-                  size_t message_len) {
-  KUDU_LOG(INFO) << "Received log message from Kudu client library";
-  KUDU_LOG(INFO) << " Severity: " << severity;
-  KUDU_LOG(INFO) << " Filename: " << filename;
-  KUDU_LOG(INFO) << " Line number: " << line_number;
-  char time_buf[32];
-  // Example: Tue Mar 24 11:46:43 2015.
-  KUDU_CHECK(strftime(time_buf, sizeof(time_buf), "%a %b %d %T %Y", time));
-  KUDU_LOG(INFO) << " Time: " << time_buf;
-  KUDU_LOG(INFO) << " Message: " << string(message, message_len);
-}
+// A helper class providing custom logging callback. It also manages
+// automatic callback installation and removal.
+class LogCallbackHelper {
+ public:
+  LogCallbackHelper() : log_cb_(&LogCallbackHelper::LogCb, NULL) {
+    kudu::client::InstallLoggingCallback(&log_cb_);
+  }
+
+  ~LogCallbackHelper() {
+    kudu::client::UninstallLoggingCallback();
+  }
+
+  static void LogCb(void* unused,
+                    kudu::client::KuduLogSeverity severity,
+                    const char* filename,
+                    int line_number,
+                    const struct ::tm* time,
+                    const char* message,
+                    size_t message_len) {
+    KUDU_LOG(INFO) << "Received log message from Kudu client library";
+    KUDU_LOG(INFO) << " Severity: " << severity;
+    KUDU_LOG(INFO) << " Filename: " << filename;
+    KUDU_LOG(INFO) << " Line number: " << line_number;
+    char time_buf[32];
+    // Example: Tue Mar 24 11:46:43 2015.
+    KUDU_CHECK(strftime(time_buf, sizeof(time_buf), "%a %b %d %T %Y", time));
+    KUDU_LOG(INFO) << " Time: " << time_buf;
+    KUDU_LOG(INFO) << " Message: " << string(message, message_len);
+  }
+
+ private:
+  kudu::client::KuduLoggingFunctionCallback<void*> log_cb_;
+};
 
 int main(int argc, char* argv[]) {
   KUDU_LOG(INFO) << "Running with Kudu client version: " <<
@@ -240,8 +258,8 @@ int main(int argc, char* argv[]) {
   KUDU_LOG(INFO) << "Long version info: " <<
       kudu::client::GetAllVersionInfo();
 
-  kudu::client::KuduLoggingFunctionCallback<void*> log_cb(&LogCb, NULL);
-  kudu::client::InstallLoggingCallback(&log_cb);
+  // This is to install and automatically un-install custom logging callback.
+  LogCallbackHelper log_cb_helper;
 
   if (argc != 2) {
     KUDU_LOG(FATAL) << "usage: " << argv[0] << " <master host>";
@@ -295,5 +313,6 @@ int main(int argc, char* argv[]) {
 
   // Done!
   KUDU_LOG(INFO) << "Done";
+
   return 0;
 }


Mime
View raw message