diff --git a/bindings/python/tests/fdbcli_tests.py b/bindings/python/tests/fdbcli_tests.py index 5bb51718c4..5e6f97d69e 100755 --- a/bindings/python/tests/fdbcli_tests.py +++ b/bindings/python/tests/fdbcli_tests.py @@ -146,6 +146,23 @@ def setclass(logger): assert 'set_class' in line # set back to unset run_fdbcli_command('setclass', random_address, 'unset') + # Attempt to set an invalid address and check error message + output3 = run_fdbcli_command('setclass', '0.0.0.0:4000', 'storage') + logger.debug(output3) + assert 'No matching addresses found' in output3 + # Verify setclass did not execute + output4 = run_fdbcli_command('setclass') + logger.debug(output4) + # except the first line, each line is one process + process_types = output4.split('\n')[1:] + assert len(process_types) == args.process_number + addresses = [] + for line in process_types: + assert '127.0.0.1' in line + # check class type + assert 'unset' in line + # check class source + assert 'command_line' in line or 'set_class' in line @enable_logging() diff --git a/fdbcli/SetClassCommand.actor.cpp b/fdbcli/SetClassCommand.actor.cpp index 7e2b1b7de7..e08b7113a6 100644 --- a/fdbcli/SetClassCommand.actor.cpp +++ b/fdbcli/SetClassCommand.actor.cpp @@ -73,40 +73,22 @@ ACTOR Future printProcessClass(Reference db) { }; ACTOR Future setProcessClass(Reference db, KeyRef network_address, KeyRef class_type) { - // Check if the network address filter matches any processes before proceeding. - state Reference preCheckFilterTr = db->createTransaction(); + state Reference tr = db->createTransaction(); loop { - preCheckFilterTr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES); + tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES); try { state ThreadFuture> result = - preCheckFilterTr->get(network_address.withPrefix(fdb_cli::processClassTypeSpecialKeyRange.begin)); + tr->get(network_address.withPrefix(fdb_cli::processClassTypeSpecialKeyRange.begin)); Optional val = wait(safeThreadFutureToFuture(result)); if (!val.present()) { printf("No matching addresses found\n"); return false; } - break; - } catch (Error& e) { - wait(safeThreadFutureToFuture(preCheckFilterTr->onError(e))); - } - } - - state Reference tr = db->createTransaction(); - loop { - tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES); - try { tr->set(network_address.withPrefix(fdb_cli::processClassTypeSpecialKeyRange.begin), class_type); wait(safeThreadFutureToFuture(tr->commit())); return true; } catch (Error& e) { - state Error err(e); - if (e.code() == error_code_special_keys_api_failure) { - std::string errorMsgStr = wait(fdb_cli::getSpecialKeysFailureErrorMessage(tr)); - // error message already has \n at the end - fprintf(stderr, "%s", errorMsgStr.c_str()); - return false; - } - wait(safeThreadFutureToFuture(tr->onError(err))); + wait(safeThreadFutureToFuture(tr->onError(e))); } } }