mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 01:42:37 +08:00
Use single transaction for setProcessClass and add fdbcli unit test.
This commit is contained in:
parent
d1fe48ce84
commit
d3055cc59a
@ -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()
|
||||
|
@ -73,40 +73,22 @@ ACTOR Future<Void> printProcessClass(Reference<IDatabase> db) {
|
||||
};
|
||||
|
||||
ACTOR Future<bool> setProcessClass(Reference<IDatabase> db, KeyRef network_address, KeyRef class_type) {
|
||||
// Check if the network address filter matches any processes before proceeding.
|
||||
state Reference<ITransaction> preCheckFilterTr = db->createTransaction();
|
||||
state Reference<ITransaction> tr = db->createTransaction();
|
||||
loop {
|
||||
preCheckFilterTr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
|
||||
tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
|
||||
try {
|
||||
state ThreadFuture<Optional<Value>> result =
|
||||
preCheckFilterTr->get(network_address.withPrefix(fdb_cli::processClassTypeSpecialKeyRange.begin));
|
||||
tr->get(network_address.withPrefix(fdb_cli::processClassTypeSpecialKeyRange.begin));
|
||||
Optional<Value> 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<ITransaction> 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user