Repository navigation
[io] Do not serve unread blocks from the cache after a read error #23832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chrisburr
wants to merge
2
commits into
root-project:master
Choose a base branch
from
chrisburr:io-cache-failed-readbuffers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #include "ROOT/TestSupport.hxx" | ||
|
|
||
| #include "TFile.h" | ||
| #include "TSystem.h" | ||
| #include "TTree.h" | ||
| #include "TTreeCacheUnzip.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| #include <vector> | ||
|
|
||
| namespace { | ||
|
|
||
| /// A file whose `failAt`-th vectored read fails without filling the buffer, as a TNetXNGFile does on a socket timeout. | ||
| class FailingReadBuffersFile : public TFile { | ||
| int fCalls = 0; | ||
| int fFailAt; | ||
|
|
||
| public: | ||
| FailingReadBuffersFile(const char *name, int failAt) : TFile(name), fFailAt(failAt) {} | ||
|
|
||
| Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override | ||
| { | ||
| if (++fCalls == fFailAt) | ||
| return kTRUE; | ||
| return TFile::ReadBuffers(buf, pos, len, nbuf); | ||
| } | ||
|
|
||
| int GetCalls() const { return fCalls; } | ||
| }; | ||
|
|
||
| class TTreeCacheReadError : public ::testing::Test { | ||
| protected: | ||
| static constexpr const char *kFileName = "ttreecache_readerror.root"; | ||
| static constexpr int kEntries = 20000; | ||
| // The size of a cache holding the baskets of a single cluster. | ||
| static constexpr int kCacheSize = 20000; | ||
|
|
||
| static void SetUpTestSuite() | ||
| { | ||
| TFile f(kFileName, "RECREATE"); | ||
| TTree t("t", "t"); | ||
| int a; | ||
| std::vector<int> v; | ||
| t.Branch("a", &a, 4000); | ||
| t.Branch("v", &v, 4000); | ||
| t.SetAutoFlush(2000); | ||
| for (int i = 0; i < kEntries; ++i) { | ||
| a = i; | ||
| v.assign(i % 7, i); | ||
| t.Fill(); | ||
| } | ||
| t.Write(); | ||
| } | ||
|
|
||
| static void TearDownTestSuite() { gSystem->Unlink(kFileName); } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note the utility class |
||
|
|
||
| /// Read all entries of `t`, checking their content, and return the number of entries that could not be read. | ||
| static int ReadAll(TTree &t) | ||
| { | ||
| int a = -1; | ||
| std::vector<int> *v = nullptr; | ||
| t.SetBranchAddress("a", &a); | ||
| t.SetBranchAddress("v", &v); | ||
| int nErrors = 0; | ||
| for (int i = 0; i < kEntries; ++i) { | ||
| if (t.GetEntry(i) <= 0) { | ||
| ++nErrors; | ||
| continue; | ||
| } | ||
| EXPECT_EQ(a, i); | ||
| EXPECT_NE(v, nullptr); | ||
| if (!v) | ||
| continue; | ||
| EXPECT_EQ(v->size(), static_cast<std::size_t>(i % 7)); | ||
| for (int x : *v) | ||
| EXPECT_EQ(x, i); | ||
| } | ||
| return nErrors; | ||
| } | ||
| }; | ||
|
|
||
| /// Use a TTreeCacheUnzip for the tree while in scope. | ||
| class UnzipCacheRAII { | ||
| public: | ||
| UnzipCacheRAII(TTree &t, Long64_t cacheSize) | ||
| { | ||
| TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable); | ||
| new TTreeCacheUnzip(&t, cacheSize); | ||
| } | ||
| ~UnzipCacheRAII() { TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kDisable); } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| // A failed read of the baskets of a cluster must not leave the cache serving the other baskets of that cluster from a | ||
| // buffer that was never filled. | ||
| TEST_F(TTreeCacheReadError, FailedReadBuffers) | ||
| { | ||
| // The first vectored read is that of the cache in learning phase, the third one that of the second cluster. | ||
| FailingReadBuffersFile f(kFileName, /*failAt=*/3); | ||
| auto t = f.Get<TTree>("t"); | ||
| ASSERT_NE(t, nullptr); | ||
| t->SetCacheSize(kCacheSize); | ||
|
|
||
| ROOT::TestSupport::CheckDiagsRAII diags; | ||
| diags.requiredDiag(kError, "TBranch::GetBasket", "badread=1", /*matchFullMessage=*/false); | ||
| // Only the entry whose read failed is lost; the other baskets of its cluster are read from the file. | ||
| EXPECT_EQ(ReadAll(*t), 1); | ||
| EXPECT_GT(f.GetCalls(), 3); | ||
| } | ||
|
|
||
| // The same for TTreeCacheUnzip, where the read that fails is retried by TBasket. | ||
| TEST_F(TTreeCacheReadError, FailedReadBuffersUnzip) | ||
| { | ||
| FailingReadBuffersFile f(kFileName, /*failAt=*/3); | ||
| auto t = f.Get<TTree>("t"); | ||
| ASSERT_NE(t, nullptr); | ||
| UnzipCacheRAII unzip(*t, kCacheSize); | ||
|
|
||
| EXPECT_EQ(ReadAll(*t), 0); | ||
| EXPECT_GT(f.GetCalls(), 3); | ||
| } | ||
|
|
||
| // When prefilling the cache during learning, the first basket is requested from TTreeCacheUnzip before its blocks are | ||
| // read; a failure to read them must not unzip whatever its buffer for compressed data holds. | ||
| TEST_F(TTreeCacheReadError, FailedReadBuffersUnzipLearnPrefill) | ||
| { | ||
| FailingReadBuffersFile f(kFileName, /*failAt=*/1); | ||
| auto t = f.Get<TTree>("t"); | ||
| ASSERT_NE(t, nullptr); | ||
| UnzipCacheRAII unzip(*t, kCacheSize); | ||
| t->GetReadCache(&f)->SetLearnPrefill(TTreeCache::kAllBranches); | ||
|
|
||
| EXPECT_EQ(ReadAll(*t), 0); | ||
| EXPECT_GT(f.GetCalls(), 1); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same pattern is found in multiple place in this file, we may want to also add this fix there.