mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-16 10:52:20 +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
|
assert 'set_class' in line
|
||||||
# set back to unset
|
# set back to unset
|
||||||
run_fdbcli_command('setclass', random_address, '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()
|
@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) {
|
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> tr = db->createTransaction();
|
||||||
state Reference<ITransaction> preCheckFilterTr = db->createTransaction();
|
|
||||||
loop {
|
loop {
|
||||||
preCheckFilterTr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
|
tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
|
||||||
try {
|
try {
|
||||||
state ThreadFuture<Optional<Value>> result =
|
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));
|
Optional<Value> val = wait(safeThreadFutureToFuture(result));
|
||||||
if (!val.present()) {
|
if (!val.present()) {
|
||||||
printf("No matching addresses found\n");
|
printf("No matching addresses found\n");
|
||||||
return false;
|
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);
|
tr->set(network_address.withPrefix(fdb_cli::processClassTypeSpecialKeyRange.begin), class_type);
|
||||||
wait(safeThreadFutureToFuture(tr->commit()));
|
wait(safeThreadFutureToFuture(tr->commit()));
|
||||||
return true;
|
return true;
|
||||||
} catch (Error& e) {
|
} catch (Error& e) {
|
||||||
state Error err(e);
|
wait(safeThreadFutureToFuture(tr->onError(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)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user