foundationdb/fdbserver/RestoreLoader.actor.h
Meng Xu 022b555b69 FastRestore:Fix bug in finish restore
RestoreMaster may not receive all acks. for the last command, i.e., finishRestore,
because RestoreLoaders and RestoreAppliers exit immediately after sending the ack.
If the ack is lost, it will not be resent.

This commit also removes some unneeded code.
This commit passes 50k random tests without errors.
2019-06-05 20:07:18 -07:00

107 lines
3.7 KiB
C++

/*
* RestoreLoader.h
*
* 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.
*/
// This file declares the actors used by the RestoreLoader role
#pragma once
#if defined(NO_INTELLISENSE) && !defined(FDBSERVER_RESTORE_LOADER_G_H)
#define FDBSERVER_RESTORE_LOADER_G_H
#include "fdbserver/RestoreLoader.actor.g.h"
#elif !defined(FDBSERVER_RESTORE_LOADER_H)
#define FDBSERVER_RESTORE_LOADER_H
#include <sstream>
#include "flow/Stats.h"
#include "fdbclient/FDBTypes.h"
#include "fdbclient/CommitTransaction.h"
#include "fdbrpc/fdbrpc.h"
#include "fdbserver/CoordinationInterface.h"
#include "fdbrpc/Locality.h"
#include "fdbserver/RestoreUtil.h"
#include "fdbserver/RestoreCommon.actor.h"
#include "fdbserver/RestoreRoleCommon.actor.h"
#include "fdbserver/RestoreWorkerInterface.actor.h"
#include "fdbclient/BackupContainer.h"
#include "flow/actorcompiler.h" // has to be last include
struct RestoreLoaderData : RestoreRoleData, public ReferenceCounted<RestoreLoaderData> {
std::map<LoadingParam, Future<Void>> processedFileParams;
// range2Applier is in master and loader node. Loader node uses this to determine which applier a mutation should be sent
std::map<Standalone<KeyRef>, UID> range2Applier; // KeyRef is the inclusive lower bound of the key range the applier (UID) is responsible for
std::map<Standalone<KeyRef>, int> keyOpsCount; // The number of operations per key which is used to determine the key-range boundary for appliers
int numSampledMutations; // The total number of mutations received from sampled data.
Reference<IBackupContainer> bc; // Backup container is used to read backup files
Key bcUrl; // The url used to get the bc
void addref() { return ReferenceCounted<RestoreLoaderData>::addref(); }
void delref() { return ReferenceCounted<RestoreLoaderData>::delref(); }
explicit RestoreLoaderData(UID loaderInterfID, int assignedIndex) {
nodeID = loaderInterfID;
nodeIndex = assignedIndex;
role = RestoreRole::Loader;
}
~RestoreLoaderData() {}
std::string describeNode() {
std::stringstream ss;
ss << "[Role: Loader] [NodeID:" << nodeID.toString().c_str()
<< "] [NodeIndex:" << std::to_string(nodeIndex) << "]";
return ss.str();
}
void resetPerVersionBatch() {
TraceEvent("FastRestore").detail("ResetPerVersionBatchOnLoader", nodeID);
RestoreRoleData::resetPerVersionBatch();
range2Applier.clear();
keyOpsCount.clear();
numSampledMutations = 0;
processedFileParams.clear();
}
// Only get the appliers that are responsible for a range
std::vector<UID> getWorkingApplierIDs() {
std::vector<UID> applierIDs;
for ( auto &applier : range2Applier ) {
applierIDs.push_back(applier.second);
}
ASSERT( !applierIDs.empty() );
return applierIDs;
}
void initBackupContainer(Key url) {
if ( bcUrl == url && bc.isValid() ) {
return;
}
bcUrl = url;
bc = IBackupContainer::openContainer(url.toString());
}
};
ACTOR Future<Void> restoreLoaderCore(Reference<RestoreLoaderData> self, RestoreLoaderInterface loaderInterf, Database cx);
#include "flow/unactorcompiler.h"
#endif