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 #306

Merged
merged 3 commits into from
Feb 5, 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
4 changes: 2 additions & 2 deletions cloud/blockstore/libs/encryption/keyring_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Y_UNIT_TEST_SUITE(TKeyringEncryptorTest)
NProto::TEncryptionSpec spec;
spec.SetMode(NProto::ENCRYPTION_AES_XTS);
auto& keyPath = *spec.MutableKeyPath();
keyPath.SetKeyringId(keyringOrError.GetResult());
keyPath.SetKeyringId(FromString<ui32>(keyringOrError.GetResult()));

auto keyProvider = CreateDefaultEncryptionKeyProvider();
auto keyOrError = keyProvider->GetKey(spec, {}).ExtractValue();
Expand Down Expand Up @@ -111,7 +111,7 @@ Y_UNIT_TEST_SUITE(TKeyringEncryptorTest)
NProto::TEncryptionSpec spec;
spec.SetMode(NProto::ENCRYPTION_AES_XTS);
auto& keyPath = *spec.MutableKeyPath();
keyPath.SetKeyringId(keyringOrError.GetResult());
keyPath.SetKeyringId(FromString<ui32>(keyringOrError.GetResult()));

auto keyProvider = CreateDefaultEncryptionKeyProvider();

Expand Down
35 changes: 3 additions & 32 deletions cloud/blockstore/libs/endpoints/service_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class TRestoringService final
}

if (auto ptr = weakPtr.lock()) {
ptr->RemovePersistentEndpointFromStorage(req);
ptr->EndpointStorage->RemoveEndpoint(req.GetUnixSocketPath());
}
return response;
});
Expand Down Expand Up @@ -448,7 +448,7 @@ class TRestoringService final
std::shared_ptr<NProto::TKickEndpointRequest> request)
{
auto requestOrError = EndpointStorage->GetEndpoint(
request->GetKeyringId());
ToString(request->GetKeyringId()));

if (HasError(requestOrError)) {
return MakeFuture<NProto::TKickEndpointResponse>(
Expand Down Expand Up @@ -494,42 +494,13 @@ class TRestoringService final
return error;
}

error = EndpointStorage->AddEndpoint(data).GetError();
error = EndpointStorage->AddEndpoint(request.GetUnixSocketPath(), data);
if (HasError(error)) {
return error;
}

return {};
}

NProto::TError RemovePersistentEndpointFromStorage(
const NProto::TStopEndpointRequest& request)
{
const auto& socketPath = request.GetUnixSocketPath();

auto [ids, error] = EndpointStorage->GetEndpointIds();
if (HasError(error)) {
return error;
}

for (auto id: ids) {
auto [data, error] = EndpointStorage->GetEndpoint(id);
if (HasError(error)) {
continue;
}

auto req = DeserializeEndpoint<NProto::TStartEndpointRequest>(data);
if (req && req->GetUnixSocketPath() == socketPath) {
if (req->GetPersistent()) {
return EndpointStorage->RemoveEndpoint(id);
}
break;
}
}

return MakeError(E_INVALID_STATE, TStringBuilder()
<< "Couldn't find endpoint " << socketPath);
}
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
62 changes: 41 additions & 21 deletions cloud/blockstore/libs/endpoints/service_endpoint_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
{
Y_UNIT_TEST(ShouldHandleKickEndpoint)
{
auto keyringId = 13;
const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);
Expand Down Expand Up @@ -180,14 +181,16 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(keyringId),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);

{
ui32 requestId = 325;
auto response = KickEndpoint(
*endpointService,
keyOrError.GetResult(),
keyringId,
requestId);
UNIT_ASSERT(!HasError(response));

Expand All @@ -200,7 +203,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
}

