You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2016/10/20 14:05:46 UTC
kudu git commit: log: add a test for race conditions
Repository: kudu
Updated Branches:
refs/heads/master af2ba10c2 -> 676c0d0cf
log: add a test for race conditions
This adds new test coverage in mt-log-test to look for races between
log rolls and other operations. It doesn't currently find any bug, but
prior to 127438af30356f1afedb862166c907ff754d1c55 it reproduced a crash
bug fairly reliably, so the additional test coverage is probably worth
having.
Change-Id: Ic6dd40cf9ac628f56f0c467bcd9eeb2191124836
Reviewed-on: http://gerrit.cloudera.org:8080/4638
Tested-by: Kudu Jenkins
Reviewed-by: Mike Percy <mp...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/676c0d0c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/676c0d0c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/676c0d0c
Branch: refs/heads/master
Commit: 676c0d0cfade74a7a7f10c7f49603e686947e23b
Parents: af2ba10
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Oct 5 16:30:29 2016 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Thu Oct 20 14:05:18 2016 +0000
----------------------------------------------------------------------
src/kudu/consensus/mt-log-test.cc | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/676c0d0c/src/kudu/consensus/mt-log-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/mt-log-test.cc b/src/kudu/consensus/mt-log-test.cc
index 7407614..a1bfb87 100644
--- a/src/kudu/consensus/mt-log-test.cc
+++ b/src/kudu/consensus/mt-log-test.cc
@@ -18,8 +18,10 @@
#include "kudu/consensus/log-test-base.h"
#include <algorithm>
+#include <atomic>
#include <memory>
#include <mutex>
+#include <thread>
#include <vector>
#include "kudu/consensus/log_index.h"
@@ -135,9 +137,28 @@ class MultiThreadedLogTest : public LogTestBase {
&MultiThreadedLogTest::LogWriterThread, this, i, &new_thread));
threads_.push_back(new_thread);
}
+
+ // Start a thread which calls some read-only methods on the log
+ // to check for races against writers.
+ std::atomic<bool> stop_reader(false);
+ std::thread reader_thread([&]() {
+ std::map<int64_t, int64_t> map;
+ OpId opid;
+ while (!stop_reader) {
+ log_->GetLatestEntryOpId(&opid);
+ log_->GetReplaySizeMap(&map);
+ IgnoreResult(log_->GetGCableDataSize(RetentionIndexes(FLAGS_num_batches_per_thread)));
+ }
+ });
+
+ // Wait for the writers to finish.
for (scoped_refptr<kudu::Thread>& thread : threads_) {
ASSERT_OK(ThreadJoiner(thread.get()).Join());
}
+
+ // Then stop the reader and join on it as well.
+ stop_reader = true;
+ reader_thread.join();
}
private:
ThreadSafeRandom random_;
@@ -146,6 +167,9 @@ class MultiThreadedLogTest : public LogTestBase {
};
TEST_F(MultiThreadedLogTest, TestAppends) {
+ // Roll frequently to stress related code paths.
+ options_.segment_size_mb = 1;
+
ASSERT_OK(BuildLog());
int start_current_id = current_index_;
LOG_TIMING(INFO, strings::Substitute("inserting $0 batches($1 threads, $2 per-thread)",