Skip to content

Commit

Permalink
Fix off by one and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Feb 14, 2024
1 parent a52e0c4 commit cf799df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/bucket/BucketApplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ BucketApplicator::BucketApplicator(Application& app,
if (newOffersOnly && !bucket->isEmpty())
{
releaseAssertOrThrow(mApp.getConfig().isUsingBucketListDB());
auto [lowOffset, highOffset] = bucket->getOfferRange();
mBucketIter.seek(lowOffset);
mUpperBoundOffset = highOffset;
auto offsetOp = bucket->getOfferRange();
if (offsetOp)
{
auto [lowOffset, highOffset] = *offsetOp;
mBucketIter.seek(lowOffset);
mUpperBoundOffset = highOffset;
}
else
{
// No offers in Bucket
mOffersRemaining = false;
}
}
}

Expand Down Expand Up @@ -112,7 +121,11 @@ BucketApplicator::advance(BucketApplicator::Counters& counters)

for (; mBucketIter; ++mBucketIter)
{
if (mNewOffersOnly && mBucketIter.pos() >= mUpperBoundOffset)
// Note: mUpperBoundOffset is not inclusive. However, mBucketIter.pos()
// returns the file offset at the end of the currently loaded entry.
// This means we must read until pos is strictly greater than the upper
// bound so that we don't skip the last offer in the range.
if (mNewOffersOnly && mBucketIter.pos() > mUpperBoundOffset)
{
mOffersRemaining = false;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/bucket/BucketInputIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BucketInputIterator::loadEntry()
}
}

size_t
std::streamoff
BucketInputIterator::pos()
{
return mIn.pos();
Expand Down
2 changes: 1 addition & 1 deletion src/bucket/BucketInputIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BucketInputIterator

BucketInputIterator& operator++();

size_t pos();
std::streamoff pos();
size_t size() const;
void seek(std::streamoff offset);
};
Expand Down

0 comments on commit cf799df

Please sign in to comment.