Merge pull request #22 from alecgrieser/37844532-expose-append-if-fits
Expose APPEND_IF_FITS to clients
This commit is contained in:
commit
2a2ac56529
|
@ -18,7 +18,6 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
import ctypes
|
||||
import random
|
||||
import struct
|
||||
|
||||
|
@ -169,7 +168,7 @@ class ApiTest(Test):
|
|||
op_choices += resets
|
||||
|
||||
idempotent_atomic_ops = [u'BIT_AND', u'BIT_OR', u'MAX', u'MIN', u'BYTE_MIN', u'BYTE_MAX']
|
||||
atomic_ops = idempotent_atomic_ops + [u'ADD', u'BIT_XOR']
|
||||
atomic_ops = idempotent_atomic_ops + [u'ADD', u'BIT_XOR', u'APPEND_IF_FITS']
|
||||
|
||||
if args.concurrency > 1:
|
||||
self.max_keys = random.randint(100, 1000)
|
||||
|
|
|
@ -1654,6 +1654,7 @@ void populateAtomicOpMap() {
|
|||
optionInfo["BIT_OR"] = FDBMutationType::FDB_MUTATION_TYPE_BIT_OR;
|
||||
optionInfo["XOR"] = FDBMutationType::FDB_MUTATION_TYPE_XOR;
|
||||
optionInfo["BIT_XOR"] = FDBMutationType::FDB_MUTATION_TYPE_BIT_XOR;
|
||||
optionInfo["APPEND_IF_FITS"] = FDBMutationType::FDB_MUTATION_TYPE_APPEND_IF_FITS;
|
||||
optionInfo["MAX"] = FDBMutationType::FDB_MUTATION_TYPE_MAX;
|
||||
optionInfo["MIN"] = FDBMutationType::FDB_MUTATION_TYPE_MIN;
|
||||
optionInfo["SET_VERSIONSTAMPED_KEY"] = FDBMutationType::FDB_MUTATION_TYPE_SET_VERSIONSTAMPED_KEY;
|
||||
|
|
|
@ -1479,7 +1479,7 @@ void ReadYourWritesTransaction::atomicOp( const KeyRef& key, const ValueRef& ope
|
|||
if(key >= getMaxWriteKey())
|
||||
throw key_outside_legal_range();
|
||||
|
||||
if(!isValidMutationType(operationType) || !isAtomicOp((MutationRef::Type) operationType) || operationType == MutationRef::AppendIfFits)
|
||||
if(!isValidMutationType(operationType) || !isAtomicOp((MutationRef::Type) operationType))
|
||||
throw invalid_mutation_type();
|
||||
|
||||
if(key.size() > (key.startsWith(systemKeys.begin) ? CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT : CLIENT_KNOBS->KEY_SIZE_LIMIT))
|
||||
|
@ -1898,4 +1898,4 @@ void ReadYourWritesTransaction::debugLogRetries(Optional<Error> error) {
|
|||
transactionDebugInfo->lastRetryLogTime = now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,6 +217,9 @@ description is not currently required but encouraged.
|
|||
<Option name="bit_xor" code="8"
|
||||
paramType="Bytes" paramDescription="value with which to perform bitwise xor"
|
||||
description="Performs a bitwise ``xor`` operation. If the existing value in the database is not present or shorter than ``param``, it is first extended to the length of ``param`` with zero bytes. If ``param`` is shorter than the existing value in the database, the existing value is truncated to match the length of ``param``."/>
|
||||
<Option name="append_if_fits" code="9"
|
||||
paramType="Bytes" paramDescription="value to append to the database value"
|
||||
description="Appends ``param`` to the end of the existing value already in the database at the given key (or creates the key and sets the value to ``param`` if the key is empty). This will only append the value if the final concatenated value size is less than or equal to the maximum value size (i.e., if it fits). WARNING: No error is surfaced back to the user if the final value is too large because the mutation will not be applied until after the transaction has been committed. Therefore, it is only safe to use this mutation type if one can guarantee that one will keep the total value size under the maximum size."/>
|
||||
<Option name="max" code="12"
|
||||
paramType="Bytes" paramDescription="value to check against database value"
|
||||
description="Performs a little-endian comparison of byte strings. If the existing value in the database is not present or shorter than ``param``, it is first extended to the length of ``param`` with zero bytes. If ``param`` is shorter than the existing value in the database, the existing value is truncated to match the length of ``param``. The larger of the two values is then stored in the database."/>
|
||||
|
|
|
@ -862,7 +862,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
std::make_pair( error_code_key_too_large, ExceptionContract::requiredIf(key.size() > (key.startsWith(systemKeys.begin) ? CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT : CLIENT_KNOBS->KEY_SIZE_LIMIT)) ),
|
||||
std::make_pair( error_code_value_too_large, ExceptionContract::requiredIf(value.size() > CLIENT_KNOBS->VALUE_SIZE_LIMIT) ),
|
||||
std::make_pair( error_code_invalid_mutation_type, ExceptionContract::requiredIf(
|
||||
!isValidMutationType(op) || !isAtomicOp((MutationRef::Type) op) || op == MutationRef::AppendIfFits ) ),
|
||||
!isValidMutationType(op) || !isAtomicOp((MutationRef::Type) op)) ),
|
||||
std::make_pair( error_code_key_outside_legal_range, ExceptionContract::requiredIf(
|
||||
(key >= (workload->useSystemKeys ? systemKeys.end : normalKeys.end))) ),
|
||||
std::make_pair( error_code_client_invalid_operation, ExceptionContract::requiredIf(
|
||||
|
|
|
@ -138,7 +138,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
|
||||
try {
|
||||
for(i = 0; i < g_random->randomInt(self->minOperationsPerTransaction,self->maxOperationsPerTransaction+1); i++) {
|
||||
j = g_random->randomInt(0,15);
|
||||
j = g_random->randomInt(0,16);
|
||||
if( j < 3 ) {
|
||||
myKeyA = format( "%010d", g_random->randomInt( 0, self->maxKeySpace+1 ) );
|
||||
myValue = format("%d", g_random->randomInt( 0, 10000000 ) );
|
||||
|
@ -237,30 +237,30 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
//else if( j < 8 ) {
|
||||
// myKeyA = format( "%010d", g_random->randomInt( 0, self->maxKeySpace+1 ) );
|
||||
// myRandomIDKey = format( "%010d", g_random->randomInt(0, 1000000000) );
|
||||
// myValue = format("%d", g_random->randomInt( 0, 10000000 ) );
|
||||
// //TraceEvent("RYOWappendIfFits").detail("Key",myKeyA).detail("Value", myValue);
|
||||
// trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::AppendIfFits);
|
||||
//
|
||||
// loop {
|
||||
// try {
|
||||
// tr.set(StringRef(clientID + "z/" + myRandomIDKey), StringRef());
|
||||
// tr.atomicOp(StringRef(clientID + "d/" + myKeyA), myValue, MutationRef::AppendIfFits);
|
||||
// Void _ = wait( tr.commit() );
|
||||
// break;
|
||||
// } catch (Error& e) {
|
||||
// error = e;
|
||||
// Void _ = wait( tr.onError(e) );
|
||||
// if(error.code() == error_code_commit_unknown_result) {
|
||||
// Optional<Value> thing = wait(tr.get(StringRef(clientID+"z/"+myRandomIDKey)));
|
||||
// if (thing.present()) break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
else if( j < 8 ) {
|
||||
myKeyA = format( "%010d", g_random->randomInt( 0, self->maxKeySpace+1 ) );
|
||||
myRandomIDKey = format( "%010d", g_random->randomInt(0, 1000000000) );
|
||||
myValue = format("%d", g_random->randomInt( 0, 10000000 ) );
|
||||
//TraceEvent("RYOWappendIfFits").detail("Key",myKeyA).detail("Value", myValue);
|
||||
trRYOW.atomicOp(StringRef(clientID + "b/" + myKeyA), myValue, MutationRef::AppendIfFits);
|
||||
|
||||
loop {
|
||||
try {
|
||||
tr.set(StringRef(clientID + "z/" + myRandomIDKey), StringRef());
|
||||
tr.atomicOp(StringRef(clientID + "d/" + myKeyA), myValue, MutationRef::AppendIfFits);
|
||||
Void _ = wait( tr.commit() );
|
||||
break;
|
||||
} catch (Error& e) {
|
||||
error = e;
|
||||
Void _ = wait( tr.onError(e) );
|
||||
if(error.code() == error_code_commit_unknown_result) {
|
||||
Optional<Value> thing = wait(tr.get(StringRef(clientID+"z/"+myRandomIDKey)));
|
||||
if (thing.present()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( j < 9 ) {
|
||||
myKeyA = format( "%010d", g_random->randomInt( 0, self->maxKeySpace+1 ) );
|
||||
myRandomIDKey = format( "%010d", g_random->randomInt(0, 1000000000) );
|
||||
myValue = format("%d", g_random->randomInt( 0, 10000000 ) );
|
||||
|
@ -283,7 +283,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if( j < 9 ) {
|
||||
else if( j < 10 ) {
|
||||
myKeyA = format( "%010d", g_random->randomInt( 0, self->maxKeySpace+1 ) );
|
||||
myRandomIDKey = format( "%010d", g_random->randomInt(0, 1000000000) );
|
||||
myValue = format("%d", g_random->randomInt( 0, 10000000 ) );
|
||||
|
@ -306,7 +306,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if( j < 10 ) {
|
||||
else if( j < 11 ) {
|
||||
myKeyA = format( "%010d", g_random->randomInt( 0, self->maxKeySpace+1 ) );
|
||||
myRandomIDKey = format( "%010d", g_random->randomInt(0, 1000000000) );
|
||||
myValue = format("%d", g_random->randomInt( 0, 10000000 ) );
|
||||
|
@ -329,7 +329,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (j < 11) {
|
||||
else if (j < 12) {
|
||||
myKeyA = format("%010d", g_random->randomInt(0, self->maxKeySpace + 1));
|
||||
myRandomIDKey = format("%010d", g_random->randomInt(0, 1000000000));
|
||||
myValue = format("%d", g_random->randomInt(0, 10000000));
|
||||
|
@ -353,7 +353,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (j < 12) {
|
||||
else if (j < 13) {
|
||||
myKeyA = format("%010d", g_random->randomInt(0, self->maxKeySpace + 1));
|
||||
myRandomIDKey = format("%010d", g_random->randomInt(0, 1000000000));
|
||||
myValue = format("%d", g_random->randomInt(0, 10000000));
|
||||
|
@ -377,7 +377,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (j < 13) {
|
||||
else if (j < 14) {
|
||||
myKeyA = format("%010d", g_random->randomInt(0, self->maxKeySpace + 1));
|
||||
myRandomIDKey = format("%010d", g_random->randomInt(0, 1000000000));
|
||||
myValue = format("%d", g_random->randomInt(0, 10000000));
|
||||
|
@ -401,7 +401,7 @@ struct RandomSelectorWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (j < 14) {
|
||||
else if (j < 15) {
|
||||
myKeyA = format("%010d", g_random->randomInt(0, self->maxKeySpace + 1));
|
||||
myRandomIDKey = format("%010d", g_random->randomInt(0, 1000000000));
|
||||
myValue = format("%d", g_random->randomInt(0, 10000000));
|
||||
|
|
Loading…
Reference in New Issue