Skip to content

Commit 501fbe4

Browse files
alexvruydbot
authored andcommitted
Support reconfiguration of BlobDepot (#29641)
1 parent 8fd50d8 commit 501fbe4

File tree

11 files changed

+97
-2
lines changed

11 files changed

+97
-2
lines changed

ydb/apps/dstool/lib/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import ydb.apps.dstool.lib.dstool_cmd_group_take_snapshot as group_take_snapshot
2828
import ydb.apps.dstool.lib.dstool_cmd_group_virtual_create as group_virtual_create
2929
import ydb.apps.dstool.lib.dstool_cmd_group_virtual_cancel as group_virtual_cancel
30+
import ydb.apps.dstool.lib.dstool_cmd_group_virtual_reconfigure as group_virtual_reconfigure
3031

3132
import ydb.apps.dstool.lib.dstool_cmd_pool_create_virtual as pool_create_virtual
3233
import ydb.apps.dstool.lib.dstool_cmd_pool_list as pool_list
@@ -52,7 +53,7 @@
5253
box_list,
5354
pool_list, pool_create_virtual,
5455
group_check, group_decommit, group_show_blob_info, group_show_storage_efficiency, group_show_usage_by_tablets,
55-
group_state, group_take_snapshot, group_add, group_list, group_virtual_create, group_virtual_cancel,
56+
group_state, group_take_snapshot, group_add, group_list, group_virtual_create, group_virtual_cancel, group_virtual_reconfigure,
5657
pdisk_add_by_serial, pdisk_remove_by_serial, pdisk_set, pdisk_list, pdisk_stop, pdisk_restart, pdisk_readonly, pdisk_move,
5758
vdisk_evict, vdisk_list, vdisk_set_read_only, vdisk_remove_donor, vdisk_wipe, vdisk_compact, device_list,
5859
]
@@ -61,7 +62,7 @@
6162
('device', ['list']),
6263
('pdisk', ['add-by-serial', 'remove-by-serial', 'set', 'list', 'stop', 'restart', 'readonly', 'move']),
6364
('vdisk', ['evict', 'list', 'set-read-only', 'remove-donor', 'wipe', 'compact']),
64-
('group', ['add', 'check', 'decommit', ('show', ['blob-info', 'storage-efficiency', 'usage-by-tablets']), 'state', 'take-snapshot', 'list', ('virtual', ['create', 'cancel'])]),
65+
('group', ['add', 'check', 'decommit', ('show', ['blob-info', 'storage-efficiency', 'usage-by-tablets']), 'state', 'take-snapshot', 'list', ('virtual', ['create', 'cancel', 'reconfigure'])]),
6566
('pool', ['list', ('create', ['virtual'])]),
6667
('box', ['list']),
6768
('node', ['list']),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import ydb.apps.dstool.lib.common as common
2+
from argparse import FileType
3+
import google.protobuf.json_format as pb_json
4+
5+
description = 'Create virtual group backed by BlobDepot'
6+
7+
8+
def add_options(p):
9+
p.add_argument('--name', type=str, required=True, help='name of virtual group that requires reconfiguring')
10+
p.add_argument('--s3-settings', type=FileType('r', encoding='utf-8'), metavar='JSON_FILE', help='path to JSON file containing S3 settings')
11+
12+
13+
def do(args):
14+
request = common.create_bsc_request(args)
15+
16+
if args.s3_settings:
17+
s3_settings = args.s3_settings.read()
18+
else:
19+
s3_settings = None
20+
21+
cmd = request.Command.add().ReconfigureVirtualGroup
22+
cmd.Name = args.name
23+
24+
if s3_settings is not None:
25+
pb_json.Parse(s3_settings, cmd.S3BackendSettings)
26+
27+
response = common.invoke_bsc_request(request)
28+
common.print_request_result(args, request, response)

