2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* simulator.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 FLOW_SIMULATOR_H
|
|
|
|
#define FLOW_SIMULATOR_H
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "flow/flow.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbrpc/FailureMonitor.h"
|
|
|
|
#include "fdbrpc/Locality.h"
|
|
|
|
#include "fdbrpc/IAsyncFile.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/TDMetric.actor.h"
|
|
|
|
#include <random>
|
|
|
|
#include "fdbrpc/ReplicationPolicy.h"
|
|
|
|
|
|
|
|
enum ClogMode { ClogDefault, ClogAll, ClogSend, ClogReceive };
|
|
|
|
|
|
|
|
class ISimulator : public INetwork {
|
|
|
|
public:
|
2019-02-01 10:20:14 +08:00
|
|
|
ISimulator() : desiredCoordinators(1), physicalDatacenters(1), processesPerMachine(0), listenersPerProcess(1), isStopped(false), lastConnectionFailure(0), connectionFailuresDisableDuration(0), speedUpSimulation(false), allSwapsDisabled(false), backupAgents(WaitForType), drAgents(WaitForType), extraDB(NULL), allowLogSetKills(true), usableRegions(1) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Order matters!
|
2018-02-18 05:51:17 +08:00
|
|
|
enum KillType { KillInstantly, InjectFaults, RebootAndDelete, RebootProcessAndDelete, Reboot, RebootProcess, None };
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
enum BackupAgentType { NoBackupAgents, WaitForType, BackupToFile, BackupToDB };
|
|
|
|
|
|
|
|
// Subclasses may subclass ProcessInfo as well
|
|
|
|
struct MachineInfo;
|
|
|
|
|
|
|
|
struct ProcessInfo : NonCopyable {
|
|
|
|
const char* name;
|
|
|
|
const char* coordinationFolder;
|
|
|
|
const char* dataFolder;
|
|
|
|
MachineInfo* machine;
|
2018-12-07 03:48:50 +08:00
|
|
|
NetworkAddressList addresses;
|
2017-05-26 04:48:44 +08:00
|
|
|
NetworkAddress address;
|
|
|
|
LocalityData locality;
|
|
|
|
ProcessClass startingClass;
|
|
|
|
TDMetricCollection tdmetrics;
|
2018-12-07 03:48:50 +08:00
|
|
|
std::map<NetworkAddress, Reference<IListener>> listenerMap;
|
2017-05-26 04:48:44 +08:00
|
|
|
bool failed;
|
2017-05-27 05:20:11 +08:00
|
|
|
bool excluded;
|
2017-10-04 01:48:16 +08:00
|
|
|
bool cleared;
|
2017-05-26 04:48:44 +08:00
|
|
|
int64_t cpuTicks;
|
|
|
|
bool rebooting;
|
|
|
|
std::vector<flowGlobalType> globals;
|
|
|
|
|
|
|
|
INetworkConnections *network;
|
|
|
|
|
|
|
|
uint64_t fault_injection_r;
|
|
|
|
double fault_injection_p1, fault_injection_p2;
|
|
|
|
|
2018-12-07 03:48:50 +08:00
|
|
|
ProcessInfo(const char* name, LocalityData locality, ProcessClass startingClass, NetworkAddressList addresses,
|
2017-05-26 04:48:44 +08:00
|
|
|
INetworkConnections *net, const char* dataFolder, const char* coordinationFolder )
|
2019-04-15 02:11:08 +08:00
|
|
|
: name(name), locality(locality), startingClass(startingClass),
|
2019-04-10 05:29:21 +08:00
|
|
|
addresses(addresses), address(addresses.address), dataFolder(dataFolder),
|
|
|
|
network(net), coordinationFolder(coordinationFolder), failed(false), excluded(false), cpuTicks(0),
|
|
|
|
rebooting(false), fault_injection_p1(0), fault_injection_p2(0),
|
|
|
|
fault_injection_r(0), machine(0), cleared(false) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
Future<KillType> onShutdown() { return shutdownSignal.getFuture(); }
|
|
|
|
|
2017-05-27 05:20:11 +08:00
|
|
|
bool isReliable() const { return !failed && fault_injection_p1 == 0 && fault_injection_p2 == 0; }
|
2017-10-05 18:07:20 +08:00
|
|
|
bool isAvailable() const { return !isExcluded() && isReliable(); }
|
2018-07-05 17:22:22 +08:00
|
|
|
bool isExcluded() const { return excluded; }
|
|
|
|
bool isCleared() const { return cleared; }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-06-20 07:48:15 +08:00
|
|
|
// Returns true if the class represents an acceptable worker
|
|
|
|
bool isAvailableClass() const {
|
|
|
|
switch (startingClass._class) {
|
|
|
|
case ProcessClass::UnsetClass: return true;
|
|
|
|
case ProcessClass::StorageClass: return true;
|
|
|
|
case ProcessClass::TransactionClass: return true;
|
|
|
|
case ProcessClass::ResolutionClass: return false;
|
|
|
|
case ProcessClass::ProxyClass: return false;
|
|
|
|
case ProcessClass::MasterClass: return false;
|
|
|
|
case ProcessClass::TesterClass: return false;
|
|
|
|
case ProcessClass::StatelessClass: return false;
|
|
|
|
case ProcessClass::LogClass: return true;
|
2017-09-08 06:32:08 +08:00
|
|
|
case ProcessClass::LogRouterClass: return false;
|
2017-10-17 07:21:25 +08:00
|
|
|
case ProcessClass::ClusterControllerClass: return false;
|
2018-12-14 05:31:37 +08:00
|
|
|
case ProcessClass::DataDistributorClass: return false;
|
2019-03-27 23:24:25 +08:00
|
|
|
case ProcessClass::RatekeeperClass: return false;
|
2019-11-13 05:01:29 +08:00
|
|
|
case ProcessClass::StorageCacheClass: return false;
|
2019-04-25 06:12:37 +08:00
|
|
|
case ProcessClass::BackupClass: return false;
|
2017-06-20 07:48:15 +08:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 03:48:50 +08:00
|
|
|
const Reference<IListener> getListener(const NetworkAddress& addr) {
|
|
|
|
auto listener = listenerMap.find(addr);
|
2019-02-01 10:20:14 +08:00
|
|
|
ASSERT( listener != listenerMap.end());
|
2018-12-07 03:48:50 +08:00
|
|
|
return listener->second;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
inline flowGlobalType global(int id) { return (globals.size() > id) ? globals[id] : NULL; };
|
|
|
|
inline void setGlobal(size_t id, flowGlobalType v) { globals.resize(std::max(globals.size(),id+1)); globals[id] = v; };
|
|
|
|
|
|
|
|
std::string toString() const {
|
2019-02-27 10:04:03 +08:00
|
|
|
return format(
|
2019-02-28 18:37:21 +08:00
|
|
|
"name: %s address: %s zone: %s datahall: %s class: %s excluded: %d cleared: %d", name,
|
2019-03-24 08:54:46 +08:00
|
|
|
formatIpPort(addresses.address.ip, addresses.address.port).c_str(),
|
2019-02-27 10:04:03 +08:00
|
|
|
(locality.zoneId().present() ? locality.zoneId().get().printable().c_str() : "[unset]"),
|
|
|
|
(locality.dataHallId().present() ? locality.dataHallId().get().printable().c_str() : "[unset]"),
|
|
|
|
startingClass.toString().c_str(), excluded, cleared);
|
2019-01-09 23:41:02 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Members not for external use
|
|
|
|
Promise<KillType> shutdownSignal;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MachineInfo {
|
|
|
|
ProcessInfo* machineProcess;
|
|
|
|
std::vector<ProcessInfo*> processes;
|
|
|
|
std::map<std::string, Future<Reference<IAsyncFile>>> openFiles;
|
2017-08-26 01:12:58 +08:00
|
|
|
std::set<std::string> deletingFiles;
|
2017-05-26 04:48:44 +08:00
|
|
|
std::set<std::string> closingFiles;
|
2019-01-19 07:42:48 +08:00
|
|
|
Optional<Standalone<StringRef>> machineId;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-05-26 07:29:02 +08:00
|
|
|
MachineInfo() : machineProcess(0) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2018-10-31 04:44:37 +08:00
|
|
|
ProcessInfo* getProcess( Endpoint const& endpoint ) { return getProcessByAddress(endpoint.getPrimaryAddress()); }
|
2017-05-26 04:48:44 +08:00
|
|
|
ProcessInfo* getCurrentProcess() { return currentProcess; }
|
2019-06-25 17:47:35 +08:00
|
|
|
virtual Future<Void> onProcess( ISimulator::ProcessInfo *process, TaskPriority taskID = TaskPriority::Zero ) = 0;
|
|
|
|
virtual Future<Void> onMachine( ISimulator::ProcessInfo *process, TaskPriority taskID = TaskPriority::Zero ) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-02-28 16:09:53 +08:00
|
|
|
virtual ProcessInfo* newProcess(const char* name, IPAddress ip, uint16_t port, uint16_t listenPerProcess,
|
|
|
|
LocalityData locality, ProcessClass startingClass, const char* dataFolder,
|
|
|
|
const char* coordinationFolder) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void killProcess( ProcessInfo* machine, KillType ) = 0;
|
|
|
|
virtual void rebootProcess(Optional<Standalone<StringRef>> zoneId, bool allProcesses ) = 0;
|
|
|
|
virtual void rebootProcess( ProcessInfo* process, KillType kt ) = 0;
|
|
|
|
virtual void killInterface( NetworkAddress address, KillType ) = 0;
|
2019-01-19 07:42:48 +08:00
|
|
|
virtual bool killMachine(Optional<Standalone<StringRef>> machineId, KillType kt, bool forceKill = false, KillType* ktFinal = NULL) = 0;
|
|
|
|
virtual bool killZone(Optional<Standalone<StringRef>> zoneId, KillType kt, bool forceKill = false, KillType* ktFinal = NULL) = 0;
|
2018-09-18 09:32:39 +08:00
|
|
|
virtual bool killDataCenter(Optional<Standalone<StringRef>> dcId, KillType kt, bool forceKill = false, KillType* ktFinal = NULL) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
//virtual KillType getMachineKillState( UID zoneID ) = 0;
|
2017-05-27 05:20:11 +08:00
|
|
|
virtual bool canKillProcesses(std::vector<ProcessInfo*> const& availableProcesses, std::vector<ProcessInfo*> const& deadProcesses, KillType kt, KillType* newKillType) const = 0;
|
|
|
|
virtual bool isAvailable() const = 0;
|
2018-07-17 01:06:57 +08:00
|
|
|
virtual bool datacenterDead(Optional<Standalone<StringRef>> dcId) const = 0;
|
2017-08-23 07:56:33 +08:00
|
|
|
virtual void displayWorkers() const;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-08-29 02:25:37 +08:00
|
|
|
virtual void addRole(NetworkAddress const& address, std::string const& role) {
|
|
|
|
roleAddresses[address][role] ++;
|
2018-09-06 06:06:14 +08:00
|
|
|
TraceEvent("RoleAdd").detail("Address", address).detail("Role", role).detail("NumRoles", roleAddresses[address].size()).detail("Value", roleAddresses[address][role]);
|
2017-08-29 02:25:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void removeRole(NetworkAddress const& address, std::string const& role) {
|
|
|
|
auto addressIt = roleAddresses.find(address);
|
|
|
|
if (addressIt != roleAddresses.end()) {
|
|
|
|
auto rolesIt = addressIt->second.find(role);
|
|
|
|
if (rolesIt != addressIt->second.end()) {
|
|
|
|
if (rolesIt->second > 1) {
|
|
|
|
rolesIt->second --;
|
2018-09-06 06:06:14 +08:00
|
|
|
TraceEvent("RoleRemove").detail("Address", address).detail("Role", role).detail("NumRoles", addressIt->second.size()).detail("Value", rolesIt->second).detail("Result", "Decremented Role");
|
2017-08-29 02:25:37 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
addressIt->second.erase(rolesIt);
|
|
|
|
if (addressIt->second.size()) {
|
2018-09-06 06:06:14 +08:00
|
|
|
TraceEvent("RoleRemove").detail("Address", address).detail("Role", role).detail("NumRoles", addressIt->second.size()).detail("Value", 0).detail("Result", "Removed Role");
|
2017-08-29 02:25:37 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
roleAddresses.erase(addressIt);
|
2018-09-06 06:06:14 +08:00
|
|
|
TraceEvent("RoleRemove").detail("Address", address).detail("Role", role).detail("NumRoles", 0).detail("Value", 0).detail("Result", "Removed Address");
|
2017-08-29 02:25:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
TraceEvent(SevWarn,"RoleRemove").detail("Address", address).detail("Role", role).detail("Result", "Role Missing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
TraceEvent(SevWarn,"RoleRemove").detail("Address", address).detail("Role", role).detail("Result", "Address Missing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string getRoles(NetworkAddress const& address, bool skipWorkers = true) const {
|
|
|
|
auto addressIt = roleAddresses.find(address);
|
|
|
|
std::string roleText;
|
|
|
|
if (addressIt != roleAddresses.end()) {
|
|
|
|
for (auto& roleIt : addressIt->second) {
|
|
|
|
if ((!skipWorkers) || (roleIt.first != "Worker"))
|
|
|
|
roleText += roleIt.first + ((roleIt.second > 1) ? format("-%d ", roleIt.second) : " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (roleText.empty())
|
|
|
|
roleText = "[unset]";
|
|
|
|
return roleText;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-10-04 01:48:16 +08:00
|
|
|
virtual void clearAddress(NetworkAddress const& address) {
|
|
|
|
clearedAddresses[address]++;
|
|
|
|
TraceEvent("ClearAddress").detail("Address", address).detail("Value", clearedAddresses[address]);
|
|
|
|
}
|
|
|
|
virtual bool isCleared(NetworkAddress const& address) const {
|
|
|
|
return clearedAddresses.find(address) != clearedAddresses.end();
|
|
|
|
}
|
|
|
|
|
2017-06-20 07:48:15 +08:00
|
|
|
virtual void excludeAddress(NetworkAddress const& address) {
|
2017-08-29 02:25:37 +08:00
|
|
|
excludedAddresses[address]++;
|
|
|
|
TraceEvent("ExcludeAddress").detail("Address", address).detail("Value", excludedAddresses[address]);
|
2017-06-20 07:48:15 +08:00
|
|
|
}
|
2017-08-29 02:25:37 +08:00
|
|
|
|
2017-06-20 07:48:15 +08:00
|
|
|
virtual void includeAddress(NetworkAddress const& address) {
|
2017-08-29 02:25:37 +08:00
|
|
|
auto addressIt = excludedAddresses.find(address);
|
|
|
|
if (addressIt != excludedAddresses.end()) {
|
|
|
|
if (addressIt->second > 1) {
|
|
|
|
addressIt->second --;
|
|
|
|
TraceEvent("IncludeAddress").detail("Address", address).detail("Value", addressIt->second).detail("Result", "Decremented");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
excludedAddresses.erase(addressIt);
|
|
|
|
TraceEvent("IncludeAddress").detail("Address", address).detail("Value", 0).detail("Result", "Removed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
TraceEvent(SevWarn,"IncludeAddress").detail("Address", address).detail("Result", "Missing");
|
|
|
|
}
|
2017-06-20 07:48:15 +08:00
|
|
|
}
|
|
|
|
virtual void includeAllAddresses() {
|
2017-08-29 02:25:37 +08:00
|
|
|
TraceEvent("IncludeAddressAll").detail("AddressTotal", excludedAddresses.size());
|
2017-06-20 07:48:15 +08:00
|
|
|
excludedAddresses.clear();
|
|
|
|
}
|
|
|
|
virtual bool isExcluded(NetworkAddress const& address) const {
|
2017-08-29 02:25:37 +08:00
|
|
|
return excludedAddresses.find(address) != excludedAddresses.end();
|
2017-06-20 07:48:15 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void disableSwapToMachine(Optional<Standalone<StringRef>> zoneId ) {
|
|
|
|
swapsDisabled.insert(zoneId);
|
|
|
|
}
|
|
|
|
virtual void enableSwapToMachine(Optional<Standalone<StringRef>> zoneId ) {
|
|
|
|
swapsDisabled.erase(zoneId);
|
|
|
|
allSwapsDisabled = false;
|
|
|
|
}
|
|
|
|
virtual bool canSwapToMachine(Optional<Standalone<StringRef>> zoneId ) {
|
|
|
|
return swapsDisabled.count( zoneId ) == 0 && !allSwapsDisabled && !extraDB;
|
|
|
|
}
|
|
|
|
virtual void enableSwapsToAll() {
|
|
|
|
swapsDisabled.clear();
|
|
|
|
allSwapsDisabled = false;
|
|
|
|
}
|
|
|
|
virtual void disableSwapsToAll() {
|
|
|
|
swapsDisabled.clear();
|
|
|
|
allSwapsDisabled = true;
|
|
|
|
}
|
|
|
|
|
2019-02-27 10:04:03 +08:00
|
|
|
virtual void clogInterface(const IPAddress& ip, double seconds, ClogMode mode = ClogDefault) = 0;
|
|
|
|
virtual void clogPair(const IPAddress& from, const IPAddress& to, double seconds) = 0;
|
2017-05-27 05:20:11 +08:00
|
|
|
virtual std::vector<ProcessInfo*> getAllProcesses() const = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual ProcessInfo* getProcessByAddress( NetworkAddress const& address ) = 0;
|
|
|
|
virtual MachineInfo* getMachineByNetworkAddress(NetworkAddress const& address) = 0;
|
2019-01-19 07:42:48 +08:00
|
|
|
virtual MachineInfo* getMachineById(Optional<Standalone<StringRef>> const& machineId) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void run() {}
|
|
|
|
virtual void destroyProcess( ProcessInfo *p ) = 0;
|
2019-01-19 07:42:48 +08:00
|
|
|
virtual void destroyMachine(Optional<Standalone<StringRef>> const& machineId ) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
int desiredCoordinators;
|
|
|
|
int physicalDatacenters;
|
|
|
|
int processesPerMachine;
|
2019-02-01 10:20:14 +08:00
|
|
|
int listenersPerProcess;
|
2017-05-26 04:48:44 +08:00
|
|
|
std::set<NetworkAddress> protectedAddresses;
|
|
|
|
std::map<NetworkAddress, ProcessInfo*> currentlyRebootingProcesses;
|
|
|
|
class ClusterConnectionString* extraDB;
|
2019-03-14 04:14:39 +08:00
|
|
|
Reference<IReplicationPolicy> storagePolicy;
|
|
|
|
Reference<IReplicationPolicy> tLogPolicy;
|
2017-10-20 06:36:32 +08:00
|
|
|
int32_t tLogWriteAntiQuorum;
|
|
|
|
Optional<Standalone<StringRef>> primaryDcId;
|
2019-03-14 04:14:39 +08:00
|
|
|
Reference<IReplicationPolicy> remoteTLogPolicy;
|
2018-06-18 10:31:15 +08:00
|
|
|
int32_t usableRegions;
|
2018-07-17 01:06:57 +08:00
|
|
|
std::string disablePrimary;
|
|
|
|
std::string disableRemote;
|
2018-09-18 09:32:39 +08:00
|
|
|
std::string originalRegions;
|
2018-07-06 05:04:42 +08:00
|
|
|
bool allowLogSetKills;
|
2017-10-20 06:36:32 +08:00
|
|
|
Optional<Standalone<StringRef>> remoteDcId;
|
|
|
|
bool hasSatelliteReplication;
|
2019-03-14 04:14:39 +08:00
|
|
|
Reference<IReplicationPolicy> satelliteTLogPolicy;
|
|
|
|
Reference<IReplicationPolicy> satelliteTLogPolicyFallback;
|
2017-10-20 06:36:32 +08:00
|
|
|
int32_t satelliteTLogWriteAntiQuorum;
|
2018-07-10 13:01:46 +08:00
|
|
|
int32_t satelliteTLogWriteAntiQuorumFallback;
|
2017-10-20 06:36:32 +08:00
|
|
|
std::vector<Optional<Standalone<StringRef>>> primarySatelliteDcIds;
|
|
|
|
std::vector<Optional<Standalone<StringRef>>> remoteSatelliteDcIds;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
//Used by workloads that perform reconfigurations
|
|
|
|
int testerCount;
|
|
|
|
std::string connectionString;
|
|
|
|
|
|
|
|
bool isStopped;
|
2017-09-19 03:46:29 +08:00
|
|
|
double lastConnectionFailure;
|
|
|
|
double connectionFailuresDisableDuration;
|
2017-05-26 04:48:44 +08:00
|
|
|
bool speedUpSimulation;
|
|
|
|
BackupAgentType backupAgents;
|
2018-02-21 05:22:31 +08:00
|
|
|
BackupAgentType drAgents;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
virtual flowGlobalType global(int id) { return getCurrentProcess()->global(id); };
|
|
|
|
virtual void setGlobal(size_t id, flowGlobalType v) { getCurrentProcess()->setGlobal(id,v); };
|
|
|
|
|
2019-06-14 05:28:30 +08:00
|
|
|
virtual void disableFor(const std::string& desc, double time) {
|
|
|
|
disabledMap[desc] = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual double checkDisabled(const std::string& desc) const
|
|
|
|
{
|
|
|
|
auto iter = disabledMap.find(desc);
|
|
|
|
if (iter != disabledMap.end()) {
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-14 12:27:23 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
static thread_local ProcessInfo* currentProcess;
|
2019-04-01 08:57:43 +08:00
|
|
|
protected:
|
2017-05-26 04:48:44 +08:00
|
|
|
Mutex mutex;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::set<Optional<Standalone<StringRef>>> swapsDisabled;
|
2017-08-29 02:25:37 +08:00
|
|
|
std::map<NetworkAddress, int> excludedAddresses;
|
2017-10-04 01:48:16 +08:00
|
|
|
std::map<NetworkAddress, int> clearedAddresses;
|
2017-08-29 02:25:37 +08:00
|
|
|
std::map<NetworkAddress, std::map<std::string, int>> roleAddresses;
|
2019-06-14 05:28:30 +08:00
|
|
|
std::map<std::string, double> disabledMap;
|
2017-05-26 04:48:44 +08:00
|
|
|
bool allSwapsDisabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Quickly make existing code work that expects g_simulator to be of class type (not a pointer)
|
|
|
|
extern ISimulator* g_pSimulator;
|
|
|
|
#define g_simulator (*g_pSimulator)
|
|
|
|
|
2019-08-07 00:25:40 +08:00
|
|
|
void startNewSimulator();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
//Parameters used to simulate disk performance
|
|
|
|
struct DiskParameters : ReferenceCounted<DiskParameters> {
|
|
|
|
double nextOperation;
|
|
|
|
int64_t iops;
|
|
|
|
int64_t bandwidth;
|
|
|
|
|
|
|
|
DiskParameters(int64_t iops, int64_t bandwidth) : nextOperation(0), iops(iops), bandwidth(bandwidth) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
//Simulates delays for performing operations on disk
|
|
|
|
extern Future<Void> waitUntilDiskReady(Reference<DiskParameters> parameters, int64_t size, bool sync = false);
|
|
|
|
|
|
|
|
|
|
|
|
class Sim2FileSystem : public IAsyncFileSystem {
|
|
|
|
public:
|
|
|
|
// Opens a file for asynchronous I/O
|
2018-07-27 08:21:23 +08:00
|
|
|
virtual Future< Reference<class IAsyncFile> > open( std::string filename, int64_t flags, int64_t mode );
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power failure.
|
2018-07-27 08:21:23 +08:00
|
|
|
virtual Future< Void > deleteFile( std::string filename, bool mustBeDurable );
|
|
|
|
|
|
|
|
virtual Future< std::time_t > lastWriteTime( std::string filename );
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
Sim2FileSystem() {}
|
|
|
|
|
|
|
|
virtual ~Sim2FileSystem() {}
|
|
|
|
|
|
|
|
static void newFileSystem();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|