Skip to content
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

positive integer class #13195

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ydb/core/tx/columnshard/data_accessor/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#include <ydb/core/tx/columnshard/hooks/abstract/abstract.h>

#include <ydb/library/accessor/positive_integer.h>

namespace NKikimr::NOlap::NDataAccessorControl {

void TLocalManager::DrainQueue() {
std::optional<ui64> lastPathId;
IGranuleDataAccessor* lastDataAccessor = nullptr;
ui32 countToFlight = 0;
TPositiveControlInteger countToFlight;
while (PortionsAskInFlight + countToFlight < NYDBTest::TControllers::GetColumnShardController()->GetLimitForPortionsMetadataAsk() &&
PortionsAsk.size()) {
THashMap<ui64, std::vector<TPortionInfo::TConstPtr>> portionsToAsk;
Expand Down Expand Up @@ -63,7 +65,6 @@ void TLocalManager::DrainQueue() {
}
}
RequestsByPortion.erase(it);
AFL_VERIFY(countToFlight);
--countToFlight;
}
if (dataAnalyzed.GetPortionsToAsk().size()) {
Expand All @@ -72,7 +73,7 @@ void TLocalManager::DrainQueue() {
}
}
}
PortionsAskInFlight += countToFlight;
PortionsAskInFlight.Add(countToFlight);
Counters.FetchingCount->Set(PortionsAskInFlight);
Counters.QueueSize->Set(PortionsAsk.size());
}
Expand Down Expand Up @@ -119,7 +120,6 @@ void TLocalManager::DoAddPortion(const TPortionDataAccessor& accessor) {
for (auto&& i : it->second) {
i->AddAccessor(accessor);
}
AFL_VERIFY(PortionsAskInFlight);
--PortionsAskInFlight;
}
RequestsByPortion.erase(it);
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/columnshard/data_accessor/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class TLocalManager: public IDataAccessorsManager {
};

std::deque<TPortionToAsk> PortionsAsk;
ui64 PortionsAskInFlight = 0;
TPositiveControlInteger PortionsAskInFlight;

void DrainQueue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
namespace NKikimr::NOlap {

bool TPlanCompactionInfo::Finish() {
if (Count > 0) {
return --Count == 0;
} else {
AFL_VERIFY(false);
return false;
}
return --Count == 0;
}

} // namespace NKikimr::NOlap
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once
#include <ydb/library/accessor/positive_integer.h>
#include <ydb/library/actors/core/monotonic.h>

#include <util/generic/string.h>
#include <util/system/yassert.h>
#include <util/stream/output.h>
#include <ydb/library/actors/core/monotonic.h>
#include <util/system/yassert.h>

#include <memory>

