2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* MachineAttrition.actor.cpp
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2019-02-18 11:25:16 +08:00
|
|
|
#include "fdbserver/TesterInterface.actor.h"
|
2019-02-18 11:13:26 +08:00
|
|
|
#include "fdbserver/WorkerInterface.actor.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbrpc/simulator.h"
|
2019-04-03 05:15:51 +08:00
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
2018-08-11 06:18:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
static std::set<int> const& normalAttritionErrors() {
|
|
|
|
static std::set<int> s;
|
|
|
|
if (s.empty()) {
|
|
|
|
s.insert( error_code_please_reboot );
|
|
|
|
s.insert( error_code_please_reboot_delete );
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MachineAttritionWorkload : TestWorkload {
|
|
|
|
bool enabled;
|
|
|
|
int machinesToKill, machinesToLeave;
|
|
|
|
double testDuration;
|
|
|
|
bool reboot;
|
|
|
|
bool killDc;
|
|
|
|
bool killSelf;
|
|
|
|
bool replacement;
|
2017-09-16 08:55:01 +08:00
|
|
|
bool waitForVersion;
|
|
|
|
bool allowFaultInjection;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// This is set in setup from the list of workers when the cluster is started
|
|
|
|
std::vector<LocalityData> machines;
|
|
|
|
|
|
|
|
MachineAttritionWorkload( WorkloadContext const& wcx )
|
|
|
|
: TestWorkload(wcx)
|
|
|
|
{
|
|
|
|
enabled = !clientId && g_network->isSimulated(); // only do this on the "first" client, and only when in simulation
|
|
|
|
machinesToKill = getOption( options, LiteralStringRef("machinesToKill"), 2 );
|
|
|
|
machinesToLeave = getOption( options, LiteralStringRef("machinesToLeave"), 1 );
|
|
|
|
testDuration = getOption( options, LiteralStringRef("testDuration"), 10.0 );
|
|
|
|
reboot = getOption( options, LiteralStringRef("reboot"), false );
|
2019-05-11 05:01:52 +08:00
|
|
|
killDc = getOption( options, LiteralStringRef("killDc"), deterministicRandom()->random01() < 0.25 );
|
2017-05-26 04:48:44 +08:00
|
|
|
killSelf = getOption( options, LiteralStringRef("killSelf"), false );
|
2019-05-11 05:01:52 +08:00
|
|
|
replacement = getOption( options, LiteralStringRef("replacement"), reboot && deterministicRandom()->random01() < 0.5 );
|
2017-09-16 08:55:01 +08:00
|
|
|
waitForVersion = getOption( options, LiteralStringRef("waitForVersion"), false );
|
|
|
|
allowFaultInjection = getOption( options, LiteralStringRef("allowFaultInjection"), true );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static vector<ISimulator::ProcessInfo*> getServers() {
|
|
|
|
vector<ISimulator::ProcessInfo*> machines;
|
|
|
|
vector<ISimulator::ProcessInfo*> all = g_simulator.getAllProcesses();
|
|
|
|
for(int i = 0; i < all.size(); i++)
|
|
|
|
if( !all[i]->failed && all[i]->name == std::string("Server") && all[i]->startingClass != ProcessClass::TesterClass)
|
|
|
|
machines.push_back( all[i] );
|
|
|
|
return machines;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string description() { return "MachineAttritionWorkload"; }
|
|
|
|
virtual Future<Void> setup( Database const& cx ) {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
virtual Future<Void> start( Database const& cx ) {
|
|
|
|
if (enabled) {
|
|
|
|
std::map<Optional<Standalone<StringRef>>,LocalityData> machineIDMap;
|
|
|
|
auto processes = getServers();
|
|
|
|
for (auto it = processes.begin(); it != processes.end(); ++it) {
|
|
|
|
machineIDMap[(*it)->locality.zoneId()] = (*it)->locality;
|
|
|
|
}
|
|
|
|
machines.clear();
|
|
|
|
for (auto it = machineIDMap.begin(); it != machineIDMap.end(); ++it) {
|
|
|
|
machines.push_back(it->second);
|
|
|
|
}
|
2019-05-11 05:01:52 +08:00
|
|
|
deterministicRandom()->randomShuffle( machines );
|
2017-05-26 04:48:44 +08:00
|
|
|
double meanDelay = testDuration / machinesToKill;
|
|
|
|
TraceEvent("AttritionStarting")
|
|
|
|
.detail("KillDataCenters", killDc)
|
|
|
|
.detail("Reboot", reboot)
|
|
|
|
.detail("MachinesToLeave", machinesToLeave)
|
|
|
|
.detail("MachinesToKill", machinesToKill)
|
|
|
|
.detail("MeanDelay", meanDelay);
|
|
|
|
|
|
|
|
return timeout(
|
2017-09-16 08:55:01 +08:00
|
|
|
reportErrorsExcept( machineKillWorker( this, meanDelay, cx ), "machineKillWorkerError", UID(), &normalAttritionErrors()),
|
2017-05-26 04:48:44 +08:00
|
|
|
testDuration, Void() );
|
|
|
|
}
|
|
|
|
if(killSelf)
|
|
|
|
throw please_reboot();
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
virtual Future<bool> check( Database const& cx ) { return true; }
|
|
|
|
virtual void getMetrics( vector<PerfMetric>& m ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
struct UIDPredicate {
|
|
|
|
UIDPredicate(StringRef uid ) : uid( uid ) {}
|
|
|
|
bool operator() ( WorkerInterface rhs ) { return rhs.locality.zoneId() != uid; }
|
|
|
|
private:
|
|
|
|
StringRef uid;
|
|
|
|
};
|
|
|
|
|
2017-09-16 08:55:01 +08:00
|
|
|
ACTOR static Future<Void> machineKillWorker( MachineAttritionWorkload *self, double meanDelay, Database cx ) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state int killedMachines = 0;
|
2019-05-11 05:01:52 +08:00
|
|
|
state double delayBeforeKill = deterministicRandom()->random01() * meanDelay;
|
2017-05-26 04:48:44 +08:00
|
|
|
state std::set<UID> killedUIDs;
|
|
|
|
|
|
|
|
ASSERT( g_network->isSimulated() );
|
|
|
|
|
|
|
|
if( self->killDc ) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( delay( delayBeforeKill ) );
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// decide on a machine to kill
|
|
|
|
ASSERT( self->machines.size() );
|
|
|
|
Optional<Standalone<StringRef>> target = self->machines.back().dcId();
|
|
|
|
|
|
|
|
ISimulator::KillType kt = ISimulator::Reboot;
|
|
|
|
if( !self->reboot ) {
|
2019-05-11 05:01:52 +08:00
|
|
|
int killType = deterministicRandom()->randomInt(0,3);
|
2017-05-26 04:48:44 +08:00
|
|
|
if( killType == 0 )
|
|
|
|
kt = ISimulator::KillInstantly;
|
|
|
|
else if( killType == 1 )
|
|
|
|
kt = ISimulator::InjectFaults;
|
|
|
|
else
|
|
|
|
kt = ISimulator::RebootAndDelete;
|
|
|
|
}
|
2019-03-15 09:40:28 +08:00
|
|
|
TraceEvent("Assassination").detail("TargetDatacenter", target).detail("Reboot", self->reboot).detail("KillType", kt);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
g_simulator.killDataCenter( target, kt );
|
|
|
|
} else {
|
|
|
|
while ( killedMachines < self->machinesToKill && self->machines.size() > self->machinesToLeave) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("WorkerKillBegin").detail("KilledMachines", killedMachines)
|
|
|
|
.detail("MachinesToKill", self->machinesToKill).detail("MachinesToLeave", self->machinesToLeave)
|
|
|
|
.detail("Machines", self->machines.size());
|
2017-05-27 08:43:28 +08:00
|
|
|
TEST(true); // Killing a machine
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( delay( delayBeforeKill ) );
|
2017-05-26 04:48:44 +08:00
|
|
|
TraceEvent("WorkerKillAfterDelay");
|
|
|
|
|
2017-09-16 08:55:01 +08:00
|
|
|
if(self->waitForVersion) {
|
|
|
|
state Transaction tr( cx );
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr.setOption(FDBTransactionOptions::PRIORITY_SYSTEM_IMMEDIATE);
|
|
|
|
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
2019-02-13 08:07:17 +08:00
|
|
|
wait(success(tr.getReadVersion()));
|
2017-09-16 08:55:01 +08:00
|
|
|
break;
|
|
|
|
} catch( Error &e ) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.onError(e) );
|
2017-09-16 08:55:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// decide on a machine to kill
|
2019-04-03 05:15:51 +08:00
|
|
|
state LocalityData targetMachine = self->machines.back();
|
|
|
|
|
|
|
|
if(BUGGIFY_WITH_PROB(0.01)) {
|
|
|
|
TEST(true); //Marked a zone for maintenance before killing it
|
2019-05-11 05:01:52 +08:00
|
|
|
wait( setHealthyZone(cx, targetMachine.zoneId().get(), deterministicRandom()->random01()*20 ) );
|
2019-04-03 05:15:51 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
TraceEvent("Assassination").detail("TargetMachine", targetMachine.toString())
|
2019-03-15 09:40:28 +08:00
|
|
|
.detail("ZoneId", targetMachine.zoneId())
|
2018-06-09 02:11:08 +08:00
|
|
|
.detail("Reboot", self->reboot).detail("KilledMachines", killedMachines)
|
|
|
|
.detail("MachinesToKill", self->machinesToKill).detail("MachinesToLeave", self->machinesToLeave)
|
|
|
|
.detail("Machines", self->machines.size()).detail("Replace", self->replacement);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
if (self->reboot) {
|
2019-05-11 05:01:52 +08:00
|
|
|
if( deterministicRandom()->random01() > 0.5 ) {
|
|
|
|
g_simulator.rebootProcess( targetMachine.zoneId(), deterministicRandom()->random01() > 0.5 );
|
2017-05-26 04:48:44 +08:00
|
|
|
} else {
|
2019-01-19 07:42:48 +08:00
|
|
|
g_simulator.killZone( targetMachine.zoneId(), ISimulator::Reboot );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-05-11 05:01:52 +08:00
|
|
|
auto randomDouble = deterministicRandom()->random01();
|
2017-08-29 02:25:37 +08:00
|
|
|
TraceEvent("WorkerKill").detail("MachineCount", self->machines.size()).detail("RandomValue", randomDouble);
|
|
|
|
if (randomDouble < 0.33 ) {
|
2017-05-26 04:48:44 +08:00
|
|
|
TraceEvent("RebootAndDelete").detail("TargetMachine", targetMachine.toString());
|
2019-01-19 07:42:48 +08:00
|
|
|
g_simulator.killZone( targetMachine.zoneId(), ISimulator::RebootAndDelete );
|
2017-05-26 04:48:44 +08:00
|
|
|
} else {
|
2019-05-11 05:01:52 +08:00
|
|
|
auto kt = (deterministicRandom()->random01() < 0.5 || !self->allowFaultInjection) ? ISimulator::KillInstantly : ISimulator::InjectFaults;
|
2019-01-19 07:42:48 +08:00
|
|
|
g_simulator.killZone( targetMachine.zoneId(), kt );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
killedMachines++;
|
|
|
|
if(!self->replacement)
|
|
|
|
self->machines.pop_back();
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( delay( meanDelay - delayBeforeKill ) );
|
2019-05-11 05:01:52 +08:00
|
|
|
delayBeforeKill = deterministicRandom()->random01() * meanDelay;
|
2017-05-26 04:48:44 +08:00
|
|
|
TraceEvent("WorkerKillAfterMeanDelay").detail("DelayBeforeKill", delayBeforeKill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(self->killSelf)
|
|
|
|
throw please_reboot();
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WorkloadFactory<MachineAttritionWorkload> MachineAttritionWorkloadFactory("Attrition");
|