diff --git a/fdbclient/MultiVersionTransaction.actor.cpp b/fdbclient/MultiVersionTransaction.actor.cpp index 16bf8afd0a..eb973b2659 100644 --- a/fdbclient/MultiVersionTransaction.actor.cpp +++ b/fdbclient/MultiVersionTransaction.actor.cpp @@ -596,9 +596,14 @@ Version MultiVersionTransaction::getCommittedVersion() { } void MultiVersionTransaction::setOption(FDBTransactionOptions::Option option, Optional value) { - if(MultiVersionApi::apiVersionAtLeast(610) && FDBTransactionOptions::optionInfo[option].persistent) { + auto itr = FDBTransactionOptions::optionInfo.find(option); + if(itr == FDBTransactionOptions::optionInfo.end()) { + TraceEvent("UnknownTransactionOption").detail("Option", option); + throw invalid_option(); + } + + if(MultiVersionApi::apiVersionAtLeast(610) && itr->second.persistent) { persistentOptions.emplace_back(option, value.castTo>()); - } auto tr = getTransaction(); if(tr.transaction) { @@ -683,7 +688,7 @@ void MultiVersionDatabase::setOption(FDBDatabaseOptions::Option option, Optional throw invalid_option(); } - int defaultFor = FDBDatabaseOptions::optionInfo[option].defaultFor; + int defaultFor = itr->second.defaultFor; if (defaultFor >= 0) { ASSERT(FDBTransactionOptions::optionInfo.find((FDBTransactionOptions::Option)defaultFor) != FDBTransactionOptions::optionInfo.end()); diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index 1d44b5a3cc..eec7ce36cd 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -756,7 +756,13 @@ uint64_t extractHexOption( StringRef value ) { } void DatabaseContext::setOption( FDBDatabaseOptions::Option option, Optional value) { - int defaultFor = FDBDatabaseOptions::optionInfo[option].defaultFor; + auto itr = FDBDatabaseOptions::optionInfo.find(option); + if(itr == FDBDatabaseOptions::optionInfo.end()) { + TraceEvent("UnknownDatabaseOption").detail("Option", option); + throw invalid_option(); + } + + int defaultFor = itr->second.defaultFor; if (defaultFor >= 0) { ASSERT(FDBTransactionOptions::optionInfo.find((FDBTransactionOptions::Option)defaultFor) != FDBTransactionOptions::optionInfo.end()); diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.actor.cpp index 013fd61596..709fd5a734 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.actor.cpp @@ -1759,9 +1759,15 @@ Future> ReadYourWritesTransaction::getVersionstamp() { } void ReadYourWritesTransaction::setOption( FDBTransactionOptions::Option option, Optional value ) { + auto itr = FDBTransactionOptions::optionInfo.find(option); + if(itr == FDBTransactionOptions::optionInfo.end()) { + TraceEvent("UnknownTransactionOption").detail("Option", option); + throw invalid_option(); + } + setOptionImpl(option, value); - if(FDBTransactionOptions::optionInfo[option].persistent) { + if(itr->second.persistent) { persistentOptions.emplace_back(option, value.castTo>()); } diff --git a/fdbclient/ThreadSafeTransaction.actor.cpp b/fdbclient/ThreadSafeTransaction.actor.cpp index 0a47c43407..c26170c8c8 100644 --- a/fdbclient/ThreadSafeTransaction.actor.cpp +++ b/fdbclient/ThreadSafeTransaction.actor.cpp @@ -283,6 +283,12 @@ ThreadFuture> ThreadSafeTransaction::getVersionstamp() { } void ThreadSafeTransaction::setOption( FDBTransactionOptions::Option option, Optional value ) { + auto itr = FDBTransactionOptions::optionInfo.find(option); + if(itr == FDBTransactionOptions::optionInfo.end()) { + TraceEvent("UnknownTransactionOption").detail("Option", option); + throw invalid_option(); + } + ReadYourWritesTransaction *tr = this->tr; Standalone> passValue = value; diff --git a/fdbserver/workloads/FuzzApiCorrectness.actor.cpp b/fdbserver/workloads/FuzzApiCorrectness.actor.cpp index 0c02bbb556..80fe24c6ed 100644 --- a/fdbserver/workloads/FuzzApiCorrectness.actor.cpp +++ b/fdbserver/workloads/FuzzApiCorrectness.actor.cpp @@ -1092,6 +1092,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload { } contract = { + std::make_pair( error_code_invalid_option, ExceptionContract::Possible ), std::make_pair( error_code_invalid_option_value, ExceptionContract::Possible ), std::make_pair( error_code_client_invalid_operation, ExceptionContract::possibleIf((FDBTransactionOptions::Option)op == FDBTransactionOptions::READ_YOUR_WRITES_DISABLE || (FDBTransactionOptions::Option)op == FDBTransactionOptions::LOG_TRANSACTION) ),