Use a transaction option to control includePort behavior

This commit is contained in:
Andrew Noyes 2019-09-05 14:58:39 -07:00
parent 11f6adf645
commit c18c4c1b83
3 changed files with 17 additions and 10 deletions

View File

@ -2137,15 +2137,11 @@ Future< Void > Transaction::watch( Reference<Watch> watch ) {
return ::watch(watch, cx, this);
}
ACTOR Future< Standalone< VectorRef< const char*>>> getAddressesForKeyActor( Key key, Future<Version> ver, Database cx, TransactionInfo info ) {
ACTOR Future<Standalone<VectorRef<const char*>>> getAddressesForKeyActor(Key key, Future<Version> ver, Database cx,
TransactionInfo info,
TransactionOptions options) {
state vector<StorageServerInterface> ssi;
state bool includePort = false;
if (key.startsWith(LiteralStringRef("\xff\xff"))) {
key = key.removePrefix(LiteralStringRef("\xff\xff"));
includePort = true;
}
// If key >= allKeys.end, then getRange will return a kv-pair with an empty value. This will result in our serverInterfaces vector being empty, which will cause us to return an empty addresses list.
state Key ksKey = keyServersKey(key);
@ -2164,7 +2160,7 @@ ACTOR Future< Standalone< VectorRef< const char*>>> getAddressesForKeyActor( Key
Standalone<VectorRef<const char*>> addresses;
for (auto i : ssi) {
std::string ipString = includePort ? i.address().toString() : i.address().ip.toString();
std::string ipString = options.includePort ? i.address().toString() : i.address().ip.toString();
char* c_string = new (addresses.arena()) char[ipString.length()+1];
strcpy(c_string, ipString.c_str());
addresses.push_back(addresses.arena(), c_string);
@ -2176,7 +2172,7 @@ Future< Standalone< VectorRef< const char*>>> Transaction::getAddressesForKey( c
++cx->transactionLogicalReads;
auto ver = getReadVersion();
return getAddressesForKeyActor(key, ver, cx, info);
return getAddressesForKeyActor(key, ver, cx, info, options);
}
ACTOR Future< Key > getKeyAndConflictRange(
@ -2974,7 +2970,12 @@ void Transaction::setOption( FDBTransactionOptions::Option option, Optional<Stri
info.useProvisionalProxies = true;
break;
default:
case FDBTransactionOptions::INCLUDE_PORT_IN_ADDRESS:
validateOptionValue(value, false);
options.includePort = true;
break;
default:
break;
}
}

View File

@ -131,6 +131,7 @@ struct TransactionOptions {
bool lockAware : 1;
bool readOnly : 1;
bool firstInBatch : 1;
bool includePort : 1;
TransactionOptions(Database const& cx);
TransactionOptions();

View File

@ -171,6 +171,9 @@ description is not currently required but encouraged.
<Option name="transaction_causal_read_risky" code="504"
description="The read version will be committed, and usually will be the latest committed, but might not be the latest committed in the event of a simultaneous fault and misbehaving clock."
defaultFor="20"/>
<Option name="transaction_include_port_in_address" code="505"
description="Addresses returned by get_addresses_for_key include the port when enabled. This will be enabled by default in api version 700, and this option will be deprecated."
defaultFor="23"/>
</Scope>
<Scope name="TransactionOption">
@ -179,6 +182,8 @@ description is not currently required but encouraged.
<Option name="causal_read_risky" code="20"
description="The read version will be committed, and usually will be the latest committed, but might not be the latest committed in the event of a simultaneous fault and misbehaving clock."/>
<Option name="causal_read_disable" code="21" />
<Option name="include_port_in_address" code="23"
description="Addresses returned by get_addresses_for_key include the port when enabled. This will be enabled by default in api version 700, and this option will be deprecated." />
<Option name="next_write_no_write_conflict_range" code="30"
description="The next write performed on this transaction will not generate a write conflict range. As a result, other transactions which read the key(s) being modified by the next write will not conflict with this transaction. Care needs to be taken when using this option on a transaction that is shared between multiple threads. When setting this option, write conflict ranges will be disabled on the next write operation, regardless of what thread it is on." />
<Option name="commit_on_first_proxy" code="40"