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/05/02 19:29:53 UTC

[1/2] incubator-kudu git commit: tracing: add a 'label' for child traces

Repository: incubator-kudu
Updated Branches:
  refs/heads/master d0ec5205a -> 071c0391d


tracing: add a 'label' for child traces

Currently, when a trace has a child trace, it's not obvious how it's related to
the parent. This adds a simple label.

Change-Id: I2b9a7655131c1013fea26e5bc87651b38ff1920f
Reviewed-on: http://gerrit.cloudera.org:8080/2888
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>


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

Branch: refs/heads/master
Commit: 20e62835d2c79ad97db4f24ba8567313df6215c7
Parents: d0ec520
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Apr 27 14:48:19 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Mon May 2 17:28:56 2016 +0000

----------------------------------------------------------------------
 .../tablet/transactions/transaction_driver.cc   |  2 +-
 src/kudu/util/memory/arena.h                    | 11 +++++++++
 src/kudu/util/trace-test.cc                     |  4 ++--
 src/kudu/util/trace.cc                          | 24 +++++++++++++-------
 src/kudu/util/trace.h                           |  9 ++++++--
 5 files changed, 37 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/20e62835/src/kudu/tablet/transactions/transaction_driver.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction_driver.cc b/src/kudu/tablet/transactions/transaction_driver.cc