{
auto wrongKeyringId = keyOrError.GetResult() + 42;
auto wrongKeyringId = keyringId + 42;
auto response = KickEndpoint(*endpointService, wrongKeyringId);
UNIT_ASSERT(HasError(response)
&& response.GetError().GetCode() == E_INVALID_STATE);
Expand Down Expand Up @@ -332,12 +335,15 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(startRequest);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto keyringId = 13;
auto error = endpointStorage->AddEndpoint(
ToString(keyringId),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);

auto request = std::make_shared<NProto::TKickEndpointRequest>();
request->MutableHeaders()->SetRequestTimeout(100);
request->SetKeyringId(keyOrError.GetResult());
request->SetKeyringId(keyringId);

auto future = endpointService->KickEndpoint(
MakeIntrusive<TCallContext>(),
Expand Down Expand Up @@ -404,13 +410,16 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
UNIT_ASSERT_C(!HasError(error), error);
};

size_t counter = 0;
size_t wrongDataCount = 3;
size_t wrongSocketCount = 4;
size_t correctCount = 5;

for (size_t i = 0; i < wrongDataCount; ++i) {
auto keyOrError = endpointStorage->AddEndpoint("invalid proto request data");
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(++counter),
"invalid proto request data");
UNIT_ASSERT_C(!HasError(error), error);
}

for (size_t i = 0; i < wrongSocketCount; ++i) {
Expand All @@ -420,8 +429,10 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(++counter),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);
}

for (size_t i = 0; i < correctCount; ++i) {
Expand All @@ -431,8 +442,10 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(++counter),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);
}

auto endpointService = CreateMultipleEndpointService(
Expand Down Expand Up @@ -552,8 +565,10 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(i),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);
}

auto endpointService = CreateMultipleEndpointService(
Expand Down Expand Up @@ -620,7 +635,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
};

ui32 endpointCount = 42;
THashMap<ui32, NProto::TStartEndpointRequest> requests;
THashMap<TString, NProto::TStartEndpointRequest> requests;

for (size_t i = 0; i < endpointCount; ++i) {
NProto::TStartEndpointRequest request;
Expand All @@ -631,10 +646,12 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(i),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);

requests.emplace(keyOrError.GetResult(), request);
requests.emplace(ToString(i), request);
}

