Skip to content

Commit

Permalink
issue-2674: cross-shard RenameNode implementation - fixed move to roo…
Browse files Browse the repository at this point in the history
…t, fixed shard id selection check for dirs
  • Loading branch information
qkrorlqr committed Jan 14, 2025
1 parent 83fa5e2 commit 785be8b
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ void TAlterFileStoreActor::ConfigureShards(const TActorContext& ctx)
request->Record.SetFileSystemId(
FileStoreConfig.ShardConfigs[i].GetFileSystemId());
request->Record.SetShardNo(i + 1);
request->Record.SetMainFileSystemId(FileSystemId);
if (StorageConfig->GetDirectoryCreationInShardsEnabled()) {
for (const auto& shard: FileStoreConfig.ShardConfigs) {
request->Record.AddShardFileSystemIds(shard.GetFileSystemId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void TCreateFileStoreActor::ConfigureShards(const TActorContext& ctx)
request->Record.SetFileSystemId(
FileStoreConfig.ShardConfigs[i].GetFileSystemId());
request->Record.SetShardNo(i + 1);
request->Record.SetMainFileSystemId(Request.GetFileSystemId());
if (StorageConfig->GetDirectoryCreationInShardsEnabled()) {
for (const auto& shard: FileStoreConfig.ShardConfigs) {
request->Record.AddShardFileSystemIds(shard.GetFileSystemId());
Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/libs/storage/tablet/protos/tablet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ message TFileSystem
uint32 ShardNo = 14;
bool AutomaticShardCreationEnabled = 15;
uint64 ShardAllocationUnit = 16;
string MainFileSystemId = 17;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,17 @@ bool TIndexTabletActor::PrepareTx_CreateNode(
{
Y_UNUSED(ctx);

const bool isMainWithLocalNodes =
IsMainTablet() && GetLastNodeId() > RootNodeId;

if (!BehaveAsShard(args.Request.GetHeaders())
&& Config->GetShardIdSelectionInLeaderEnabled()
&& !GetFileSystem().GetShardFileSystemIds().empty()
&& (args.Attrs.GetType() == NProto::E_REGULAR_NODE
|| Config->GetDirectoryCreationInShardsEnabled()
// otherwise there might be some local nodes which breaks
// current cross-shard RenameNode implementation
&& GetLastNodeId() == RootNodeId))
&& !isMainWithLocalNodes))
{
args.Error = SelectShard(args.Attrs.GetSize(), &args.ShardId);
if (HasError(args.Error)) {
Expand Down
51 changes: 32 additions & 19 deletions cloud/filestore/libs/storage/tablet/tablet_actor_renamenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,39 @@ void TIndexTabletActor::HandleRenameNode(

const auto newParentShardNo =
ExtractShardNo(msg->Record.GetNewParentId());
if (newParentShardNo > static_cast<ui32>(shardIds.size())
|| newParentShardNo == 0)
{
auto message = ReportInvalidShardNo(
TStringBuilder() << "RenameNode: "
<< msg->Record.ShortDebugString() << " newParentShardNo: "
<< newParentShardNo << ", shard count: "
<< shardIds.size());
auto response = std::make_unique<TEvService::TEvRenameNodeResponse>(
MakeError(E_ARGUMENT, std::move(message)));
NCloud::Reply(ctx, *requestInfo, std::move(response));
return;
}

if (newParentShardNo != GetFileSystem().GetShardNo()) {
ExecuteTx<TPrepareRenameNodeInSource>(
ctx,
std::move(requestInfo),
std::move(msg->Record),
shardIds[newParentShardNo - 1]);
if (newParentShardNo > static_cast<ui32>(shardIds.size())) {
auto message = ReportInvalidShardNo(
TStringBuilder() << "RenameNode: "
<< msg->Record.ShortDebugString() << " newParentShardNo"
<< ": " << newParentShardNo << ", shard count: "
<< shardIds.size());
auto response =
std::make_unique<TEvService::TEvRenameNodeResponse>(
MakeError(E_ARGUMENT, std::move(message)));
NCloud::Reply(ctx, *requestInfo, std::move(response));
} else if (newParentShardNo == 0
&& msg->Record.GetNewParentId() != RootNodeId)
{
auto message = ReportInvalidShardNo(
TStringBuilder() << "RenameNode: "
<< msg->Record.ShortDebugString() << " newParentShardNo"
<< ": " << newParentShardNo << ", NewParentId: "
<< msg->Record.GetNewParentId());
auto response =
std::make_unique<TEvService::TEvRenameNodeResponse>(
MakeError(E_ARGUMENT, std::move(message)));
NCloud::Reply(ctx, *requestInfo, std::move(response));
} else {
ExecuteTx<TPrepareRenameNodeInSource>(
ctx,
std::move(requestInfo),
std::move(msg->Record),
newParentShardNo
? shardIds[newParentShardNo - 1]
: GetMainFileSystemId());
}

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void TIndexTabletActor::HandleUpdateConfig(
*newConfig.MutableShardFileSystemIds() =
oldConfig.GetShardFileSystemIds();
newConfig.SetShardNo(oldConfig.GetShardNo());
newConfig.SetMainFileSystemId(oldConfig.GetMainFileSystemId());
newConfig.SetAutomaticShardCreationEnabled(
oldConfig.GetAutomaticShardCreationEnabled());
newConfig.SetShardAllocationUnit(oldConfig.GetShardAllocationUnit());
Expand Down Expand Up @@ -430,6 +431,7 @@ void TIndexTabletActor::ExecuteTx_ConfigureAsShard(

auto config = GetFileSystem();
config.SetShardNo(args.Request.GetShardNo());
config.SetMainFileSystemId(args.Request.GetMainFileSystemId());
*config.MutableShardFileSystemIds() =
std::move(*args.Request.MutableShardFileSystemIds());

Expand Down
5 changes: 5 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ class TIndexTabletState
return FileSystem.GetFileSystemId();
}

TString GetMainFileSystemId() const
{
return FileSystem.GetMainFileSystemId();
}

ui32 GetGeneration() const
{
return Generation;
Expand Down
4 changes: 3 additions & 1 deletion cloud/filestore/private/api/protos/tablet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,10 @@ message TConfigureAsShardRequest
// ShardNo (will be used for the high bits of NodeId and HandleId)
uint32 ShardNo = 2;

// Shard FileSystem identifiers. Needed for directory creation in shards.
// Shard FileSystem identifiers and main FileSystem identifier (manages
// RootNode). Needed for directory creation in shards.
repeated string ShardFileSystemIds = 3;
string MainFileSystemId = 4;
}

message TConfigureAsShardResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"Name": "a1",
"Mode": 511,
"Id": 17
},
{
"Type": 1,
"Links": 1,
"Size": 62,
"Name": "f18.txt",
"Id": 29
}
][
{
Expand All @@ -21,6 +28,10 @@
{
"ShardFileSystemId": "masked_for_test_stability",
"Name": "a1"
},
{
"ShardFileSystemId": "masked_for_test_stability",
"Name": "f18.txt"
}
]- LINK: /does/not/matter/2
+ LINK: /does/not/matter/3
4 changes: 4 additions & 0 deletions cloud/filestore/tests/client_sharded_dir/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def _l(path, symlink):
_l("/a1/b2/l1", "/does/not/matter"),
_f("/a1/b2/f16.txt", "ZZZZZZZZZZZ2"),
_f("/f17.txt", "010101010101010101"),
_f("/a1/f18.txt", "xxxxxxxxxxxxxxxxxxxxxxxxxx"),
_d("/a1/b3"),
]

Expand All @@ -154,6 +155,9 @@ def _l(path, symlink):
client.mv("fs1", "/a0/b0/c0/f17.txt", "/a0/b0/c0/d0/f17.txt")
client.mv("fs1", "/a0/b0/c0/d0/f17.txt", "/a1/f17.txt")
client.mv("fs1", "/a1/f17.txt", "/a1/b2/f17.txt")
# checking that cross-directory mv to root works
client.mv("fs0", "/a1/f18.txt", "/f18.txt")
client.mv("fs1", "/a1/f18.txt", "/f18.txt")
# checking that readlink works (indirectly - via diff)
client.ln("fs0", "/a1/b2/l2", "--symlink", "/does/not/matter/2")
client.ln("fs1", "/a1/b2/l2", "--symlink", "/does/not/matter/3")
Expand Down

0 comments on commit 785be8b

Please sign in to comment.