Skip to content

Commit

Permalink
Merge 00b30c2 into 96abd52
Browse files Browse the repository at this point in the history
  • Loading branch information
SammyVimes authored Jan 8, 2025
2 parents 96abd52 + 00b30c2 commit 8a1d2ae
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 27 deletions.
6 changes: 4 additions & 2 deletions ydb/apps/dstool/lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ydb.apps.dstool.lib.dstool_cmd_pdisk_set as pdisk_set
import ydb.apps.dstool.lib.dstool_cmd_pdisk_list as pdisk_list
import ydb.apps.dstool.lib.dstool_cmd_pdisk_stop as pdisk_stop
import ydb.apps.dstool.lib.dstool_cmd_pdisk_restart as pdisk_restart
import ydb.apps.dstool.lib.dstool_cmd_pdisk_readonly as pdisk_readonly

import ydb.apps.dstool.lib.dstool_cmd_vdisk_evict as vdisk_evict
import ydb.apps.dstool.lib.dstool_cmd_vdisk_list as vdisk_list
Expand Down Expand Up @@ -49,14 +51,14 @@
pool_list, pool_create_virtual,
group_check, group_decommit, group_show_blob_info, group_show_storage_efficiency, group_show_usage_by_tablets,
group_state, group_take_snapshot, group_add, group_list, group_virtual_create, group_virtual_cancel,
pdisk_add_by_serial, pdisk_remove_by_serial, pdisk_set, pdisk_list, pdisk_stop,
pdisk_add_by_serial, pdisk_remove_by_serial, pdisk_set, pdisk_list, pdisk_stop, pdisk_restart, pdisk_readonly,
vdisk_evict, vdisk_list, vdisk_set_read_only, vdisk_remove_donor, vdisk_wipe,
device_list,
]

