-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
312 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,46 @@ | ||
#include "lag_provider.h" | ||
|
||
namespace NKikimr::NReplication::NController { | ||
|
||
void TLagProvider::AddPendingLag(ui64 childId) { | ||
Pending.insert(childId); | ||
} | ||
|
||
bool TLagProvider::UpdateLag(TItemWithLag& child, ui64 childId, TDuration lag) { | ||
bool updated = false; | ||
|
||
if (const auto& prevLag = child.Lag) { | ||
auto it = ChildrenByLag.find(*prevLag); | ||
Y_ABORT_UNLESS(it != ChildrenByLag.end()); | ||
|
||
it->second.erase(childId); | ||
if (it->second.empty()) { | ||
updated = true; | ||
ChildrenByLag.erase(it); | ||
} | ||
} | ||
|
||
child.Lag = lag; | ||
ChildrenByLag[lag].insert(childId); | ||
|
||
const bool pending = !Pending.empty(); | ||
Pending.erase(childId); | ||
|
||
if (Pending) { | ||
return false; | ||
} else if (pending) { | ||
return true; | ||
} | ||
|
||
return updated; | ||
} | ||
|
||
const TMaybe<TDuration> TLagProvider::GetLag() const { | ||
if (ChildrenByLag.empty() || !Pending.empty()) { | ||
return Nothing(); | ||
} | ||
|
||
return ChildrenByLag.rbegin()->first; | ||
} | ||
|
||
} |
This file contains 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,25 @@ | ||
#pragma once | ||
|
||
#include <util/datetime/base.h> | ||
#include <util/generic/hash_set.h> | ||
#include <util/generic/map.h> | ||
#include <util/generic/maybe.h> | ||
|
||
namespace NKikimr::NReplication::NController { | ||
|
||
struct TItemWithLag { | ||
TMaybe<TDuration> Lag; | ||
}; | ||
|
||
class TLagProvider { | ||
public: | ||
void AddPendingLag(ui64 childId); | ||
bool UpdateLag(TItemWithLag& child, ui64 childId, TDuration lag); | ||
const TMaybe<TDuration> GetLag() const; | ||
|
||
private: | ||
TMap<TDuration, THashSet<ui64>> ChildrenByLag; | ||
THashSet<ui64> Pending; | ||
}; | ||
|
||
} |
This file contains 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 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 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 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 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 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
Oops, something went wrong.