Skip to content

Commit

Permalink
issue-1146: populate in-memory cache upon RO transactions as well (#2232
Browse files Browse the repository at this point in the history
)

issue-1146: populate in-memory cache upon RO transactions as well
  • Loading branch information
debnatkh committed Oct 16, 2024
1 parent 7deecde commit 21672b0
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 31 deletions.
43 changes: 24 additions & 19 deletions cloud/filestore/libs/storage/core/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ class TTabletBase

////////////////////////////////////////////////////////////////////////////////

#define FILESTORE_IMPLEMENT_COMMON_TRANSACTION(name, ns) \
void CompleteAndUpdateState( \
const NActors::TActorContext& ctx, \
ns::T##name& args) \
{ \
UpdateInMemoryIndexState(args); \
CompleteTx_##name(ctx, args); \
} \
// FILESTORE_IMPLEMENT_COMMON_TRANSACTION

#define FILESTORE_IMPLEMENT_RW_TRANSACTION(name, ns) \
struct T##name \
{ \
Expand Down Expand Up @@ -261,13 +271,7 @@ class TTabletBase
const NActors::TActorContext& ctx, \
ns::T##name& args); \
\
void CompleteAndUpdateState( \
const NActors::TActorContext& ctx, \
ns::T##name& args) \
{ \
UpdateInMemoryIndexState(args); \
CompleteTx_##name(ctx, args); \
} \
FILESTORE_IMPLEMENT_COMMON_TRANSACTION(name, ns) \
// FILESTORE_IMPLEMENT_RW_TRANSACTION

// For RO transactions we allow to alternatively declare ValidateTx_, PrepareTx_
Expand All @@ -291,38 +295,37 @@ class TTabletBase
static constexpr NKikimr::TTxType TxType = TCounters::TX_##name; \
static constexpr bool IsReadOnly = true; \
\
template <typename T, typename ...Args> \
template <typename T> \
static bool PrepareTx( \
T& target, \
const NActors::TActorContext& ctx, \
NKikimr::NTabletFlatExecutor::TTransactionContext& tx, \
Args&& ...args) \
ns::T##name& args) \
{ \
if (target.ValidateTx_##name(ctx, std::forward<Args>(args)...)) { \
dbType db(tx.DB); \
return target.PrepareTx_##name( \
ctx, db, std::forward<Args>(args)...); \
if (target.ValidateTx_##name(ctx, args)) { \
dbType db(tx.DB, args.NodeUpdates); \
return target.PrepareTx_##name(ctx, db, args); \
} \
return true; \
} \
\
template <typename T, typename ...Args> \
template <typename T> \
static void ExecuteTx( \
T& target, \
const NActors::TActorContext& ctx, \
NKikimr::NTabletFlatExecutor::TTransactionContext& tx, \
Args&& ...args) \
ns::T##name& args) \
{ \
Y_UNUSED(target, ctx, tx, std::forward<Args>(args)...); \
Y_UNUSED(target, ctx, tx, args); \
} \
\
template <typename T, typename ...Args> \
template <typename T> \
static void CompleteTx( \
T& target, \
const NActors::TActorContext& ctx, \
Args&& ...args) \
ns::T##name& args) \
{ \
target.CompleteTx_##name(ctx, std::forward<Args>(args)...); \
target.CompleteAndUpdateState(ctx, args); \
} \
}; \
\
Expand Down Expand Up @@ -351,6 +354,8 @@ class TTabletBase
args.Clear(); \
return false; \
} \
\
FILESTORE_IMPLEMENT_COMMON_TRANSACTION(name, ns) \
// FILESTORE_IMPLEMENT_RO_TRANSACTION

} // namespace NCloud::NFileStore::NStorage
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ void TNodeIndexCache::RegisterGetNodeAttrResult(
const TString& name,
const NProto::TNodeAttr& response)
{
if (AttrByParentNodeId.size() >= MaxNodes) {
if (MaxNodes == 0) {
return;
}
if (AttrByParentNodeId.size() == MaxNodes) {
KeyByNodeId.clear();
AttrByParentNodeId.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/filestore/libs/storage/tablet/tablet_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ class TIndexTabletActor final
FILESTORE_TABLET_INDEX_RO_TRANSACTIONS(
FILESTORE_IMPLEMENT_RO_TRANSACTION,
TTxIndexTablet,
TIndexTabletDatabase,
TIndexTabletDatabaseProxy,
IIndexTabletDatabase);

STFUNC(StateBoot);
Expand Down
85 changes: 85 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,22 @@ TIndexTabletDatabaseProxy::TIndexTabletDatabaseProxy(
, NodeUpdates(nodeUpdates)
{}

bool TIndexTabletDatabaseProxy::ReadNode(
ui64 nodeId,
ui64 commitId,
TMaybe<IIndexTabletDatabase::TNode>& node)
{
auto result = TIndexTabletDatabase::ReadNode(nodeId, commitId, node);
if (result && node) {
// If ReadNode was successful, it is reasonable to update the cache with
// the value that has just been read.
NodeUpdates.emplace_back(TInMemoryIndexState::TWriteNodeRequest{
.NodeId = nodeId,
.Row = {.CommitId = node->MinCommitId, .Node = node->Attrs}});
}
return result;
}

void TIndexTabletDatabaseProxy::WriteNode(
ui64 nodeId,
ui64 commitId,
Expand Down Expand Up @@ -1934,6 +1950,27 @@ void TIndexTabletDatabaseProxy::DeleteNodeVer(ui64 nodeId, ui64 commitId)
// TODO(#1146): _Ver tables not yet supported
}

bool TIndexTabletDatabaseProxy::ReadNodeAttr(
ui64 nodeId,
ui64 commitId,
const TString& name,
TMaybe<TNodeAttr>& attr)
{
auto result =
TIndexTabletDatabase::ReadNodeAttr(nodeId, commitId, name, attr);
if (result && attr) {
// If ReadNodeAttr was successful, it is reasonable to update the cache
// with the value that has just been read.
NodeUpdates.emplace_back(TInMemoryIndexState::TWriteNodeAttrsRequest{
.NodeAttrsKey = {nodeId, name},
.NodeAttrsRow = {
.CommitId = attr->MinCommitId,
.Value = attr->Value,
.Version = attr->Version}});
}
return result;
}

void TIndexTabletDatabaseProxy::WriteNodeAttr(
ui64 nodeId,
ui64 commitId,
Expand Down Expand Up @@ -1982,6 +2019,54 @@ void TIndexTabletDatabaseProxy::DeleteNodeAttrVer(
// TODO(#1146): _Ver tables not yet supported
}

bool TIndexTabletDatabaseProxy::ReadNodeRef(
ui64 nodeId,
ui64 commitId,
const TString& name,
TMaybe<IIndexTabletDatabase::TNodeRef>& ref)
{
auto result =
TIndexTabletDatabase::ReadNodeRef(nodeId, commitId, name, ref);
if (result && ref) {
// If ReadNodeRef was successful, it is reasonable to update the cache
// with the value that has just been read.
NodeUpdates.emplace_back(TInMemoryIndexState::TWriteNodeRefsRequest{
.NodeRefsKey = {nodeId, name},
.NodeRefsRow = {
.CommitId = ref->MinCommitId,
.ChildId = ref->ChildNodeId,
.FollowerId = ref->FollowerId,
.FollowerName = ref->FollowerName}});
}
return result;
}

bool TIndexTabletDatabaseProxy::ReadNodeRefs(
ui64 nodeId,
ui64 commitId,
const TString& cookie,
TVector<IIndexTabletDatabase::TNodeRef>& refs,
ui32 maxBytes,
TString* next)
{
auto result = TIndexTabletDatabase::ReadNodeRefs(
nodeId, commitId, cookie, refs, maxBytes, next);
if (result) {
// If ReadNodeRefs was successful, it is reasonable to update the cache
// with the values that have just been read.
for (const auto& ref: refs) {
NodeUpdates.emplace_back(TInMemoryIndexState::TWriteNodeRefsRequest{
.NodeRefsKey = {nodeId, ref.Name},
.NodeRefsRow = {
.CommitId = ref.MinCommitId,
.ChildId = ref.ChildNodeId,
.FollowerId = ref.FollowerId,
.FollowerName = ref.FollowerName}});
}
}
return result;
}

void TIndexTabletDatabaseProxy::WriteNodeRef(
ui64 nodeId,
ui64 commitId,
Expand Down
25 changes: 25 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ class TIndexTabletDatabaseProxy: public TIndexTabletDatabase
// Nodes
//

bool ReadNode(
ui64 nodeId,
ui64 commitId,
TMaybe<IIndexTabletDatabase::TNode>& node) final;

void WriteNode(
ui64 nodeId,
ui64 commitId,
Expand All @@ -556,6 +561,12 @@ class TIndexTabletDatabaseProxy: public TIndexTabletDatabase
// NodeAttrs
//

bool ReadNodeAttr(
ui64 nodeId,
ui64 commitId,
const TString& name,
TMaybe<TNodeAttr>& attr) override;

void WriteNodeAttr(
ui64 nodeId,
ui64 commitId,
Expand Down Expand Up @@ -586,6 +597,20 @@ class TIndexTabletDatabaseProxy: public TIndexTabletDatabase
// NodeRefs
//

bool ReadNodeRef(
ui64 nodeId,
ui64 commitId,
const TString& name,
TMaybe<IIndexTabletDatabase::TNodeRef>& ref) override;

bool ReadNodeRefs(
ui64 nodeId,
ui64 commitId,
const TString& cookie,
TVector<IIndexTabletDatabase::TNodeRef>& refs,
ui32 maxBytes,
TString* next = nullptr) override;

void WriteNodeRef(
ui64 nodeId,
ui64 commitId,
Expand Down
Loading

0 comments on commit 21672b0

Please sign in to comment.