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

issue-1657: resize pvc with nbd-lightweight and minikube #1846

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/blockstore/config/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ message TNullServiceConfig
message TLocalServiceConfig
{
optional string DataDir = 1;
// Shutdown timeout (in milliseconds).
optional uint32 ShutdownTimeout = 2;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
138 changes: 105 additions & 33 deletions cloud/blockstore/libs/service_local/service_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cloud/blockstore/libs/service/storage.h>
#include <cloud/blockstore/libs/service/storage_provider.h>
#include <cloud/storage/core/libs/common/error.h>
#include <cloud/storage/core/libs/common/timer.h>

#include <library/cpp/protobuf/util/pb_io.h>

Expand Down Expand Up @@ -62,17 +63,27 @@ struct TMountSession
{
const TString SessionId;
const TString ClientId;
const IStoragePtr Storage;
const TStorageAdapter StorageAdapter;

TMountSession(TString clientId, IStoragePtr storage, ui32 blockSize)
const NProto::EVolumeAccessMode AccessMode;
IStoragePtr Storage;
std::unique_ptr<TStorageAdapter> StorageAdapter;

TMountSession(
TString clientId,
NProto::EVolumeAccessMode accessMode,
IStoragePtr storage,
ui32 blockSize,
TDuration storageShutdownTimeout)
: SessionId(CreateGuidAsString())
, ClientId(std::move(clientId))
, AccessMode(accessMode)
, Storage(storage)
, StorageAdapter(
std::move(storage),
blockSize,
true)
, StorageAdapter(std::make_unique<TStorageAdapter>(
std::move(storage),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а тут какие-то 2 лишних пробела добавилось в отступ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потому что теперь это параметры std::make_unique

blockSize,
true,
0,
TDuration::Zero(),
storageShutdownTimeout))
{}
};

Expand All @@ -83,7 +94,7 @@ using TMountSessionMap = THashMap<TString, TMountSessionPtr>;

struct TMountedVolume
{
const NProto::TVolume Volume;
NProto::TVolume Volume;

TMountSessionMap Sessions;
TMutex SessionLock;
Expand All @@ -92,13 +103,19 @@ struct TMountedVolume
: Volume(std::move(volume))
{}

TMountSessionPtr CreateSession(TString clientId, IStoragePtr storage)
TMountSessionPtr CreateSession(
TString clientId,
NProto::EVolumeAccessMode accessMode,
IStoragePtr storage,
TDuration storageShutdownTimeout)
{
with_lock (SessionLock) {
auto session = std::make_shared<TMountSession>(
std::move(clientId),
accessMode,
std::move(storage),
Volume.GetBlockSize());
Volume.GetBlockSize(),
storageShutdownTimeout);

Sessions.emplace(session->SessionId, session);
return session;
Expand Down Expand Up @@ -143,14 +160,19 @@ class TVolumeManager
{
private:
const TString DataDir;
const TDuration StorageShutdownTimeout;
const IStorageProviderPtr StorageProvider;

TMountedVolumeMap MountedVolumes;
TMutex MountLock;

public:
TVolumeManager(const TString& dataDir, IStorageProviderPtr storageProvider)
TVolumeManager(
const TString& dataDir,
TDuration storageShutdownTimeout,
IStorageProviderPtr storageProvider)
: DataDir(dataDir ? dataDir : NFs::CurrentWorkingDirectory())
, StorageShutdownTimeout(storageShutdownTimeout)
, StorageProvider(std::move(storageProvider))
{}

Expand Down Expand Up @@ -201,6 +223,32 @@ class TVolumeManager

TFile fileData(MakeDataPath(diskId), EOpenModeFlag::OpenExisting);
fileData.Resize(volume.GetBlockSize() * blocksCount);

auto mountedVolume = FindMountedVolume(diskId);
if (!mountedVolume) {
return;
}
with_lock (mountedVolume->SessionLock) {
mountedVolume->Volume = volume;
for (auto& session: mountedVolume->Sessions) {
auto dataPath = MakeDataPath(volume.GetDiskId());
volume.SetDiskId(dataPath);
session.second->Storage = StorageProvider
qkrorlqr marked this conversation as resolved.
Show resolved Hide resolved
->CreateStorage(
volume,
session.second->ClientId,
session.second->AccessMode)
.GetValueSync();
session.second->StorageAdapter =
std::make_unique<TStorageAdapter>(
session.second->Storage,
volume.GetBlockSize(),
true,
0,
TDuration::Zero(),
StorageShutdownTimeout);
}
}
}

void DestroyVolume(const TString& diskId)
Expand Down Expand Up @@ -254,25 +302,29 @@ class TVolumeManager
NProto::TVolume volume = mountedVolume->Volume;
volume.SetDiskId(dataPath);
return StorageProvider->CreateStorage(volume, clientId, accessMode)
.Apply([=] (const auto& future) {
auto storage = future.GetValue();
if (!storage) {
.Apply(
[this, mountedVolume, clientId, accessMode](const auto& future)
{
auto storage = future.GetValue();
if (!storage) {
NProto::TMountVolumeResponse response;
auto& error = *response.MutableError();
error.SetCode(E_FAIL);
error.SetMessage("Failed to create storage");
return response;
}

auto session = mountedVolume->CreateSession(
clientId,
accessMode,
std::move(storage),
StorageShutdownTimeout);

NProto::TMountVolumeResponse response;
auto& error = *response.MutableError();
error.SetCode(E_FAIL);
error.SetMessage("Failed to create storage");
response.SetSessionId(session->SessionId);
*response.MutableVolume() = mountedVolume->Volume;
return response;
}

auto session = mountedVolume->CreateSession(
clientId,
std::move(storage));

NProto::TMountVolumeResponse response;
response.SetSessionId(session->SessionId);
*response.MutableVolume() = mountedVolume->Volume;
return response;
});
});
}

void UnmountVolume(const TString& diskId, const TString& sessionId)
Expand Down Expand Up @@ -353,6 +405,8 @@ struct TLocalServiceBase

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

const ui32 kDefaultStorageShutdownTimeoutInMilliseconds = 60000;

class TLocalService final
: public TLocalServiceBase
{
Expand All @@ -366,7 +420,13 @@ class TLocalService final
IDiscoveryServicePtr discoveryService,
IStorageProviderPtr storageProvider)
: DiscoveryService(std::move(discoveryService))
, VolumeManager(config.GetDataDir(), std::move(storageProvider))
, VolumeManager(
config.GetDataDir(),
TDuration::MilliSeconds(
config.HasShutdownTimeout()
? config.GetShutdownTimeout()
: kDefaultStorageShutdownTimeoutInMilliseconds),
std::move(storageProvider))
{}

void Start() override {}
Expand Down Expand Up @@ -666,7 +726,11 @@ TFuture<NProto::TReadBlocksResponse> TLocalService::ReadBlocks(
<< "Out of bounds read request";
}

return session->StorageAdapter.ReadBlocks(
if (!session->StorageAdapter) {
ythrow TServiceError(E_FAIL) << "Invalid storage adapter";
}

return session->StorageAdapter->ReadBlocks(
Now(),
std::move(ctx),
std::move(request),
Expand Down Expand Up @@ -725,7 +789,11 @@ TFuture<NProto::TWriteBlocksResponse> TLocalService::WriteBlocks(
<< "Out of bounds write request";
}

return session->StorageAdapter.WriteBlocks(
if (!session->StorageAdapter) {
ythrow TServiceError(E_FAIL) << "Invalid storage adapter";
}

return session->StorageAdapter->WriteBlocks(
Now(),
std::move(ctx),
std::move(request),
Expand Down Expand Up @@ -776,7 +844,11 @@ TFuture<NProto::TZeroBlocksResponse> TLocalService::ZeroBlocks(
<< "Out of bounds write request";
}

return session->StorageAdapter.ZeroBlocks(
if (!session->StorageAdapter) {
ythrow TServiceError(E_FAIL) << "Invalid storage adapter";
}

return session->StorageAdapter->ZeroBlocks(
Now(),
std::move(ctx),
std::move(request),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ spec:
requests:
storage: 1Gi
limits:
storage: 1Gi
storage: 10Gi
storageClassName: nbs-csi-sc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ metadata:
name: nbs-csi-sc
provisioner: nbs.csi.nebius.ai
volumeBindingMode: Immediate
allowVolumeExpansion: true
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ spec:
volumeMounts:
- name: socket-dir
mountPath: /csi
- name: csi-resizer
image: registry.k8s.io/sig-storage/csi-resizer:v1.11.2
imagePullPolicy: IfNotPresent
args:
- "--v=5"
- "--csi-address=/csi/csi.sock"
- "--leader-election"
- "--http-endpoint=:8081"
env:
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "250m"
ports:
- containerPort: 8081
name: http-endpoint
protocol: TCP
volumeMounts:
- name: socket-dir
mountPath: /csi
- name: csi-nbs-driver
image: nbs-csi-driver:latest
imagePullPolicy: IfNotPresent
Expand Down
Loading