Skip to content

Commit

Permalink
Add new test case and amended assertion to repro issue #467
Browse files Browse the repository at this point in the history
Rework large_inserts_bugs_stress test to generate assertion failure.

This commit slightly enhances do_inserts_n_threads() in this
test case to cajole an assertion seen from BTree split code, or
thereabouts:

OS-pid=1839020, Thread-ID=5, Assertion failed at src/trunk.c:5521:trunk_split_leaf(): "(num_leaves + trunk_num_pivot_keys(spl, parent) <= spl->cfg.max_pivot_keys)". num_leaves=6, trunk_num_pivot_keys()=9, cfg.max_pivot_keys=14

The changes are:
- Provide options to use same / diff start-key for each thread.
- Increase TEST_KEY_SIZE to 30 and TEST_VALUE_SIZE to 256 bytes.
- Provide an option to either generate sequential values or to
  use fully-packed values for each key. The latter seems to be
  the condition that triggers this assertion.

Many diff variations of test cases are provided in this one large
framework. See large_inserts_bugs_stress_test --list for names of
individual test cases.
  • Loading branch information
gapisback committed Dec 6, 2022
1 parent 83de5e0 commit 3005050
Show file tree
Hide file tree
Showing 5 changed files with 620 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TESTSRC := $(COMMON_TESTSRC) $(FUNCTIONAL_TESTSRC) $(UNIT_TESTSRC)
# run as fast as it can.
# - Skip tests that are to be invoked with specialized command-line arguments.
# These skipped tests which will have to be run stand-alone.
FAST_UNIT_TESTSRC := $(shell find $(UNIT_TESTSDIR) -name "*.c" | egrep -v -e"splinter_test|config_parse_test")
FAST_UNIT_TESTSRC := $(shell find $(UNIT_TESTSDIR) -name "*.c" | egrep -v -e"splinter_test|config_parse_test|large_inserts_bugs_stress")

EXAMPLES_SRC := $(shell find $(EXAMPLES_DIR) -name "*.c")

Expand Down Expand Up @@ -428,6 +428,10 @@ $(BINDIR)/$(UNITDIR)/task_system_test: $(UTIL_SYS)
$(OBJDIR)/$(FUNCTIONAL_TESTSDIR)/test_async.o \
$(LIBDIR)/libsplinterdb.so

$(BINDIR)/$(UNITDIR)/large_inserts_bugs_stress_test: $(UTIL_SYS) \
$(OBJDIR)/$(TESTS_DIR)/config.o \
$(LIBDIR)/libsplinterdb.so

########################################
# Convenience mini unit-test targets
unit/util_test: $(BINDIR)/$(UNITDIR)/util_test
Expand Down
9 changes: 7 additions & 2 deletions src/trunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5426,8 +5426,13 @@ trunk_split_leaf(trunk_handle *spl,
key_buffer_init_from_key(
&scratch->pivot[num_leaves], spl->heap_id, trunk_max_key(spl, leaf));

platform_assert(num_leaves + trunk_num_pivot_keys(spl, parent)
<= spl->cfg.max_pivot_keys);
platform_assert((num_leaves + trunk_num_pivot_keys(spl, parent)
<= spl->cfg.max_pivot_keys),
"num_leaves=%u, trunk_num_pivot_keys()=%u"
", cfg.max_pivot_keys=%lu\n",
num_leaves,
trunk_num_pivot_keys(spl, parent),
spl->cfg.max_pivot_keys);

/*
* 3. Clear old bundles from leaf and put all branches in a new bundle
Expand Down
3 changes: 3 additions & 0 deletions tests/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
// Configs that are usually changed by different tests
#define TEST_CONFIG_DEFAULT_SEED 0
#define TEST_CONFIG_DEFAULT_NUM_INSERTS 0
#define TEST_CONFIG_DEFAULT_NUM_THREADS 8

// clang-format off
void
Expand Down Expand Up @@ -65,6 +66,7 @@ config_set_defaults(master_config *cfg)
.max_key_size = TEST_CONFIG_DEFAULT_KEY_SIZE,
.message_size = TEST_CONFIG_DEFAULT_MESSAGE_SIZE,
.num_inserts = TEST_CONFIG_DEFAULT_NUM_INSERTS,
.num_threads = TEST_CONFIG_DEFAULT_NUM_THREADS,
.seed = TEST_CONFIG_DEFAULT_SEED,
};
}
Expand Down Expand Up @@ -276,6 +278,7 @@ config_parse(master_config *cfg, const uint8 num_config, int argc, char *argv[])
// Test-execution configuration parameters
config_set_uint64("seed", cfg, seed) {}
config_set_uint64("num-inserts", cfg, num_inserts) {}
config_set_uint64("num-threads", cfg, num_threads) {}

config_set_else
{
Expand Down
1 change: 1 addition & 0 deletions tests/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef struct master_config {
// Test-execution configuration parameters
uint64 seed;
uint64 num_inserts;
uint64 num_threads;
} master_config;


Expand Down
Loading

0 comments on commit 3005050

Please sign in to comment.