You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/06/19 15:29:06 UTC
(kudu) branch master updated: [arm64] Fix TestLeafNode unit test by ensuring proper node alignment
This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new fd5d02258 [arm64] Fix TestLeafNode unit test by ensuring proper node alignment
fd5d02258 is described below
commit fd5d0225880ae36f2437c83fa46c3a65c86f8931
Author: kedeng <kd...@gmail.com>
AuthorDate: Wed Jun 4 10:58:06 2025 +0800
[arm64] Fix TestLeafNode unit test by ensuring proper node alignment
The following error occurs when running `bin/cbtree-test
--gtest_filter=TestCBTree.TestLeafNode` in an Rocky ARM environment.
*** Aborted at 1748486900 (unix time) try "date -d @1748486900" if you are using GNU date ***
PC: @ 0x0 (unknown)
*** SIGBUS (@0xffffc794b2af) received by PID 32172 (TID 0xffff838a0040) from PID 18446744072762995375; stack trace: ***
@ 0xffff83f0e890 google::(anonymous namespace)::FailureSignalHandler()
@ 0xffff853b07a0 ([vdso]+0x79f)
@ 0x279efc kudu::tablet::btree::VersionField::Lock()
@ 0x2815e4 kudu::tablet::btree::NodeBase<>::Lock()
@ 0x2788a4 kudu::tablet::btree::TestCBTree::InsertInLeaf<>()
@ 0x269d18 kudu::tablet::btree::TestCBTree_TestLeafNode_Test::TestBody()
@ 0xffff83de0608 testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0xffff83dd2348 testing::Test::Run()
@ 0xffff83dd24e8 testing::TestInfo::Run()
@ 0xffff83dd2b90 testing::TestSuite::Run()
@ 0xffff83dd7274 testing::internal::UnitTestImpl::RunAllTests()
@ 0xffff83dd25f0 testing::UnitTest::Run()
@ 0xffff85335f84 (unknown)
@ 0xffff853353e4 (unknown)
@ 0xffff838e7280 __libc_start_call_main
@ 0xffff838e7358 __libc_start_main_alias_2
@ 0x2698b0 _start
Bus error
The TestLeafNode unit test was triggering SIGBUS crashes on ARM64
architectures due to unaligned access of atomic version fields.
This occurred because the test created LeafNode instances on the stack
without guaranteed alignment, while ARM64 strictly requires 8-byte
alignment for atomic uint64_t operations.
This test-specific fix complements the production code alignment
measures and ensures:
- Unit tests respect the same alignment requirements as production
- ARM64 environments don't trigger SIGBUS during test execution
- Test reliability across different architectures
Testing environment:
- ARM64 (Neoverse-N1) with Rocky Linux 9.5
- Docker container runtime
- Strict alignment enforcement causing SIGBUS on unaligned access
We extend our gratitude to Zoltan for his essential testing validation
and remediation recommendations in this fix.
Change-Id: Ib838699ce3f966b2e7c371d5c74701f2f8d21a55
Change-I: I6fea46308f942ded97d93d27ae466fd13a31b53
Reviewed-on: http://gerrit.cloudera.org:8080/23049
Reviewed-by: Zoltan Martonka <zm...@cloudera.com>
Tested-by: Alexey Serbin <al...@apache.org>
Reviewed-by: Alexey Serbin <al...@apache.org>
---
src/kudu/tablet/cbtree-test.cc | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/kudu/tablet/cbtree-test.cc b/src/kudu/tablet/cbtree-test.cc
index e76d96738..33289d285 100644
--- a/src/kudu/tablet/cbtree-test.cc
+++ b/src/kudu/tablet/cbtree-test.cc
@@ -69,6 +69,17 @@ namespace kudu {
namespace tablet {
namespace btree {
+// In unit tests, we explicitly enforce 8-byte alignment for LeafNode/InternalNode
+// instances created on the stack. This is critical because:
+// 1. ARM64 architectures require 8-byte alignment for atomic operations on uint64_t.
+// Unaligned access triggers SIGBUS.
+// 2. Production code guarantees alignment through:
+// a) PACKED in NodeBase definition
+// b) Arena allocator's alignment-aware allocations
+// 3. Stack-allocated test nodes lack these guarantees, making explicit alignment
+// necessary to match production behavior and prevent architecture-specific crashes.
+// 4. This ensures test validity across x86 (tolerant to unaligned access) and ARM
+// (strict alignment requirements) platforms.
class TestCBTree : public KuduTest {
protected:
template<class T>
@@ -97,7 +108,7 @@ class TestCBTree : public KuduTest {
Slice key(kbuf, key_size);
Slice val(vbuf, val_size);
- LeafNode<BTreeTraits> lnode(false);
+ alignas(sizeof(AtomicVersion)) LeafNode<BTreeTraits> lnode(false);
ASSERT_EQ(INSERT_SUCCESS,
InsertInLeaf(&lnode, &arena, key, val));
}
@@ -114,16 +125,17 @@ class TestCBTree : public KuduTest {
TEST_F(TestCBTree, TestNodeSizes) {
ThreadSafeArena arena(1024);
- LeafNode<BTreeTraits> lnode(false);
+ alignas(sizeof(AtomicVersion)) LeafNode<BTreeTraits> lnode(false);
ASSERT_LE(sizeof(lnode), BTreeTraits::kLeafNodeSize);
- InternalNode<BTreeTraits> inode(Slice("split"), &lnode, &lnode, &arena);
+ alignas(sizeof(AtomicVersion)) InternalNode<BTreeTraits> inode(Slice("split"), &lnode,
+ &lnode, &arena);
ASSERT_LE(sizeof(inode), BTreeTraits::kInternalNodeSize);
}
TEST_F(TestCBTree, TestLeafNode) {
- LeafNode<BTreeTraits> lnode(false);
+ alignas(sizeof(AtomicVersion)) LeafNode<BTreeTraits> lnode(false);
ThreadSafeArena arena(1024);
Slice k1("key1");
@@ -178,7 +190,7 @@ TEST_F(TestCBTree, TestLeafNode) {
// Directly test leaf node with keys and values which are large (such that
// only zero or one would fit in the actual allocated space)
TEST_F(TestCBTree, TestLeafNodeBigKVs) {
- LeafNode<BTreeTraits> lnode(false);
+ alignas(sizeof(AtomicVersion)) LeafNode<BTreeTraits> lnode(false);
DoBigKVTest(1000, 1000);
}