2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* BackupContainer.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "flow/flow.h"
|
|
|
|
#include "fdbrpc/IAsyncFile.h"
|
2017-11-15 15:33:17 +08:00
|
|
|
#include "FDBTypes.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Append-only file interface for writing backup data
|
2017-11-27 14:02:14 +08:00
|
|
|
// Once finish() is called the file cannot be further written to.
|
|
|
|
// Backup containers should not attempt to use files for which finish was not called or did not complete.
|
2017-11-16 05:33:09 +08:00
|
|
|
// TODO: Move the log file and range file format encoding/decoding stuff to this file and behind interfaces.
|
2017-11-15 15:33:17 +08:00
|
|
|
class IBackupFile {
|
2017-05-26 04:48:44 +08:00
|
|
|
public:
|
2017-11-15 15:33:17 +08:00
|
|
|
IBackupFile(std::string fileName) : m_fileName(fileName), m_offset(0) {}
|
|
|
|
virtual ~IBackupFile() {}
|
|
|
|
// Backup files are append-only and cannot have more than 1 append outstanding at once.
|
2017-11-16 05:33:09 +08:00
|
|
|
virtual Future<Void> append(const void *data, int len) = 0;
|
2017-11-15 15:33:17 +08:00
|
|
|
virtual Future<Void> finish() = 0;
|
|
|
|
inline std::string getFileName() const {
|
|
|
|
return m_fileName;
|
|
|
|
}
|
|
|
|
inline int64_t size() const {
|
|
|
|
return m_offset;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual void addref() = 0;
|
|
|
|
virtual void delref() = 0;
|
2017-11-16 05:33:09 +08:00
|
|
|
|
|
|
|
Future<Void> appendString(Standalone<StringRef> s);
|
2017-11-15 15:33:17 +08:00
|
|
|
protected:
|
|
|
|
std::string m_fileName;
|
|
|
|
int64_t m_offset;
|
|
|
|
};
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Structures for various backup components
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
struct LogFile {
|
|
|
|
Version beginVersion;
|
|
|
|
Version endVersion;
|
|
|
|
uint32_t blockSize;
|
|
|
|
std::string fileName;
|
|
|
|
int64_t fileSize;
|
|
|
|
|
|
|
|
// Order by beginVersion, break ties with endVersion
|
|
|
|
bool operator< (const LogFile &rhs) const {
|
|
|
|
return beginVersion == rhs.beginVersion ? endVersion < rhs.endVersion : beginVersion < rhs.beginVersion;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RangeFile {
|
|
|
|
Version version;
|
|
|
|
uint32_t blockSize;
|
|
|
|
std::string fileName;
|
|
|
|
int64_t fileSize;
|
|
|
|
|
|
|
|
// Order by version, break ties with name
|
|
|
|
bool operator< (const RangeFile &rhs) const {
|
|
|
|
return version == rhs.version ? fileName < rhs.fileName : version < rhs.version;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyspaceSnapshotFile {
|
|
|
|
Version beginVersion;
|
|
|
|
Version endVersion;
|
|
|
|
std::string fileName;
|
|
|
|
int64_t totalSize;
|
|
|
|
|
|
|
|
// Order by beginVersion, break ties with endVersion
|
|
|
|
bool operator< (const KeyspaceSnapshotFile &rhs) const {
|
|
|
|
return beginVersion == rhs.beginVersion ? endVersion < rhs.endVersion : beginVersion < rhs.beginVersion;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-19 20:28:22 +08:00
|
|
|
struct FullBackupListing {
|
|
|
|
std::vector<RangeFile> ranges;
|
|
|
|
std::vector<LogFile> logs;
|
|
|
|
std::vector<KeyspaceSnapshotFile> snapshots;
|
|
|
|
};
|
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
struct BackupDescription {
|
2017-12-22 13:15:26 +08:00
|
|
|
BackupDescription() : totalSnapshotBytes(0), totalLogBytes(0) {}
|
2017-11-15 15:33:17 +08:00
|
|
|
std::string url;
|
|
|
|
std::vector<KeyspaceSnapshotFile> snapshots;
|
2017-12-22 13:15:26 +08:00
|
|
|
int64_t totalSnapshotBytes;
|
2017-11-15 15:33:17 +08:00
|
|
|
Optional<Version> minLogBegin;
|
|
|
|
Optional<Version> maxLogEnd;
|
|
|
|
Optional<Version> contiguousLogEnd;
|
|
|
|
Optional<Version> maxRestorableVersion;
|
|
|
|
Optional<Version> minRestorableVersion;
|
2017-12-22 13:15:26 +08:00
|
|
|
int64_t totalLogBytes;
|
2017-11-15 15:33:17 +08:00
|
|
|
std::string extendedDetail; // Freeform container-specific info.
|
|
|
|
std::string toString() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RestorableFileSet {
|
|
|
|
Version targetVersion;
|
|
|
|
std::vector<LogFile> logs;
|
|
|
|
std::vector<RangeFile> ranges;
|
2017-11-25 16:46:16 +08:00
|
|
|
KeyspaceSnapshotFile snapshot;
|
2017-11-15 15:33:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* IBackupContainer is an interface to a set of backup data, which contains
|
|
|
|
* - backup metadata
|
|
|
|
* - log files
|
|
|
|
* - range files
|
|
|
|
* - keyspace snapshot files defining a complete non overlapping key space snapshot
|
|
|
|
*
|
|
|
|
* Files in a container are identified by a name. This can be any string, whatever
|
|
|
|
* makes sense for the underlying storage system.
|
|
|
|
*
|
|
|
|
* Reading files is done by file name. File names are discovered by getting a RestorableFileSet.
|
|
|
|
*
|
|
|
|
* For remote data stores that are filesystem-like, it's probably best to inherit BackupContainerFileSystem.
|
|
|
|
*/
|
|
|
|
class IBackupContainer {
|
|
|
|
public:
|
|
|
|
virtual void addref() = 0;
|
|
|
|
virtual void delref() = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
IBackupContainer() {}
|
|
|
|
virtual ~IBackupContainer() {}
|
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Create the container
|
2017-05-26 04:48:44 +08:00
|
|
|
virtual Future<Void> create() = 0;
|
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Open a log file or range file for writing
|
|
|
|
virtual Future<Reference<IBackupFile>> writeLogFile(Version beginVersion, Version endVersion, int blockSize) = 0;
|
|
|
|
virtual Future<Reference<IBackupFile>> writeRangeFile(Version version, int blockSize) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Write a KeyspaceSnapshotFile of range file names representing a full non overlapping
|
|
|
|
// snapshot of the key ranges this backup is targeting.
|
|
|
|
virtual Future<Void> writeKeyspaceSnapshotFile(std::vector<std::string> fileNames, int64_t totalBytes) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Open a file for read by name
|
|
|
|
virtual Future<Reference<IAsyncFile>> readFile(std::string name) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Delete all data up to (but not including endVersion)
|
|
|
|
virtual Future<Void> expireData(Version endVersion) = 0;
|
|
|
|
|
|
|
|
// Delete entire container. During the process, if pNumDeleted is not null it will be
|
|
|
|
// updated with the count of deleted files so that progress can be seen.
|
|
|
|
virtual Future<Void> deleteContainer(int *pNumDeleted = nullptr) = 0;
|
|
|
|
|
|
|
|
// Uses the virtual methods to describe the backup contents
|
|
|
|
virtual Future<BackupDescription> describeBackup() = 0;
|
|
|
|
|
2017-11-19 20:28:22 +08:00
|
|
|
virtual Future<FullBackupListing> listBackup() = 0;
|
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
// Get exactly the files necessary to restore to targetVersion. Returns non-present if
|
|
|
|
// restore to given version is not possible.
|
|
|
|
virtual Future<Optional<RestorableFileSet>> getRestoreSet(Version targetVersion) = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Get an IBackupContainer based on a container spec string
|
2017-11-15 15:33:17 +08:00
|
|
|
static Reference<IBackupContainer> openContainer(std::string url);
|
|
|
|
static std::vector<std::string> getURLFormats();
|
2017-12-21 05:48:31 +08:00
|
|
|
static Future<std::vector<std::string>> listContainers(std::string baseURL);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
std::string getURL() const {
|
|
|
|
return URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string lastOpenError;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string URL;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|