index 6b9ff23..cf065cf 100644
--- a/src/kudu/tablet/transactions/transaction_driver.cc
+++ b/src/kudu/tablet/transactions/transaction_driver.cc
@@ -63,7 +63,7 @@ TransactionDriver::TransactionDriver(TransactionTracker *txn_tracker,
       replication_state_(NOT_REPLICATING),
       prepare_state_(NOT_PREPARED) {
   if (Trace::CurrentTrace()) {
-    Trace::CurrentTrace()->AddChildTrace(trace_.get());
+    Trace::CurrentTrace()->AddChildTrace("txn", trace_.get());
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/20e62835/src/kudu/util/memory/arena.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/arena.h b/src/kudu/util/memory/arena.h
index 2362f21..4abd1d5 100644
--- a/src/kudu/util/memory/arena.h
+++ b/src/kudu/util/memory/arena.h
@@ -127,6 +127,9 @@ class ArenaBase {
   // See AddSlice above for detail on memory lifetime.
   bool RelocateSlice(const Slice &src, Slice *dst);
 
+  // Similar to the above, but for StringPiece.
+  bool RelocateStringPiece(const StringPiece& src, StringPiece* sp);
+
   // Reserves a blob of the specified size in the arena, and returns a pointer
   // to it. The caller can then fill the allocated memory. The pointer is
   // guaranteed to remain valid during the lifetime of the arena.
@@ -460,6 +463,14 @@ inline bool ArenaBase<THREADSAFE>::RelocateSlice(const Slice &src, Slice *dst) {
 }
 
 
+template <bool THREADSAFE>
+inline bool ArenaBase<THREADSAFE>::RelocateStringPiece(const StringPiece& src, StringPiece* sp) {
+  Slice slice(src.data(), src.size());
+  if (!RelocateSlice(slice, &slice)) return false;
+  *sp = StringPiece(reinterpret_cast<const char*>(slice.data()), slice.size());
+  return true;
+}
+
 template<bool THREADSAFE>
 template<class T>
 inline T *ArenaBase<THREADSAFE>::NewObject() {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/20e62835/src/kudu/util/trace-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/trace-test.cc b/src/kudu/util/trace-test.cc
index 753dda1..28ce940 100644
--- a/src/kudu/util/trace-test.cc
+++ b/src/kudu/util/trace-test.cc
@@ -93,7 +93,7 @@ TEST_F(TraceTest, TestChildTrace) {
   scoped_refptr<Trace> traceA(new Trace);
   scoped_refptr<Trace> traceB(new Trace);
   ADOPT_TRACE(traceA.get());
-  traceA->AddChildTrace(traceB.get());
+  traceA->AddChildTrace("child", traceB.get());
   TRACE("hello from traceA");
   {
     ADOPT_TRACE(traceB.get());
@@ -101,7 +101,7 @@ TEST_F(TraceTest, TestChildTrace) {
   }
   EXPECT_EQ(XOutDigits(traceA->DumpToString(Trace::NO_FLAGS)),
             "XXXX XX:XX:XX.XXXXXX trace-test.cc:XX] hello from traceA\n"
-            "Related trace:\n"
+            "Related trace 'child':\n"
             "XXXX XX:XX:XX.XXXXXX trace-test.cc:XXX] hello from traceB\n");
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/20e62835/src/kudu/util/trace.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/trace.cc b/src/kudu/util/trace.cc
index cde3830..ee68fbb 100644
--- a/src/kudu/util/trace.cc
+++ b/src/kudu/util/trace.cc
@@ -22,6 +22,7 @@
 #include <iostream>
 #include <strstream>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include "kudu/gutil/strings/substitute.h"
@@ -122,7 +123,7 @@ void Trace::Dump(std::ostream* out, int flags) const {
   // (whereas doing the logging itself while holding the lock might be
   // too slow, if the output stream is a file, for example).
   vector<TraceEntry*> entries;
-  vector<scoped_refptr<Trace> > child_traces;
+  vector<pair<StringPiece, scoped_refptr<Trace>>> child_traces;
   {
     lock_guard<simple_spinlock> l(&lock_);
     for (TraceEntry* cur = entries_head_;
@@ -172,9 +173,10 @@ void Trace::Dump(std::ostream* out, int flags) const {
     *out << std::endl;
   }
 
-  for (scoped_refptr<Trace> child_trace : child_traces) {
-    *out << "Related trace:" << std::endl;
-    *out << child_trace->DumpToString(flags & (~INCLUDE_METRICS));
+  for (const auto& entry : child_traces) {
+    const auto& t = entry.second;
+    *out << "Related trace '" << entry.first << "':" << std::endl;
+    *out << t->DumpToString(flags & (~INCLUDE_METRICS));
   }
 
   if (flags & INCLUDE_METRICS) {
@@ -208,8 +210,12 @@ void Trace::MetricsToJSON(JsonWriter* jw) const {
   if (!child_traces_.empty()) {
     jw->String("child_traces");
     jw->StartArray();
-    for (const auto& t : child_traces_) {
-      t->MetricsToJSON(jw);
+
+    for (const auto& e : child_traces_) {
+      jw->StartArray();
+      jw->String(e.first.data(), e.first.size());
+      e.second->MetricsToJSON(jw);
+      jw->EndArray();
     }
     jw->EndArray();
   }
@@ -225,10 +231,12 @@ void Trace::DumpCurrentTrace() {
   t->Dump(&std::cerr, true);
 }
 
-void Trace::AddChildTrace(Trace* child_trace) {
+void Trace::AddChildTrace(StringPiece label, Trace* child_trace) {
+  CHECK(arena_->RelocateStringPiece(label, &label));
+
   lock_guard<simple_spinlock> l(&lock_);
   scoped_refptr<Trace> ptr(child_trace);
-  child_traces_.push_back(ptr);
+  child_traces_.emplace_back(label, ptr);
 }
 
 } // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/20e62835/src/kudu/util/trace.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/trace.h b/src/kudu/util/trace.h
index 99e1da7..ec76a35 100644
--- a/src/kudu/util/trace.h
+++ b/src/kudu/util/trace.h
@@ -19,6 +19,7 @@
 
 #include <iosfwd>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include "kudu/gutil/macros.h"
@@ -145,7 +146,11 @@ class Trace : public RefCountedThreadSafe<Trace> {
   std::string MetricsAsJSON() const;
 
   // Attaches the given trace which will get appended at the end when Dumping.
-  void AddChildTrace(Trace* child_trace);
+  //
+  // The 'label' does not necessarily have to be unique, and is used to identify
+  // the child trace when dumped. The contents of the StringPiece are copied
+  // into this trace's arena.
+  void AddChildTrace(StringPiece label, Trace* child_trace);
 
   // Return the current trace attached to this thread, if there is one.
   static Trace* CurrentTrace() {
@@ -189,7 +194,7 @@ class Trace : public RefCountedThreadSafe<Trace> {
   // The tail of the linked list of entries (allocated inside arena_)
   TraceEntry* entries_tail_;
 
-  std::vector<scoped_refptr<Trace> > child_traces_;
+  std::vector<std::pair<StringPiece, scoped_refptr<Trace>>> child_traces_;
 
   TraceMetrics metrics_;
 


[2/2] incubator-kudu git commit: rpc: bump default max message size to 50MB

Posted by to...@apache.org.
rpc: bump default max message size to 50MB

It seems that the current default of only 8MB can be problematic
in a few cases:

* If tables contain larger cells, it's not hard to overflow the 8MB for scanner
  results.
* When writing, if users aren't very careful about managing batch sizes,
  it's also possible to overflow.

Of course, it's also possible to overflow 50MB, so in some cases this
commit just "delays the inevitable". But, I did a survey of other RPC
systems and found that 8MB is far lower than what those expect:

- GRPC max frame size is 100MB by default, and allows the user to increase
  it if necessary[1]
- Hadoop RPC defaults to 64MB and is configurable[2]. Responses larger than
  1MB will be logged by default. Note that HDFS does not use RPC for
  data transfer, so >1MB RPCs are unlikely.
- HBase RPC sets the maximum request to 256MB and warns for responses
  larger than 100MB.[3]

This commit also changes the remote bootstrap code path to aim for 4MB
chunks regardless of the max RPC message size, since it doesn't make
sense to do IO in 50MB units.

[1] https://github.com/grpc/grpc-java/issues/917
[2] https://github.com/apache/hadoop-common/blob/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java#L77
[3] https://github.com/apache/hbase/blob/master/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java#L268

Change-Id: I1df399c5dd28ec9539fbd701d26ff2c7467991c8
Reviewed-on: http://gerrit.cloudera.org:8080/2889
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>


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

Branch: refs/heads/master
Commit: 071c0391ddca1bd9f470eaa00e34e0b329a2ee53
Parents: 20e6283
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Apr 27 20:29:35 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Mon May 2 17:29:18 2016 +0000

----------------------------------------------------------------------
 src/kudu/rpc/transfer.cc                     | 15 +++++++++--
 src/kudu/tserver/remote_bootstrap_client.cc  |  6 ++---
 src/kudu/tserver/remote_bootstrap_session.cc | 31 +++++++++++++----------
 3 files changed, 34 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/071c0391/src/kudu/rpc/transfer.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/transfer.cc b/src/kudu/rpc/transfer.cc
index 553de5f..a105ad6 100644
--- a/src/kudu/rpc/transfer.cc
+++ b/src/kudu/rpc/transfer.cc
@@ -33,11 +33,22 @@
 #include "kudu/util/net/sockaddr.h"
 #include "kudu/util/net/socket.h"
 
-DEFINE_int32(rpc_max_message_size, (8 * 1024 * 1024),
-             "The maximum size of a message that any RPC that the server will accept.");
+DEFINE_int32(rpc_max_message_size, (50 * 1024 * 1024),
+             "The maximum size of a message that any RPC that the server will accept. "
+             "Must be at least 1MB.");
 TAG_FLAG(rpc_max_message_size, advanced);
 TAG_FLAG(rpc_max_message_size, runtime);
 
+static bool ValidateMaxMessageSize(const char* flagname, int32_t value) {
+  if (value < 1 * 1024 * 1024) {
+    LOG(ERROR) << flagname << " must be at least 1MB.";
+    return false;
+  }
+  return true;
+}
+static bool dummy = google::RegisterFlagValidator(
+    &FLAGS_rpc_max_message_size, &ValidateMaxMessageSize);
+
 namespace kudu {
 namespace rpc {
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/071c0391/src/kudu/tserver/remote_bootstrap_client.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/remote_bootstrap_client.cc b/src/kudu/tserver/remote_bootstrap_client.cc
index 4e00a06..13b698e 100644
--- a/src/kudu/tserver/remote_bootstrap_client.cc
+++ b/src/kudu/tserver/remote_bootstrap_client.cc
@@ -61,6 +61,8 @@ DEFINE_int32(remote_bootstrap_dowload_file_inject_latency_ms, 0,
              "to take much longer. For use in tests only.");
 TAG_FLAG(remote_bootstrap_dowload_file_inject_latency_ms, hidden);
 
+DECLARE_int32(remote_bootstrap_transfer_chunk_size_bytes);
+
 // RETURN_NOT_OK_PREPEND() with a remote-error unwinding step.
 #define RETURN_NOT_OK_UNWIND_PREPEND(status, controller, msg) \
   RETURN_NOT_OK_PREPEND(UnwindRemoteError(status, controller), msg)
@@ -497,8 +499,6 @@ template<class Appendable>
 Status RemoteBootstrapClient::DownloadFile(const DataIdPB& data_id,
                                            Appendable* appendable) {
   uint64_t offset = 0;
-  int32_t max_length = FLAGS_rpc_max_message_size - 1024; // Leave 1K for message headers.
-
   rpc::RpcController controller;
   controller.set_timeout(MonoDelta::FromMilliseconds(session_idle_timeout_millis_));
   FetchDataRequestPB req;
@@ -509,7 +509,7 @@ Status RemoteBootstrapClient::DownloadFile(const DataIdPB& data_id,
     req.set_session_id(session_id_);
     req.mutable_data_id()->CopyFrom(data_id);
     req.set_offset(offset);
-    req.set_max_length(max_length);
+    req.set_max_length(FLAGS_remote_bootstrap_transfer_chunk_size_bytes);
 
     FetchDataResponsePB resp;
     RETURN_NOT_OK_UNWIND_PREPEND(proxy_->FetchData(req, &resp, &controller),

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/071c0391/src/kudu/tserver/remote_bootstrap_session.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/remote_bootstrap_session.cc b/src/kudu/tserver/remote_bootstrap_session.cc
index 964abe5..5369680 100644
--- a/src/kudu/tserver/remote_bootstrap_session.cc
+++ b/src/kudu/tserver/remote_bootstrap_session.cc
@@ -27,9 +27,15 @@
 #include "kudu/rpc/transfer.h"
 #include "kudu/server/metadata.h"
 #include "kudu/tablet/tablet_peer.h"
+#include "kudu/util/flag_tags.h"
 #include "kudu/util/stopwatch.h"
 #include "kudu/util/trace.h"
 
+DEFINE_int32(remote_bootstrap_transfer_chunk_size_bytes, 4 * 1024 * 1024,
+             "Size of chunks to transfer when copying tablets between "
+             "tablet servers.");
+TAG_FLAG(remote_bootstrap_transfer_chunk_size_bytes, hidden);
+
 namespace kudu {
 namespace tserver {
 
@@ -153,20 +159,19 @@ const std::string& RemoteBootstrapSession::requestor_uuid() const {
 
 // Determine the length of the data chunk to return to the client.
 static int64_t DetermineReadLength(int64_t bytes_remaining, int64_t requested_len) {
-  // Determine the size of the chunks we want to read.
-  // Choose "system max" as a multiple of typical HDD block size (4K) with 4K to
-  // spare for other stuff in the message, like headers, other protobufs, etc.
-  const int32_t kSpareBytes = 4096;
-  const int32_t kDiskSectorSize = 4096;
-  int32_t system_max_chunk_size =
-      ((FLAGS_rpc_max_message_size - kSpareBytes) / kDiskSectorSize) * kDiskSectorSize;
-  CHECK_GT(system_max_chunk_size, 0) << "rpc_max_message_size is too low to transfer data: "
-                                     << FLAGS_rpc_max_message_size;
+  // Overhead in the RPC for things like headers, protobuf data, etc.
+  static const int kOverhead = 4096;
 
-  // The min of the {requested, system} maxes is the effective max.
-  int64_t maxlen = (requested_len > 0) ? std::min<int64_t>(requested_len, system_max_chunk_size) :
-                                        system_max_chunk_size;
-  return std::min(bytes_remaining, maxlen);
+  if (requested_len <= 0) {
+    requested_len = FLAGS_remote_bootstrap_transfer_chunk_size_bytes;
+  } else {
+    requested_len = std::min<int64_t>(requested_len,
+                                      FLAGS_remote_bootstrap_transfer_chunk_size_bytes);
+  }
+  requested_len = std::min<int64_t>(requested_len, FLAGS_rpc_max_message_size - kOverhead);
+  CHECK_GT(requested_len, 0) << "rpc_max_message_size is too low to transfer data: "
+                                     << FLAGS_rpc_max_message_size;
+  return std::min(bytes_remaining, requested_len);
 }
 
 // Calculate the size of the data to return given a maximum client message