Skip to content

Commit

Permalink
cleanup- replaced assert with releaseAssert to maintain consistency i…
Browse files Browse the repository at this point in the history
…n codebase stellar#2852
  • Loading branch information
seekaddo committed Jan 9, 2021
1 parent a3ded40 commit 9eb12bc
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 101 deletions.
13 changes: 7 additions & 6 deletions src/bucket/Bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include "util/XDRStream.h"
#include "xdrpp/message.h"
#include <Tracy.hpp>
#include <cassert>
//#include <cassert>
#include "util/GlobalChecks.h"
#include <fmt/format.h>
#include <future>

Expand All @@ -35,7 +36,7 @@ namespace stellar
Bucket::Bucket(std::string const& filename, Hash const& hash)
: mFilename(filename), mHash(hash)
{
assert(filename.empty() || fs::exists(filename));
releaseAssert(filename.empty() || fs::exists(filename));
if (!filename.empty())
{
CLOG_TRACE(Bucket, "Bucket::Bucket() created, file exists : {}",
Expand Down Expand Up @@ -127,7 +128,7 @@ Bucket::convertToBucketEntry(bool useInit,

BucketEntryIdCmp cmp;
std::sort(bucket.begin(), bucket.end(), cmp);
assert(std::adjacent_find(
releaseAssert(std::adjacent_find(
bucket.begin(), bucket.end(),
[&cmp](BucketEntry const& lhs, BucketEntry const& rhs) {
return !cmp(lhs, rhs);
Expand Down Expand Up @@ -600,8 +601,8 @@ Bucket::merge(BucketManager& bucketManager, uint32_t maxProtocolVersion,
// buckets together into a new 3rd bucket, while calculating its hash,
// in a single pass.

assert(oldBucket);
assert(newBucket);
releaseAssert(oldBucket);
releaseAssert(newBucket);

MergeCounters mc;
BucketInputIterator oi(oldBucket);
Expand Down Expand Up @@ -660,7 +661,7 @@ Bucket::merge(BucketManager& bucketManager, uint32_t maxProtocolVersion,
uint32_t
Bucket::getBucketVersion(std::shared_ptr<Bucket> const& bucket)
{
assert(bucket);
releaseAssert(bucket);
BucketInputIterator it(bucket);
return it.getMetadata().ledgerVersion;
}
Expand Down
6 changes: 4 additions & 2 deletions src/bucket/BucketInputIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ BucketInputIterator::operator bool() const
return mEntryPtr != nullptr;
}

BucketEntry const& BucketInputIterator::operator*()
BucketEntry const&
BucketInputIterator::operator*()
{
return *mEntryPtr;
}
Expand Down Expand Up @@ -110,7 +111,8 @@ BucketInputIterator::~BucketInputIterator()
mIn.close();
}

BucketInputIterator& BucketInputIterator::operator++()
BucketInputIterator&
BucketInputIterator::operator++()
{
if (mIn)
{
Expand Down
37 changes: 19 additions & 18 deletions src/bucket/BucketList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "util/XDRStream.h"
#include "util/types.h"
#include <Tracy.hpp>
#include <cassert>
//#include <cassert>
#include "util/GlobalChecks.h"
#include <fmt/format.h>

namespace stellar
Expand Down Expand Up @@ -112,7 +113,7 @@ BucketLevel::commit()
{
setCurr(mNextCurr.resolve());
}
assert(!mNextCurr.isMerging());
releaseAssert(!mNextCurr.isMerging());
}

// prepare builds a FutureBucket for the _next state_ of the current level,
Expand Down Expand Up @@ -158,7 +159,7 @@ BucketLevel::prepare(Application& app, uint32_t currLedger,
ZoneScoped;
// If more than one absorb is pending at the same time, we have a logic
// error in our caller (and all hell will break loose).
assert(!mNextCurr.isMerging());
releaseAssert(!mNextCurr.isMerging());
auto curr = BucketList::shouldMergeWithEmptyCurr(currLedger, mLevel)
? std::make_shared<Bucket>()
: mCurr;
Expand All @@ -169,7 +170,7 @@ BucketLevel::prepare(Application& app, uint32_t currLedger,
: shadows;
mNextCurr = FutureBucket(app, curr, snap, shadowsBasedOnProtocol,
currLedgerProtocol, countMergeEvents, mLevel);
assert(mNextCurr.isMerging());
releaseAssert(mNextCurr.isMerging());
}

std::shared_ptr<Bucket>
Expand Down Expand Up @@ -214,7 +215,7 @@ BucketListDepth::operator uint32_t() const
uint32_t
BucketList::levelSize(uint32_t level)
{
assert(level < kNumLevels);
releaseAssert(level < kNumLevels);
return 1UL << (2 * (level + 1));
}

Expand Down Expand Up @@ -248,8 +249,8 @@ BucketList::mask(uint32_t v, uint32_t m)
uint32_t
BucketList::sizeOfCurr(uint32_t ledger, uint32_t level)
{
assert(ledger != 0);
assert(level < kNumLevels);
releaseAssert(ledger != 0);
releaseAssert(level < kNumLevels);
if (level == 0)
{
return (ledger == 1) ? 1 : (1 + ledger % 2);
Expand Down Expand Up @@ -295,8 +296,8 @@ BucketList::sizeOfCurr(uint32_t ledger, uint32_t level)
uint32_t
BucketList::sizeOfSnap(uint32_t ledger, uint32_t level)
{
assert(ledger != 0);
assert(level < kNumLevels);
releaseAssert(ledger != 0);
releaseAssert(level < kNumLevels);
if (level == BucketList::kNumLevels - 1)
{
return 0;
Expand All @@ -321,8 +322,8 @@ BucketList::sizeOfSnap(uint32_t ledger, uint32_t level)
uint32_t
BucketList::oldestLedgerInCurr(uint32_t ledger, uint32_t level)
{
assert(ledger != 0);
assert(level < kNumLevels);
releaseAssert(ledger != 0);
releaseAssert(level < kNumLevels);
if (sizeOfCurr(ledger, level) == 0)
{
return std::numeric_limits<uint32_t>::max();
Expand All @@ -341,8 +342,8 @@ BucketList::oldestLedgerInCurr(uint32_t ledger, uint32_t level)
uint32_t
BucketList::oldestLedgerInSnap(uint32_t ledger, uint32_t level)
{
assert(ledger != 0);
assert(level < kNumLevels);
releaseAssert(ledger != 0);
releaseAssert(level < kNumLevels);
if (sizeOfSnap(ledger, level) == 0)
{
return std::numeric_limits<uint32_t>::max();
Expand Down Expand Up @@ -436,7 +437,7 @@ bool
BucketList::futuresAllResolved(uint32_t maxLevel) const
{
ZoneScoped;
assert(maxLevel < mLevels.size());
releaseAssert(maxLevel < mLevels.size());

for (uint32_t i = 0; i <= maxLevel; i++)
{
Expand Down Expand Up @@ -470,7 +471,7 @@ BucketList::addBatch(Application& app, uint32_t currLedger,
std::vector<LedgerKey> const& deadEntries)
{
ZoneScoped;
assert(currLedger > 0);
releaseAssert(currLedger > 0);

std::vector<std::shared_ptr<Bucket>> shadows;
for (auto& level : mLevels)
Expand Down Expand Up @@ -505,13 +506,13 @@ BucketList::addBatch(Application& app, uint32_t currLedger,
// elements of 'shadows', and then inside the loop we pop two more for each
// iteration.

assert(shadows.size() >= 2);
releaseAssert(shadows.size() >= 2);
shadows.pop_back();
shadows.pop_back();

for (uint32_t i = static_cast<uint32>(mLevels.size()) - 1; i != 0; --i)
{
assert(shadows.size() >= 2);
releaseAssert(shadows.size() >= 2);
shadows.pop_back();
shadows.pop_back();

Expand Down Expand Up @@ -561,7 +562,7 @@ BucketList::addBatch(Application& app, uint32_t currLedger,
bool countMergeEvents =
!app.getConfig().ARTIFICIALLY_REDUCE_MERGE_COUNTS_FOR_TESTING;
bool doFsync = !app.getConfig().DISABLE_XDR_FSYNC;
assert(shadows.size() == 0);
releaseAssert(shadows.size() == 0);
mLevels[0].prepare(app, currLedger, currLedgerProtocol,
Bucket::fresh(app.getBucketManager(), currLedgerProtocol,
initEntries, liveEntries, deadEntries,
Expand Down
6 changes: 3 additions & 3 deletions src/bucket/BucketManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <map>
#include <regex>
#include <set>

#include "util/GlobalChecks.h"
#include "medida/counter.h"
#include "medida/meter.h"
#include "medida/metrics_registry.h"
Expand Down Expand Up @@ -219,7 +219,7 @@ BucketManagerImpl::deleteTmpDirAndUnlockBucketDir()
{
std::string d = mApp.getConfig().BUCKET_DIR_PATH;
std::string lock = d + "/" + kLockFilename;
assert(fs::exists(lock));
releaseAssert(fs::exists(lock));
fs::unlockFile(lock);
mLockedBucketDir.reset();
}
Expand Down Expand Up @@ -412,7 +412,7 @@ BucketManagerImpl::adoptFileAsBucket(std::string const& filename,
mSharedBucketsSize.set_count(mSharedBuckets.size());
}
}
assert(b);
releaseAssert(b);
if (mergeKey)
{
// Second half of the mergeKey record-keeping, above: if we successfully
Expand Down
3 changes: 2 additions & 1 deletion src/bucket/BucketMergeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "crypto/Hex.h"
#include "util/Logging.h"
#include <Tracy.hpp>
#include "util/GlobalChecks.h"

namespace
{
Expand Down Expand Up @@ -54,7 +55,7 @@ BucketMergeMap::forgetAllMergesProducing(Hash const& outputBeingDropped)
{
auto const& output = mergeProducingOutput->first;
auto const& mergeKeyProducingOutput = mergeProducingOutput->second;
assert(output == outputBeingDropped);
releaseAssert(output == outputBeingDropped);
ret.emplace(mergeKeyProducingOutput);

// It's possible for the same output to occur for multiple
Expand Down
7 changes: 4 additions & 3 deletions src/bucket/BucketOutputIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "bucket/BucketManager.h"
#include "crypto/Random.h"
#include <Tracy.hpp>
#include "util/GlobalChecks.h"

namespace stellar
{
Expand Down Expand Up @@ -88,7 +89,7 @@ BucketOutputIterator::put(BucketEntry const& e)
{
// mCmp(e, *mBuf) means e < *mBuf; this should never be true since
// it would mean that we're getting entries out of order.
assert(!mCmp(e, *mBuf));
releaseAssert(!mCmp(e, *mBuf));

// Check to see if the new entry should flush (greater identity), or
// merely replace (same identity), the buffered entry.
Expand Down Expand Up @@ -124,8 +125,8 @@ BucketOutputIterator::getBucket(BucketManager& bucketManager,
mOut.close();
if (mObjectsPut == 0 || mBytesPut == 0)
{
assert(mObjectsPut == 0);
assert(mBytesPut == 0);
releaseAssert(mObjectsPut == 0);
releaseAssert(mBytesPut == 0);
CLOG_DEBUG(Bucket, "Deleting empty bucket file {}", mFilename);
std::remove(mFilename.c_str());
if (mergeKey)
Expand Down
Loading

0 comments on commit 9eb12bc

Please sign in to comment.