ydb/apps/dstool/lib/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ PY_SRCS(
3838
dstool_cmd_group_take_snapshot.py
3939
dstool_cmd_group_virtual_create.py
4040
dstool_cmd_group_virtual_cancel.py
41+
dstool_cmd_group_virtual_reconfigure.py
4142

4243
dstool_cmd_pool_create_virtual.py
4344
dstool_cmd_pool_list.py

ydb/core/blob_depot/data.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ namespace NKikimr::NBlobDepot {
8888
return false; // no such key existed and will not be created as it hits the barrier
8989
}
9090

91+
Y_DEFER {
92+
Self->JsonHandler.Invalidate();
93+
};
94+
9195
const auto [it, inserted] = Data.try_emplace(std::move(key), std::forward<TArgs>(args)...);
9296
{
9397
auto& [key, value] = *it;

ydb/core/blob_depot/op_apply_config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ namespace NKikimr::NBlobDepot {
5050

5151
if (!std::exchange(Self->Configured, true)) {
5252
Self->StartOperation();
53+
} else {
54+
// TODO(alexvru): handle it in a better way, without tablet restart
55+
Self->Send(Self->Tablet(), new TEvents::TEvPoison);
5356
}
5457

5558
TActivationContext::Send(Response.release());

ydb/core/mind/bscontroller/bsc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ ui32 TBlobStorageController::GetEventPriority(IEventHandle *ev) {
11591159
case NKikimrBlobStorage::TConfigRequest::TCommand::kGetInterfaceVersion:
11601160
case NKikimrBlobStorage::TConfigRequest::TCommand::kMovePDisk:
11611161
case NKikimrBlobStorage::TConfigRequest::TCommand::kUpdateBridgeGroupInfo:
1162+
case NKikimrBlobStorage::TConfigRequest::TCommand::kReconfigureVirtualGroup:
11621163
return 2; // read-write commands go with higher priority as they are needed to keep cluster intact
11631164

11641165
case NKikimrBlobStorage::TConfigRequest::TCommand::kReadHostConfig:

ydb/core/mind/bscontroller/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ namespace NKikimr {
366366
void ExecuteStep(const NKikimrBlobStorage::TGetInterfaceVersion& cmd, TStatus& status);
367367
void ExecuteStep(const NKikimrBlobStorage::TMovePDisk& cmd, TStatus& status);
368368
void ExecuteStep(const NKikimrBlobStorage::TUpdateBridgeGroupInfo& cmd, TStatus& status);
369+
void ExecuteStep(const NKikimrBlobStorage::TReconfigureVirtualGroup& cmd, TStatus& status);
369370
};
370371

371372
} // NBsController

ydb/core/mind/bscontroller/config_cmd.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ namespace NKikimr::NBsController {
254254
MAP_TIMING(SanitizeGroup, SANITIZE_GROUP)
255255
MAP_TIMING(CancelVirtualGroup, CANCEL_VIRTUAL_GROUP)
256256
MAP_TIMING(ChangeGroupSizeInUnits, CHANGE_GROUP_SIZE_IN_UNITS)
257+
MAP_TIMING(ReconfigureVirtualGroup, RECONFIGURE_VIRTUAL_GROUP)
257258

258259
default:
259260
break;
@@ -370,6 +371,7 @@ namespace NKikimr::NBsController {
370371
HANDLE_COMMAND(GetInterfaceVersion)
371372
HANDLE_COMMAND(MovePDisk)
372373
HANDLE_COMMAND(UpdateBridgeGroupInfo)
374+
HANDLE_COMMAND(ReconfigureVirtualGroup)
373375

374376
case NKikimrBlobStorage::TConfigRequest::TCommand::kAddMigrationPlan:
375377
case NKikimrBlobStorage::TConfigRequest::TCommand::kDeleteMigrationPlan:

ydb/core/mind/bscontroller/virtual_group.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,52 @@ namespace NKikimr::NBsController {
209209
}
210210
}
211211

212+
void TBlobStorageController::TConfigState::ExecuteStep(const NKikimrBlobStorage::TReconfigureVirtualGroup& cmd,
213+
TStatus& /*status*/) {
214+
if (!cmd.GetName()) {
215+
throw TExError() << "TReconfigureVirtualGroup.Name must be set and be nonempty";
216+
}
217+
218+
std::optional<TGroupId> groupId;
219+
Groups.ForEach([&](TGroupId key, const TGroupInfo& value) {
220+
if (value.VirtualGroupName == cmd.GetName()) {
221+
if (groupId) {
222+
throw TExError() << "Duplicate virtual group name";
223+
}
224+
groupId.emplace(key);
225+
}
226+
});
227+
if (!groupId) {
228+
throw TExError() << "Virtual group not found by designated name";
229+
}
230+
231+
TGroupInfo *group = Groups.FindForUpdate(*groupId);
232+
if (!group->BlobDepotConfig) {
233+
Y_DEBUG_ABORT(); // this should never happen
234+
throw TExError() << "Virtual group does not contain BlobDepotConfig";
235+
}
236+
237+
// parse current config
238+
NKikimrBlobDepot::TBlobDepotConfig config;
239+
bool success = config.ParseFromString(*group->BlobDepotConfig);
240+
if (!success) {
241+
Y_DEBUG_ABORT();
242+
throw TExError() << "Failed to parse BlobDepotConfig";
243+
}
244+
245+
// update fields in current config
246+
if (cmd.HasS3BackendSettings()) {
247+
config.MutableS3BackendSettings()->CopyFrom(cmd.GetS3BackendSettings());
248+
}
249+
250+
// overwrite the config
251+
success = config.SerializeToString(&group->BlobDepotConfig.ConstructInPlace());
252+
Y_ABORT_UNLESS(success);
253+
254+
// start altering machinery
255+
group->NeedAlter = true;
256+
}
257+
212258
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
213259

214260
class TBlobStorageController::TVirtualGroupSetupMachine : public TActorBootstrapped<TVirtualGroupSetupMachine> {

ydb/core/protos/blobstorage_config.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,11 @@ message TUpdateBridgeGroupInfo {
591591
NKikimrBlobStorage.TGroupInfo BridgeGroupInfo = 3; // new value for bridge group info
592592
}
593593

594+
message TReconfigureVirtualGroup {
595+
string Name = 1;
596+
optional NKikimrBlobDepot.TS3BackendSettings S3BackendSettings = 2;
597+
}
598+
594599
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
595600
// INTERFACE PART
596601
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -641,6 +646,7 @@ message TConfigRequest {
641646
TChangeGroupSizeInUnits ChangeGroupSizeInUnits = 52;
642647
TMovePDisk MovePDisk = 53;
643648
TUpdateBridgeGroupInfo UpdateBridgeGroupInfo = 54;
649+
TReconfigureVirtualGroup ReconfigureVirtualGroup = 55;
644650

645651
// commands intended for internal use
646652
TReassignGroupDisk ReassignGroupDisk = 19;

0 commit comments

Comments
 (0)