You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2016/09/16 17:13:32 UTC

kudu git commit: [c++client] added TestAutoFlushBackgroundDropSession

Repository: kudu
Updated Branches:
  refs/heads/master 09b1e09cb -> 1961305d8


[c++client] added TestAutoFlushBackgroundDropSession

As a follow-up for 1a062253e3fdc900a4b0b418520d2870b6de8846,
added new TestAutoFlushBackgroundDropSession test.
The test verifies that a session in AUTO_FLUSH_BACKGROUND mode can
be safely abandoned so its pending operations are not flushed.

Also, reduced number of write operations applied to the session and
updated the limit on mutation buffer size accordingly in
TestApplyTooMuchWithoutFlushing test to reduce running time for
ASAN/TSAN configurations.  The semantics of the test is to try
adding more data into the mutation buffer than the limit on the buffer
size: the crux here is in the relative sizes, not the absolute ones.

Change-Id: If136872a4200e18acbb587276fed28975afe3810
Reviewed-on: http://gerrit.cloudera.org:8080/4432
Tested-by: Kudu Jenkins
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/1961305d
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/1961305d
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/1961305d

Branch: refs/heads/master
Commit: 1961305d89b93382c485dc7c62a4d506530d28a7
Parents: 09b1e09
Author: Alexey Serbin <as...@cloudera.com>
Authored: Thu Sep 15 17:54:49 2016 -0700
Committer: Adar Dembo <ad...@cloudera.com>
Committed: Fri Sep 16 17:12:15 2016 +0000

----------------------------------------------------------------------
 src/kudu/client/client-test.cc | 62 +++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/1961305d/src/kudu/client/client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index 54e8c9e..daf4629 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -2134,32 +2134,30 @@ TEST_F(ClientTest, TestApplyToSessionWithoutFlushing_OpsBuffered) {
   DoApplyWithoutFlushTest(10000);
 }
 
-// Apply a large amount of data without calling Flush() in MANUAL_FLUSH mode,
+// Apply a large amount of data (relative to size of the mutation buffer)
+// without calling Flush() in MANUAL_FLUSH mode,
 // and ensure that we get an error on Apply() rather than sending a too-large
 // RPC to the server.
 TEST_F(ClientTest, TestApplyTooMuchWithoutFlushing) {
-
   // Applying a bunch of small rows without a flush should result
   // in an error.
-  {
-    const size_t kBufferSizeBytes = 1024 * 1024;
-    bool got_expected_error = false;
-    shared_ptr<KuduSession> session = client_->NewSession();
-    ASSERT_OK(session->SetFlushMode(KuduSession::MANUAL_FLUSH));
-    ASSERT_OK(session->SetMutationBufferSpace(kBufferSizeBytes));
-    for (int i = 0; i < kBufferSizeBytes; i++) {
-      Status s = ApplyInsertToSession(session.get(), client_table_, 1, 1, "x");
-      if (s.IsIncomplete()) {
-        ASSERT_STR_CONTAINS(s.ToString(), "not enough mutation buffer space");
-        got_expected_error = true;
-        break;
-      } else {
-        ASSERT_OK(s);
-      }
+  const size_t kBufferSizeBytes = 1024;
+  bool got_expected_error = false;
+  shared_ptr<KuduSession> session = client_->NewSession();
+  ASSERT_OK(session->SetFlushMode(KuduSession::MANUAL_FLUSH));
+  ASSERT_OK(session->SetMutationBufferSpace(kBufferSizeBytes));
+  for (int i = 0; i < kBufferSizeBytes; i++) {
+    Status s = ApplyInsertToSession(session.get(), client_table_, 1, 1, "x");
+    if (s.IsIncomplete()) {
+      ASSERT_STR_CONTAINS(s.ToString(), "not enough mutation buffer space");
+      got_expected_error = true;
+      break;
+    } else {
+      ASSERT_OK(s);
     }
-    ASSERT_TRUE(got_expected_error);
-    EXPECT_TRUE(session->HasPendingOperations());
   }
+  ASSERT_TRUE(got_expected_error);
+  EXPECT_TRUE(session->HasPendingOperations());
 }
 
 // Applying a big operation which does not fit into the buffer should
@@ -2429,6 +2427,32 @@ TEST_F(ClientTest, TestFlushModesCompareOpRatesRandomSize) {
   EXPECT_GT(t_afs.wall, t_afb.wall);
 }
 
+// A test which verifies that a session in AUTO_FLUSH_BACKGROUND mode can
+// be safely abandoned: its pending data should not be flushed.
+// This test also checks that the reference to a session stored by the
+// background flusher task is not leaked: the leak might appear due to
+// circular reference between the session and the messenger's reactor
+// which is used to execute the background flush task.
+TEST_F(ClientTest, TestAutoFlushBackgroundDropSession) {
+  const int32_t kFlushIntervalMs = 1000;
+  shared_ptr<KuduSession> session(client_->NewSession());
+  ASSERT_OK(session->SetMutationBufferFlushInterval(kFlushIntervalMs));
+  ASSERT_OK(session->SetFlushMode(KuduSession::AUTO_FLUSH_BACKGROUND));
+  ASSERT_OK(ApplyInsertToSession(session.get(), client_table_, 1, 1, "x"));
+  session.reset();
+
+  // Wait for the background flusher task to awake and try to do its job.
+  // The 3x extra is to deal with occasional delays to avoid flakiness.
+  SleepFor(MonoDelta::FromMilliseconds(3L * kFlushIntervalMs));
+
+  // The session should be gone, and the background flusher thread
+  // should notice that and do not perform flush, so no data is supposed
+  // to appear in the table.
+  vector<string> rows;
+  ScanTableToStrings(client_table_.get(), &rows);
+  EXPECT_TRUE(rows.empty());
+}
+
 // A test scenario for AUTO_FLUSH_BACKGROUND mode:
 // applying a bunch of small rows without a flush should not result in
 // an error, even with low limit on the buffer space. This is because