default_structure = [
('device', ['list']),
('pdisk', ['add-by-serial', 'remove-by-serial', 'set', 'list', 'stop']),
('pdisk', ['add-by-serial', 'remove-by-serial', 'set', 'list', 'stop', 'restart', 'readonly']),
('vdisk', ['evict', 'list', 'set-read-only', 'remove-donor', 'wipe']),
('group', ['add', 'check', 'decommit', ('show', ['blob-info', 'storage-efficiency', 'usage-by-tablets']), 'state', 'take-snapshot', 'list', ('virtual', ['create', 'cancel'])]),
('pool', ['list', ('create', ['virtual'])]),
Expand Down
58 changes: 58 additions & 0 deletions ydb/apps/dstool/lib/dstool_cmd_pdisk_readonly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import ydb.apps.dstool.lib.common as common
import sys

description = 'Change PDisk read-only status'


def add_options(p):
common.add_pdisk_select_options(p)
common.add_ignore_degraded_group_check_option(p)
common.add_ignore_failure_model_group_check_option(p)
common.add_ignore_vslot_quotas_option(p)
common.add_basic_format_options(p)
p.add_argument('--enabled', type=str, choices=['true', 'false'], help='Enable read-only mode')


def create_request(args, pdisk):
request = common.create_bsc_request(args)
cmd = request.Command.add().SetPDiskReadOnly

cmd.TargetPDiskId.NodeId = pdisk[0]
cmd.TargetPDiskId.PDiskId = pdisk[1]

cmd.Value = args.enabled == 'true'

return request


def perform_request(request):
return common.invoke_bsc_request(request)


def is_successful_response(response):
return common.is_successful_bsc_response(response)


def do(args):
base_config = common.fetch_base_config()

assert not args.dry_run, '--dry-run is not supported for this command'

pdisks = common.get_selected_pdisks(args, base_config)

if len(pdisks) != 1:
common.print_status(args, success=False, error_reason='Only change one PDisk read-only status at a time')
sys.exit(1)

success = True
error_reason = ''

request = create_request(args, list(pdisks)[0])
response = perform_request(request)
if not is_successful_response(response):
success = False
error_reason += 'Request has failed: \n{0}\n{1}\n'.format(request, response)

common.print_status(args, success, error_reason)
if not success:
sys.exit(1)
55 changes: 55 additions & 0 deletions ydb/apps/dstool/lib/dstool_cmd_pdisk_restart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import ydb.apps.dstool.lib.common as common
import sys

description = 'Restart PDisk'


def add_options(p):
common.add_pdisk_select_options(p)
common.add_ignore_degraded_group_check_option(p)
common.add_ignore_failure_model_group_check_option(p)
common.add_ignore_vslot_quotas_option(p)
common.add_basic_format_options(p)


def create_request(args, pdisk):
request = common.create_bsc_request(args)
cmd = request.Command.add().RestartPDisk

cmd.TargetPDiskId.NodeId = pdisk[0]
cmd.TargetPDiskId.PDiskId = pdisk[1]

return request


def perform_request(request):
return common.invoke_bsc_request(request)


def is_successful_response(response):
return common.is_successful_bsc_response(response)


def do(args):
base_config = common.fetch_base_config()

assert not args.dry_run, '--dry-run is not supported for this command'

pdisks = common.get_selected_pdisks(args, base_config)

if len(pdisks) != 1:
common.print_status(args, success=False, error_reason='Only restart one PDisk at a time')
sys.exit(1)

success = True
error_reason = ''

request = create_request(args, list(pdisks)[0])
response = perform_request(request)
if not is_successful_response(response):
success = False
error_reason += 'Request has failed: \n{0}\n{1}\n'.format(request, response)

common.print_status(args, success, error_reason)
if not success:
sys.exit(1)
2 changes: 2 additions & 0 deletions ydb/apps/dstool/lib/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ PY_SRCS(

dstool_cmd_pdisk_add_by_serial.py
dstool_cmd_pdisk_list.py
dstool_cmd_pdisk_readonly.py
dstool_cmd_pdisk_remove_by_serial.py
dstool_cmd_pdisk_restart.py
dstool_cmd_pdisk_set.py
dstool_cmd_pdisk_stop.py

Expand Down
74 changes: 49 additions & 25 deletions ydb/core/mind/bscontroller/cmds_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,54 @@ namespace NKikimr::NBsController {
boxes.erase(cmd.GetOriginBoxId());
}

void TBlobStorageController::TConfigState::ExecuteStep(const NKikimrBlobStorage::TRestartPDisk& cmd, TStatus& /*status*/) {
auto targetPDiskId = cmd.GetTargetPDiskId();
TPDiskId GetPDiskId(const TBlobStorageController::TConfigState& state, const TString& fqdn, ui32 icPort, ui32 nodeId, const TString& diskPath, ui32 pdiskId) {
ui32 targetNodeId = nodeId;

bool foundNode = false;

if (!nodeId) {
const TBlobStorageController::THostId key(fqdn, icPort);
if (const auto& nodeId = state.HostRecords->ResolveNodeId(key)) {
targetNodeId = *nodeId;
foundNode = true;
}
} else if (!fqdn && !icPort) {
if (const auto& hostId = state.HostRecords->GetHostId(nodeId)) {
foundNode = true;
}
} else {
// when both fqdn:port and node id were filled, we have to ensure that they match each other
foundNode = state.HostRecords->GetHostId(nodeId) == std::make_tuple(fqdn, icPort);
}

if (!foundNode) {
throw TExHostNotFound({fqdn, icPort}) << " HostKey# " << fqdn << ":" << icPort << " incorrect";
}

TPDiskId res;

if (pdiskId) {
if (diskPath) {
throw TExError() << "TUpdateDriveStatus.Path and PDiskId are mutually exclusive";
}
res = TPDiskId(targetNodeId, pdiskId);
if (!state.PDisks.Find(res) || state.PDisksToRemove.count(res)) {
throw TExPDiskNotFound(targetNodeId, pdiskId);
}
} else {
const std::optional<TPDiskId> found = state.FindPDiskByLocation(targetNodeId, diskPath);
if (found && !state.PDisksToRemove.count(*found)) {
res = *found;
} else {
throw TExPDiskNotFound(nodeId, diskPath);
}
}

return res;
}

TPDiskId pdiskId(targetPDiskId.GetNodeId(), targetPDiskId.GetPDiskId());
void TBlobStorageController::TConfigState::ExecuteStep(const NKikimrBlobStorage::TRestartPDisk& cmd, TStatus& /*status*/) {
TPDiskId pdiskId = GetPDiskId(*this, cmd.GetFqdn(), cmd.GetIcPort(), cmd.GetTargetPDiskId().GetNodeId(), cmd.GetPath(), cmd.GetTargetPDiskId().GetPDiskId());

TPDiskInfo *pdisk = PDisks.FindForUpdate(pdiskId);

Expand All @@ -252,9 +296,7 @@ namespace NKikimr::NBsController {
}

void TBlobStorageController::TConfigState::ExecuteStep(const NKikimrBlobStorage::TSetPDiskReadOnly& cmd, TStatus& /*status*/) {
auto targetPDiskId = cmd.GetTargetPDiskId();

TPDiskId pdiskId(targetPDiskId.GetNodeId(), targetPDiskId.GetPDiskId());
TPDiskId pdiskId = GetPDiskId(*this, cmd.GetFqdn(), cmd.GetIcPort(), cmd.GetTargetPDiskId().GetNodeId(), cmd.GetPath(), cmd.GetTargetPDiskId().GetPDiskId());

TPDiskInfo *pdisk = PDisks.FindForUpdate(pdiskId);

Expand All @@ -281,25 +323,7 @@ namespace NKikimr::NBsController {
}

void TBlobStorageController::TConfigState::ExecuteStep(const NKikimrBlobStorage::TStopPDisk& cmd, TStatus& /*status*/) {
const auto& host = NormalizeHostKey(cmd.GetHostKey());

TPDiskId pdiskId;
if (cmd.GetPDiskId()) {
if (cmd.GetPath()) {
throw TExError() << "TUpdateDriveStatus.Path and PDiskId are mutually exclusive";
}
pdiskId = TPDiskId(host.GetNodeId(), cmd.GetPDiskId());
if (!PDisks.Find(pdiskId) || PDisksToRemove.count(pdiskId)) {
throw TExPDiskNotFound(host, cmd.GetPDiskId(), TString());
}
} else {
const std::optional<TPDiskId> found = FindPDiskByLocation(host.GetNodeId(), cmd.GetPath());
if (found && !PDisksToRemove.count(*found)) {
pdiskId = *found;
} else {
throw TExPDiskNotFound(host, 0, cmd.GetPath());
}
}
TPDiskId pdiskId = GetPDiskId(*this, cmd.GetHostKey().GetFqdn(), cmd.GetHostKey().GetIcPort(), cmd.GetHostKey().GetNodeId(), cmd.GetPath(), cmd.GetPDiskId());

TPDiskInfo *pdisk = PDisks.FindForUpdate(pdiskId);

Expand Down
6 changes: 6 additions & 0 deletions ydb/core/mind/bscontroller/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ namespace NKikimr::NBsController {
<< TErrorParams::PDiskId(pdiskId);
}

TExPDiskNotFound(ui32 nodeId, TString path) {
*this << "PDisk not found"
<< TErrorParams::NodeId(nodeId)
<< TErrorParams::Path(path);
}

NKikimrBlobStorage::TConfigResponse::TStatus::EFailReason GetFailReason() const override {
return NKikimrBlobStorage::TConfigResponse::TStatus::kPDiskNotFound;
}
Expand Down
6 changes: 6 additions & 0 deletions ydb/core/protos/blobstorage_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,17 @@ message TWipeVDisk {

message TRestartPDisk {
NKikimrBlobStorage.TPDiskId TargetPDiskId = 1;
string Path = 2;
string Fqdn = 3;
int32 IcPort = 4;
}

message TSetPDiskReadOnly {
NKikimrBlobStorage.TPDiskId TargetPDiskId = 1;
bool Value = 2;
string Path = 3;
string Fqdn = 4;
int32 IcPort = 5;
}

message TStopPDisk {
Expand Down

0 comments on commit 8a1d2ae

Please sign in to comment.