Skip to content

Commit

Permalink
tests: Limit the segments to be merged under tsan to suppress deadlock (
Browse files Browse the repository at this point in the history
#9259)

close #9257
  • Loading branch information
JaySon-Huang authored Jul 29, 2024
1 parent 1b318a7 commit 334d9b9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ ninja gtests_libcommon
There are known false positives reported from leak sanitizer (which is included in address sanitizer). To suppress these errors, set the following environment variables before running the executables:

```shell
LSAN_OPTIONS=suppressions=test/sanitize/asan.suppression
LSAN_OPTIONS="suppressions=tests/sanitize/asan.suppression" ./dbms/gtests_dbms ...
# or
TSAN_OPTIONS="suppressions=tests/sanitize/tsan.suppression" ./dbms/gtests_dbms ...
```

## Run Integration Tests
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/DeltaMergeStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class DeltaMergeStore : private boost::noncopyable
* It is ensured that there are at least 2 elements in the returned vector.
* When there is no mergeable segment, the returned vector will be empty.
*/
std::vector<SegmentPtr> getMergeableSegments(const DMContextPtr & context, const SegmentPtr & baseSegment);
std::vector<SegmentPtr> getMergeableSegments(const DMContextPtr & context, const SegmentPtr & base_segment);

/// Apply schema change on `table_columns`
void applySchemaChanges(TableInfo & table_info);
Expand Down
20 changes: 13 additions & 7 deletions dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ void DeltaMergeStore::setUpBackgroundTask(const DMContextPtr & dm_context)

std::vector<SegmentPtr> DeltaMergeStore::getMergeableSegments(
const DMContextPtr & context,
const SegmentPtr & baseSegment)
const SegmentPtr & base_segment)
{
// Last segment cannot be merged.
if (baseSegment->getRowKeyRange().isEndInfinite())
if (base_segment->getRowKeyRange().isEndInfinite())
return {};

// We only merge small segments into a larger one.
Expand All @@ -329,22 +329,28 @@ std::vector<SegmentPtr> DeltaMergeStore::getMergeableSegments(
{
std::shared_lock lock(read_write_mutex);

if (!isSegmentValid(lock, baseSegment))
if (!isSegmentValid(lock, base_segment))
return {};

results.reserve(4); // In most cases we will only find <= 4 segments to merge.
results.emplace_back(baseSegment);
auto accumulated_rows = baseSegment->getEstimatedRows();
auto accumulated_bytes = baseSegment->getEstimatedBytes();
results.emplace_back(base_segment);
auto accumulated_rows = base_segment->getEstimatedRows();
auto accumulated_bytes = base_segment->getEstimatedBytes();

auto it = segments.upper_bound(baseSegment->getRowKeyRange().getEnd());
auto it = segments.upper_bound(base_segment->getRowKeyRange().getEnd());
while (it != segments.end())
{
const auto & this_seg = it->second;
const auto this_rows = this_seg->getEstimatedRows();
const auto this_bytes = this_seg->getEstimatedBytes();
if (accumulated_rows + this_rows >= max_total_rows || accumulated_bytes + this_bytes >= max_total_bytes)
break;
#if defined(THREAD_SANITIZER)
// Limit the segments to be merged less than 30, or thread sanitizer will fail
// https://github.com/pingcap/tiflash/issues/9257
if (results.size() > 30)
break;
#endif
results.emplace_back(this_seg);
accumulated_rows += this_rows;
accumulated_bytes += this_bytes;
Expand Down
1 change: 1 addition & 0 deletions tests/sanitize/tsan.suppression
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ race:fiu_fail
race:dbms/src/DataStreams/BlockStreamProfileInfo.h
race:StackTrace::toString
race:DB::SyncPointCtl::sync
race:XXH3_hashLong_64b_withSeed_selection

0 comments on commit 334d9b9

Please sign in to comment.