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

merge to stable-23-3: filestore: GetNodeAttrBatch + some convenience methods, params, tests + some minor fixes + LocalService mode in filestore-vhost #1689

Merged
merged 11 commits into from
Jul 30, 2024
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
2 changes: 2 additions & 0 deletions cloud/filestore/apps/client/lib/CMakeLists.darwin-x86_64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ target_sources(filestore-apps-client-lib PRIVATE
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/create_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/describe.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/execute_action.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/factory.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/find_garbage.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/kick_endpoint.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_cluster_nodes.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_endpoints.cpp
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/apps/client/lib/CMakeLists.linux-aarch64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ target_sources(filestore-apps-client-lib PRIVATE
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/create_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/describe.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/execute_action.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/factory.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/find_garbage.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/kick_endpoint.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_cluster_nodes.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_endpoints.cpp
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/apps/client/lib/CMakeLists.linux-x86_64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ target_sources(filestore-apps-client-lib PRIVATE
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/create_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/describe.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/execute_action.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/factory.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/find_garbage.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/kick_endpoint.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_cluster_nodes.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_endpoints.cpp
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/apps/client/lib/CMakeLists.windows-x86_64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ target_sources(filestore-apps-client-lib PRIVATE
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/create_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/describe.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/destroy_session.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/execute_action.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/factory.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/find_garbage.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/kick_endpoint.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_cluster_nodes.cpp
${CMAKE_SOURCE_DIR}/cloud/filestore/apps/client/lib/list_endpoints.cpp
Expand Down
5 changes: 5 additions & 0 deletions cloud/filestore/apps/client/lib/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ TFileStoreCommand::TFileStoreCommand()
.Required()
.RequiredArgument("STR")
.StoreResult(&FileSystemId);

Opts.AddLongOption("disable-multitablet-forwarding")
.NoArgument()
.SetFlag(&DisableMultiTabletForwarding);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -309,6 +313,7 @@ TFileStoreCommand::TSessionGuard TFileStoreCommand::CreateSession()

Headers.SetClientId(ClientId);
Headers.SetSessionId(sessionId);
Headers.SetDisableMultiTabletForwarding(DisableMultiTabletForwarding);

return TSessionGuard(*this);
}
Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/apps/client/lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class TFileStoreServiceCommand
protected:
TString ClientId;
TString FileSystemId;
bool DisableMultiTabletForwarding = false;

IFileStoreServicePtr Client;

Expand Down
71 changes: 71 additions & 0 deletions cloud/filestore/apps/client/lib/destroy_session.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "command.h"

#include <cloud/filestore/public/api/protos/session.pb.h>

namespace NCloud::NFileStore::NClient {

namespace {

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

void Print(const NProto::TDestroySessionResponse& response, bool jsonOutput)
{
if (jsonOutput) {
Cout << response.AsJSON() << Endl;
} else {
Cout << response.DebugString() << Endl;
}
}

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

class TDestroySessionCommand final
: public TFileStoreCommand
{
private:
TString SessionId;
ui64 SeqNo = 0;

public:
TDestroySessionCommand()
{
Opts.AddLongOption("session-id")
.RequiredArgument("SESSION_ID")
.StoreResult(&SessionId);

Opts.AddLongOption("client-id")
.RequiredArgument("CLIENT_ID")
.StoreResult(&ClientId);

Opts.AddLongOption("seq-no")
.RequiredArgument("SEQ_NO")
.StoreResult(&SeqNo);
}

bool Execute() override
{
auto request = std::make_shared<NProto::TDestroySessionRequest>();
request->SetFileSystemId(FileSystemId);
request->MutableHeaders()->SetSessionId(SessionId);
request->MutableHeaders()->SetClientId(ClientId);
request->MutableHeaders()->SetSessionSeqNo(SeqNo);

TCallContextPtr ctx = MakeIntrusive<TCallContext>();
auto response = WaitFor(Client->DestroySession(ctx, std::move(request)));
CheckResponse(response);
Print(response, JsonOutput);

return true;
}
};

} // namespace

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

TCommandPtr NewDestroySessionCommand()
{
return std::make_shared<TDestroySessionCommand>();
}

} // namespace NCloud::NFileStore::NClient
4 changes: 4 additions & 0 deletions cloud/filestore/apps/client/lib/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ TCommandPtr NewWriteCommand();
TCommandPtr NewExecuteActionCommand();
TCommandPtr NewCreateSessionCommand();
TCommandPtr NewResetSessionCommand();
TCommandPtr NewDestroySessionCommand();
TCommandPtr NewStatCommand();
TCommandPtr NewSetNodeAttrCommand();
TCommandPtr NewFindGarbageCommand();

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

Expand All @@ -45,7 +47,9 @@ static const TMap<TString, TFactoryFunc> Commands = {
{ "createsession", NewCreateSessionCommand },
{ "describe", NewDescribeCommand },
{ "destroy", NewDestroyCommand },
{ "destroysession", NewDestroySessionCommand },
{ "executeaction", NewExecuteActionCommand },
{ "findgarbage", NewFindGarbageCommand },
{ "kickendpoint", NewKickEndpointCommand },
{ "listclusternodes", NewListClusterNodesCommand },
{ "listendpoints", NewListEndpointsCommand },
Expand Down
164 changes: 164 additions & 0 deletions cloud/filestore/apps/client/lib/find_garbage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#include "command.h"

#include <cloud/filestore/public/api/protos/fs.pb.h>

#include <sys/stat.h>

namespace NCloud::NFileStore::NClient {

namespace {

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

struct TNode
{
ui64 Id = 0;
TString Name;
TString FollowerFileSystemId;
TString FollowerNodeName;
};

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

class TFindGarbageCommand final
: public TFileStoreCommand
{
private:
TVector<TString> Shards;

public:
TFindGarbageCommand()
{
Opts.AddLongOption("shard")
.RequiredArgument("STR")
.AppendTo(&Shards);
}

NProto::TListNodesResponse ListAll(const TString& fsId, ui64 parentId)
{
NProto::TListNodesResponse fullResult;
TString cookie;
do {
auto request = CreateRequest<NProto::TListNodesRequest>();
request->SetFileSystemId(fsId);
request->SetNodeId(parentId);
request->MutableHeaders()->SetDisableMultiTabletForwarding(true);
// TODO: traverse all pages
// TODO: async listing

auto response = WaitFor(Client->ListNodes(
PrepareCallContext(),
std::move(request)));

Y_ENSURE_EX(
!HasError(response.GetError()),
yexception() << "ListNodes error: "
<< FormatError(response.GetError()));

Y_ENSURE_EX(
response.NamesSize() == response.NodesSize(),
yexception() << "invalid ListNodes response: "
<< response.DebugString().Quote());

for (ui32 i = 0; i < response.NamesSize(); ++i) {
fullResult.AddNames(*response.MutableNames(i));
*fullResult.AddNodes() = std::move(*response.MutableNodes(i));
}

cookie = response.GetCookie();
} while (cookie);

return fullResult;
}

void FetchAll(
const TString& fsId,
ui64 parentId,
TVector<TNode>* nodes)
{
// TODO: async listing
auto response = ListAll(fsId, parentId);

for (ui32 i = 0; i < response.NodesSize(); ++i) {
const auto& node = response.GetNodes(i);
const auto& name = response.GetNames(i);
if (node.GetType() == NProto::E_DIRECTORY_NODE) {
FetchAll(fsId, node.GetId(), nodes);
} else {
nodes->push_back({
node.GetId(),
name,
node.GetFollowerFileSystemId(),
node.GetFollowerNodeName(),
});
}
}
}

bool Exists(const TString& fsId, ui64 parentId, const TString& name)
{
auto request = CreateRequest<NProto::TGetNodeAttrRequest>();
request->SetFileSystemId(fsId);
request->SetNodeId(parentId);
request->SetName(name);

auto response = WaitFor(Client->GetNodeAttr(
PrepareCallContext(),
std::move(request)));

if (response.GetError().GetCode() == E_FS_NOENT) {
return false;
}

Y_ENSURE_EX(
!HasError(response.GetError()),
yexception() << "GetNodeAttr error: "
<< FormatError(response.GetError()));

return true;
}

bool Execute() override
{
auto sessionGuard = CreateSession();
TMap<TString, TVector<TNode>> shard2Nodes;
for (const auto& shard: Shards) {
FetchAll(shard, RootNodeId, &shard2Nodes[shard]);
}

TVector<TNode> leaderNodes;
FetchAll(FileSystemId, RootNodeId, &leaderNodes);

THashSet<TString> followerNames;
for (const auto& node: leaderNodes) {
if (!node.FollowerFileSystemId) {
continue;
}

followerNames.insert(node.FollowerNodeName);
}

for (const auto& [shard, nodes]: shard2Nodes) {
for (const auto& node: nodes) {
if (!followerNames.contains(node.Name)) {
if (Exists(shard, RootNodeId, node.Name)) {
Cout << shard << "\t" << node.Name << "\n";
}
}
}
}

return true;
}
};

} // namespace

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

TCommandPtr NewFindGarbageCommand()
{
return std::make_shared<TFindGarbageCommand>();
}

} // namespace NCloud::NFileStore::NClient
2 changes: 1 addition & 1 deletion cloud/filestore/apps/client/lib/set_node_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace {
class TSetNodeAttrCommand final: public TFileStoreCommand
{
private:
ui32 NodeId = 0;
ui64 NodeId = 0;
std::optional<ui32> ModeAttr;
std::optional<ui32> UidAttr;
std::optional<ui32> GidAttr;
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/apps/client/lib/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ SRCS(
create_session.cpp
describe.cpp
destroy.cpp
destroy_session.cpp
execute_action.cpp
factory.cpp
find_garbage.cpp
kick_endpoint.cpp
list_cluster_nodes.cpp
list_endpoints.cpp
Expand Down
4 changes: 4 additions & 0 deletions cloud/filestore/config/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,8 @@ message TStorageConfig

// Allow to destroy filestore with active sessions
optional bool AllowFileStoreForceDestroy = 357;

// Enables usage of GetNodeAttrBatch requests instead of GetNodeAttr when
// appropriate.
optional bool GetNodeAttrBatchEnabled = 358;
}
3 changes: 3 additions & 0 deletions cloud/filestore/config/vhost.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ message TVhostServiceConfig

// Causes E_NOT_IMPLEMENTED errors in endpoint storages to be logged.
optional bool EndpointStorageNotImplementedErrorIsFatal = 8;

// Causes LocalService to be used if service != null and service != kikimr.
optional TLocalServiceConfig LocalServiceConfig = 9;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion cloud/filestore/libs/daemon/common/bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace NCloud::NFileStore::NDaemon {

using IUserCounterSupplier = NCloud::NStorage::NUserStats::IUserCounterSupplier;

class TBootstrapCommon {
class TBootstrapCommon
{
private:
const TString MetricsComponent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ target_link_libraries(libs-daemon-vhost PUBLIC
filestore-libs-server
filestore-libs-service
filestore-libs-service_kikimr
filestore-libs-service_local
filestore-libs-service_null
libs-vfs_fuse-vhost
filestore-libs-vhost
core-libs-common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ target_link_libraries(libs-daemon-vhost PUBLIC
filestore-libs-server
filestore-libs-service
filestore-libs-service_kikimr
filestore-libs-service_local
filestore-libs-service_null
libs-vfs_fuse-vhost
filestore-libs-vhost
core-libs-common
Expand Down
Loading
Loading