auto endpointService = CreateMultipleEndpointService(
Expand Down Expand Up @@ -854,6 +871,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

Y_UNIT_TEST(ShouldWaitForRestoredEndpoints)
{
auto keyringId = 13;
const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);
Expand Down Expand Up @@ -916,8 +934,10 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto strOrError = SerializeEndpoint(*startRequest);
UNIT_ASSERT_C(!HasError(strOrError), strOrError.GetError());

auto keyOrError = endpointStorage->AddEndpoint(strOrError.GetResult());
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
auto error = endpointStorage->AddEndpoint(
ToString(keyringId),
strOrError.GetResult());
UNIT_ASSERT_C(!HasError(error), error);

auto restoreFuture = endpointService->RestoreEndpoints();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class TBootstrap

struct TOptions
{
TString UnixSocketPath = "./testSocket";
TString UnixSocketPath = CreateGuidAsString() + ".sock";
TString ClientId = "testClientId";
TString DiskId = "testDiskId";
ui32 UnixSocketBacklog = 16;
Expand Down Expand Up @@ -329,7 +329,7 @@ Y_UNIT_TEST_SUITE(TSocketEndpointListenerTest)
Y_UNIT_TEST(ShouldHandleStartStopEndpoint)
{
auto logging = CreateLoggingService("console");
TFsPath unixSocket("./testSocket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");

auto clientAcceptor = std::make_shared<TTestClientAcceptor>();
auto listener = CreateSocketEndpointListener(logging, 16);
Expand Down Expand Up @@ -374,7 +374,7 @@ Y_UNIT_TEST_SUITE(TSocketEndpointListenerTest)
Y_UNIT_TEST(ShouldHandleClientDisconnection)
{
auto logging = CreateLoggingService("console");
TFsPath unixSocket("./testSocket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");

auto clientAcceptor = std::make_shared<TTestClientAcceptor>();
auto listener = CreateSocketEndpointListener(logging, 16);
Expand Down Expand Up @@ -415,7 +415,7 @@ Y_UNIT_TEST_SUITE(TSocketEndpointListenerTest)
TString diskId = "testDiskId";
ui32 unixSocketBacklog = 16;
auto blocksCount = 42;
TFsPath unixSocket("./testSocket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");

TPortManager portManager;
ui16 dataPort = portManager.GetPort(9001);
Expand Down Expand Up @@ -914,15 +914,15 @@ Y_UNIT_TEST_SUITE(TSocketEndpointListenerTest)

Y_UNIT_TEST(ShouldStartEndpointIfSocketAlreadyExists)
{
TOptions options;
options.UnixSocketPath = "./TestUnixSocket";

TFsPath unixSocket(options.UnixSocketPath);
TFsPath unixSocket(CreateGuidAsString() + ".sock");
unixSocket.Touch();
Y_DEFER {
unixSocket.DeleteIfExists();
};

TOptions options;
options.UnixSocketPath = unixSocket.GetPath();

auto bootstrap = CreateBootstrap(options);
bootstrap.Start();
Y_DEFER {
Expand Down
7 changes: 4 additions & 3 deletions cloud/blockstore/libs/nbd/server_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/testing/unittest/tests_data.h>

#include <util/generic/guid.h>
#include <util/generic/scope.h>

namespace NCloud::NBlockStore::NBD {
Expand Down Expand Up @@ -588,7 +589,7 @@ Y_UNIT_TEST_SUITE(TServerTest)

Y_UNIT_TEST(ShouldRemoveUnixSocketAfterStopEndpoint)
{
TFsPath unixSocket("./TestUnixSocket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");
TNetworkAddress connectAddress(TUnixSocketPath(unixSocket.GetPath()));

auto storage = std::make_shared<TTestStorage>();
Expand Down Expand Up @@ -627,7 +628,7 @@ Y_UNIT_TEST_SUITE(TServerTest)
auto serverCode1 = E_FAIL;
auto serverCode2 = E_ARGUMENT;

TFsPath unixSocket("./TestUnixSocket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");
TNetworkAddress connectAddress(TUnixSocketPath(unixSocket.GetPath()));

auto storage1 = std::make_shared<TTestStorage>();
Expand Down Expand Up @@ -712,7 +713,7 @@ Y_UNIT_TEST_SUITE(TServerTest)

Y_UNIT_TEST(ShouldStartEndpointIfSocketAlreadyExists)
{
TFsPath unixSocket("./TestUnixSocket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");
unixSocket.Touch();
Y_DEFER {
unixSocket.DeleteIfExists();
Expand Down
7 changes: 4 additions & 3 deletions cloud/blockstore/libs/server/server_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <library/cpp/testing/unittest/tests_data.h>

#include <util/folder/path.h>
#include <util/generic/guid.h>
#include <util/generic/scope.h>

namespace NCloud::NBlockStore::NServer {
Expand Down Expand Up @@ -815,7 +816,7 @@ Y_UNIT_TEST_SUITE(TServerTest)

Y_UNIT_TEST(ShouldIdentifyFdControlChannelSource)
{
TFsPath unixSocket("./test_socket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");

auto service = std::make_shared<TTestService>();
service->ReadBlocksHandler =
Expand Down Expand Up @@ -866,7 +867,7 @@ Y_UNIT_TEST_SUITE(TServerTest)
TPortManager portManager;
ui16 serverPort = portManager.GetPort(9001);
ui16 clientPort = portManager.GetPort(9002);
TFsPath unixSocket("./test_socket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");

auto service = std::make_shared<TTestService>();
service->ReadBlocksHandler =
Expand Down Expand Up @@ -1087,7 +1088,7 @@ Y_UNIT_TEST_SUITE(TServerTest)
TPortManager portManager;
ui16 serverPort = portManager.GetPort(9001);
ui16 clientPort = portManager.GetPort(9002);
TFsPath unixSocket("./test_socket");
TFsPath unixSocket(CreateGuidAsString() + ".sock");

auto service = std::make_shared<TTestService>();
service->ReadBlocksHandler =
Expand Down
Loading
Loading