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 2017/05/04 01:06:36 UTC
[1/3] kudu git commit: [integration-tests] fixed flake in
SecurityUnknownTskTest
Repository: kudu
Updated Branches:
refs/heads/master b797913a6 -> 579cb0b14
[integration-tests] fixed flake in SecurityUnknownTskTest
As it turned out, running the ErrorUnavailableCommonOperations scenario
of the SecurityUnknownTskTest test along with other activity sometimes
leads to timeout on creating the test table: ~200 out of 1000 runs fail
if running with --stress-cpu-threads=8 (that was 0 out of 1000 if
running without the parallel stress treads). Bumping up the timeout
from 1 to 3 seconds fixes the issue (0 out of 1000 runs fail even if
running with --stress-cpu-threads=10).
Change-Id: I57fbceacaaf20ccf242156cdea72afff1714e1c3
Reviewed-on: http://gerrit.cloudera.org:8080/6771
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/c6af7185
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/c6af7185
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/c6af7185
Branch: refs/heads/master
Commit: c6af71856a23522ac3fae46a17d9d027cc6ee5c9
Parents: b797913
Author: Alexey Serbin <as...@cloudera.com>
Authored: Sun Apr 30 22:25:10 2017 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Wed May 3 23:58:12 2017 +0000
----------------------------------------------------------------------
src/kudu/integration-tests/security-unknown-tsk-itest.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/c6af7185/src/kudu/integration-tests/security-unknown-tsk-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/security-unknown-tsk-itest.cc b/src/kudu/integration-tests/security-unknown-tsk-itest.cc
index e610b6c..d537ad9 100644
--- a/src/kudu/integration-tests/security-unknown-tsk-itest.cc
+++ b/src/kudu/integration-tests/security-unknown-tsk-itest.cc
@@ -187,7 +187,7 @@ class SecurityUnknownTskTest : public KuduTest {
// and failure scenarios for the selected subset of RPCs.
TEST_F(SecurityUnknownTskTest, ErrorUnavailableCommonOperations) {
const string table_name = "security-unknown-tsk-itest";
- const int64_t timeout_seconds = 1;
+ const int64_t timeout_seconds = 3;
shared_ptr<KuduClient> client;
ASSERT_OK(cluster_->CreateClient(
[3/3] kudu git commit: KUDU-1992. striped64: don't heap-allocate the
threadlocal hashcode
Posted by to...@apache.org.
KUDU-1992. striped64: don't heap-allocate the threadlocal hashcode
KUDU-1992 describes a bug in which the destructor of one threadlocal
object ended up referring to another threadlocal object. Specifically, a
threadlocal cached block destructor ended up incrementing a metric which
was implemented by a LongAdder (inheriting from Striped64). The
LongAdder uses a threadlocal hashcode to avoid contention.
In the crash described in the bug, the striped64's TLS hashcode was
destructed before the other destructor ran, causing a
heap-use-after-free.
This patch should fix the issue by making the threadlocal hashcode be a
POD threadlocal rather than a pointer to a heap-allocated object. Thus
there is no destructor to run, and no chance that the destruction order
can cause this crash.
This fix seemed simpler than trying to ensure some specific ordering of
threadlocal destructors (eg by assigning destructor priorities or adding
some kind of dependency graph).
Before the patch, I was able to reproduce the crash 2/1000 times running
RaftConsensusITest.TestAutoCreateReplica. After the patch, I ran it 5000
times with no failures.
Change-Id: I2d4e5264134c70ced434c3ae8da5866a151464d5
Reviewed-on: http://gerrit.cloudera.org:8080/6791
Reviewed-by: Adar Dembo <ad...@cloudera.com>
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/579cb0b1
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/579cb0b1
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/579cb0b1
Branch: refs/heads/master
Commit: 579cb0b145ad141cd3b49324406c85fe2ca96b15
Parents: d07ecd6
Author: Todd Lipcon <to...@apache.org>
Authored: Wed May 3 14:33:50 2017 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu May 4 00:30:09 2017 +0000
----------------------------------------------------------------------
src/kudu/util/striped64.cc | 40 +++++++++++++++++++++-------------------
src/kudu/util/striped64.h | 14 +++++---------
2 files changed, 26 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/579cb0b1/src/kudu/util/striped64.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/striped64.cc b/src/kudu/util/striped64.cc
index a0951c7..8343177 100644
--- a/src/kudu/util/striped64.cc
+++ b/src/kudu/util/striped64.cc
@@ -15,27 +15,18 @@
// specific language governing permissions and limitations
// under the License.
+#include "kudu/util/striped64.h"
+
#include "kudu/util/monotime.h"
#include "kudu/util/random.h"
-#include "kudu/util/striped64.h"
#include "kudu/util/threadlocal.h"
-using kudu::striped64::internal::HashCode;
using kudu::striped64::internal::Cell;
namespace kudu {
namespace striped64 {
namespace internal {
-//
-// HashCode
-//
-
-HashCode::HashCode() {
- Random r((MonoTime::Now() - MonoTime::Min()).ToNanoseconds());
- const uint64_t hash = r.Next64();
- code_ = (hash == 0) ? 1 : hash; // Avoid zero to allow xorShift rehash
-}
//
// Cell
@@ -50,8 +41,8 @@ Cell::Cell()
//
// Striped64
//
+__thread uint64_t Striped64::tls_hashcode_ = 0;
const uint32_t Striped64::kNumCpus = sysconf(_SC_NPROCESSORS_ONLN);
-DEFINE_STATIC_THREAD_LOCAL(HashCode, Striped64, hashcode_);
Striped64::Striped64()
: busy_(false),
@@ -60,13 +51,25 @@ Striped64::Striped64()
num_cells_(0) {
}
+uint64_t Striped64::get_tls_hashcode() {
+ if (PREDICT_FALSE(tls_hashcode_ == 0)) {
+ Random r((MonoTime::Now() - MonoTime::Min()).ToNanoseconds());
+ const uint64_t hash = r.Next64();
+ // Avoid zero to allow xorShift rehash, and because 0 indicates an unset
+ // hashcode above.
+ tls_hashcode_ = (hash == 0) ? 1 : hash;
+ }
+ return tls_hashcode_;
+}
+
+
Striped64::~Striped64() {
// Cell is a POD, so no need to destruct each one.
free(cell_buffer_);
}
-void Striped64::RetryUpdate(int64_t x, Rehash contention) {
- uint64_t h = hashcode_->code_;
+void Striped64::RetryUpdate(int64_t x, Rehash to_rehash) {
+ uint64_t h = get_tls_hashcode();
// There are three operations in this loop.
//
// 1. Try to add to the Cell hash table entry for the thread if the table exists.
@@ -79,9 +82,9 @@ void Striped64::RetryUpdate(int64_t x, Rehash contention) {
while (true) {
int32_t n = base::subtle::Acquire_Load(&num_cells_);
if (n > 0) {
- if (contention == kRehash) {
+ if (to_rehash == kRehash) {
// CAS failed already, rehash before trying to increment.
- contention = kNoRehash;
+ to_rehash = kNoRehash;
} else {
Cell *cell = &(cells_[(n - 1) & h]);
int64_t v = cell->value_.Load();
@@ -124,7 +127,7 @@ void Striped64::RetryUpdate(int64_t x, Rehash contention) {
}
}
// Record index for next time
- hashcode_->code_ = h;
+ tls_hashcode_ = h;
}
void Striped64::InternalReset(int64_t initialValue) {
@@ -136,12 +139,11 @@ void Striped64::InternalReset(int64_t initialValue) {
}
void LongAdder::IncrementBy(int64_t x) {
- INIT_STATIC_THREAD_LOCAL(HashCode, hashcode_);
// Use hash table if present. If that fails, call RetryUpdate to rehash and retry.
// If no hash table, try to CAS the base counter. If that fails, RetryUpdate to init the table.
const int32_t n = base::subtle::Acquire_Load(&num_cells_);
if (n > 0) {
- Cell *cell = &(cells_[(n - 1) & hashcode_->code_]);
+ Cell *cell = &(cells_[(n - 1) & get_tls_hashcode()]);
DCHECK_EQ(0, reinterpret_cast<const uintptr_t>(cell) & (sizeof(Cell) - 1))
<< " unaligned Cell not allowed for Striped64" << std::endl;
const int64_t old = cell->value_.Load();
http://git-wip-us.apache.org/repos/asf/kudu/blob/579cb0b1/src/kudu/util/striped64.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/striped64.h b/src/kudu/util/striped64.h
index a7ffec7..a3b829b 100644
--- a/src/kudu/util/striped64.h
+++ b/src/kudu/util/striped64.h
@@ -29,12 +29,6 @@ class Striped64;
namespace striped64 {
namespace internal {
-struct HashCode {
- public:
- HashCode();
- uint64_t code_;
-};
-
#define ATOMIC_INT_SIZE sizeof(AtomicInt<int64_t>)
// Padded POD container for AtomicInt. This prevents false sharing of cache lines.
class Cell {
@@ -137,12 +131,14 @@ class Striped64 {
striped64::internal::Cell* cells_;
int32_t num_cells_;
+ protected:
+ static uint64_t get_tls_hashcode();
+
+ private:
// Static hash code per-thread. Shared across all instances to limit thread-local pollution.
// Also, if a thread hits a collision on one Striped64, it's also likely to collide on
// other Striped64s too.
- DECLARE_STATIC_THREAD_LOCAL(striped64::internal::HashCode, hashcode_);
-
- private:
+ static __thread uint64_t tls_hashcode_;
// Number of CPUs, to place bound on table size.
static const uint32_t kNumCpus;
[2/3] kudu git commit: [java-client] clear non-covered entries from
meta cache on table open
Posted by to...@apache.org.
[java-client] clear non-covered entries from meta cache on table open
Clearing non-covered range entries from the meta cache on table open
makes it easier to share client instances among different contexts
without having to worry about polluting the non-covering range cache.
Change-Id: I2d18f23045135a2276657da6808d65294be77653
Reviewed-on: http://gerrit.cloudera.org:8080/6719
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/d07ecd6d
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/d07ecd6d
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/d07ecd6d
Branch: refs/heads/master
Commit: d07ecd6ded01201c912d2e336611a6a941f48d98
Parents: c6af718
Author: Dan Burkert <da...@apache.org>
Authored: Fri Apr 21 17:43:42 2017 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu May 4 00:10:28 2017 +0000
----------------------------------------------------------------------
.../org/apache/kudu/client/AsyncKuduClient.java | 17 +++++++-
.../java/org/apache/kudu/client/KuduClient.java | 8 +++-
.../apache/kudu/client/TableLocationsCache.java | 16 ++++++++
.../org/apache/kudu/client/TestKuduClient.java | 42 ++++++++++++++++++++
4 files changed, 79 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/d07ecd6d/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
index fbc181a..c2126a4 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
@@ -419,8 +419,13 @@ public class AsyncKuduClient implements AutoCloseable {
}
/**
- * Open the table with the given name. If the table was just created, the Deferred will only get
- * called back when all the tablets have been successfully created.
+ * Open the table with the given name. If the table was just created, the
+ * Deferred will only get called back when all the tablets have been
+ * successfully created.
+ *
+ * New range partitions created by other clients will immediately be available
+ * after opening the table.
+ *
* @param name table to open
* @return a KuduTable if the table exists, else a MasterErrorException
*/
@@ -466,6 +471,14 @@ public class AsyncKuduClient implements AutoCloseable {
// return a different, non-triggered Deferred.
Deferred<KuduTable> d = fakeRpc.getDeferred();
if (response.isCreateTableDone()) {
+ // When opening a table, clear the existing cached non-covered range entries.
+ // This avoids surprises where a new table instance won't be able to see the
+ // current range partitions of a table for up to the ttl.
+ TableLocationsCache cache = tableLocations.get(response.getTableId());
+ if (cache != null) {
+ cache.clearNonCoveredRangeEntries();
+ }
+
LOG.debug("Opened table {}", name);
fakeRpc.callback(table);
} else {
http://git-wip-us.apache.org/repos/asf/kudu/blob/d07ecd6d/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
index fc2e4da..b6ecb68 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
@@ -175,8 +175,12 @@ public class KuduClient implements AutoCloseable {
}
/**
- * Open the table with the given name. If the table was just created, this method will block until
- * all its tablets have also been created.
+ * Open the table with the given name. If the table was just created, this
+ * method will block until all its tablets have also been created.
+ *
+ * New range partitions created by other clients will immediately be available
+ * after opening the table.
+ *
* @param name table to open
* @return a KuduTable if the table exists
* @throws KuduException if anything went wrong
http://git-wip-us.apache.org/repos/asf/kudu/blob/d07ecd6d/java/kudu-client/src/main/java/org/apache/kudu/client/TableLocationsCache.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/TableLocationsCache.java b/java/kudu-client/src/main/java/org/apache/kudu/client/TableLocationsCache.java
index 12400d4..7b60579 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/TableLocationsCache.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/TableLocationsCache.java
@@ -19,6 +19,7 @@ package org.apache.kudu.client;
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
@@ -211,6 +212,21 @@ class TableLocationsCache {
}
}
+ /**
+ * Clears all non-covered range entries from the cache.
+ */
+ public void clearNonCoveredRangeEntries() {
+ rwl.writeLock().lock();
+ try {
+ Iterator<Map.Entry<byte[], Entry>> it = entries.entrySet().iterator();
+ while (it.hasNext()) {
+ if (it.next().getValue().isNonCoveredRange()) it.remove();
+ }
+ } finally {
+ rwl.writeLock().unlock();
+ }
+ }
+
@Override
public String toString() {
return entries.values().toString();
http://git-wip-us.apache.org/repos/asf/kudu/blob/d07ecd6d/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
index 6d3be3e..42f0f9b 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
@@ -853,5 +853,47 @@ public class TestKuduClient extends BaseKuduTest {
syncClient.createTable(tableName, basicSchema, new CreateTableOptions());
}
+ @Test(timeout = 100000)
+ public void testOpenTableClearsNonCoveringRangePartitions() throws KuduException {
+ CreateTableOptions options = createTableOptions();
+ PartialRow lower = basicSchema.newPartialRow();
+ PartialRow upper = basicSchema.newPartialRow();
+ lower.addInt("key", 0);
+ upper.addInt("key", 1);
+ options.addRangePartition(lower, upper);
+
+ syncClient.createTable(tableName, basicSchema, options);
+ KuduTable table = syncClient.openTable(tableName);
+
+ // Count the number of tablets.
+ KuduScanToken.KuduScanTokenBuilder tokenBuilder = syncClient.newScanTokenBuilder(table);
+ List<KuduScanToken> tokens = tokenBuilder.build();
+ assertEquals(1, tokens.size());
+ // Add a range partition with a separate client. The new client is necessary
+ // in order to avoid clearing the meta cache as part of the alter operation.
+ try (KuduClient alterClient = new KuduClient.KuduClientBuilder(masterAddresses)
+ .defaultAdminOperationTimeoutMs(DEFAULT_SLEEP)
+ .build()) {
+ AlterTableOptions alter = new AlterTableOptions();
+ lower = basicSchema.newPartialRow();
+ upper = basicSchema.newPartialRow();
+ lower.addInt("key", 1);
+ alter.addRangePartition(lower, upper);
+ alterClient.alterTable(tableName, alter);
+ assertTrue(syncClient.isAlterTableDone(tableName));
+ }
+
+ // Count the number of tablets. The result should still be the same, since
+ // the new tablet is still cached as a non-covered range.
+ tokenBuilder = syncClient.newScanTokenBuilder(table);
+ tokens = tokenBuilder.build();
+ assertEquals(1, tokens.size());
+
+ // Reopen the table and count the tablets again. The new tablet should now show up.
+ table = syncClient.openTable(tableName);
+ tokenBuilder = syncClient.newScanTokenBuilder(table);
+ tokens = tokenBuilder.build();
+ assertEquals(2, tokens.size());
+ }
}