2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* ApiWorkload.h
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FDBSERVER_APIWORKLOAD_H
|
|
|
|
#define FDBSERVER_APIWORKLOAD_H
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2021-10-11 11:44:56 +08:00
|
|
|
#include "fdbclient/ClusterConnectionMemoryRecord.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/ReadYourWrites.h"
|
|
|
|
#include "fdbclient/ThreadSafeTransaction.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/workloads/MemoryKeyValueStore.h"
|
2018-08-11 05:05:28 +08:00
|
|
|
#include "flow/actorcompiler.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// an enumeration of apis being tested
|
|
|
|
enum TransactionType { NATIVE, READ_YOUR_WRITES, THREAD_SAFE, MULTI_VERSION };
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// A wrapper interface for dealing with different Transaction implementations
|
2017-05-26 04:48:44 +08:00
|
|
|
struct TransactionWrapper : public ReferenceCounted<TransactionWrapper> {
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual ~TransactionWrapper() {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Sets a key-value pair in the database
|
|
|
|
virtual void set(KeyRef& key, ValueRef& value) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Commits modifications to the database
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Future<Void> commit() = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a value associated with a given key from the database
|
|
|
|
virtual Future<Optional<Value>> get(KeyRef& key) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a range of key-value pairs from the database specified by a key range
|
2021-07-03 12:41:50 +08:00
|
|
|
virtual Future<RangeResult> getRange(KeyRangeRef& keys, int limit, Reverse reverse) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a range of key-value pairs from the database specified by a pair of key selectors
|
2021-07-03 12:41:50 +08:00
|
|
|
virtual Future<RangeResult> getRange(KeySelectorRef& begin, KeySelectorRef& end, int limit, Reverse reverse) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the key from the database specified by a given key selector
|
|
|
|
virtual Future<Key> getKey(KeySelectorRef& key) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears a key from the database
|
|
|
|
virtual void clear(KeyRef& key) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears a range of keys from the database
|
|
|
|
virtual void clear(KeyRangeRef& range) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Processes transaction error conditions
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Future<Void> onError(Error const& e) = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the read version of a transaction
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Future<Version> getReadVersion() = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the committed version of a transaction
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Version getCommittedVersion() = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Prints debugging messages for a transaction; not implemented for all transaction types
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void debugTransaction(UID debugId) {}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual void addReadConflictRange(KeyRangeRef const& keys) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// A wrapper class for flow based transactions (NativeAPI, ReadYourWrites)
|
|
|
|
template <class T>
|
2017-05-26 04:48:44 +08:00
|
|
|
struct FlowTransactionWrapper : public TransactionWrapper {
|
2017-06-01 07:23:37 +08:00
|
|
|
Database cx;
|
|
|
|
Database extraDB;
|
|
|
|
bool useExtraDB;
|
2017-05-26 04:48:44 +08:00
|
|
|
T transaction;
|
2017-06-01 07:23:37 +08:00
|
|
|
T lastTransaction;
|
2021-03-11 02:06:03 +08:00
|
|
|
FlowTransactionWrapper(Database cx, Database extraDB, bool useExtraDB)
|
|
|
|
: cx(cx), extraDB(extraDB), useExtraDB(useExtraDB), transaction(cx) {
|
|
|
|
if (useExtraDB && deterministicRandom()->random01() < 0.5) {
|
2017-06-01 07:23:37 +08:00
|
|
|
transaction = T(extraDB);
|
|
|
|
}
|
|
|
|
}
|
2021-01-26 09:55:43 +08:00
|
|
|
~FlowTransactionWrapper() override {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Sets a key-value pair in the database
|
2021-01-26 09:55:43 +08:00
|
|
|
void set(KeyRef& key, ValueRef& value) override { transaction.set(key, value); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Commits modifications to the database
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Void> commit() override { return transaction.commit(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a value associated with a given key from the database
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Optional<Value>> get(KeyRef& key) override { return transaction.get(key); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a range of key-value pairs from the database specified by a key range
|
2021-07-03 12:41:50 +08:00
|
|
|
Future<RangeResult> getRange(KeyRangeRef& keys, int limit, Reverse reverse) override {
|
2021-07-17 15:11:40 +08:00
|
|
|
return transaction.getRange(keys, limit, Snapshot::False, reverse);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a range of key-value pairs from the database specified by a pair of key selectors
|
2021-07-03 12:41:50 +08:00
|
|
|
Future<RangeResult> getRange(KeySelectorRef& begin, KeySelectorRef& end, int limit, Reverse reverse) override {
|
2021-07-17 15:11:40 +08:00
|
|
|
return transaction.getRange(begin, end, limit, Snapshot::False, reverse);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the key from the database specified by a given key selector
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Key> getKey(KeySelectorRef& key) override { return transaction.getKey(key); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears a key from the database
|
2021-01-26 09:55:43 +08:00
|
|
|
void clear(KeyRef& key) override { transaction.clear(key); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears a range of keys from the database
|
2021-01-26 09:55:43 +08:00
|
|
|
void clear(KeyRangeRef& range) override { transaction.clear(range); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Processes transaction error conditions
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Void> onError(Error const& e) override {
|
2017-06-01 07:23:37 +08:00
|
|
|
Future<Void> returnVal = transaction.onError(e);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (useExtraDB) {
|
2017-06-01 07:23:37 +08:00
|
|
|
lastTransaction = std::move(transaction);
|
2021-03-11 02:06:03 +08:00
|
|
|
transaction = T(deterministicRandom()->random01() < 0.5 ? extraDB : cx);
|
2017-06-01 07:23:37 +08:00
|
|
|
}
|
|
|
|
return returnVal;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the read version of a transaction
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Version> getReadVersion() override { return transaction.getReadVersion(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the committed version of a transaction
|
2021-01-26 09:55:43 +08:00
|
|
|
Version getCommittedVersion() override { return transaction.getCommittedVersion(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Prints debugging messages for a transaction
|
2021-01-26 09:55:43 +08:00
|
|
|
void debugTransaction(UID debugId) override { transaction.debugTransaction(debugId); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-01-26 09:55:43 +08:00
|
|
|
void addReadConflictRange(KeyRangeRef const& keys) override { transaction.addReadConflictRange(keys); }
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// A wrapper class for ThreadSafeTransactions. Converts ThreadFutures into Futures for interchangeability with flow
|
|
|
|
// transactions
|
2017-05-26 04:48:44 +08:00
|
|
|
struct ThreadTransactionWrapper : public TransactionWrapper {
|
|
|
|
|
|
|
|
Reference<ITransaction> transaction;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ThreadTransactionWrapper(Reference<IDatabase> db, Reference<IDatabase> extraDB, bool useExtraDB)
|
|
|
|
: transaction(db->createTransaction()) {}
|
2021-01-26 09:55:43 +08:00
|
|
|
~ThreadTransactionWrapper() override {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Sets a key-value pair in the database
|
2021-01-26 09:55:43 +08:00
|
|
|
void set(KeyRef& key, ValueRef& value) override { transaction->set(key, value); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Commits modifications to the database
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Void> commit() override { return unsafeThreadFutureToFuture(transaction->commit()); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a value associated with a given key from the database
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Optional<Value>> get(KeyRef& key) override { return unsafeThreadFutureToFuture(transaction->get(key)); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a range of key-value pairs from the database specified by a key range
|
2021-07-03 12:41:50 +08:00
|
|
|
Future<RangeResult> getRange(KeyRangeRef& keys, int limit, Reverse reverse) override {
|
2021-07-17 15:11:40 +08:00
|
|
|
return unsafeThreadFutureToFuture(transaction->getRange(keys, limit, Snapshot::False, reverse));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets a range of key-value pairs from the database specified by a pair of key selectors
|
2021-07-03 12:41:50 +08:00
|
|
|
Future<RangeResult> getRange(KeySelectorRef& begin, KeySelectorRef& end, int limit, Reverse reverse) override {
|
2021-07-17 15:11:40 +08:00
|
|
|
return unsafeThreadFutureToFuture(transaction->getRange(begin, end, limit, Snapshot::False, reverse));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the key from the database specified by a given key selector
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Key> getKey(KeySelectorRef& key) override { return unsafeThreadFutureToFuture(transaction->getKey(key)); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears a key from the database
|
2021-01-26 09:55:43 +08:00
|
|
|
void clear(KeyRef& key) override { transaction->clear(key); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears a range of keys from the database
|
2021-01-26 09:55:43 +08:00
|
|
|
void clear(KeyRangeRef& range) override { transaction->clear(range); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Processes transaction error conditions
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Void> onError(Error const& e) override { return unsafeThreadFutureToFuture(transaction->onError(e)); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the read version of a transaction
|
2021-01-26 09:55:43 +08:00
|
|
|
Future<Version> getReadVersion() override { return unsafeThreadFutureToFuture(transaction->getReadVersion()); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Gets the committed version of a transaction
|
2021-01-26 09:55:43 +08:00
|
|
|
Version getCommittedVersion() override { return transaction->getCommittedVersion(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-01-26 09:55:43 +08:00
|
|
|
void addReadConflictRange(KeyRangeRef const& keys) override { transaction->addReadConflictRange(keys); }
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// A factory interface for creating different kinds of TransactionWrappers
|
2017-05-26 04:48:44 +08:00
|
|
|
struct TransactionFactoryInterface : public ReferenceCounted<TransactionFactoryInterface> {
|
2021-03-11 02:06:03 +08:00
|
|
|
virtual ~TransactionFactoryInterface() {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Creates a new transaction
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Reference<TransactionWrapper> createTransaction() = 0;
|
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Templated implementation of TransactionFactoryInterface which creates a specific type of TransactionWrapper
|
|
|
|
template <class T, class DB>
|
2017-05-26 04:48:44 +08:00
|
|
|
struct TransactionFactory : public TransactionFactoryInterface {
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The database used to create transaction (of type Database, Reference<ThreadSafeDatabase>, etc.)
|
2017-05-26 04:48:44 +08:00
|
|
|
DB dbHandle;
|
2017-06-01 07:23:37 +08:00
|
|
|
DB extraDbHandle;
|
|
|
|
bool useExtraDB;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
TransactionFactory(DB dbHandle, DB extraDbHandle, bool useExtraDB)
|
|
|
|
: dbHandle(dbHandle), extraDbHandle(extraDbHandle), useExtraDB(useExtraDB) {}
|
2021-01-26 09:55:43 +08:00
|
|
|
~TransactionFactory() override {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Creates a new transaction
|
2021-01-26 09:55:43 +08:00
|
|
|
Reference<TransactionWrapper> createTransaction() override {
|
2017-06-01 07:23:37 +08:00
|
|
|
return Reference<TransactionWrapper>(new T(dbHandle, extraDbHandle, useExtraDB));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ApiWorkload : TestWorkload {
|
2017-06-01 07:23:37 +08:00
|
|
|
bool useExtraDB;
|
|
|
|
Database extraDB;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ApiWorkload(WorkloadContext const& wcx, int maxClients = -1)
|
2021-07-23 13:48:27 +08:00
|
|
|
: TestWorkload(wcx), maxClients(maxClients), success(true), transactionFactory(nullptr) {
|
2017-05-26 04:48:44 +08:00
|
|
|
clientPrefixInt = getOption(options, LiteralStringRef("clientId"), clientId);
|
|
|
|
clientPrefix = format("%010d", clientPrefixInt);
|
|
|
|
|
|
|
|
numKeys = getOption(options, LiteralStringRef("numKeys"), 5000);
|
|
|
|
onlyLowerCase = getOption(options, LiteralStringRef("onlyLowerCase"), false);
|
|
|
|
shortKeysRatio = getOption(options, LiteralStringRef("shortKeysRatio"), 0.5);
|
|
|
|
minShortKeyLength = getOption(options, LiteralStringRef("minShortKeyLength"), 1);
|
|
|
|
maxShortKeyLength = getOption(options, LiteralStringRef("maxShortKeyLength"), 3);
|
|
|
|
minLongKeyLength = getOption(options, LiteralStringRef("minLongKeyLength"), 1);
|
|
|
|
maxLongKeyLength = getOption(options, LiteralStringRef("maxLongKeyLength"), 128);
|
|
|
|
minValueLength = getOption(options, LiteralStringRef("minValueLength"), 1);
|
|
|
|
maxValueLength = getOption(options, LiteralStringRef("maxValueLength"), 10000);
|
2017-06-01 07:23:37 +08:00
|
|
|
|
2020-08-19 05:18:50 +08:00
|
|
|
useExtraDB = g_simulator.extraDB != nullptr;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (useExtraDB) {
|
2021-10-11 11:44:56 +08:00
|
|
|
auto extraFile = makeReference<ClusterConnectionMemoryRecord>(*g_simulator.extraDB);
|
2018-09-22 06:58:14 +08:00
|
|
|
extraDB = Database::createDatabase(extraFile, -1);
|
2017-06-01 07:23:37 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-08 02:46:23 +08:00
|
|
|
Future<Void> setup(Database const& cx) override;
|
|
|
|
Future<Void> start(Database const& cx) override;
|
|
|
|
Future<bool> check(Database const& cx) override;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Compares the contents of this client's key-space in the database with the in-memory key-value store
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<bool> compareDatabaseToMemory();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Verifies that the results of a getRange are the same in the database and in memory
|
2017-05-26 04:48:44 +08:00
|
|
|
bool compareResults(VectorRef<KeyValueRef> dbResults, VectorRef<KeyValueRef> storeResults, Version readVersion);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Generates a set of random key-value pairs with an optional prefix
|
|
|
|
Standalone<VectorRef<KeyValueRef>> generateData(int numKeys,
|
|
|
|
int minKeyLength,
|
|
|
|
int maxKeyLength,
|
|
|
|
int minValueLength,
|
|
|
|
int maxValueLength,
|
|
|
|
std::string prefix = "",
|
|
|
|
bool allowDuplicates = true);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Generates a random key
|
2017-05-26 04:48:44 +08:00
|
|
|
Key generateKey(VectorRef<KeyValueRef> const& data, int minKeyLength, int maxKeyLength, std::string prefix = "");
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Generates a random key selector with a specified maximum offset
|
2017-05-26 04:48:44 +08:00
|
|
|
KeySelector generateKeySelector(VectorRef<KeyValueRef> const& data, int maxOffset);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Selects a random key. There is a <probabilityKeyExists> probability that the key will be chosen from the keyset
|
|
|
|
// in data, otherwise the key will be a randomly generated key
|
2017-05-26 04:48:44 +08:00
|
|
|
Key selectRandomKey(VectorRef<KeyValueRef> const& data, double probabilityKeyExists);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Generates a random value
|
2017-05-26 04:48:44 +08:00
|
|
|
Value generateValue(int minValueLength, int maxValueLength);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Generates a random value
|
2017-05-26 04:48:44 +08:00
|
|
|
Value generateValue();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Convenience function for reporting a test failure to trace log and stdout
|
2017-05-26 04:48:44 +08:00
|
|
|
void testFailure(std::string reason);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Creates a random transaction factory to produce transaction of one of the TransactionType choices
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<Void> chooseTransactionFactory(Database const& cx, std::vector<TransactionType> const& choices);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Creates a new transaction using the current transaction factory
|
2017-05-26 04:48:44 +08:00
|
|
|
Reference<TransactionWrapper> createTransaction();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Implemented by subclasses; called during the setup function to prepare the database
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Future<Void> performSetup(Database const& cx) = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Implemented by subclasses; called during the start function to run the tests
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Future<Void> performTest(Database const& cx, Standalone<VectorRef<KeyValueRef>> const& data) = 0;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Returns whether or not success is false
|
2017-05-26 04:48:44 +08:00
|
|
|
bool hasFailed();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Clears the keyspace used by this test
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<Void> clearKeyspace();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The maximum number of tester clients that will run the test
|
2017-05-26 04:48:44 +08:00
|
|
|
int maxClients;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// A key prefix used by this client. This is so each client can operate on a key space without worrying about
|
|
|
|
// the operations of other clients. Otherwise, it would be challenging to maintain an in-memory representation
|
|
|
|
// of what the database should contain
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string clientPrefix;
|
|
|
|
int clientPrefixInt;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Whether or not the test passed
|
2017-05-26 04:48:44 +08:00
|
|
|
bool success;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// How many keys each client should generate to put in the database. This may not be exact, as some keys may be
|
|
|
|
// duplicates of each other
|
2017-05-26 04:48:44 +08:00
|
|
|
int numKeys;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The ratio of keys which should have small length (to encourage collisions)
|
2017-05-26 04:48:44 +08:00
|
|
|
double shortKeysRatio;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The minimum length of a short key
|
2017-05-26 04:48:44 +08:00
|
|
|
int minShortKeyLength;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The maximum length of a short key
|
2017-05-26 04:48:44 +08:00
|
|
|
int maxShortKeyLength;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The minimum length of a long key
|
2017-05-26 04:48:44 +08:00
|
|
|
int minLongKeyLength;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The maximum length of a long key
|
2017-05-26 04:48:44 +08:00
|
|
|
int maxLongKeyLength;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The minimum length of a value
|
2017-05-26 04:48:44 +08:00
|
|
|
int minValueLength;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The maximum length of a value
|
2017-05-26 04:48:44 +08:00
|
|
|
int maxValueLength;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// If true, then random keys will only contain lower case letters. Otherwise, they will contain all character
|
|
|
|
// values
|
2017-05-26 04:48:44 +08:00
|
|
|
bool onlyLowerCase;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The in-memory representation of this client's key space
|
2017-05-26 04:48:44 +08:00
|
|
|
MemoryKeyValueStore store;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// The transaction factory used to create transactions in this run
|
2017-05-26 04:48:44 +08:00
|
|
|
Reference<TransactionFactoryInterface> transactionFactory;
|
|
|
|
};
|
|
|
|
|
2018-08-11 05:05:28 +08:00
|
|
|
#include "flow/unactorcompiler.h"
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|