Skip to content

Commit

Permalink
[tablet] fix race condition in RowSetMetadata::GetAllBlocks()
Browse files Browse the repository at this point in the history
The race condition was reported by the TSAN like the following
(with some information omitted):

  WARNING: ThreadSanitizer: data race (pid=1924273)
    Write of size 8 at 0x7b30002fe7c0 by thread T6 (mutexes: write M247597861, write M247597860, write M247597300):
      #0 std::__1::enable_if<(...), void>::type std::__1::swap<kudu::BlockId*>(...) thirdparty/installed/tsan/include/c++/v1/type_traits:4076:9
      ...
      #4 kudu::tablet::RowSetMetadata::CommitRedoDeltaDataBlock(...) src/kudu/tablet/rowset_metadata.cc:197:22
      #5 kudu::tablet::DeltaTracker::FlushDMS(...) src/kudu/tablet/delta_tracker.cc:826:23
      #6 kudu::tablet::DeltaTracker::Flush(...) src/kudu/tablet/delta_tracker.cc:877:14
      #7 kudu::tablet::DiskRowSet::FlushDeltas(...) src/kudu/tablet/diskrowset.cc:552:26
      ...

    Previous read of size 8 at 0x7b30002fe7c0 by thread T34 (mutexes: write M247598319, write M919714229363433616, write M303002710007881612):
      #0 std::__1::vector<...>::size() const thirdparty/installed/tsan/include/c++/v1/vector:658:61
      #1 kudu::tablet::RowSetMetadata::GetAllBlocks() const src/kudu/tablet/rowset_metadata.cc:306:37
      #2 kudu::tablet::TabletMetadata::UpdateUnlocked(...) src/kudu/tablet/tablet_metadata.cc:677:40
      #3 kudu::tablet::TabletMetadata::UpdateAndFlush(...) src/kudu/tablet/tablet_metadata.cc:549:5
      #4 kudu::tablet::Tablet::FlushMetadata(...) src/kudu/tablet/tablet.cc:1992:21
      #5 kudu::tablet::Tablet::HandleEmptyCompactionOrFlush() src/kudu/tablet/tablet.cc:2308:3
      #6 kudu::tablet::Tablet::DeleteAncientDeletedRowsets() src/kudu/tablet/tablet.cc:3084:3
      ...

Change-Id: I07103269526d0ee98b0bb19e76e11f7d47a5b217
Reviewed-on: http://gerrit.cloudera.org:8080/21799
Reviewed-by: Abhishek Chennaka <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
  • Loading branch information
alexeyserbin committed Sep 14, 2024
1 parent e5d11b2 commit fe54010
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/kudu/tablet/rowset_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ int64_t RowSetMetadata::live_row_count() const {

BlockIdContainer RowSetMetadata::GetAllBlocks() const {
BlockIdContainer blocks;

std::lock_guard l(lock_);
blocks.reserve(blocks_by_col_id_.size() +
undo_delta_blocks_.size() +
redo_delta_blocks_.size() +
2); // '2' is reserved for 'adhoc_index_block_' and 'bloom_block_'
std::lock_guard l(lock_);

if (!adhoc_index_block_.IsNull()) {
blocks.push_back(adhoc_index_block_);
}
Expand Down

0 comments on commit fe54010

Please sign in to comment.