Skip to content

Commit

Permalink
update stored endpoint's size during resize; fix #2928
Browse files Browse the repository at this point in the history
  • Loading branch information
tpashkin authored Jan 27, 2025
1 parent 77951e7 commit 9f40246
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cloud/blockstore/libs/endpoint_proxy/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ struct TServer: IEndpointProxyServer
void DoProcessRequest(
const NProto::TResizeProxyDeviceRequest& request,
TEndpoint& ep,
NProto::TResizeProxyDeviceResponse& response) const
NProto::TResizeProxyDeviceResponse& response)
{
if (ep.NbdDevice) {
auto err = ep.NbdDevice->Resize(request.GetDeviceSizeInBytes())
Expand All @@ -874,6 +874,9 @@ struct TServer: IEndpointProxyServer

ep.NbdOptions.BlocksCount =
request.GetDeviceSizeInBytes() / ep.NbdOptions.BlockSize;

StoreEndpointIfNeeded(ep);

STORAGE_INFO(
request.ShortDebugString().Quote()
<< " - NBD device was resized");
Expand Down
27 changes: 24 additions & 3 deletions cloud/blockstore/tests/e2e-tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import subprocess
import tempfile
import yaml

from pathlib import Path

Expand All @@ -29,7 +30,11 @@
"cloud/blockstore/apps/endpoint_proxy/blockstore-endpoint-proxy")


def init(with_netlink=True, with_endpoint_proxy=True):
def init(
with_netlink=True,
with_endpoint_proxy=True,
stored_endpoints_path=None
):
server_config_patch = TServerConfig()
server_config_patch.NbdEnabled = True
if with_endpoint_proxy:
Expand Down Expand Up @@ -57,13 +62,16 @@ def init(with_netlink=True, with_endpoint_proxy=True):
server.ServerConfig.StrictContractValidation = True
server.KikimrServiceConfig.CopyFrom(TKikimrServiceConfig())
subprocess.check_call(["modprobe", "nbd"], timeout=20)
if stored_endpoints_path:
stored_endpoints_path.mkdir(exist_ok=True)
env = LocalLoadTest(
endpoint="",
server_app_config=server,
storage_config_patches=None,
use_in_memory_pdisks=True,
with_endpoint_proxy=with_endpoint_proxy,
with_netlink=with_netlink)
with_netlink=with_netlink,
stored_endpoints_path=stored_endpoints_path)

client_config_path = Path(yatest_common.output_path()) / "client-config.txt"
client_config = TClientAppConfig()
Expand Down Expand Up @@ -118,13 +126,16 @@ def log_called_process_error(exc):
@pytest.mark.parametrize('with_netlink,with_endpoint_proxy',
[(True, False), (True, True), (False, False), (False, True)])
def test_resize_device(with_netlink, with_endpoint_proxy):
env, run = init(with_netlink, with_endpoint_proxy)
stored_endpoints_path = Path(common.output_path()) / "stored_endpoints"
env, run = init(with_netlink, with_endpoint_proxy, stored_endpoints_path)

volume_name = "example-disk"
block_size = 4096
blocks_count = 10000
volume_size = blocks_count * block_size
nbd_device = "/dev/nbd0"
socket_path = "/tmp/nbd.sock"
stored_endpoint_path = stored_endpoints_path / socket_path.replace("/", "_")
try:
result = run(
"createvolume",
Expand Down Expand Up @@ -174,6 +185,11 @@ def test_resize_device(with_netlink, with_endpoint_proxy):
stderr=subprocess.STDOUT)
assert result.returncode == 0

if with_endpoint_proxy:
with open(stored_endpoint_path) as stream:
stored_endpoint = yaml.safe_load(stream)
assert stored_endpoint["BlocksCount"] == volume_size / block_size

new_volume_size = 2 * volume_size
result = run(
"resizevolume",
Expand Down Expand Up @@ -206,6 +222,11 @@ def test_resize_device(with_netlink, with_endpoint_proxy):
stderr=subprocess.STDOUT)
assert result.returncode == 0

if with_endpoint_proxy:
with open(stored_endpoint_path) as stream:
stored_endpoint = yaml.safe_load(stream)
assert stored_endpoint["BlocksCount"] == new_volume_size / block_size

except subprocess.CalledProcessError as e:
log_called_process_error(e)
raise
Expand Down
10 changes: 9 additions & 1 deletion cloud/blockstore/tests/python/lib/endpoint_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

class EndpointProxy(Daemon):

def __init__(self, working_dir, unix_socket_path, with_netlink):
def __init__(
self,
working_dir,
unix_socket_path,
with_netlink,
stored_endpoints_path
):
command = [yatest_common.binary_path(
"cloud/blockstore/apps/endpoint_proxy/blockstore-endpoint-proxy")]
command += [
"--unix-socket-path", unix_socket_path, "--verbose"
]
if stored_endpoints_path:
command += ["--stored-endpoints-path", stored_endpoints_path]

if with_netlink:
command += ["--netlink"]
Expand Down
4 changes: 3 additions & 1 deletion cloud/blockstore/tests/python/lib/loadtest_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
with_netlink=False,
access_service_type=AccessService,
load_configs_from_cms=True,
stored_endpoints_path=None,
):

self.__endpoint = endpoint
Expand Down Expand Up @@ -125,7 +126,8 @@ def __init__(
self.endpoint_proxy = EndpointProxy(
working_dir=self.nbs.cwd,
unix_socket_path=server_app_config.ServerConfig.EndpointProxySocketPath,
with_netlink=with_netlink)
with_netlink=with_netlink,
stored_endpoints_path=stored_endpoints_path)

if run_kikimr:
self.nbs.setup_cms(self.kikimr_cluster.client)
Expand Down

0 comments on commit 9f40246

Please sign in to comment.