120 lines
4.4 KiB
C++
120 lines
4.4 KiB
C++
/*
|
|
* Rollback.actor.cpp
|
|
*
|
|
* This source file is part of the FoundationDB open source project
|
|
*
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
|
*
|
|
* 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
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include "flow/actorcompiler.h"
|
|
#include "fdbclient/NativeAPI.h"
|
|
#include "fdbserver/TesterInterface.h"
|
|
#include "workloads.h"
|
|
#include "fdbrpc/simulator.h"
|
|
#include "fdbserver/MasterInterface.h"
|
|
#include "fdbclient/SystemData.h"
|
|
#include "fdbserver/ServerDBInfo.h"
|
|
|
|
struct RollbackWorkload : TestWorkload {
|
|
bool enableFailures, multiple, enabled;
|
|
double meanDelay, clogDuration, testDuration;
|
|
|
|
RollbackWorkload( WorkloadContext const& wcx )
|
|
: TestWorkload(wcx)
|
|
{
|
|
enabled = !clientId; // only do this on the "first" client
|
|
meanDelay = getOption( options, LiteralStringRef("meanDelay"), 20.0 ); // Only matters if multiple==true
|
|
clogDuration = getOption( options, LiteralStringRef("clogDuration"), 3.0 );
|
|
testDuration = getOption( options, LiteralStringRef("testDuration"), 10.0 );
|
|
enableFailures = getOption( options, LiteralStringRef("enableFailures"), false );
|
|
multiple = getOption( options, LiteralStringRef("multiple"), true );
|
|
}
|
|
|
|
virtual std::string description() { return "RollbackWorkload"; }
|
|
virtual Future<Void> setup( Database const& cx ) { return Void(); }
|
|
virtual Future<Void> start( Database const& cx ) {
|
|
if (&g_simulator == g_network && enabled)
|
|
return timeout(
|
|
reportErrors( rollbackFailureWorker( cx, this, meanDelay ), "rollbackFailureWorkerError" ),
|
|
testDuration, Void() );
|
|
return Void();
|
|
}
|
|
virtual Future<bool> check( Database const& cx ) { return true; }
|
|
virtual void getMetrics( vector<PerfMetric>& m ) {
|
|
}
|
|
|
|
ACTOR Future<Void> simulateFailure( Database cx, RollbackWorkload* self ) {
|
|
auto system = self->dbInfo->get();
|
|
auto tlogs = system.logSystemConfig.allPresentLogs();
|
|
|
|
if( tlogs.empty() ) {
|
|
TraceEvent(SevInfo, "UnableToTriggerRollback").detail("Reason", "No tlogs in System Map");
|
|
return Void();
|
|
}
|
|
int utIndex = g_random->randomInt(0, tlogs.size());
|
|
state NetworkAddress uncloggedTLog = tlogs[utIndex].address();
|
|
|
|
for(int t=0; t<tlogs.size(); t++)
|
|
if (t != utIndex)
|
|
if( tlogs[ t ].address().ip == system.master.address().ip ) {
|
|
TraceEvent(SevInfo, "UnableToTriggerRollback").detail("Reason", "master-clogged tLog shared IPs");
|
|
return Void();
|
|
}
|
|
|
|
TraceEvent("AttemptingToTriggerRollback")
|
|
.detail("Master", system.master.address())
|
|
.detail("UncloggedTLog", uncloggedTLog);
|
|
|
|
for(int t=0; t<tlogs.size(); t++)
|
|
if (t != utIndex)
|
|
g_simulator.clogPair(
|
|
system.master.address().ip,
|
|
tlogs[t].address().ip,
|
|
self->clogDuration );
|
|
//g_simulator.clogInterface( g_simulator.getProcess( system.tlogs[t].commit.getEndpoint() ), self->clogDuration, ClogAll );
|
|
|
|
// While the clogged machines are still clogged...
|
|
Void _ = wait( delay( self->clogDuration/3 ) );
|
|
auto system = self->dbInfo->get();
|
|
|
|
// Kill the master and the unclogged tlog
|
|
if (self->enableFailures) {
|
|
g_simulator.killProcess( g_simulator.getProcessByAddress( system.master.address() ), ISimulator::KillInstantly );
|
|
g_simulator.clogInterface( uncloggedTLog.ip, self->clogDuration, ClogAll );
|
|
} else {
|
|
g_simulator.clogInterface( system.master.address().ip, self->clogDuration, ClogAll );
|
|
g_simulator.clogInterface( uncloggedTLog.ip, self->clogDuration, ClogAll );
|
|
}
|
|
return Void();
|
|
}
|
|
|
|
ACTOR Future<Void> rollbackFailureWorker( Database cx, RollbackWorkload* self, double delay ) {
|
|
state PromiseStream<Void> events;
|
|
if (self->multiple) {
|
|
state double lastTime = now();
|
|
loop {
|
|
Void _ = wait( poisson( &lastTime, delay ) );
|
|
Void _ = wait( self->simulateFailure( cx, self ) );
|
|
}
|
|
} else {
|
|
Void _ = wait( ::delay( g_random->random01()*std::max(0.0, self->testDuration - self->clogDuration*13.0) ) );
|
|
Void _ = wait( self->simulateFailure(cx, self) );
|
|
}
|
|
return Void();
|
|
}
|
|
};
|
|
|
|
WorkloadFactory<RollbackWorkload> RollbackWorkloadFactory("Rollback");
|