2019-05-10 11:55:44 +08:00
|
|
|
/*
|
2020-07-17 06:30:27 +08:00
|
|
|
* RestoreController.actor.cpp
|
2019-05-10 11:55:44 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
// This file implements the functions for RestoreController role
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-04-16 04:32:52 +08:00
|
|
|
#include "fdbrpc/RangeMap.h"
|
2019-05-10 11:55:44 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
|
|
|
#include "fdbclient/SystemData.h"
|
|
|
|
#include "fdbclient/BackupAgent.actor.h"
|
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
|
|
|
#include "fdbclient/MutationList.h"
|
|
|
|
#include "fdbclient/BackupContainer.h"
|
2019-05-16 12:15:15 +08:00
|
|
|
#include "fdbserver/RestoreUtil.h"
|
2019-05-10 11:55:44 +08:00
|
|
|
#include "fdbserver/RestoreCommon.actor.h"
|
|
|
|
#include "fdbserver/RestoreRoleCommon.actor.h"
|
2020-07-17 06:30:27 +08:00
|
|
|
#include "fdbserver/RestoreController.actor.h"
|
2019-05-10 11:55:44 +08:00
|
|
|
#include "fdbserver/RestoreApplier.actor.h"
|
|
|
|
#include "fdbserver/RestoreLoader.actor.h"
|
|
|
|
|
2020-07-26 10:12:25 +08:00
|
|
|
#include "flow/Platform.h"
|
2019-08-02 08:00:13 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2019-09-04 06:50:21 +08:00
|
|
|
ACTOR static Future<Void> clearDB(Database cx);
|
2020-03-19 06:38:06 +08:00
|
|
|
ACTOR static Future<Version> collectBackupFiles(Reference<IBackupContainer> bc, std::vector<RestoreFileFR>* rangeFiles,
|
2020-04-18 00:30:36 +08:00
|
|
|
std::vector<RestoreFileFR>* logFiles, Version* minRangeVersion,
|
|
|
|
Database cx, RestoreRequest request);
|
2020-04-16 04:32:52 +08:00
|
|
|
ACTOR static Future<Void> buildRangeVersions(KeyRangeMap<Version>* pRangeVersions,
|
|
|
|
std::vector<RestoreFileFR>* pRangeFiles, Key url);
|
2019-07-25 07:59:05 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Version> processRestoreRequest(Reference<RestoreControllerData> self, Database cx,
|
|
|
|
RestoreRequest request);
|
|
|
|
ACTOR static Future<Void> startProcessRestoreRequests(Reference<RestoreControllerData> self, Database cx);
|
|
|
|
ACTOR static Future<Void> distributeWorkloadPerVersionBatch(Reference<RestoreControllerData> self, int batchIndex,
|
2020-01-16 08:20:55 +08:00
|
|
|
Database cx, RestoreRequest request,
|
|
|
|
VersionBatch versionBatch);
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> recruitRestoreRoles(Reference<RestoreWorkerData> controllerWorker,
|
|
|
|
Reference<RestoreControllerData> controllerData);
|
|
|
|
ACTOR static Future<Void> distributeRestoreSysInfo(Reference<RestoreControllerData> controllerData,
|
2020-04-16 04:32:52 +08:00
|
|
|
KeyRangeMap<Version>* pRangeVersions);
|
2019-05-27 11:53:12 +08:00
|
|
|
|
2020-06-22 14:53:41 +08:00
|
|
|
ACTOR static Future<std::vector<RestoreRequest>> collectRestoreRequests(Database cx);
|
2020-01-16 08:20:55 +08:00
|
|
|
ACTOR static Future<Void> initializeVersionBatch(std::map<UID, RestoreApplierInterface> appliersInterf,
|
|
|
|
std::map<UID, RestoreLoaderInterface> loadersInterf, int batchIndex);
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> notifyApplierToApplyMutations(Reference<ControllerBatchData> batchData,
|
|
|
|
Reference<ControllerBatchStatus> batchStatus,
|
2020-01-22 06:49:13 +08:00
|
|
|
std::map<UID, RestoreApplierInterface> appliersInterf,
|
2020-01-24 08:24:12 +08:00
|
|
|
int batchIndex, NotifiedVersion* finishedBatch);
|
2020-02-27 05:43:30 +08:00
|
|
|
ACTOR static Future<Void> notifyLoadersVersionBatchFinished(std::map<UID, RestoreLoaderInterface> loadersInterf,
|
|
|
|
int batchIndex);
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> notifyRestoreCompleted(Reference<RestoreControllerData> self, bool terminate);
|
|
|
|
ACTOR static Future<Void> signalRestoreCompleted(Reference<RestoreControllerData> self, Database cx);
|
|
|
|
ACTOR static Future<Void> updateHeartbeatTime(Reference<RestoreControllerData> self);
|
|
|
|
ACTOR static Future<Void> checkRolesLiveness(Reference<RestoreControllerData> self);
|
2019-05-21 08:52:40 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
void splitKeyRangeForAppliers(Reference<ControllerBatchData> batchData,
|
2020-01-16 08:20:55 +08:00
|
|
|
std::map<UID, RestoreApplierInterface> appliersInterf, int batchIndex);
|
2019-05-21 08:52:40 +08:00
|
|
|
|
2020-08-05 04:35:36 +08:00
|
|
|
ACTOR Future<Void> sampleBackups(Reference<RestoreControllerData> self, RestoreControllerInterface ci) {
|
|
|
|
loop {
|
|
|
|
try {
|
2020-08-05 14:04:38 +08:00
|
|
|
RestoreSamplesRequest req = waitNext(ci.samples.getFuture());
|
2020-08-06 02:32:04 +08:00
|
|
|
TraceEvent(SevDebug, "FastRestoreControllerSampleBackups")
|
|
|
|
.detail("SampleID", req.id)
|
|
|
|
.detail("BatchIndex", req.batchIndex)
|
|
|
|
.detail("Samples", req.samples.size());
|
2020-08-13 01:36:31 +08:00
|
|
|
ASSERT(req.batchIndex <= self->batch.size()); // batchIndex starts from 1
|
2020-08-08 07:52:07 +08:00
|
|
|
|
2020-08-05 04:35:36 +08:00
|
|
|
Reference<ControllerBatchData> batch = self->batch[req.batchIndex];
|
2020-08-28 00:31:57 +08:00
|
|
|
ASSERT(batch.isValid());
|
2020-08-05 04:35:36 +08:00
|
|
|
if (batch->sampleMsgs.find(req.id) != batch->sampleMsgs.end()) {
|
2020-08-08 07:50:36 +08:00
|
|
|
req.reply.send(RestoreCommonReply(req.id));
|
2020-08-05 04:35:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
batch->sampleMsgs.insert(req.id);
|
|
|
|
for (auto& m : req.samples) {
|
|
|
|
batch->samples.addMetric(m.key, m.size);
|
2020-08-06 02:32:04 +08:00
|
|
|
batch->samplesSize += m.size;
|
2020-08-05 04:35:36 +08:00
|
|
|
}
|
2020-08-06 02:32:04 +08:00
|
|
|
req.reply.send(RestoreCommonReply(req.id));
|
2020-08-05 04:35:36 +08:00
|
|
|
} catch (Error& e) {
|
2020-08-05 14:04:38 +08:00
|
|
|
TraceEvent(SevWarn, "FastRestoreControllerSampleBackupsError", self->id()).error(e);
|
2020-08-05 04:35:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR Future<Void> startRestoreController(Reference<RestoreWorkerData> controllerWorker, Database cx) {
|
2020-08-04 06:06:15 +08:00
|
|
|
ASSERT(controllerWorker.isValid());
|
|
|
|
ASSERT(controllerWorker->controllerInterf.present());
|
|
|
|
state Reference<RestoreControllerData> self =
|
2020-08-05 14:04:38 +08:00
|
|
|
Reference<RestoreControllerData>(new RestoreControllerData(controllerWorker->controllerInterf.get().id()));
|
2020-09-23 04:32:26 +08:00
|
|
|
state Future<Void> error = actorCollection(self->addActor.getFuture());
|
2019-07-25 07:59:05 +08:00
|
|
|
|
2019-10-17 02:31:30 +08:00
|
|
|
try {
|
2020-07-17 06:30:27 +08:00
|
|
|
// recruitRestoreRoles must come after controllerWorker has finished collectWorkerInterface
|
|
|
|
wait(recruitRestoreRoles(controllerWorker, self));
|
2019-07-25 07:59:05 +08:00
|
|
|
|
2020-09-23 04:32:26 +08:00
|
|
|
self->addActor.send(updateHeartbeatTime(self));
|
|
|
|
self->addActor.send(checkRolesLiveness(self));
|
|
|
|
self->addActor.send(updateProcessMetrics(self));
|
|
|
|
self->addActor.send(traceProcessMetrics(self, "RestoreController"));
|
|
|
|
self->addActor.send(sampleBackups(self, controllerWorker->controllerInterf.get()));
|
2020-02-27 07:45:21 +08:00
|
|
|
|
2020-09-23 04:32:26 +08:00
|
|
|
wait(startProcessRestoreRequests(self, cx) || error);
|
2019-10-17 02:31:30 +08:00
|
|
|
} catch (Error& e) {
|
2020-02-29 03:22:53 +08:00
|
|
|
if (e.code() != error_code_operation_cancelled) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerStart").detail("Reason", "Unexpected unhandled error").error(e);
|
2020-02-29 03:22:53 +08:00
|
|
|
}
|
2019-10-17 02:31:30 +08:00
|
|
|
}
|
2019-07-25 07:59:05 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
// RestoreWorker that has restore controller role: Recruite a role for each worker
|
|
|
|
ACTOR Future<Void> recruitRestoreRoles(Reference<RestoreWorkerData> controllerWorker,
|
|
|
|
Reference<RestoreControllerData> controllerData) {
|
2019-12-11 14:55:40 +08:00
|
|
|
state int nodeIndex = 0;
|
|
|
|
state RestoreRole role = RestoreRole::Invalid;
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreController", controllerData->id())
|
|
|
|
.detail("RecruitRestoreRoles", controllerWorker->workerInterfaces.size())
|
2020-01-24 22:58:33 +08:00
|
|
|
.detail("NumLoaders", SERVER_KNOBS->FASTRESTORE_NUM_LOADERS)
|
|
|
|
.detail("NumAppliers", SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS);
|
2020-07-17 06:30:27 +08:00
|
|
|
ASSERT(controllerData->loadersInterf.empty() && controllerData->appliersInterf.empty());
|
2020-08-04 06:06:15 +08:00
|
|
|
ASSERT(controllerWorker->controllerInterf.present());
|
2019-07-25 07:59:05 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ASSERT(controllerData.isValid());
|
2020-01-24 22:58:33 +08:00
|
|
|
ASSERT(SERVER_KNOBS->FASTRESTORE_NUM_LOADERS > 0 && SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS > 0);
|
2019-08-02 08:00:13 +08:00
|
|
|
// We assign 1 role per worker for now
|
2020-01-24 22:58:33 +08:00
|
|
|
ASSERT(SERVER_KNOBS->FASTRESTORE_NUM_LOADERS + SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS <=
|
2020-07-17 06:30:27 +08:00
|
|
|
controllerWorker->workerInterfaces.size());
|
2019-08-02 08:00:13 +08:00
|
|
|
|
2019-07-25 07:59:05 +08:00
|
|
|
// Assign a role to each worker
|
2019-12-03 06:33:31 +08:00
|
|
|
std::vector<std::pair<UID, RestoreRecruitRoleRequest>> requests;
|
2020-07-17 06:30:27 +08:00
|
|
|
for (auto& workerInterf : controllerWorker->workerInterfaces) {
|
2020-01-24 22:58:33 +08:00
|
|
|
if (nodeIndex >= 0 && nodeIndex < SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS) {
|
2019-07-25 07:59:05 +08:00
|
|
|
// [0, numApplier) are appliers
|
|
|
|
role = RestoreRole::Applier;
|
2020-01-24 22:58:33 +08:00
|
|
|
} else if (nodeIndex >= SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS &&
|
|
|
|
nodeIndex < SERVER_KNOBS->FASTRESTORE_NUM_LOADERS + SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS) {
|
2019-07-25 07:59:05 +08:00
|
|
|
// [numApplier, numApplier + numLoader) are loaders
|
|
|
|
role = RestoreRole::Loader;
|
2019-07-26 08:16:33 +08:00
|
|
|
} else {
|
|
|
|
break;
|
2019-07-25 07:59:05 +08:00
|
|
|
}
|
|
|
|
|
2020-08-18 11:34:33 +08:00
|
|
|
TraceEvent("FastRestoreController", controllerData->id())
|
|
|
|
.detail("WorkerNode", workerInterf.first)
|
|
|
|
.detail("NodeRole", role)
|
|
|
|
.detail("NodeIndex", nodeIndex);
|
2020-08-04 06:06:15 +08:00
|
|
|
requests.emplace_back(workerInterf.first,
|
|
|
|
RestoreRecruitRoleRequest(controllerWorker->controllerInterf.get(), role, nodeIndex));
|
2019-07-25 07:59:05 +08:00
|
|
|
nodeIndex++;
|
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
|
2019-07-25 07:59:05 +08:00
|
|
|
state std::vector<RestoreRecruitRoleReply> replies;
|
2020-07-17 06:30:27 +08:00
|
|
|
wait(getBatchReplies(&RestoreWorkerInterface::recruitRole, controllerWorker->workerInterfaces, requests, &replies));
|
2019-07-25 07:59:05 +08:00
|
|
|
for (auto& reply : replies) {
|
2019-08-02 08:00:13 +08:00
|
|
|
if (reply.role == RestoreRole::Applier) {
|
2019-07-25 07:59:05 +08:00
|
|
|
ASSERT_WE_THINK(reply.applier.present());
|
2020-07-17 06:30:27 +08:00
|
|
|
controllerData->appliersInterf[reply.applier.get().id()] = reply.applier.get();
|
2019-08-02 08:00:13 +08:00
|
|
|
} else if (reply.role == RestoreRole::Loader) {
|
2019-07-25 07:59:05 +08:00
|
|
|
ASSERT_WE_THINK(reply.loader.present());
|
2020-07-17 06:30:27 +08:00
|
|
|
controllerData->loadersInterf[reply.loader.get().id()] = reply.loader.get();
|
2019-07-25 07:59:05 +08:00
|
|
|
} else {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreController").detail("RecruitRestoreRolesInvalidRole", reply.role);
|
2019-07-25 07:59:05 +08:00
|
|
|
}
|
|
|
|
}
|
2020-08-06 02:32:04 +08:00
|
|
|
controllerData->recruitedRoles.send(Void());
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreRecruitRestoreRolesDone", controllerData->id())
|
|
|
|
.detail("Workers", controllerWorker->workerInterfaces.size())
|
2020-02-19 08:41:59 +08:00
|
|
|
.detail("RecruitedRoles", replies.size());
|
2019-07-25 07:59:05 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR Future<Void> distributeRestoreSysInfo(Reference<RestoreControllerData> controllerData,
|
2020-04-16 04:32:52 +08:00
|
|
|
KeyRangeMap<Version>* pRangeVersions) {
|
2020-07-17 06:30:27 +08:00
|
|
|
ASSERT(controllerData.isValid());
|
|
|
|
ASSERT(!controllerData->loadersInterf.empty());
|
|
|
|
RestoreSysInfo sysInfo(controllerData->appliersInterf);
|
2020-04-16 04:32:52 +08:00
|
|
|
// Construct serializable KeyRange versions
|
|
|
|
Standalone<VectorRef<std::pair<KeyRangeRef, Version>>> rangeVersionsVec;
|
|
|
|
auto ranges = pRangeVersions->ranges();
|
|
|
|
int i = 0;
|
|
|
|
for (auto r = ranges.begin(); r != ranges.end(); ++r) {
|
|
|
|
rangeVersionsVec.push_back(rangeVersionsVec.arena(),
|
|
|
|
std::make_pair(KeyRangeRef(r->begin(), r->end()), r->value()));
|
2020-04-18 06:00:07 +08:00
|
|
|
TraceEvent("DistributeRangeVersions")
|
2020-04-16 04:32:52 +08:00
|
|
|
.detail("RangeIndex", i++)
|
|
|
|
.detail("RangeBegin", r->begin())
|
|
|
|
.detail("RangeEnd", r->end())
|
|
|
|
.detail("RangeVersion", r->value());
|
|
|
|
}
|
2019-07-25 07:59:05 +08:00
|
|
|
std::vector<std::pair<UID, RestoreSysInfoRequest>> requests;
|
2020-07-17 06:30:27 +08:00
|
|
|
for (auto& loader : controllerData->loadersInterf) {
|
2020-04-16 04:32:52 +08:00
|
|
|
requests.emplace_back(loader.first, RestoreSysInfoRequest(sysInfo, rangeVersionsVec));
|
2019-07-25 07:59:05 +08:00
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreDistributeRestoreSysInfoToLoaders", controllerData->id())
|
|
|
|
.detail("Loaders", controllerData->loadersInterf.size());
|
|
|
|
wait(sendBatchRequests(&RestoreLoaderInterface::updateRestoreSysInfo, controllerData->loadersInterf, requests));
|
|
|
|
TraceEvent("FastRestoreDistributeRestoreSysInfoToLoadersDone", controllerData->id())
|
|
|
|
.detail("Loaders", controllerData->loadersInterf.size());
|
2019-08-02 08:00:13 +08:00
|
|
|
|
2019-07-25 07:59:05 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
// The server of the restore controller. It drives the restore progress with the following steps:
|
2019-06-01 02:09:31 +08:00
|
|
|
// 1) Lock database and clear the normal keyspace
|
2020-07-02 23:16:39 +08:00
|
|
|
// 2) Wait on each RestoreRequest, which is sent by RestoreTool operated by DBA
|
2019-06-01 02:09:31 +08:00
|
|
|
// 3) Process each restore request in actor processRestoreRequest;
|
|
|
|
// 3.1) Sample workload to decide the key range for each applier, which is implemented as a dummy sampling;
|
|
|
|
// 3.2) Send each loader the map of key-range to applier interface;
|
|
|
|
// 3.3) Construct requests of which file should be loaded by which loader, and send requests to loaders;
|
|
|
|
// 4) After process all restore requests, finish restore by cleaning up the restore related system key
|
2019-05-13 13:05:49 +08:00
|
|
|
// and ask all restore roles to quit.
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR Future<Void> startProcessRestoreRequests(Reference<RestoreControllerData> self, Database cx) {
|
2019-07-26 01:46:11 +08:00
|
|
|
state UID randomUID = deterministicRandom()->randomUniqueID();
|
2020-06-22 14:53:41 +08:00
|
|
|
state std::vector<RestoreRequest> restoreRequests = wait(collectRestoreRequests(cx));
|
2019-12-11 14:55:40 +08:00
|
|
|
state int restoreIndex = 0;
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerWaitOnRestoreRequests", self->id())
|
|
|
|
.detail("RestoreRequests", restoreRequests.size());
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-06-09 13:12:17 +08:00
|
|
|
// TODO: Sanity check restoreRequests' key ranges do not overlap
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2019-06-01 02:09:31 +08:00
|
|
|
// Step: Perform the restore requests
|
2019-07-25 07:59:05 +08:00
|
|
|
try {
|
2019-08-02 08:00:13 +08:00
|
|
|
for (restoreIndex = 0; restoreIndex < restoreRequests.size(); restoreIndex++) {
|
2020-06-09 13:12:17 +08:00
|
|
|
state RestoreRequest request = restoreRequests[restoreIndex];
|
2020-06-19 01:35:41 +08:00
|
|
|
state KeyRange range = request.range.removePrefix(request.removePrefix).withPrefix(request.addPrefix);
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerProcessRestoreRequests", self->id())
|
2020-06-19 01:35:41 +08:00
|
|
|
.detail("RestoreRequestInfo", request.toString())
|
|
|
|
.detail("TransformedKeyRange", range);
|
2020-07-17 06:30:27 +08:00
|
|
|
// TODO: Initialize controllerData and all loaders and appliers' data for each restore request!
|
2020-01-17 08:19:51 +08:00
|
|
|
self->resetPerRestoreRequest();
|
2020-06-09 13:12:17 +08:00
|
|
|
|
|
|
|
// clear the key range that will be restored
|
|
|
|
wait(runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2020-06-19 01:35:41 +08:00
|
|
|
tr->clear(range);
|
2020-06-09 13:12:17 +08:00
|
|
|
return Void();
|
|
|
|
}));
|
|
|
|
|
2019-09-26 14:19:42 +08:00
|
|
|
wait(success(processRestoreRequest(self, cx, request)));
|
2020-01-17 08:19:51 +08:00
|
|
|
wait(notifyRestoreCompleted(self, false));
|
2019-07-25 07:59:05 +08:00
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
} catch (Error& e) {
|
2019-12-11 14:55:40 +08:00
|
|
|
if (restoreIndex < restoreRequests.size()) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerProcessRestoreRequestsFailed", self->id())
|
2020-08-06 02:32:04 +08:00
|
|
|
.error(e)
|
|
|
|
.detail("RestoreRequest", restoreRequests[restoreIndex].toString());
|
2019-12-11 14:55:40 +08:00
|
|
|
} else {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerProcessRestoreRequestsFailed", self->id())
|
2020-08-06 02:32:04 +08:00
|
|
|
.error(e)
|
2019-12-12 23:44:57 +08:00
|
|
|
.detail("RestoreRequests", restoreRequests.size())
|
2020-08-06 02:32:04 +08:00
|
|
|
.detail("RestoreIndex", restoreIndex);
|
2019-12-11 14:55:40 +08:00
|
|
|
}
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
|
2019-06-01 02:09:31 +08:00
|
|
|
// Step: Notify all restore requests have been handled by cleaning up the restore keys
|
2020-01-17 08:19:51 +08:00
|
|
|
wait(signalRestoreCompleted(self, cx));
|
2019-06-05 02:40:23 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerRestoreCompleted", self->id());
|
2019-06-01 02:09:31 +08:00
|
|
|
|
2019-05-10 11:55:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> monitorFinishedVersion(Reference<RestoreControllerData> self, RestoreRequest request) {
|
2020-02-06 06:25:26 +08:00
|
|
|
loop {
|
2020-02-19 08:41:59 +08:00
|
|
|
TraceEvent("FastRestoreMonitorFinishedVersion", self->id())
|
|
|
|
.detail("RestoreRequest", request.toString())
|
2020-02-20 03:52:24 +08:00
|
|
|
.detail("BatchIndex", self->finishedBatch.get());
|
2020-02-06 06:25:26 +08:00
|
|
|
wait(delay(SERVER_KNOBS->FASTRESTORE_VB_MONITOR_DELAY));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Version> processRestoreRequest(Reference<RestoreControllerData> self, Database cx,
|
2019-09-04 06:50:21 +08:00
|
|
|
RestoreRequest request) {
|
2020-01-06 09:54:44 +08:00
|
|
|
state std::vector<RestoreFileFR> rangeFiles;
|
|
|
|
state std::vector<RestoreFileFR> logFiles;
|
2019-07-25 07:59:05 +08:00
|
|
|
state std::vector<RestoreFileFR> allFiles;
|
2020-04-18 00:30:36 +08:00
|
|
|
state Version minRangeVersion = MAX_VERSION;
|
2019-07-25 07:59:05 +08:00
|
|
|
|
|
|
|
self->initBackupContainer(request.url);
|
|
|
|
|
2019-08-03 07:09:38 +08:00
|
|
|
// Get all backup files' description and save them to files
|
2020-04-18 00:30:36 +08:00
|
|
|
state Version targetVersion =
|
|
|
|
wait(collectBackupFiles(self->bc, &rangeFiles, &logFiles, &minRangeVersion, cx, request));
|
2020-03-19 06:38:06 +08:00
|
|
|
ASSERT(targetVersion > 0);
|
2020-08-01 14:23:12 +08:00
|
|
|
ASSERT(minRangeVersion != MAX_VERSION); // otherwise, all mutations will be skipped
|
2020-01-06 09:54:44 +08:00
|
|
|
|
|
|
|
std::sort(rangeFiles.begin(), rangeFiles.end());
|
2020-01-10 03:31:27 +08:00
|
|
|
std::sort(logFiles.begin(), logFiles.end(), [](RestoreFileFR const& f1, RestoreFileFR const& f2) -> bool {
|
2020-01-23 07:02:20 +08:00
|
|
|
return std::tie(f1.endVersion, f1.beginVersion, f1.fileIndex, f1.fileName) <
|
|
|
|
std::tie(f2.endVersion, f2.beginVersion, f2.fileIndex, f2.fileName);
|
2020-01-10 03:31:27 +08:00
|
|
|
});
|
2020-01-06 09:54:44 +08:00
|
|
|
|
2020-04-16 04:32:52 +08:00
|
|
|
// Build range versions: version of key ranges in range file
|
2020-04-18 00:30:36 +08:00
|
|
|
state KeyRangeMap<Version> rangeVersions(minRangeVersion, allKeys.end);
|
2020-04-18 01:02:53 +08:00
|
|
|
if (SERVER_KNOBS->FASTRESTORE_GET_RANGE_VERSIONS_EXPENSIVE) {
|
|
|
|
wait(buildRangeVersions(&rangeVersions, &rangeFiles, request.url));
|
2020-04-18 04:38:09 +08:00
|
|
|
} else {
|
|
|
|
// Debug purpose, dump range versions
|
|
|
|
auto ranges = rangeVersions.ranges();
|
|
|
|
int i = 0;
|
|
|
|
for (auto r = ranges.begin(); r != ranges.end(); ++r) {
|
|
|
|
TraceEvent(SevDebug, "SingleRangeVersion")
|
|
|
|
.detail("RangeIndex", i++)
|
|
|
|
.detail("RangeBegin", r->begin())
|
|
|
|
.detail("RangeEnd", r->end())
|
|
|
|
.detail("RangeVersion", r->value());
|
|
|
|
}
|
2020-04-18 01:02:53 +08:00
|
|
|
}
|
2020-04-16 04:32:52 +08:00
|
|
|
|
|
|
|
wait(distributeRestoreSysInfo(self, &rangeVersions));
|
|
|
|
|
2020-03-22 04:44:02 +08:00
|
|
|
// Divide files into version batches.
|
|
|
|
self->buildVersionBatches(rangeFiles, logFiles, &self->versionBatches, targetVersion);
|
2020-01-06 09:54:44 +08:00
|
|
|
self->dumpVersionBatches(self->versionBatches);
|
2019-07-25 07:59:05 +08:00
|
|
|
|
2020-01-29 02:16:44 +08:00
|
|
|
state std::vector<Future<Void>> fBatches;
|
|
|
|
state std::vector<VersionBatch> versionBatches; // To randomize invoking order of version batchs
|
2020-01-28 14:12:00 +08:00
|
|
|
for (auto& vb : self->versionBatches) {
|
|
|
|
versionBatches.push_back(vb.second);
|
|
|
|
}
|
|
|
|
|
2020-04-05 08:33:59 +08:00
|
|
|
// releaseVBOutOfOrder can only be true in simulation
|
|
|
|
state bool releaseVBOutOfOrder = g_network->isSimulated() ? deterministicRandom()->random01() < 0.5 : false;
|
|
|
|
ASSERT(g_network->isSimulated() || !releaseVBOutOfOrder);
|
|
|
|
if (releaseVBOutOfOrder) {
|
2020-01-28 14:12:00 +08:00
|
|
|
// Randomize invoking order of version batches
|
|
|
|
int permTimes = deterministicRandom()->randomInt(0, 100);
|
|
|
|
while (permTimes-- > 0) {
|
|
|
|
std::next_permutation(versionBatches.begin(), versionBatches.end());
|
2020-01-18 03:06:07 +08:00
|
|
|
}
|
2020-01-28 14:12:00 +08:00
|
|
|
}
|
|
|
|
|
2020-08-11 12:34:47 +08:00
|
|
|
self->addActor.send(monitorFinishedVersion(self, request));
|
2020-01-29 02:16:44 +08:00
|
|
|
state std::vector<VersionBatch>::iterator versionBatch = versionBatches.begin();
|
|
|
|
for (; versionBatch != versionBatches.end(); versionBatch++) {
|
2020-04-05 08:33:59 +08:00
|
|
|
while (self->runningVersionBatches.get() >= SERVER_KNOBS->FASTRESTORE_VB_PARALLELISM && !releaseVBOutOfOrder) {
|
2020-01-29 02:16:44 +08:00
|
|
|
// Control how many batches can be processed in parallel. Avoid dead lock due to OOM on loaders
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerDispatchVersionBatches")
|
2020-01-29 02:16:44 +08:00
|
|
|
.detail("WaitOnRunningVersionBatches", self->runningVersionBatches.get());
|
|
|
|
wait(self->runningVersionBatches.onChange());
|
|
|
|
}
|
2020-01-28 14:12:00 +08:00
|
|
|
int batchIndex = versionBatch->batchIndex;
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerDispatchVersionBatches")
|
2020-02-19 08:41:59 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("BatchSize", versionBatch->size)
|
2020-05-06 10:12:15 +08:00
|
|
|
.detail("RunningVersionBatches", self->runningVersionBatches.get())
|
|
|
|
.detail("VersionBatches", versionBatches.size());
|
2020-07-17 06:30:27 +08:00
|
|
|
self->batch[batchIndex] = Reference<ControllerBatchData>(new ControllerBatchData());
|
|
|
|
self->batchStatus[batchIndex] = Reference<ControllerBatchStatus>(new ControllerBatchStatus());
|
2020-01-28 14:12:00 +08:00
|
|
|
fBatches.push_back(distributeWorkloadPerVersionBatch(self, batchIndex, cx, request, *versionBatch));
|
2020-02-09 14:10:57 +08:00
|
|
|
// Wait a bit to give the current version batch a head start from the next version batch
|
|
|
|
wait(delay(SERVER_KNOBS->FASTRESTORE_VB_LAUNCH_DELAY));
|
2019-05-31 07:38:08 +08:00
|
|
|
}
|
|
|
|
|
2020-08-11 12:34:47 +08:00
|
|
|
try {
|
2020-09-23 04:32:26 +08:00
|
|
|
wait(waitForAll(fBatches));
|
2020-08-11 12:34:47 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
TraceEvent(SevError, "FastRestoreControllerDispatchVersionBatchesUnexpectedError").error(e);
|
|
|
|
}
|
2020-01-16 09:24:01 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreController").detail("RestoreToVersion", request.targetVersion);
|
2019-05-31 07:38:08 +08:00
|
|
|
return request.targetVersion;
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> loadFilesOnLoaders(Reference<ControllerBatchData> batchData,
|
|
|
|
Reference<ControllerBatchStatus> batchStatus,
|
2020-01-16 08:20:55 +08:00
|
|
|
std::map<UID, RestoreLoaderInterface> loadersInterf, int batchIndex,
|
|
|
|
Database cx, RestoreRequest request, VersionBatch versionBatch,
|
|
|
|
bool isRangeFile) {
|
2020-01-22 14:10:08 +08:00
|
|
|
// set is internally sorted
|
2020-02-18 06:36:09 +08:00
|
|
|
std::set<RestoreFileFR>* files = isRangeFile ? &versionBatch.rangeFiles : &versionBatch.logFiles;
|
2019-05-31 07:38:08 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseLoadFilesStart")
|
2020-06-19 01:35:41 +08:00
|
|
|
.detail("RestoreRequestID", request.randomUid)
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("FileTypeLoadedInVersionBatch", isRangeFile)
|
|
|
|
.detail("BeginVersion", versionBatch.beginVersion)
|
|
|
|
.detail("EndVersion", versionBatch.endVersion)
|
|
|
|
.detail("Files", (files != nullptr ? files->size() : -1));
|
|
|
|
|
2019-05-31 07:38:08 +08:00
|
|
|
std::vector<std::pair<UID, RestoreLoadFileRequest>> requests;
|
2020-01-16 08:20:55 +08:00
|
|
|
std::map<UID, RestoreLoaderInterface>::iterator loader = loadersInterf.begin();
|
2020-01-22 06:49:13 +08:00
|
|
|
state std::vector<RestoreAsset> assets; // all assets loaded, used for sanity check restore progress
|
2019-06-01 02:09:31 +08:00
|
|
|
|
2020-01-24 15:21:06 +08:00
|
|
|
// Balance workload on loaders for parsing range and log files across version batches
|
|
|
|
int random = deterministicRandom()->randomInt(0, loadersInterf.size());
|
|
|
|
while (random-- > 0) {
|
|
|
|
loader++;
|
|
|
|
}
|
|
|
|
|
2020-01-22 13:25:36 +08:00
|
|
|
int paramIdx = 0;
|
2019-08-02 08:00:13 +08:00
|
|
|
for (auto& file : *files) {
|
2020-04-08 06:56:44 +08:00
|
|
|
// TODO: Allow empty files in version batch; Filter out them here.
|
2020-01-16 08:20:55 +08:00
|
|
|
if (loader == loadersInterf.end()) {
|
|
|
|
loader = loadersInterf.begin();
|
2019-05-31 07:38:08 +08:00
|
|
|
}
|
|
|
|
// Prepare loading
|
|
|
|
LoadingParam param;
|
2019-10-17 02:31:30 +08:00
|
|
|
param.url = request.url;
|
2019-05-31 07:38:08 +08:00
|
|
|
param.isRangeFile = file.isRange;
|
2020-01-07 12:32:26 +08:00
|
|
|
param.rangeVersion = file.isRange ? file.version : -1;
|
2019-05-31 07:38:08 +08:00
|
|
|
param.blockSize = file.blockSize;
|
2019-12-20 08:50:39 +08:00
|
|
|
|
2020-01-08 04:46:51 +08:00
|
|
|
param.asset.uid = deterministicRandom()->randomUniqueID();
|
2019-12-20 08:50:39 +08:00
|
|
|
param.asset.filename = file.fileName;
|
|
|
|
param.asset.fileIndex = file.fileIndex;
|
2020-02-18 06:36:09 +08:00
|
|
|
param.asset.partitionId = file.partitionId;
|
2019-12-20 08:50:39 +08:00
|
|
|
param.asset.offset = 0;
|
|
|
|
param.asset.len = file.fileSize;
|
|
|
|
param.asset.range = request.range;
|
|
|
|
param.asset.beginVersion = versionBatch.beginVersion;
|
2020-03-11 10:42:36 +08:00
|
|
|
param.asset.endVersion = (isRangeFile || request.targetVersion == -1)
|
|
|
|
? versionBatch.endVersion
|
|
|
|
: std::min(versionBatch.endVersion, request.targetVersion + 1);
|
2020-06-19 01:35:41 +08:00
|
|
|
param.asset.addPrefix = request.addPrefix;
|
|
|
|
param.asset.removePrefix = request.removePrefix;
|
2020-09-07 13:39:58 +08:00
|
|
|
param.asset.batchIndex = batchIndex;
|
2019-12-20 08:50:39 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseLoadFiles")
|
2020-01-28 10:13:20 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("LoadParamIndex", paramIdx)
|
|
|
|
.detail("LoaderID", loader->first.toString())
|
|
|
|
.detail("LoadParam", param.toString());
|
2020-01-09 01:42:08 +08:00
|
|
|
ASSERT_WE_THINK(param.asset.len > 0);
|
2019-12-20 08:50:39 +08:00
|
|
|
ASSERT_WE_THINK(param.asset.offset >= 0);
|
|
|
|
ASSERT_WE_THINK(param.asset.offset <= file.fileSize);
|
2020-01-08 04:46:51 +08:00
|
|
|
ASSERT_WE_THINK(param.asset.beginVersion <= param.asset.endVersion);
|
2019-05-31 07:38:08 +08:00
|
|
|
|
2020-01-16 08:20:55 +08:00
|
|
|
requests.emplace_back(loader->first, RestoreLoadFileRequest(batchIndex, param));
|
2020-01-22 06:49:13 +08:00
|
|
|
// Restore asset should only be loaded exactly once.
|
2020-01-22 13:25:36 +08:00
|
|
|
if (batchStatus->raStatus.find(param.asset) != batchStatus->raStatus.end()) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerPhaseLoadFiles")
|
2020-01-22 06:49:13 +08:00
|
|
|
.detail("LoadingParam", param.toString())
|
2020-01-22 13:25:36 +08:00
|
|
|
.detail("RestoreAssetAlreadyProcessed", batchStatus->raStatus[param.asset]);
|
2020-01-22 06:49:13 +08:00
|
|
|
}
|
|
|
|
batchStatus->raStatus[param.asset] = RestoreAssetStatus::Loading;
|
|
|
|
assets.push_back(param.asset);
|
2020-01-28 10:13:14 +08:00
|
|
|
++loader;
|
2020-01-22 13:25:36 +08:00
|
|
|
++paramIdx;
|
2019-05-31 07:38:08 +08:00
|
|
|
}
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(files->size() != paramIdx ? SevError : SevInfo, "FastRestoreControllerPhaseLoadFiles")
|
2020-05-06 10:29:53 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2020-01-28 10:13:20 +08:00
|
|
|
.detail("Files", files->size())
|
|
|
|
.detail("LoadParams", paramIdx);
|
2019-05-31 07:38:08 +08:00
|
|
|
|
2019-12-03 06:33:31 +08:00
|
|
|
state std::vector<RestoreLoadFileReply> replies;
|
2019-05-31 07:38:08 +08:00
|
|
|
// Wait on the batch of load files or log files
|
2020-02-11 12:26:56 +08:00
|
|
|
wait(getBatchReplies(&RestoreLoaderInterface::loadFile, loadersInterf, requests, &replies,
|
|
|
|
TaskPriority::RestoreLoaderLoadFiles));
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseLoadFilesReply")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("SamplingReplies", replies.size());
|
2019-12-03 06:33:31 +08:00
|
|
|
for (auto& reply : replies) {
|
2020-01-22 06:49:13 +08:00
|
|
|
// Update and sanity check restore asset's status
|
|
|
|
RestoreAssetStatus status = batchStatus->raStatus[reply.param.asset];
|
|
|
|
if (status == RestoreAssetStatus::Loading && !reply.isDuplicated) {
|
|
|
|
batchStatus->raStatus[reply.param.asset] = RestoreAssetStatus::Loaded;
|
|
|
|
} else if (status == RestoreAssetStatus::Loading && reply.isDuplicated) {
|
|
|
|
// Duplicate request wait on the restore asset to be processed before it replies
|
|
|
|
batchStatus->raStatus[reply.param.asset] = RestoreAssetStatus::Loaded;
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevWarn, "FastRestoreControllerPhaseLoadFilesReply")
|
2020-01-22 06:49:13 +08:00
|
|
|
.detail("RestoreAsset", reply.param.asset.toString())
|
|
|
|
.detail("DuplicateRequestArriveEarly", "RestoreAsset should have been processed");
|
|
|
|
} else if (status == RestoreAssetStatus::Loaded && reply.isDuplicated) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevDebug, "FastRestoreControllerPhaseLoadFilesReply")
|
2020-01-22 06:49:13 +08:00
|
|
|
.detail("RestoreAsset", reply.param.asset.toString())
|
|
|
|
.detail("RequestIgnored", "Loading request was sent more than once");
|
|
|
|
} else {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerPhaseLoadFilesReply")
|
2020-01-22 06:49:13 +08:00
|
|
|
.detail("RestoreAsset", reply.param.asset.toString())
|
|
|
|
.detail("UnexpectedReply", reply.toString());
|
|
|
|
}
|
2019-12-03 06:33:31 +08:00
|
|
|
}
|
2019-05-31 07:38:08 +08:00
|
|
|
|
2020-01-22 06:49:13 +08:00
|
|
|
// Sanity check: all restore assets status should be Loaded
|
|
|
|
for (auto& asset : assets) {
|
|
|
|
if (batchStatus->raStatus[asset] != RestoreAssetStatus::Loaded) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerPhaseLoadFilesReply")
|
2020-01-22 06:49:13 +08:00
|
|
|
.detail("RestoreAsset", asset.toString())
|
|
|
|
.detail("UnexpectedStatus", batchStatus->raStatus[asset]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseLoadFilesDone")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("FileTypeLoadedInVersionBatch", isRangeFile)
|
|
|
|
.detail("BeginVersion", versionBatch.beginVersion)
|
2020-02-10 11:19:32 +08:00
|
|
|
.detail("EndVersion", versionBatch.endVersion);
|
2019-05-31 07:38:08 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2019-11-13 08:28:09 +08:00
|
|
|
// Ask loaders to send its buffered mutations to appliers
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> sendMutationsFromLoaders(Reference<ControllerBatchData> batchData,
|
|
|
|
Reference<ControllerBatchStatus> batchStatus,
|
2020-01-16 08:20:55 +08:00
|
|
|
std::map<UID, RestoreLoaderInterface> loadersInterf, int batchIndex,
|
|
|
|
bool useRangeFile) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseSendMutationsFromLoadersStart")
|
2020-01-24 06:40:08 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("UseRangeFiles", useRangeFile)
|
|
|
|
.detail("Loaders", loadersInterf.size());
|
2019-11-13 08:28:09 +08:00
|
|
|
|
|
|
|
std::vector<std::pair<UID, RestoreSendMutationsToAppliersRequest>> requests;
|
2020-01-16 08:20:55 +08:00
|
|
|
for (auto& loader : loadersInterf) {
|
2020-01-15 06:18:41 +08:00
|
|
|
requests.emplace_back(
|
2020-01-16 08:20:55 +08:00
|
|
|
loader.first, RestoreSendMutationsToAppliersRequest(batchIndex, batchData->rangeToApplier, useRangeFile));
|
2020-01-22 06:49:13 +08:00
|
|
|
batchStatus->loadStatus[loader.first] =
|
|
|
|
useRangeFile ? RestoreSendStatus::SendingRanges : RestoreSendStatus::SendingLogs;
|
|
|
|
}
|
|
|
|
state std::vector<RestoreCommonReply> replies;
|
2020-02-11 12:26:56 +08:00
|
|
|
wait(getBatchReplies(&RestoreLoaderInterface::sendMutations, loadersInterf, requests, &replies,
|
|
|
|
TaskPriority::RestoreLoaderSendMutations));
|
2020-01-22 06:49:13 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseSendMutationsFromLoadersDone")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("UseRangeFiles", useRangeFile)
|
|
|
|
.detail("Loaders", loadersInterf.size());
|
|
|
|
|
2019-11-13 08:28:09 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-01-16 08:20:55 +08:00
|
|
|
// Process a version batch. Phases (loading files, send mutations) should execute in order
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> distributeWorkloadPerVersionBatch(Reference<RestoreControllerData> self, int batchIndex,
|
2020-01-16 08:20:55 +08:00
|
|
|
Database cx, RestoreRequest request,
|
|
|
|
VersionBatch versionBatch) {
|
2020-07-17 06:30:27 +08:00
|
|
|
state Reference<ControllerBatchData> batchData = self->batch[batchIndex];
|
|
|
|
state Reference<ControllerBatchStatus> batchStatus = self->batchStatus[batchIndex];
|
2020-05-02 04:30:45 +08:00
|
|
|
state double startTime = now();
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerDispatchVersionBatchesStart", self->id())
|
2020-05-02 04:30:45 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("BatchSize", versionBatch.size)
|
|
|
|
.detail("RunningVersionBatches", self->runningVersionBatches.get());
|
2020-01-16 08:20:55 +08:00
|
|
|
|
2020-01-29 02:16:44 +08:00
|
|
|
self->runningVersionBatches.set(self->runningVersionBatches.get() + 1);
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
// In case sampling data takes too much memory on controller
|
2020-02-27 06:40:01 +08:00
|
|
|
wait(isSchedulable(self, batchIndex, __FUNCTION__));
|
|
|
|
|
2020-01-16 08:20:55 +08:00
|
|
|
wait(initializeVersionBatch(self->appliersInterf, self->loadersInterf, batchIndex));
|
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
ASSERT(!versionBatch.isEmpty());
|
|
|
|
ASSERT(self->loadersInterf.size() > 0);
|
|
|
|
ASSERT(self->appliersInterf.size() > 0);
|
2019-05-31 07:38:08 +08:00
|
|
|
|
|
|
|
// Parse log files and send mutations to appliers before we parse range files
|
2019-11-13 08:28:09 +08:00
|
|
|
// TODO: Allow loading both range and log files in parallel
|
2020-01-16 09:24:01 +08:00
|
|
|
ASSERT(batchData->samples.empty());
|
|
|
|
ASSERT(batchData->samplesSize < 1 && batchData->samplesSize > -1); // samplesSize should be 0
|
2020-01-22 06:49:13 +08:00
|
|
|
ASSERT(batchStatus->raStatus.empty());
|
|
|
|
ASSERT(batchStatus->loadStatus.empty());
|
|
|
|
ASSERT(batchStatus->applyStatus.empty());
|
2020-01-16 09:24:01 +08:00
|
|
|
|
2020-03-27 04:17:44 +08:00
|
|
|
// New backup has subversion to order mutations at the same version. For mutations at the same version,
|
|
|
|
// range file's mutations have the largest subversion and larger than log file's.
|
|
|
|
// SOMEDAY: Extend subversion to old-style backup.
|
2020-03-28 07:55:52 +08:00
|
|
|
wait(
|
|
|
|
loadFilesOnLoaders(batchData, batchStatus, self->loadersInterf, batchIndex, cx, request, versionBatch, false) &&
|
|
|
|
loadFilesOnLoaders(batchData, batchStatus, self->loadersInterf, batchIndex, cx, request, versionBatch, true));
|
2019-08-02 08:00:13 +08:00
|
|
|
|
2020-01-16 09:24:01 +08:00
|
|
|
ASSERT(batchData->rangeToApplier.empty());
|
2020-01-16 08:20:55 +08:00
|
|
|
splitKeyRangeForAppliers(batchData, self->appliersInterf, batchIndex);
|
2019-12-03 06:33:31 +08:00
|
|
|
|
2020-03-28 07:54:17 +08:00
|
|
|
// Ask loaders to send parsed mutations to appliers;
|
|
|
|
// log mutations should be applied before range mutations at the same version, which is ensured by LogMessageVersion
|
|
|
|
wait(sendMutationsFromLoaders(batchData, batchStatus, self->loadersInterf, batchIndex, false) &&
|
2020-03-28 07:55:52 +08:00
|
|
|
sendMutationsFromLoaders(batchData, batchStatus, self->loadersInterf, batchIndex, true));
|
2019-11-13 08:28:09 +08:00
|
|
|
|
2020-02-29 03:22:53 +08:00
|
|
|
// Synchronization point for version batch pipelining.
|
|
|
|
// self->finishedBatch will continuously increase by 1 per version batch.
|
2020-01-24 08:24:12 +08:00
|
|
|
wait(notifyApplierToApplyMutations(batchData, batchStatus, self->appliersInterf, batchIndex, &self->finishedBatch));
|
2019-05-31 07:38:08 +08:00
|
|
|
|
2020-02-27 05:43:30 +08:00
|
|
|
wait(notifyLoadersVersionBatchFinished(self->loadersInterf, batchIndex));
|
|
|
|
|
2020-01-29 02:16:44 +08:00
|
|
|
self->runningVersionBatches.set(self->runningVersionBatches.get() - 1);
|
2020-02-27 06:40:01 +08:00
|
|
|
|
|
|
|
if (self->delayedActors > 0) {
|
|
|
|
self->checkMemory.trigger();
|
|
|
|
}
|
2020-05-02 04:30:45 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerDispatchVersionBatchesDone", self->id())
|
2020-05-02 04:30:45 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("BatchSize", versionBatch.size)
|
|
|
|
.detail("RunningVersionBatches", self->runningVersionBatches.get())
|
|
|
|
.detail("Latency", now() - startTime);
|
|
|
|
|
2019-05-31 07:38:08 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2019-12-03 06:33:31 +08:00
|
|
|
// Decide which key range should be taken by which applier
|
2020-01-16 08:20:55 +08:00
|
|
|
// Input: samples in batchData
|
|
|
|
// Output: rangeToApplier in batchData
|
2020-07-17 06:30:27 +08:00
|
|
|
void splitKeyRangeForAppliers(Reference<ControllerBatchData> batchData,
|
2020-01-16 08:20:55 +08:00
|
|
|
std::map<UID, RestoreApplierInterface> appliersInterf, int batchIndex) {
|
|
|
|
ASSERT(batchData->samplesSize >= 0);
|
2020-05-05 02:49:36 +08:00
|
|
|
// Sanity check: samples should not be used after freed
|
|
|
|
ASSERT((batchData->samplesSize > 0 && !batchData->samples.empty()) ||
|
2020-08-31 16:23:47 +08:00
|
|
|
(batchData->samplesSize == 0 && batchData->samples.empty()));
|
2020-01-16 08:20:55 +08:00
|
|
|
int numAppliers = appliersInterf.size();
|
|
|
|
double slotSize = std::max(batchData->samplesSize / numAppliers, 1.0);
|
2019-12-03 06:33:31 +08:00
|
|
|
double cumulativeSize = slotSize;
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCalculateApplierKeyRangesStart")
|
2020-01-24 06:40:08 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2020-01-28 12:44:13 +08:00
|
|
|
.detail("SamplingSize", batchData->samplesSize)
|
|
|
|
.detail("SlotSize", slotSize);
|
2020-04-06 06:00:36 +08:00
|
|
|
|
|
|
|
std::set<Key> keyrangeSplitter; // unique key to split key range for appliers
|
|
|
|
keyrangeSplitter.insert(normalKeys.begin); // First slot
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCalculateApplierKeyRanges")
|
2020-04-08 06:57:03 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("CumulativeSize", cumulativeSize)
|
|
|
|
.detail("Slot", 0)
|
|
|
|
.detail("LowerBoundKey", normalKeys.begin);
|
2020-01-28 12:44:13 +08:00
|
|
|
int slotIdx = 1;
|
2020-01-16 08:20:55 +08:00
|
|
|
while (cumulativeSize < batchData->samplesSize) {
|
|
|
|
IndexedSet<Key, int64_t>::iterator lowerBound = batchData->samples.index(cumulativeSize);
|
|
|
|
if (lowerBound == batchData->samples.end()) {
|
2019-12-03 06:33:31 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-01-28 12:04:36 +08:00
|
|
|
keyrangeSplitter.insert(*lowerBound);
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCalculateApplierKeyRanges")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2019-12-04 13:27:06 +08:00
|
|
|
.detail("CumulativeSize", cumulativeSize)
|
2020-02-13 03:20:18 +08:00
|
|
|
.detail("Slot", slotIdx++)
|
|
|
|
.detail("LowerBoundKey", lowerBound->toString());
|
2019-12-03 06:33:31 +08:00
|
|
|
cumulativeSize += slotSize;
|
|
|
|
}
|
|
|
|
if (keyrangeSplitter.size() < numAppliers) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevWarnAlways, "FastRestoreControllerPhaseCalculateApplierKeyRanges")
|
2019-12-04 13:27:06 +08:00
|
|
|
.detail("NotAllAppliersAreUsed", keyrangeSplitter.size())
|
|
|
|
.detail("NumAppliers", numAppliers);
|
2019-12-03 06:33:31 +08:00
|
|
|
} else if (keyrangeSplitter.size() > numAppliers) {
|
2020-01-28 12:44:13 +08:00
|
|
|
bool expected = (keyrangeSplitter.size() == numAppliers + 1);
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(expected ? SevWarn : SevError, "FastRestoreControllerPhaseCalculateApplierKeyRanges")
|
2019-12-04 13:27:06 +08:00
|
|
|
.detail("TooManySlotsThanAppliers", keyrangeSplitter.size())
|
2020-01-28 12:04:36 +08:00
|
|
|
.detail("NumAppliers", numAppliers)
|
2020-01-28 12:44:13 +08:00
|
|
|
.detail("SamplingSize", batchData->samplesSize)
|
|
|
|
.detail("PerformanceMayDegrade", "Last applier handles more data than others");
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2020-01-28 12:04:36 +08:00
|
|
|
|
|
|
|
std::set<Key>::iterator splitter = keyrangeSplitter.begin();
|
2020-01-16 08:20:55 +08:00
|
|
|
batchData->rangeToApplier.clear();
|
|
|
|
for (auto& applier : appliersInterf) {
|
2020-01-28 12:04:36 +08:00
|
|
|
if (splitter == keyrangeSplitter.end()) {
|
2019-12-03 06:33:31 +08:00
|
|
|
break; // Not all appliers will be used
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2020-01-28 12:04:36 +08:00
|
|
|
batchData->rangeToApplier[*splitter] = applier.first;
|
|
|
|
splitter++;
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2020-01-16 08:20:55 +08:00
|
|
|
ASSERT(batchData->rangeToApplier.size() > 0);
|
|
|
|
ASSERT(batchData->sanityCheckApplierKeyRange());
|
2020-02-09 14:10:57 +08:00
|
|
|
batchData->logApplierKeyRange(batchIndex);
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCalculateApplierKeyRangesDone")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("SamplingSize", batchData->samplesSize)
|
|
|
|
.detail("SlotSize", slotSize);
|
2020-05-05 02:49:36 +08:00
|
|
|
batchData->samples.clear();
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
|
|
|
|
2020-06-22 14:53:41 +08:00
|
|
|
ACTOR static Future<std::vector<RestoreRequest>> collectRestoreRequests(Database cx) {
|
|
|
|
state std::vector<RestoreRequest> restoreRequests;
|
2019-05-10 11:55:44 +08:00
|
|
|
state Future<Void> watch4RestoreRequest;
|
2019-12-11 14:55:40 +08:00
|
|
|
state ReadYourWritesTransaction tr(cx);
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-05-13 07:38:43 +08:00
|
|
|
// restoreRequestTriggerKey should already been set
|
2019-08-02 08:00:13 +08:00
|
|
|
loop {
|
2019-05-10 11:55:44 +08:00
|
|
|
try {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCollectRestoreRequestsWait");
|
2019-05-10 11:55:44 +08:00
|
|
|
tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
2020-05-13 07:38:43 +08:00
|
|
|
|
|
|
|
// Sanity check
|
2019-09-04 06:50:21 +08:00
|
|
|
Optional<Value> numRequests = wait(tr.get(restoreRequestTriggerKey));
|
2020-05-13 07:38:43 +08:00
|
|
|
ASSERT(numRequests.present());
|
|
|
|
|
|
|
|
Standalone<RangeResultRef> restoreRequestValues =
|
|
|
|
wait(tr.getRange(restoreRequestKeys, CLIENT_KNOBS->TOO_MANY));
|
|
|
|
ASSERT(!restoreRequestValues.more);
|
|
|
|
if (restoreRequestValues.size()) {
|
|
|
|
for (auto& it : restoreRequestValues) {
|
2020-06-22 14:53:41 +08:00
|
|
|
restoreRequests.push_back(decodeRestoreRequestValue(it.value));
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCollectRestoreRequests")
|
2020-05-13 07:38:43 +08:00
|
|
|
.detail("RestoreRequest", restoreRequests.back().toString());
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2019-05-23 04:20:55 +08:00
|
|
|
break;
|
2020-05-13 07:38:43 +08:00
|
|
|
} else {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerPhaseCollectRestoreRequestsEmptyRequests");
|
2020-05-13 07:38:43 +08:00
|
|
|
wait(delay(5.0));
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
} catch (Error& e) {
|
2019-05-10 11:55:44 +08:00
|
|
|
wait(tr.onError(e));
|
|
|
|
}
|
2019-05-23 04:20:55 +08:00
|
|
|
}
|
2019-05-23 04:30:33 +08:00
|
|
|
|
2019-05-10 11:55:44 +08:00
|
|
|
return restoreRequests;
|
|
|
|
}
|
|
|
|
|
2019-07-25 07:59:05 +08:00
|
|
|
// Collect the backup files' description into output_files by reading the backupContainer bc.
|
2020-03-19 06:38:06 +08:00
|
|
|
// Returns the restore target version.
|
|
|
|
ACTOR static Future<Version> collectBackupFiles(Reference<IBackupContainer> bc, std::vector<RestoreFileFR>* rangeFiles,
|
2020-04-18 00:30:36 +08:00
|
|
|
std::vector<RestoreFileFR>* logFiles, Version* minRangeVersion,
|
|
|
|
Database cx, RestoreRequest request) {
|
2020-04-09 06:50:21 +08:00
|
|
|
state BackupDescription desc = wait(bc->describeBackup());
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2019-09-04 06:50:21 +08:00
|
|
|
// Convert version to real time for operators to read the BackupDescription desc.
|
2019-05-10 11:55:44 +08:00
|
|
|
wait(desc.resolveVersionTimes(cx));
|
|
|
|
|
2020-01-06 09:54:44 +08:00
|
|
|
if (request.targetVersion == invalidVersion && desc.maxRestorableVersion.present()) {
|
2019-06-01 02:09:31 +08:00
|
|
|
request.targetVersion = desc.maxRestorableVersion.get();
|
2020-01-06 09:54:44 +08:00
|
|
|
}
|
2020-03-13 05:38:40 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCollectBackupFilesStart")
|
2020-03-22 04:44:02 +08:00
|
|
|
.detail("TargetVersion", request.targetVersion)
|
2020-08-01 01:40:29 +08:00
|
|
|
.detail("BackupDesc", desc.toString())
|
|
|
|
.detail("UseRangeFile", SERVER_KNOBS->FASTRESTORE_USE_RANGE_FILE)
|
|
|
|
.detail("UseLogFile", SERVER_KNOBS->FASTRESTORE_USE_LOG_FILE);
|
2020-03-13 05:38:40 +08:00
|
|
|
if (g_network->isSimulated()) {
|
|
|
|
std::cout << "Restore to version: " << request.targetVersion << "\nBackupDesc: \n" << desc.toString() << "\n\n";
|
|
|
|
}
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-09-18 08:56:36 +08:00
|
|
|
state VectorRef<KeyRangeRef> restoreRanges;
|
|
|
|
restoreRanges.add(request.range);
|
2020-09-16 00:38:40 +08:00
|
|
|
Optional<RestorableFileSet> restorable = wait(bc->getRestoreSet(request.targetVersion, restoreRanges));
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
if (!restorable.present()) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevWarn, "FastRestoreControllerPhaseCollectBackupFiles")
|
|
|
|
.detail("NotRestorable", request.targetVersion);
|
2019-05-10 11:55:44 +08:00
|
|
|
throw restore_missing_data();
|
|
|
|
}
|
|
|
|
|
2020-01-09 01:42:08 +08:00
|
|
|
ASSERT(rangeFiles->empty());
|
|
|
|
ASSERT(logFiles->empty());
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-01-22 13:53:06 +08:00
|
|
|
std::set<RestoreFileFR> uniqueRangeFiles;
|
|
|
|
std::set<RestoreFileFR> uniqueLogFiles;
|
2020-07-26 10:12:25 +08:00
|
|
|
double rangeSize = 0;
|
|
|
|
double logSize = 0;
|
2020-04-18 00:30:36 +08:00
|
|
|
*minRangeVersion = MAX_VERSION;
|
2020-08-01 01:40:29 +08:00
|
|
|
if (SERVER_KNOBS->FASTRESTORE_USE_RANGE_FILE) {
|
|
|
|
for (const RangeFile& f : restorable.get().ranges) {
|
|
|
|
TraceEvent(SevFRDebugInfo, "FastRestoreControllerPhaseCollectBackupFiles")
|
|
|
|
.detail("RangeFile", f.toString());
|
|
|
|
if (f.fileSize <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RestoreFileFR file(f);
|
|
|
|
TraceEvent(SevFRDebugInfo, "FastRestoreControllerPhaseCollectBackupFiles")
|
|
|
|
.detail("RangeFileFR", file.toString());
|
|
|
|
uniqueRangeFiles.insert(file);
|
|
|
|
rangeSize += file.fileSize;
|
|
|
|
*minRangeVersion = std::min(*minRangeVersion, file.version);
|
2020-01-06 09:54:44 +08:00
|
|
|
}
|
2020-08-01 01:40:29 +08:00
|
|
|
}
|
2020-08-01 14:23:12 +08:00
|
|
|
if (MAX_VERSION == *minRangeVersion) {
|
|
|
|
*minRangeVersion = 0; // If no range file, range version must be 0 so that we apply all mutations
|
|
|
|
}
|
2020-08-01 01:40:29 +08:00
|
|
|
|
|
|
|
if (SERVER_KNOBS->FASTRESTORE_USE_LOG_FILE) {
|
|
|
|
for (const LogFile& f : restorable.get().logs) {
|
|
|
|
TraceEvent(SevFRDebugInfo, "FastRestoreControllerPhaseCollectBackupFiles").detail("LogFile", f.toString());
|
|
|
|
if (f.fileSize <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RestoreFileFR file(f);
|
|
|
|
TraceEvent(SevFRDebugInfo, "FastRestoreControllerPhaseCollectBackupFiles")
|
|
|
|
.detail("LogFileFR", file.toString());
|
|
|
|
logFiles->push_back(file);
|
|
|
|
uniqueLogFiles.insert(file);
|
|
|
|
logSize += file.fileSize;
|
2020-01-06 09:54:44 +08:00
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
}
|
2020-08-01 01:40:29 +08:00
|
|
|
|
2020-01-22 13:53:06 +08:00
|
|
|
// Assign unique range files and log files to output
|
|
|
|
rangeFiles->assign(uniqueRangeFiles.begin(), uniqueRangeFiles.end());
|
|
|
|
logFiles->assign(uniqueLogFiles.begin(), uniqueLogFiles.end());
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseCollectBackupFilesDone")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BackupDesc", desc.toString())
|
2020-02-10 11:19:32 +08:00
|
|
|
.detail("RangeFiles", rangeFiles->size())
|
2020-07-26 10:12:25 +08:00
|
|
|
.detail("LogFiles", logFiles->size())
|
|
|
|
.detail("RangeFileBytes", rangeSize)
|
2020-08-01 01:40:29 +08:00
|
|
|
.detail("LogFileBytes", logSize)
|
|
|
|
.detail("UseRangeFile", SERVER_KNOBS->FASTRESTORE_USE_RANGE_FILE)
|
|
|
|
.detail("UseLogFile", SERVER_KNOBS->FASTRESTORE_USE_LOG_FILE);
|
2020-03-19 06:38:06 +08:00
|
|
|
return request.targetVersion;
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
|
|
|
|
2020-04-18 01:02:53 +08:00
|
|
|
// By the first and last block of *file to get (beginKey, endKey);
|
|
|
|
// set (beginKey, endKey) and file->version to pRangeVersions
|
2020-04-16 04:32:52 +08:00
|
|
|
ACTOR static Future<Void> insertRangeVersion(KeyRangeMap<Version>* pRangeVersions, RestoreFileFR* file,
|
|
|
|
Reference<IBackupContainer> bc) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerDecodeRangeVersion").detail("File", file->toString());
|
2020-04-28 02:18:04 +08:00
|
|
|
RangeFile rangeFile = { file->version, (uint32_t)file->blockSize, file->fileName, file->fileSize };
|
2020-04-16 04:32:52 +08:00
|
|
|
|
|
|
|
// First and last key are the range for this file: endKey is exclusive
|
2020-04-22 02:38:45 +08:00
|
|
|
KeyRange fileRange = wait(bc->getSnapshotFileKeyRange(rangeFile));
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerInsertRangeVersion")
|
2020-04-16 04:32:52 +08:00
|
|
|
.detail("DecodedRangeFile", file->fileName)
|
|
|
|
.detail("KeyRange", fileRange)
|
2020-04-18 00:30:36 +08:00
|
|
|
.detail("Version", file->version);
|
2020-04-16 04:32:52 +08:00
|
|
|
// Update version for pRangeVersions's ranges in fileRange
|
|
|
|
auto ranges = pRangeVersions->modify(fileRange);
|
|
|
|
for (auto r = ranges.begin(); r != ranges.end(); ++r) {
|
2020-04-18 06:00:07 +08:00
|
|
|
r->value() = std::max(r->value(), file->version);
|
2020-04-16 04:32:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dump the new key ranges
|
|
|
|
ranges = pRangeVersions->ranges();
|
|
|
|
int i = 0;
|
|
|
|
for (auto r = ranges.begin(); r != ranges.end(); ++r) {
|
|
|
|
TraceEvent(SevDebug, "RangeVersionsAfterUpdate")
|
|
|
|
.detail("File", file->toString())
|
|
|
|
.detail("FileRange", fileRange.toString())
|
|
|
|
.detail("FileVersion", file->version)
|
|
|
|
.detail("RangeIndex", i++)
|
|
|
|
.detail("RangeBegin", r->begin())
|
|
|
|
.detail("RangeEnd", r->end())
|
|
|
|
.detail("RangeVersion", r->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-04-18 01:02:53 +08:00
|
|
|
// Build the version skyline of snapshot ranges by parsing range files;
|
|
|
|
// Expensive and slow operation that should not run in real prod.
|
2020-04-16 04:32:52 +08:00
|
|
|
ACTOR static Future<Void> buildRangeVersions(KeyRangeMap<Version>* pRangeVersions,
|
|
|
|
std::vector<RestoreFileFR>* pRangeFiles, Key url) {
|
2020-04-18 01:02:53 +08:00
|
|
|
if (!g_network->isSimulated()) {
|
|
|
|
TraceEvent(SevError, "ExpensiveBuildRangeVersions")
|
|
|
|
.detail("Reason", "Parsing all range files is slow and memory intensive");
|
|
|
|
return Void();
|
|
|
|
}
|
2020-04-16 04:32:52 +08:00
|
|
|
Reference<IBackupContainer> bc = IBackupContainer::openContainer(url.toString());
|
|
|
|
|
|
|
|
// Key ranges not in range files are empty;
|
|
|
|
// Assign highest version to avoid applying any mutation in these ranges
|
|
|
|
state int fileIndex = 0;
|
|
|
|
state std::vector<Future<Void>> fInsertRangeVersions;
|
|
|
|
for (; fileIndex < pRangeFiles->size(); ++fileIndex) {
|
|
|
|
fInsertRangeVersions.push_back(insertRangeVersion(pRangeVersions, &pRangeFiles->at(fileIndex), bc));
|
|
|
|
}
|
|
|
|
|
|
|
|
wait(waitForAll(fInsertRangeVersions));
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2019-09-04 06:50:21 +08:00
|
|
|
ACTOR static Future<Void> clearDB(Database cx) {
|
2019-08-02 08:00:13 +08:00
|
|
|
wait(runRYWTransaction(cx, [](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
tr->clear(normalKeys);
|
|
|
|
return Void();
|
|
|
|
}));
|
2019-05-10 11:55:44 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-01-16 08:20:55 +08:00
|
|
|
ACTOR static Future<Void> initializeVersionBatch(std::map<UID, RestoreApplierInterface> appliersInterf,
|
|
|
|
std::map<UID, RestoreLoaderInterface> loadersInterf, int batchIndex) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseInitVersionBatchForAppliersStart")
|
2020-01-24 06:40:08 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("Appliers", appliersInterf.size());
|
2019-09-04 06:50:21 +08:00
|
|
|
std::vector<std::pair<UID, RestoreVersionBatchRequest>> requestsToAppliers;
|
2020-01-16 08:20:55 +08:00
|
|
|
for (auto& applier : appliersInterf) {
|
2020-01-22 13:25:36 +08:00
|
|
|
requestsToAppliers.emplace_back(applier.first, RestoreVersionBatchRequest(batchIndex));
|
2019-05-21 08:52:40 +08:00
|
|
|
}
|
2020-02-22 07:39:13 +08:00
|
|
|
wait(sendBatchRequests(&RestoreApplierInterface::initVersionBatch, appliersInterf, requestsToAppliers));
|
2019-05-21 08:52:40 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseInitVersionBatchForLoaders")
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("Loaders", loadersInterf.size());
|
2019-09-04 06:50:21 +08:00
|
|
|
std::vector<std::pair<UID, RestoreVersionBatchRequest>> requestsToLoaders;
|
2020-01-16 08:20:55 +08:00
|
|
|
for (auto& loader : loadersInterf) {
|
2020-01-22 13:25:36 +08:00
|
|
|
requestsToLoaders.emplace_back(loader.first, RestoreVersionBatchRequest(batchIndex));
|
2019-05-21 08:52:40 +08:00
|
|
|
}
|
2020-02-22 07:39:13 +08:00
|
|
|
wait(sendBatchRequests(&RestoreLoaderInterface::initVersionBatch, loadersInterf, requestsToLoaders));
|
2019-12-04 08:55:23 +08:00
|
|
|
|
2020-08-01 01:40:29 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseInitVersionBatchForAppliersDone").detail("BatchIndex", batchIndex);
|
2019-05-10 11:55:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-09-22 23:14:23 +08:00
|
|
|
// Calculate the amount of data each applier should keep outstanding to DB;
|
|
|
|
// This is the amount of data that are in in-progress transactions.
|
|
|
|
ACTOR static Future<Void> updateApplierWriteBW(Reference<ControllerBatchData> batchData,
|
|
|
|
std::map<UID, RestoreApplierInterface> appliersInterf, int batchIndex) {
|
|
|
|
state std::map<UID, double> applierRemainMB;
|
|
|
|
state double totalRemainMB = SERVER_KNOBS->FASTRESTORE_WRITE_BW_MB;
|
|
|
|
state double standardAvgBW = SERVER_KNOBS->FASTRESTORE_WRITE_BW_MB / SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS;
|
|
|
|
state int loopCount = 0;
|
|
|
|
state std::vector<RestoreUpdateRateReply> replies;
|
|
|
|
state std::vector<std::pair<UID, RestoreUpdateRateRequest>> requests;
|
|
|
|
for (auto& applier : appliersInterf) {
|
|
|
|
applierRemainMB[applier.first] = SERVER_KNOBS->FASTRESTORE_WRITE_BW_MB / SERVER_KNOBS->FASTRESTORE_NUM_APPLIERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
loop {
|
|
|
|
requests.clear();
|
|
|
|
for (auto& applier : appliersInterf) {
|
|
|
|
double writeRate = totalRemainMB > 1 ? (applierRemainMB[applier.first] / totalRemainMB) *
|
|
|
|
SERVER_KNOBS->FASTRESTORE_WRITE_BW_MB
|
|
|
|
: standardAvgBW;
|
|
|
|
requests.emplace_back(applier.first, RestoreUpdateRateRequest(batchIndex, writeRate));
|
|
|
|
}
|
|
|
|
replies.clear();
|
|
|
|
wait(getBatchReplies(
|
|
|
|
&RestoreApplierInterface::updateRate, appliersInterf, requests, &replies,
|
|
|
|
TaskPriority::DefaultEndpoint)); // DefaultEndpoint has higher priority than fast restore endpoints
|
|
|
|
ASSERT(replies.size() == requests.size());
|
|
|
|
totalRemainMB = 0;
|
|
|
|
for (int i = 0; i < replies.size(); i++) {
|
|
|
|
UID& applierID = requests[i].first;
|
|
|
|
applierRemainMB[applierID] = replies[i].remainMB;
|
|
|
|
totalRemainMB += replies[i].remainMB;
|
|
|
|
}
|
|
|
|
ASSERT(totalRemainMB >= 0);
|
|
|
|
double delayTime = SERVER_KNOBS->FASTRESTORE_RATE_UPDATE_SECONDS;
|
|
|
|
if (loopCount == 0) { // First loop: Need to update writeRate quicker
|
|
|
|
delayTime = 0.2;
|
|
|
|
}
|
|
|
|
loopCount++;
|
|
|
|
wait(delay(delayTime));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 02:09:31 +08:00
|
|
|
// Ask each applier to apply its received mutations to DB
|
2020-07-17 06:30:27 +08:00
|
|
|
// NOTE: Controller cannot start applying mutations at batchIndex until all appliers have applied for (batchIndex - 1)
|
2020-01-24 08:24:12 +08:00
|
|
|
// because appliers at different batchIndex may have overlapped key ranges.
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> notifyApplierToApplyMutations(Reference<ControllerBatchData> batchData,
|
|
|
|
Reference<ControllerBatchStatus> batchStatus,
|
2020-01-22 06:49:13 +08:00
|
|
|
std::map<UID, RestoreApplierInterface> appliersInterf,
|
2020-01-24 08:24:12 +08:00
|
|
|
int batchIndex, NotifiedVersion* finishedBatch) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseApplyToDBStart")
|
2020-01-24 06:40:08 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("FinishedBatch", finishedBatch->get());
|
2020-01-24 08:24:12 +08:00
|
|
|
|
2020-05-02 07:31:51 +08:00
|
|
|
wait(finishedBatch->whenAtLeast(batchIndex - 1));
|
|
|
|
|
2020-09-22 23:14:23 +08:00
|
|
|
state Future<Void> updateRate;
|
|
|
|
|
2020-01-24 08:24:12 +08:00
|
|
|
if (finishedBatch->get() == batchIndex - 1) {
|
|
|
|
// Prepare the applyToDB requests
|
|
|
|
std::vector<std::pair<UID, RestoreVersionBatchRequest>> requests;
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseApplyToDBRunning")
|
2020-01-24 08:24:12 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("Appliers", appliersInterf.size());
|
|
|
|
for (auto& applier : appliersInterf) {
|
|
|
|
ASSERT(batchStatus->applyStatus.find(applier.first) == batchStatus->applyStatus.end());
|
|
|
|
requests.emplace_back(applier.first, RestoreVersionBatchRequest(batchIndex));
|
|
|
|
batchStatus->applyStatus[applier.first] = RestoreApplyStatus::Applying;
|
2020-01-22 06:49:13 +08:00
|
|
|
}
|
2020-01-24 08:24:12 +08:00
|
|
|
state std::vector<RestoreCommonReply> replies;
|
|
|
|
// The actor at each batchIndex should only occur once.
|
|
|
|
// Use batchData->applyToDB just incase the actor at a batchIndex is executed more than once.
|
|
|
|
if (!batchData->applyToDB.present()) {
|
|
|
|
batchData->applyToDB = Never();
|
2020-02-11 12:26:56 +08:00
|
|
|
batchData->applyToDB = getBatchReplies(&RestoreApplierInterface::applyToDB, appliersInterf, requests,
|
|
|
|
&replies, TaskPriority::RestoreApplierWriteDB);
|
2020-09-22 23:14:23 +08:00
|
|
|
updateRate = updateApplierWriteBW(batchData, appliersInterf, batchIndex);
|
2020-01-24 08:24:12 +08:00
|
|
|
} else {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerPhaseApplyToDB")
|
2020-01-24 08:24:12 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
|
|
|
.detail("Attention", "Actor should not be invoked twice for the same batch index");
|
|
|
|
}
|
2020-01-28 10:13:14 +08:00
|
|
|
|
2020-01-24 08:24:12 +08:00
|
|
|
ASSERT(batchData->applyToDB.present());
|
2020-06-06 08:41:03 +08:00
|
|
|
ASSERT(!batchData->applyToDB.get().isError());
|
2020-01-24 08:24:12 +08:00
|
|
|
wait(batchData->applyToDB.get());
|
|
|
|
|
|
|
|
// Sanity check all appliers have applied data to destination DB
|
|
|
|
for (auto& reply : replies) {
|
|
|
|
if (batchStatus->applyStatus[reply.id] == RestoreApplyStatus::Applying) {
|
|
|
|
batchStatus->applyStatus[reply.id] = RestoreApplyStatus::Applied;
|
|
|
|
if (reply.isDuplicated) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevWarn, "FastRestoreControllerPhaseApplyToDB")
|
2020-01-24 08:24:12 +08:00
|
|
|
.detail("Applier", reply.id)
|
|
|
|
.detail("DuplicateRequestReturnEarlier", "Apply db request should have been processed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto& applier : appliersInterf) {
|
|
|
|
if (batchStatus->applyStatus[applier.first] != RestoreApplyStatus::Applied) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent(SevError, "FastRestoreControllerPhaseApplyToDB")
|
2020-01-24 08:24:12 +08:00
|
|
|
.detail("Applier", applier.first)
|
|
|
|
.detail("ApplyStatus", batchStatus->applyStatus[applier.first]);
|
|
|
|
}
|
2020-01-22 06:49:13 +08:00
|
|
|
}
|
2020-01-24 08:24:12 +08:00
|
|
|
finishedBatch->set(batchIndex);
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2020-02-07 11:43:36 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseApplyToDBDone")
|
2020-02-07 11:43:36 +08:00
|
|
|
.detail("BatchIndex", batchIndex)
|
2020-02-09 14:10:57 +08:00
|
|
|
.detail("FinishedBatch", finishedBatch->get());
|
2019-05-10 11:55:44 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-02-27 05:43:30 +08:00
|
|
|
// Notify loaders that all data in the version batch has been applied to DB.
|
|
|
|
ACTOR static Future<Void> notifyLoadersVersionBatchFinished(std::map<UID, RestoreLoaderInterface> loadersInterf,
|
|
|
|
int batchIndex) {
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseNotifyLoadersVersionBatchFinishedStart").detail("BatchIndex", batchIndex);
|
2020-02-27 05:43:30 +08:00
|
|
|
std::vector<std::pair<UID, RestoreVersionBatchRequest>> requestsToLoaders;
|
|
|
|
for (auto& loader : loadersInterf) {
|
|
|
|
requestsToLoaders.emplace_back(loader.first, RestoreVersionBatchRequest(batchIndex));
|
|
|
|
}
|
|
|
|
wait(sendBatchRequests(&RestoreLoaderInterface::finishVersionBatch, loadersInterf, requestsToLoaders));
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseNotifyLoadersVersionBatchFinishedDone").detail("BatchIndex", batchIndex);
|
2020-02-27 05:43:30 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-01-17 08:19:51 +08:00
|
|
|
// Ask all loaders and appliers to perform housecleaning at the end of a restore request
|
|
|
|
// Terminate those roles if terminate = true
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> notifyRestoreCompleted(Reference<RestoreControllerData> self, bool terminate = false) {
|
2020-01-17 08:19:51 +08:00
|
|
|
std::vector<std::pair<UID, RestoreFinishRequest>> requests;
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseNotifyRestoreCompletedStart");
|
2019-08-02 08:00:13 +08:00
|
|
|
for (auto& loader : self->loadersInterf) {
|
2020-01-22 13:25:36 +08:00
|
|
|
requests.emplace_back(loader.first, RestoreFinishRequest(terminate));
|
2019-05-30 06:09:28 +08:00
|
|
|
}
|
2020-01-24 06:40:08 +08:00
|
|
|
|
2019-06-05 13:17:08 +08:00
|
|
|
Future<Void> endLoaders = sendBatchRequests(&RestoreLoaderInterface::finishRestore, self->loadersInterf, requests);
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2019-06-05 13:17:08 +08:00
|
|
|
requests.clear();
|
2019-08-02 08:00:13 +08:00
|
|
|
for (auto& applier : self->appliersInterf) {
|
2020-01-22 13:25:36 +08:00
|
|
|
requests.emplace_back(applier.first, RestoreFinishRequest(terminate));
|
2019-05-10 11:55:44 +08:00
|
|
|
}
|
2020-01-28 10:13:20 +08:00
|
|
|
Future<Void> endAppliers =
|
2019-08-02 08:00:13 +08:00
|
|
|
sendBatchRequests(&RestoreApplierInterface::finishRestore, self->appliersInterf, requests);
|
2020-01-22 14:10:08 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
// If terminate = true, loaders and appliers exits immediately after it receives the request. Controller may not
|
|
|
|
// receive acks.
|
2020-01-22 14:10:08 +08:00
|
|
|
if (!terminate) {
|
|
|
|
wait(endLoaders && endAppliers);
|
|
|
|
}
|
2019-06-05 13:17:08 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerPhaseNotifyRestoreCompletedDone");
|
2020-01-17 08:19:51 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the restoreRequestDoneKey to signal the end of restore
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> signalRestoreCompleted(Reference<RestoreControllerData> self, Database cx) {
|
2020-01-17 08:19:51 +08:00
|
|
|
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
|
|
|
|
|
2020-06-10 06:40:24 +08:00
|
|
|
wait(notifyRestoreCompleted(self, true)); // notify workers the restore has completed
|
2020-01-17 08:19:51 +08:00
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
wait(delay(5.0)); // Give some time for loaders and appliers to exit
|
2019-05-10 11:55:44 +08:00
|
|
|
|
|
|
|
// Notify tester that the restore has finished
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2019-05-30 06:09:28 +08:00
|
|
|
tr->clear(restoreRequestTriggerKey);
|
|
|
|
tr->clear(restoreRequestKeys);
|
|
|
|
Version readVersion = wait(tr->getReadVersion());
|
|
|
|
tr->set(restoreRequestDoneKey, restoreRequestDoneVersionValue(readVersion));
|
2019-08-02 08:00:13 +08:00
|
|
|
wait(tr->commit());
|
2019-05-10 11:55:44 +08:00
|
|
|
break;
|
2019-08-02 08:00:13 +08:00
|
|
|
} catch (Error& e) {
|
2019-05-10 11:55:44 +08:00
|
|
|
wait(tr->onError(e));
|
|
|
|
}
|
2019-05-30 06:09:28 +08:00
|
|
|
}
|
2019-05-10 11:55:44 +08:00
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
TraceEvent("FastRestoreControllerAllRestoreCompleted");
|
2019-05-30 06:09:28 +08:00
|
|
|
|
2019-05-10 11:55:44 +08:00
|
|
|
return Void();
|
2020-02-27 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
2020-07-17 06:30:27 +08:00
|
|
|
// Update the most recent time when controller receives hearbeat from each loader and applier
|
2020-09-23 04:32:26 +08:00
|
|
|
// TODO: Replace the heartbeat mechanism with FDB failure monitoring mechanism
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> updateHeartbeatTime(Reference<RestoreControllerData> self) {
|
2020-08-06 02:32:04 +08:00
|
|
|
wait(self->recruitedRoles.getFuture());
|
|
|
|
|
2020-02-29 12:31:59 +08:00
|
|
|
int numRoles = self->loadersInterf.size() + self->appliersInterf.size();
|
2020-02-27 07:45:21 +08:00
|
|
|
state std::map<UID, RestoreLoaderInterface>::iterator loader = self->loadersInterf.begin();
|
|
|
|
state std::map<UID, RestoreApplierInterface>::iterator applier = self->appliersInterf.begin();
|
2020-02-29 12:31:59 +08:00
|
|
|
state std::vector<Future<RestoreCommonReply>> fReplies(numRoles, Never()); // TODO: Reserve memory for this vector
|
2020-02-27 07:45:21 +08:00
|
|
|
state std::vector<UID> nodes;
|
2020-02-29 12:31:59 +08:00
|
|
|
state int index = 0;
|
2020-03-02 12:39:56 +08:00
|
|
|
state Future<Void> fTimeout = Void();
|
2020-02-29 12:31:59 +08:00
|
|
|
|
|
|
|
// Initialize nodes only once
|
2020-03-02 12:39:56 +08:00
|
|
|
std::transform(self->loadersInterf.begin(), self->loadersInterf.end(), std::back_inserter(nodes),
|
|
|
|
[](const std::pair<UID, RestoreLoaderInterface>& in) { return in.first; });
|
|
|
|
std::transform(self->appliersInterf.begin(), self->appliersInterf.end(), std::back_inserter(nodes),
|
|
|
|
[](const std::pair<UID, RestoreApplierInterface>& in) { return in.first; });
|
2020-02-28 10:46:31 +08:00
|
|
|
|
2020-02-27 07:45:21 +08:00
|
|
|
loop {
|
|
|
|
loader = self->loadersInterf.begin();
|
|
|
|
applier = self->appliersInterf.begin();
|
2020-02-29 12:31:59 +08:00
|
|
|
index = 0;
|
|
|
|
std::fill(fReplies.begin(), fReplies.end(), Never());
|
2020-02-27 07:45:21 +08:00
|
|
|
// ping loaders and appliers
|
|
|
|
while(loader != self->loadersInterf.end()) {
|
2020-02-29 12:31:59 +08:00
|
|
|
fReplies[index] = loader->second.heartbeat.getReply(RestoreSimpleRequest());
|
2020-02-27 07:45:21 +08:00
|
|
|
loader++;
|
2020-02-29 12:31:59 +08:00
|
|
|
index++;
|
2020-02-27 07:45:21 +08:00
|
|
|
}
|
|
|
|
while(applier != self->appliersInterf.end()) {
|
2020-02-29 12:31:59 +08:00
|
|
|
fReplies[index] = applier->second.heartbeat.getReply(RestoreSimpleRequest());
|
2020-02-27 07:45:21 +08:00
|
|
|
applier++;
|
2020-02-29 12:31:59 +08:00
|
|
|
index++;
|
2020-02-27 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
2020-03-02 12:39:56 +08:00
|
|
|
fTimeout = delay(SERVER_KNOBS->FASTRESTORE_HEARTBEAT_DELAY);
|
2020-09-23 04:32:26 +08:00
|
|
|
|
|
|
|
// Here we have to handle error, otherwise controller worker will fail and exit.
|
|
|
|
try {
|
|
|
|
wait(waitForAll(fReplies) || fTimeout);
|
|
|
|
} catch (Error& e) {
|
|
|
|
// This should be an ignorable error.
|
|
|
|
TraceEvent(g_network->isSimulated() ? SevWarnAlways : SevError, "FastRestoreUpdateHeartbeatError").error(e);
|
|
|
|
}
|
|
|
|
|
2020-02-27 07:45:21 +08:00
|
|
|
// Update the most recent heart beat time for each role
|
|
|
|
for (int i = 0; i < fReplies.size(); ++i) {
|
2020-09-23 06:41:07 +08:00
|
|
|
if (!fReplies[i].isError() && fReplies[i].isReady()) {
|
2020-02-27 07:45:21 +08:00
|
|
|
double currentTime = now();
|
|
|
|
auto item = self->rolesHeartBeatTime.emplace(nodes[i], currentTime);
|
|
|
|
item.first->second = currentTime;
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 12:39:56 +08:00
|
|
|
wait(fTimeout); // Ensure not updating heartbeat too quickly
|
2020-02-27 07:45:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if a restore role dies or disconnected
|
2020-07-17 06:30:27 +08:00
|
|
|
ACTOR static Future<Void> checkRolesLiveness(Reference<RestoreControllerData> self) {
|
2020-02-27 07:45:21 +08:00
|
|
|
loop {
|
|
|
|
wait(delay(SERVER_KNOBS->FASTRESTORE_HEARTBEAT_MAX_DELAY));
|
|
|
|
for (auto& role : self->rolesHeartBeatTime) {
|
|
|
|
if (now() - role.second > SERVER_KNOBS->FASTRESTORE_HEARTBEAT_MAX_DELAY) {
|
|
|
|
TraceEvent(SevWarnAlways, "FastRestoreUnavailableRole", role.first).detail("Delta", now() - role.second).detail("LastAliveTime", role.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-17 08:19:51 +08:00
|
|
|
}
|