From eacfdf6da3ef1471a28c20a485a7210eb3db492f Mon Sep 17 00:00:00 2001 From: chaoguang <13974480+zjuLcg@users.noreply.github.com> Date: Tue, 26 Nov 2019 00:25:37 -0800 Subject: [PATCH] Add a simple workload, ReportConflictingKeysWorkload, to test correctness of the API and performance overhead added to the resovler. --- bindings/flow/tester/Tester.actor.cpp | 1 - fdbclient/CommitTransaction.h | 1 - fdbclient/MasterProxyInterface.h | 7 +- fdbclient/NativeAPI.actor.cpp | 2 - fdbclient/ReadYourWrites.actor.cpp | 21 +- fdbclient/vexillographer/fdb.options | 3 - fdbserver/CMakeLists.txt | 1 + fdbserver/MasterProxyServer.actor.cpp | 20 +- fdbserver/ResolverInterface.h | 2 +- fdbserver/fdbserver.vcxproj | 1 + fdbserver/fdbserver.vcxproj.filters | 3 + fdbserver/workloads/Mako.actor.cpp | 16 +- .../workloads/ReportConflictingKeys.actor.cpp | 188 ++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/Mako.txt | 6 +- tests/ReportConflictingKeys.txt | 11 + 16 files changed, 241 insertions(+), 43 deletions(-) create mode 100644 fdbserver/workloads/ReportConflictingKeys.actor.cpp create mode 100644 tests/ReportConflictingKeys.txt diff --git a/bindings/flow/tester/Tester.actor.cpp b/bindings/flow/tester/Tester.actor.cpp index 508d3ae30f..28a0b64f7c 100644 --- a/bindings/flow/tester/Tester.actor.cpp +++ b/bindings/flow/tester/Tester.actor.cpp @@ -1584,7 +1584,6 @@ struct UnitTestsFunc : InstructionFunc { data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_RETRY_LIMIT, Optional(StringRef((const uint8_t*)&noRetryLimit, 8))); data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_CAUSAL_READ_RISKY); data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_INCLUDE_PORT_IN_ADDRESS); - data->db->setDatabaseOption(FDBDatabaseOption::FDB_DB_OPTION_TRANSACTION_REPORT_CONFLICTING_KEYS); state Reference tr = data->db->createTransaction(); tr->setOption(FDBTransactionOption::FDB_TR_OPTION_PRIORITY_SYSTEM_IMMEDIATE); diff --git a/fdbclient/CommitTransaction.h b/fdbclient/CommitTransaction.h index 700cf75a4f..02b426d21f 100644 --- a/fdbclient/CommitTransaction.h +++ b/fdbclient/CommitTransaction.h @@ -163,7 +163,6 @@ struct CommitTransactionRef { } void clear( Arena& arena, KeyRangeRef const& keys ) { - // TODO: check do I need to clear flag here mutations.push_back_deep(arena, MutationRef(MutationRef::ClearRange, keys.begin, keys.end)); write_conflict_ranges.push_back_deep(arena, keys); } diff --git a/fdbclient/MasterProxyInterface.h b/fdbclient/MasterProxyInterface.h index ae0e76ce36..1c2143a66d 100644 --- a/fdbclient/MasterProxyInterface.h +++ b/fdbclient/MasterProxyInterface.h @@ -103,8 +103,7 @@ struct CommitID { constexpr static FileIdentifier file_identifier = 14254927; Version version; // returns invalidVersion if transaction conflicts uint16_t txnBatchId; - Optional metadataVersion; - // TODO : data structure okay here ? + Optional metadataVersion; Optional>> conflictingKeyRanges; template @@ -120,13 +119,11 @@ struct CommitTransactionRequest : TimedRequest { constexpr static FileIdentifier file_identifier = 93948; enum { FLAG_IS_LOCK_AWARE = 0x1, - FLAG_FIRST_IN_BATCH = 0x2, - FLAG_REPORT_CONFLICTING_KEYS = 0x4 + FLAG_FIRST_IN_BATCH = 0x2 }; bool isLockAware() const { return (flags & FLAG_IS_LOCK_AWARE) != 0; } bool firstInBatch() const { return (flags & FLAG_FIRST_IN_BATCH) != 0; } - bool isReportConflictingKeys() const { return (flags & FLAG_REPORT_CONFLICTING_KEYS) != 0; } Arena arena; CommitTransactionRef transaction; diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index 6195434854..08ac380775 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -2789,8 +2789,6 @@ Future Transaction::commitMutations() { tr.flags = tr.flags | CommitTransactionRequest::FLAG_FIRST_IN_BATCH; } if(options.reportConflictingKeys) { - // TODO : Is it better to keep it as a flag? - tr.flags = tr.flags | CommitTransactionRequest::FLAG_REPORT_CONFLICTING_KEYS; tr.reportConflictingKeys(); } diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.actor.cpp index e459d05af8..c30bea1e1a 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.actor.cpp @@ -23,7 +23,6 @@ #include "fdbclient/DatabaseContext.h" #include "fdbclient/StatusClient.h" #include "fdbclient/MonitorLeader.h" -#include "fdbclient/JsonBuilder.h" #include "flow/Util.h" #include "flow/actorcompiler.h" // This must be the last #include. @@ -1229,17 +1228,23 @@ Future< Optional > ReadYourWritesTransaction::get( const Key& key, bool s return Optional(); } - // TODO : add conflict keys to special key space + // Add conflicting keys to special key space if (key == LiteralStringRef("\xff\xff/conflicting_keys/json")){ if (!tr.info.conflictingKeyRanges.empty()){ - // TODO : return a json value which represents all the values - JsonBuilderArray conflictingKeysArray; - for (auto & cKR : tr.info.conflictingKeyRanges) { - for (auto & kr : cKR) { - conflictingKeysArray.push_back(format("[%s, %s)", kr.begin.toString().c_str(), kr.end.toString().c_str())); + json_spirit::mArray root; + json_spirit::mArray keyranges; + json_spirit::mObject keyrange; + for (int i = 0; i < tr.info.conflictingKeyRanges.size(); ++i) { + for (const auto & kr : tr.info.conflictingKeyRanges[i]) { + keyrange["begin"] = kr.begin.toString(); + keyrange["end"] = kr.end.toString(); + keyranges.push_back(keyrange); + keyrange.clear(); } + root.push_back(keyranges); + keyranges.clear(); } - Optional output = StringRef(conflictingKeysArray.getJson()); + Optional output = StringRef(json_spirit::write_string(json_spirit::mValue(root), json_spirit::Output_options::raw_utf8).c_str()); return output; } else { return Optional(); diff --git a/fdbclient/vexillographer/fdb.options b/fdbclient/vexillographer/fdb.options index 035335e2a2..089bc4e1c2 100644 --- a/fdbclient/vexillographer/fdb.options +++ b/fdbclient/vexillographer/fdb.options @@ -174,9 +174,6 @@ description is not currently required but encouraged.