namespace NKikimr::NOlap {
Expand All @@ -12,7 +15,7 @@ class TPlanCompactionInfo {
private:
ui64 PathId = 0;
TMonotonic StartTime = TMonotonic::Now();
ui32 Count = 0;
TPositiveControlInteger Count;

public:
void Start() {
Expand All @@ -28,12 +31,11 @@ class TPlanCompactionInfo {

TPlanCompactionInfo(const ui64 pathId)
: PathId(pathId) {

}

ui64 GetPathId() const {
return PathId;
}
};

}
} // namespace NKikimr::NOlap
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TPortionsChain {
class TCompactionTaskData {
private:
YDB_ACCESSOR_DEF(std::vector<TPortionInfo::TConstPtr>, Portions);
const ui64 TargetCompactionLevel = 0;
const TPositiveControlInteger TargetCompactionLevel;
std::shared_ptr<NCompaction::TGeneralCompactColumnEngineChanges::IMemoryPredictor> Predictor =
NCompaction::TGeneralCompactColumnEngineChanges::BuildMemoryPredictor();
ui64 MemoryUsage = 0;
Expand All @@ -135,12 +135,7 @@ class TCompactionTaskData {
public:
ui64 GetTargetCompactionLevel() const {
if (MemoryUsage > ((ui64)1 << 30)) {
if (TargetCompactionLevel) {
return TargetCompactionLevel - 1;
} else {
AFL_VERIFY(false);
return 0;
}
return TargetCompactionLevel.GetDec();
} else {
return TargetCompactionLevel;
}
Expand Down
24 changes: 4 additions & 20 deletions ydb/core/tx/limiter/grouped_memory/usage/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ydb/core/tx/limiter/grouped_memory/service/counters.h>

#include <ydb/library/accessor/accessor.h>
#include <ydb/library/accessor/positive_integer.h>
#include <ydb/library/actors/core/actor.h>
#include <ydb/library/actors/core/actorid.h>
#include <ydb/library/actors/core/log.h>
Expand Down Expand Up @@ -75,23 +76,6 @@ class TAllocationGuard {
~TAllocationGuard();
};

class TPositiveControlInteger {
private:
ui64 Value = 0;

public:
void Add(const ui64 value) {
Value += value;
}
void Sub(const ui64 value) {
AFL_VERIFY(value <= Value)("base", Value)("delta", value);
Value -= value;
}
ui64 Val() const {
return Value;
}
};

class TStageFeatures {
private:
YDB_READONLY_DEF(TString, Name);
Expand Down Expand Up @@ -130,9 +114,9 @@ class TStageFeatures {
if (HardLimit < Usage.Val() + volume) {
Counters->OnCannotAllocate();
AFL_DEBUG(NKikimrServices::GROUPED_MEMORY_LIMITER)("name", Name)("event", "cannot_allocate")("limit", HardLimit)(
"usage", Usage.Val())(
"delta", volume);
return TConclusionStatus::Fail(TStringBuilder() << Name << "::(limit:" << HardLimit << ";val:" << Usage.Val() << ";delta=" << volume << ");");
"usage", Usage.Val())("delta", volume);
return TConclusionStatus::Fail(
TStringBuilder() << Name << "::(limit:" << HardLimit << ";val:" << Usage.Val() << ";delta=" << volume << ");");
}
Usage.Add(volume);
AFL_DEBUG(NKikimrServices::GROUPED_MEMORY_LIMITER)("name", Name)("event", "allocate")("usage", Usage.Val())("delta", volume);
Expand Down
1 change: 0 additions & 1 deletion ydb/core/tx/tiering/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ TTiersManager::TTierRefGuard::~TTierRefGuard() {
if (Owner) {
auto findTier = Owner->TierRefCount.FindPtr(TierName);
AFL_VERIFY(findTier);
AFL_VERIFY(*findTier);
--*findTier;
if (!*findTier) {
AFL_VERIFY(Owner->TierRefCount.erase(TierName));
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/tx/tiering/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ydb/core/tx/tiering/tier/object.h>

#include <ydb/public/sdk/cpp/client/ydb_types/s3_settings.h>
#include <ydb/library/accessor/positive_integer.h>
#include <ydb/services/metadata/secret/snapshot.h>
#include <ydb/services/metadata/service.h>

Expand Down Expand Up @@ -77,7 +78,7 @@ class TTiersManager: public ITiersManager {
IActor* Actor = nullptr;
TManagers Managers;

using TTierRefCount = THashMap<TString, ui64>;
using TTierRefCount = THashMap<TString, TPositiveControlInteger>;
using TTierRefsByPathId = THashMap<ui64, std::vector<TTierRefGuard>>;
YDB_READONLY_DEF(TTierRefCount, TierRefCount);
YDB_READONLY_DEF(TTierRefsByPathId, UsedTiers);
Expand Down
38 changes: 38 additions & 0 deletions ydb/library/accessor/positive_integer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "positive_integer.h"
#include <ydb/library/actors/core/log.h>

namespace NKikimr {

TPositiveControlInteger::TPositiveControlInteger(const i64 value)
: Value(value) {
AFL_VERIFY(0 <= value);
}

ui64 TPositiveControlInteger::Add(const ui64 value) {
Value += value;
return Value;
}

ui64 TPositiveControlInteger::Sub(const ui64 value) {
if (value <= Value) {
Value -= value;
} else {
AFL_VERIFY(false)("base", Value)("delta", value);
}
return Value;
}

ui64 TPositiveControlInteger::GetDec() const {
if (Value) {
return Value - 1;
} else {
AFL_VERIFY(false);
}
return 0;
}

ui64 TPositiveControlInteger::Val() const {
return Value;
}

}
40 changes: 40 additions & 0 deletions ydb/library/accessor/positive_integer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include <util/system/types.h>

namespace NKikimr {

class TPositiveControlInteger {
private:
ui64 Value = 0;
public:
TPositiveControlInteger() = default;
TPositiveControlInteger(const ui64 value)
: Value(value) {

}
TPositiveControlInteger(const i64 value);
ui64 Add(const ui64 value);
ui64 Sub(const ui64 value);
ui64 Inc() {
return Add(1);
}
ui64 Dec() {
return Sub(1);
}
ui64 GetDec() const;
ui64 Val() const;
bool operator!() const {
return !Value;
}
operator ui64() const {
return Value;
}
ui64 operator++() {
return Inc();
}
ui64 operator--() {
return Dec();
}
};

}
1 change: 1 addition & 0 deletions ydb/library/accessor/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PEERDIR(
SRCS(
accessor.cpp
validator.cpp
positive_integer.cpp
)

END()
Expand Down
Loading