-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare for add infra common bg_tasks (#4302)
- Loading branch information
1 parent
601fa99
commit 4549fb4
Showing
118 changed files
with
2,812 additions
and
512 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,5 @@ | ||
#include "adapter.h" | ||
|
||
namespace NKikimr::NOlap::NBackground { | ||
|
||
} |
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,63 @@ | ||
#pragma once | ||
#include "session.h" | ||
#include <ydb/core/tablet_flat/tablet_flat_executor.h> | ||
#include <ydb/library/actors/core/actorid.h> | ||
#include <ydb/library/accessor/accessor.h> | ||
#include <ydb/library/conclusion/status.h> | ||
|
||
namespace NKikimr::NTabletFlatExecutor { | ||
class TTabletExecutedFlat; | ||
} | ||
|
||
namespace NKikimr::NOlap::NBackground { | ||
|
||
class ITabletAdapter { | ||
private: | ||
YDB_READONLY_DEF(NActors::TActorId, TabletActorId); | ||
YDB_READONLY(TTabletId, TabletId, TTabletId(0)); | ||
NTabletFlatExecutor::TTabletExecutedFlat& TabletExecutor; | ||
virtual bool DoLoadSessionsFromLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, std::deque<TSessionRecord>& records) = 0; | ||
virtual void DoSaveProgressToLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TSessionRecord& container) = 0; | ||
virtual void DoSaveStateToLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TSessionRecord& container) = 0; | ||
virtual void DoSaveSessionToLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TSessionRecord& container) = 0; | ||
virtual void DoRemoveSessionFromLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TString& className, const TString& identifier) = 0; | ||
public: | ||
ITabletAdapter(const NActors::TActorId& tabletActorId, const TTabletId tabletId, NTabletFlatExecutor::TTabletExecutedFlat& tabletExecutor) | ||
: TabletActorId(tabletActorId) | ||
, TabletId(tabletId) | ||
, TabletExecutor(tabletExecutor) | ||
{ | ||
AFL_VERIFY(!!TabletActorId); | ||
AFL_VERIFY(!!(ui64)TabletId); | ||
} | ||
virtual ~ITabletAdapter() = default; | ||
|
||
template <class T> | ||
T& GetTabletExecutorVerifiedAs() { | ||
T* result = dynamic_cast<T*>(&TabletExecutor); | ||
AFL_VERIFY(result); | ||
return *result; | ||
} | ||
|
||
void RemoveSessionFromLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TString& className, const TString& identifier) { | ||
return DoRemoveSessionFromLocalDatabase(txc, className, identifier); | ||
} | ||
|
||
[[nodiscard]] bool LoadSessionsFromLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, std::deque<TSessionRecord>& records) { | ||
return DoLoadSessionsFromLocalDatabase(txc, records); | ||
} | ||
|
||
void SaveSessionToLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TSessionRecord& session) { | ||
return DoSaveSessionToLocalDatabase(txc, session); | ||
} | ||
|
||
void SaveStateToLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TSessionRecord& session) { | ||
return DoSaveStateToLocalDatabase(txc, session); | ||
} | ||
|
||
void SaveProgressToLocalDatabase(NTabletFlatExecutor::TTransactionContext& txc, const TSessionRecord& session) { | ||
return DoSaveProgressToLocalDatabase(txc, session); | ||
} | ||
}; | ||
|
||
} |
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,35 @@ | ||
#include "control.h" | ||
#include <ydb/core/tx/columnshard/bg_tasks/protos/data.pb.h> | ||
|
||
namespace NKikimr::NOlap::NBackground { | ||
|
||
NKikimrTxBackgroundProto::TSessionControlContainer TSessionControlContainer::SerializeToProto() const { | ||
NKikimrTxBackgroundProto::TSessionControlContainer result; | ||
*result.MutableStatusChannelContainer() = ChannelContainer.SerializeToString(); | ||
*result.MutableLogicControlContainer() = LogicControlContainer.SerializeToProto(); | ||
return result; | ||
} | ||
|
||
NKikimr::TConclusionStatus TSessionControlContainer::DeserializeFromProto(const NKikimrTxBackgroundProto::TSessionControlContainer& proto) { | ||
if (!ChannelContainer.DeserializeFromString(proto.GetStatusChannelContainer())) { | ||
return TConclusionStatus::Fail("cannot parse channel from proto"); | ||
} | ||
if (!LogicControlContainer.DeserializeFromProto(proto.GetLogicControlContainer())) { | ||
return TConclusionStatus::Fail("cannot parse logic from proto"); | ||
} | ||
return TConclusionStatus::Success(); | ||
} | ||
|
||
NKikimr::TConclusionStatus ISessionLogicControl::DeserializeFromProto(const TProto& data) { | ||
SessionClassName = data.GetSessionClassName(); | ||
SessionIdentifier = data.GetSessionIdentifier(); | ||
return DeserializeFromString(data.GetSessionControlDescription()); | ||
} | ||
|
||
void ISessionLogicControl::SerializeToProto(TProto& proto) const { | ||
proto.SetSessionClassName(SessionClassName); | ||
proto.SetSessionIdentifier(SessionIdentifier); | ||
proto.SetSessionControlDescription(SerializeToString()); | ||
} | ||
|
||
} |
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,80 @@ | ||
#pragma once | ||
#include "session.h" | ||
#include "status_channel.h" | ||
#include <ydb/services/bg_tasks/abstract/interface.h> | ||
#include <ydb/library/accessor/accessor.h> | ||
|
||
namespace NKikimrTxBackgroundProto { | ||
class TSessionControlContainer; | ||
class TSessionLogicControlContainer; | ||
} | ||
|
||
namespace NKikimr::NOlap::NBackground { | ||
|
||
class ISessionLogicControl { | ||
private: | ||
YDB_READONLY_DEF(TString, SessionClassName); | ||
YDB_READONLY_DEF(TString, SessionIdentifier); | ||
virtual TConclusionStatus DoApply(const std::shared_ptr<ISessionLogic>& session) const = 0; | ||
|
||
virtual TConclusionStatus DoDeserializeFromString(const TString& data) = 0; | ||
virtual TString DoSerializeToString() const = 0; | ||
protected: | ||
TConclusionStatus DeserializeFromString(const TString& data) { | ||
return DoDeserializeFromString(data); | ||
} | ||
TString SerializeToString() const { | ||
return DoSerializeToString(); | ||
} | ||
public: | ||
using TProto = NKikimrTxBackgroundProto::TSessionLogicControlContainer; | ||
using TFactory = NObjectFactory::TObjectFactory<ISessionLogicControl, TString>; | ||
|
||
virtual ~ISessionLogicControl() = default; | ||
ISessionLogicControl() = default; | ||
ISessionLogicControl(const TString& sessionClassName, const TString& sessionIdentifier) | ||
: SessionClassName(sessionClassName) | ||
, SessionIdentifier(sessionIdentifier) | ||
{ | ||
|
||
} | ||
|
||
TConclusionStatus DeserializeFromProto(const TProto& data); | ||
void SerializeToProto(TProto& proto) const; | ||
|
||
TConclusionStatus Apply(const std::shared_ptr<ISessionLogic>& session) const { | ||
session->CheckStatusCorrect(); | ||
auto result = DoApply(session); | ||
session->CheckStatusCorrect(); | ||
return result; | ||
} | ||
|
||
virtual TString GetClassName() const = 0; | ||
}; | ||
|
||
class TSessionLogicControlContainer: public NBackgroundTasks::TInterfaceProtoContainer<ISessionLogicControl> { | ||
private: | ||
using TBase = NBackgroundTasks::TInterfaceProtoContainer<ISessionLogicControl>; | ||
public: | ||
using TBase::TBase; | ||
}; | ||
|
||
class TSessionControlContainer { | ||
private: | ||
YDB_READONLY_DEF(TStatusChannelContainer, ChannelContainer); | ||
YDB_READONLY_DEF(TSessionLogicControlContainer, LogicControlContainer); | ||
public: | ||
NKikimrTxBackgroundProto::TSessionControlContainer SerializeToProto() const; | ||
TConclusionStatus DeserializeFromProto(const NKikimrTxBackgroundProto::TSessionControlContainer& proto); | ||
|
||
TSessionControlContainer() = default; | ||
|
||
TSessionControlContainer(const TStatusChannelContainer& channel, const TSessionLogicControlContainer& logic) | ||
: ChannelContainer(channel) | ||
, LogicControlContainer(logic) { | ||
AFL_VERIFY(!!ChannelContainer); | ||
AFL_VERIFY(!!LogicControlContainer); | ||
} | ||
}; | ||
|
||
} |
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,14 @@ | ||
#include "session.h" | ||
#include "adapter.h" | ||
#include <ydb/public/api/protos/ydb_operation.pb.h> | ||
|
||
namespace NKikimr::NOlap::NBackground { | ||
|
||
Ydb::Operations::Operation TSessionInfoReport::SerializeToProto() const { | ||
Ydb::Operations::Operation result; | ||
result.set_id(ClassName + "::" + Identifier); | ||
result.set_ready(IsFinished); | ||
return result; | ||
} | ||
|
||
} |
Oops, something went wrong.