2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* BackupContainer.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-10-11 11:10:12 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <ostream>
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// FIXME: Trim this down
|
2020-05-07 04:39:18 +08:00
|
|
|
#include "flow/Platform.actor.h"
|
2020-10-11 11:10:12 +08:00
|
|
|
#include "fdbclient/AsyncTaskThread.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/BackupContainer.h"
|
2019-03-07 14:34:25 +08:00
|
|
|
#include "fdbclient/BackupAgent.actor.h"
|
2020-04-17 06:11:09 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
2019-03-07 14:34:25 +08:00
|
|
|
#include "fdbclient/JsonBuilder.h"
|
2020-08-30 10:53:04 +08:00
|
|
|
#include "flow/Arena.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/Trace.h"
|
|
|
|
#include "flow/UnitTest.h"
|
|
|
|
#include "flow/Hash3.h"
|
|
|
|
#include "fdbrpc/AsyncFileReadAhead.actor.h"
|
2020-08-26 03:18:01 +08:00
|
|
|
#include "fdbrpc/simulator.h"
|
2020-02-29 06:56:10 +08:00
|
|
|
#include "flow/Platform.h"
|
2018-10-27 04:49:42 +08:00
|
|
|
#include "fdbclient/AsyncFileBlobStore.actor.h"
|
2020-10-21 15:48:40 +08:00
|
|
|
#include "fdbclient/BackupContainerAzureBlobStore.h"
|
2020-10-21 07:40:04 +08:00
|
|
|
#include "fdbclient/BackupContainerFileSystem.actor.h"
|
2020-10-21 15:06:59 +08:00
|
|
|
#include "fdbclient/BackupContainerLocalDirectory.h"
|
2020-10-22 00:24:15 +08:00
|
|
|
#include "fdbclient/BackupContainerS3BlobStore.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/Status.h"
|
2018-01-17 20:09:43 +08:00
|
|
|
#include "fdbclient/SystemData.h"
|
|
|
|
#include "fdbclient/ReadYourWrites.h"
|
|
|
|
#include "fdbclient/KeyBackedTypes.h"
|
|
|
|
#include "fdbclient/RunTransaction.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <algorithm>
|
2019-05-04 08:01:22 +08:00
|
|
|
#include <cinttypes>
|
2018-01-17 20:09:43 +08:00
|
|
|
#include <time.h>
|
2019-02-18 06:55:47 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-16 05:33:09 +08:00
|
|
|
namespace IBackupFile_impl {
|
|
|
|
|
2019-08-30 11:32:49 +08:00
|
|
|
ACTOR Future<Void> appendStringRefWithLen(Reference<IBackupFile> file, Standalone<StringRef> s) {
|
2020-10-21 07:16:31 +08:00
|
|
|
state uint32_t lenBuf = bigEndian32((uint32_t)s.size());
|
|
|
|
wait(file->append(&lenBuf, sizeof(lenBuf)));
|
|
|
|
wait(file->append(s.begin(), s.size()));
|
|
|
|
return Void();
|
2017-11-16 05:33:09 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 07:16:31 +08:00
|
|
|
} // namespace IBackupFile_impl
|
|
|
|
|
2018-01-17 20:09:43 +08:00
|
|
|
Future<Void> IBackupFile::appendStringRefWithLen(Standalone<StringRef> s) {
|
|
|
|
return IBackupFile_impl::appendStringRefWithLen(Reference<IBackupFile>::addRef(this), s);
|
2017-11-16 05:33:09 +08:00
|
|
|
}
|
|
|
|
|
2018-12-20 16:23:26 +08:00
|
|
|
std::string IBackupContainer::ExpireProgress::toString() const {
|
|
|
|
std::string s = step + "...";
|
|
|
|
if(total > 0) {
|
|
|
|
s += format("%d/%d (%.2f%%)", done, total, double(done) / total * 100);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-12-22 14:42:29 +08:00
|
|
|
void BackupFileList::toStream(FILE *fout) const {
|
|
|
|
for(const RangeFile &f : ranges) {
|
2019-05-04 08:01:22 +08:00
|
|
|
fprintf(fout, "range %" PRId64 " %s\n", f.fileSize, f.fileName.c_str());
|
2018-12-22 14:42:29 +08:00
|
|
|
}
|
|
|
|
for(const LogFile &f : logs) {
|
2019-05-04 08:01:22 +08:00
|
|
|
fprintf(fout, "log %" PRId64 " %s\n", f.fileSize, f.fileName.c_str());
|
2018-12-22 14:42:29 +08:00
|
|
|
}
|
|
|
|
for(const KeyspaceSnapshotFile &f : snapshots) {
|
2019-05-04 08:01:22 +08:00
|
|
|
fprintf(fout, "snapshotManifest %" PRId64 " %s\n", f.totalSize, f.fileName.c_str());
|
2018-12-22 14:42:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 20:09:43 +08:00
|
|
|
Future<Void> fetchTimes(Reference<ReadYourWritesTransaction> tr, std::map<Version, int64_t> *pVersionTimeMap) {
|
|
|
|
std::vector<Future<Void>> futures;
|
|
|
|
|
|
|
|
// Resolve each version in the map,
|
|
|
|
for(auto &p : *pVersionTimeMap) {
|
2018-01-23 15:57:01 +08:00
|
|
|
futures.push_back(map(timeKeeperEpochsFromVersion(p.first, tr), [=](Optional<int64_t> t) {
|
2018-01-17 20:09:43 +08:00
|
|
|
if(t.present())
|
|
|
|
pVersionTimeMap->at(p.first) = t.get();
|
|
|
|
else
|
|
|
|
pVersionTimeMap->erase(p.first);
|
|
|
|
return Void();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return waitForAll(futures);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> BackupDescription::resolveVersionTimes(Database cx) {
|
|
|
|
// Populate map with versions needed
|
|
|
|
versionTimeMap.clear();
|
|
|
|
|
|
|
|
for(const KeyspaceSnapshotFile &m : snapshots) {
|
|
|
|
versionTimeMap[m.beginVersion];
|
|
|
|
versionTimeMap[m.endVersion];
|
|
|
|
}
|
|
|
|
if(minLogBegin.present())
|
|
|
|
versionTimeMap[minLogBegin.get()];
|
|
|
|
if(maxLogEnd.present())
|
|
|
|
versionTimeMap[maxLogEnd.get()];
|
|
|
|
if(contiguousLogEnd.present())
|
|
|
|
versionTimeMap[contiguousLogEnd.get()];
|
|
|
|
if(minRestorableVersion.present())
|
|
|
|
versionTimeMap[minRestorableVersion.get()];
|
|
|
|
if(maxRestorableVersion.present())
|
|
|
|
versionTimeMap[maxRestorableVersion.get()];
|
|
|
|
|
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) { return fetchTimes(tr, &versionTimeMap); });
|
|
|
|
};
|
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
std::string BackupDescription::toString() const {
|
|
|
|
std::string info;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
info.append(format("URL: %s\n", url.c_str()));
|
|
|
|
info.append(format("Restorable: %s\n", maxRestorableVersion.present() ? "true" : "false"));
|
2020-04-09 11:12:09 +08:00
|
|
|
info.append(format("Partitioned logs: %s\n", partitioned ? "true" : "false"));
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2018-01-17 20:09:43 +08:00
|
|
|
auto formatVersion = [&](Version v) {
|
|
|
|
std::string s;
|
|
|
|
if(!versionTimeMap.empty()) {
|
|
|
|
auto i = versionTimeMap.find(v);
|
|
|
|
if(i != versionTimeMap.end())
|
2019-03-07 14:34:25 +08:00
|
|
|
s = format("%lld (%s)", v, BackupAgentBase::formatTime(i->second).c_str());
|
2018-01-17 20:09:43 +08:00
|
|
|
else
|
|
|
|
s = format("%lld (unknown)", v);
|
|
|
|
}
|
2018-12-20 08:53:39 +08:00
|
|
|
else if(maxLogEnd.present()) {
|
|
|
|
double days = double(maxLogEnd.get() - v) / (CLIENT_KNOBS->CORE_VERSIONSPERSECOND * 24 * 60 * 60);
|
|
|
|
s = format("%lld (maxLogEnd %s%.2f days)", v, days < 0 ? "+" : "-", days);
|
|
|
|
}
|
2018-01-17 20:09:43 +08:00
|
|
|
else {
|
|
|
|
s = format("%lld", v);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const KeyspaceSnapshotFile &m : snapshots) {
|
2019-03-07 06:14:06 +08:00
|
|
|
info.append(format("Snapshot: startVersion=%s endVersion=%s totalBytes=%lld restorable=%s expiredPct=%.2f\n",
|
|
|
|
formatVersion(m.beginVersion).c_str(), formatVersion(m.endVersion).c_str(), m.totalSize, m.restorable.orDefault(false) ? "true" : "false", m.expiredPct(expiredEndVersion)));
|
2018-01-17 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2018-01-03 15:22:35 +08:00
|
|
|
info.append(format("SnapshotBytes: %lld\n", snapshotBytes));
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2018-12-16 16:18:13 +08:00
|
|
|
if(expiredEndVersion.present())
|
|
|
|
info.append(format("ExpiredEndVersion: %s\n", formatVersion(expiredEndVersion.get()).c_str()));
|
|
|
|
if(unreliableEndVersion.present())
|
|
|
|
info.append(format("UnreliableEndVersion: %s\n", formatVersion(unreliableEndVersion.get()).c_str()));
|
2017-11-15 15:33:17 +08:00
|
|
|
if(minLogBegin.present())
|
2018-01-17 20:09:43 +08:00
|
|
|
info.append(format("MinLogBeginVersion: %s\n", formatVersion(minLogBegin.get()).c_str()));
|
2017-11-15 15:33:17 +08:00
|
|
|
if(contiguousLogEnd.present())
|
2018-01-17 20:09:43 +08:00
|
|
|
info.append(format("ContiguousLogEndVersion: %s\n", formatVersion(contiguousLogEnd.get()).c_str()));
|
2017-11-15 15:33:17 +08:00
|
|
|
if(maxLogEnd.present())
|
2018-01-17 20:09:43 +08:00
|
|
|
info.append(format("MaxLogEndVersion: %s\n", formatVersion(maxLogEnd.get()).c_str()));
|
2017-11-15 15:33:17 +08:00
|
|
|
if(minRestorableVersion.present())
|
2018-01-17 20:09:43 +08:00
|
|
|
info.append(format("MinRestorableVersion: %s\n", formatVersion(minRestorableVersion.get()).c_str()));
|
2017-11-15 15:33:17 +08:00
|
|
|
if(maxRestorableVersion.present())
|
2018-01-17 20:09:43 +08:00
|
|
|
info.append(format("MaxRestorableVersion: %s\n", formatVersion(maxRestorableVersion.get()).c_str()));
|
2017-11-15 15:33:17 +08:00
|
|
|
|
|
|
|
if(!extendedDetail.empty())
|
|
|
|
info.append("ExtendedDetail: ").append(extendedDetail);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2019-03-07 06:14:06 +08:00
|
|
|
std::string BackupDescription::toJSON() const {
|
|
|
|
JsonBuilderObject doc;
|
|
|
|
|
2019-03-14 17:10:14 +08:00
|
|
|
doc.setKey("SchemaVersion", "1.0.0");
|
2019-03-07 06:14:06 +08:00
|
|
|
doc.setKey("URL", url.c_str());
|
|
|
|
doc.setKey("Restorable", maxRestorableVersion.present());
|
2020-04-09 11:12:09 +08:00
|
|
|
doc.setKey("Partitioned", partitioned);
|
2019-03-07 06:14:06 +08:00
|
|
|
|
|
|
|
auto formatVersion = [&](Version v) {
|
|
|
|
JsonBuilderObject doc;
|
|
|
|
doc.setKey("Version", v);
|
|
|
|
if(!versionTimeMap.empty()) {
|
|
|
|
auto i = versionTimeMap.find(v);
|
2019-03-07 14:34:25 +08:00
|
|
|
if(i != versionTimeMap.end()) {
|
|
|
|
doc.setKey("Timestamp", BackupAgentBase::formatTime(i->second));
|
2019-03-11 07:00:01 +08:00
|
|
|
doc.setKey("EpochSeconds", i->second);
|
2019-03-07 14:34:25 +08:00
|
|
|
}
|
2019-03-07 06:14:06 +08:00
|
|
|
}
|
|
|
|
else if(maxLogEnd.present()) {
|
|
|
|
double days = double(v - maxLogEnd.get()) / (CLIENT_KNOBS->CORE_VERSIONSPERSECOND * 24 * 60 * 60);
|
|
|
|
doc.setKey("RelativeDays", days);
|
|
|
|
}
|
|
|
|
return doc;
|
|
|
|
};
|
|
|
|
|
|
|
|
JsonBuilderArray snapshotsArray;
|
|
|
|
for(const KeyspaceSnapshotFile &m : snapshots) {
|
|
|
|
JsonBuilderObject snapshotDoc;
|
2019-03-07 14:34:25 +08:00
|
|
|
snapshotDoc.setKey("Start", formatVersion(m.beginVersion));
|
|
|
|
snapshotDoc.setKey("End", formatVersion(m.endVersion));
|
2019-03-07 06:14:06 +08:00
|
|
|
snapshotDoc.setKey("Restorable", m.restorable.orDefault(false));
|
|
|
|
snapshotDoc.setKey("TotalBytes", m.totalSize);
|
|
|
|
snapshotDoc.setKey("PercentageExpired", m.expiredPct(expiredEndVersion));
|
|
|
|
snapshotsArray.push_back(snapshotDoc);
|
|
|
|
}
|
|
|
|
doc.setKey("Snapshots", snapshotsArray);
|
|
|
|
|
|
|
|
doc.setKey("TotalSnapshotBytes", snapshotBytes);
|
|
|
|
|
|
|
|
if(expiredEndVersion.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("ExpiredEnd", formatVersion(expiredEndVersion.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
if(unreliableEndVersion.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("UnreliableEnd", formatVersion(unreliableEndVersion.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
if(minLogBegin.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("MinLogBegin", formatVersion(minLogBegin.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
if(contiguousLogEnd.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("ContiguousLogEnd", formatVersion(contiguousLogEnd.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
if(maxLogEnd.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("MaxLogEnd", formatVersion(maxLogEnd.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
if(minRestorableVersion.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("MinRestorablePoint", formatVersion(minRestorableVersion.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
if(maxRestorableVersion.present())
|
2019-03-07 14:34:25 +08:00
|
|
|
doc.setKey("MaxRestorablePoint", formatVersion(maxRestorableVersion.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
|
|
|
|
if(!extendedDetail.empty())
|
|
|
|
doc.setKey("ExtendedDetail", extendedDetail);
|
|
|
|
|
|
|
|
return doc.getJson();
|
|
|
|
}
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
std::string IBackupContainer::lastOpenError;
|
2020-04-17 06:11:09 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
std::vector<std::string> IBackupContainer::getURLFormats() {
|
|
|
|
std::vector<std::string> formats;
|
|
|
|
formats.push_back(BackupContainerLocalDirectory::getURLFormat());
|
2020-10-22 00:24:15 +08:00
|
|
|
formats.push_back(BackupContainerS3BlobStore::getURLFormat());
|
2020-10-21 07:40:04 +08:00
|
|
|
return formats;
|
|
|
|
}
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// Get an IBackupContainer based on a container URL string
|
|
|
|
Reference<IBackupContainer> IBackupContainer::openContainer(std::string url) {
|
|
|
|
static std::map<std::string, Reference<IBackupContainer>> m_cache;
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
Reference<IBackupContainer>& r = m_cache[url];
|
|
|
|
if (r) return r;
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
try {
|
|
|
|
StringRef u(url);
|
|
|
|
if (u.startsWith(LiteralStringRef("file://"))) {
|
|
|
|
r = Reference<IBackupContainer>(new BackupContainerLocalDirectory(url));
|
|
|
|
} else if (u.startsWith(LiteralStringRef("blobstore://"))) {
|
|
|
|
std::string resource;
|
2018-01-18 05:28:56 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// The URL parameters contain blobstore endpoint tunables as well as possible backup-specific options.
|
|
|
|
BlobStoreEndpoint::ParametersT backupParams;
|
|
|
|
Reference<BlobStoreEndpoint> bstore =
|
|
|
|
BlobStoreEndpoint::fromString(url, &resource, &lastOpenError, &backupParams);
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
if (resource.empty()) throw backup_invalid_url();
|
|
|
|
for (auto c : resource)
|
|
|
|
if (!isalnum(c) && c != '_' && c != '-' && c != '.' && c != '/') throw backup_invalid_url();
|
2020-10-22 00:24:15 +08:00
|
|
|
r = Reference<IBackupContainer>(new BackupContainerS3BlobStore(bstore, resource, backupParams));
|
2020-10-21 07:40:04 +08:00
|
|
|
} else if (u.startsWith(LiteralStringRef("http"))) {
|
|
|
|
r = Reference<IBackupContainer>(new BackupContainerAzureBlobStore());
|
|
|
|
} else {
|
|
|
|
lastOpenError = "invalid URL prefix";
|
|
|
|
throw backup_invalid_url();
|
2020-04-16 14:08:19 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
r->URL = url;
|
|
|
|
return r;
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled) throw;
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
TraceEvent m(SevWarn, "BackupContainer");
|
|
|
|
m.detail("Description", "Invalid container specification. See help.");
|
|
|
|
m.detail("URL", url);
|
|
|
|
m.error(e);
|
|
|
|
if (e.code() == error_code_backup_invalid_url) m.detail("LastOpenError", lastOpenError);
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
throw;
|
2017-11-15 15:33:17 +08:00
|
|
|
}
|
2020-10-21 07:40:04 +08:00
|
|
|
}
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// Get a list of URLS to backup containers based on some a shorter URL. This function knows about some set of supported
|
|
|
|
// URL types which support this sort of backup discovery.
|
|
|
|
ACTOR Future<std::vector<std::string>> listContainers_impl(std::string baseURL) {
|
|
|
|
try {
|
|
|
|
StringRef u(baseURL);
|
|
|
|
if (u.startsWith(LiteralStringRef("file://"))) {
|
|
|
|
std::vector<std::string> results = wait(BackupContainerLocalDirectory::listURLs(baseURL));
|
2017-11-15 15:33:17 +08:00
|
|
|
return results;
|
2020-10-21 07:40:04 +08:00
|
|
|
} else if (u.startsWith(LiteralStringRef("blobstore://"))) {
|
|
|
|
std::string resource;
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
BlobStoreEndpoint::ParametersT backupParams;
|
|
|
|
Reference<BlobStoreEndpoint> bstore =
|
|
|
|
BlobStoreEndpoint::fromString(baseURL, &resource, &IBackupContainer::lastOpenError, &backupParams);
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
if (!resource.empty()) {
|
|
|
|
TraceEvent(SevWarn, "BackupContainer")
|
|
|
|
.detail("Description", "Invalid backup container base URL, resource aka path should be blank.")
|
|
|
|
.detail("URL", baseURL);
|
|
|
|
throw backup_invalid_url();
|
2018-11-23 21:23:56 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// Create a dummy container to parse the backup-specific parameters from the URL and get a final bucket name
|
2020-10-22 00:24:15 +08:00
|
|
|
BackupContainerS3BlobStore dummy(bstore, "dummy", backupParams);
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-22 00:24:15 +08:00
|
|
|
std::vector<std::string> results = wait(BackupContainerS3BlobStore::listURLs(bstore, dummy.getBucket()));
|
2017-11-15 15:33:17 +08:00
|
|
|
return results;
|
2020-04-09 06:50:21 +08:00
|
|
|
} else {
|
2020-10-21 07:40:04 +08:00
|
|
|
IBackupContainer::lastOpenError = "invalid URL prefix";
|
|
|
|
throw backup_invalid_url();
|
2020-04-09 06:50:21 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled) throw;
|
2017-11-17 08:19:56 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
TraceEvent m(SevWarn, "BackupContainer");
|
2018-12-20 02:35:06 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
m.detail("Description", "Invalid backup container URL prefix. See help.");
|
|
|
|
m.detail("URL", baseURL);
|
|
|
|
m.error(e);
|
|
|
|
if (e.code() == error_code_backup_invalid_url) m.detail("LastOpenError", IBackupContainer::lastOpenError);
|
2018-12-20 02:35:06 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 13:52:23 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
Future<std::vector<std::string>> IBackupContainer::listContainers(std::string baseURL) {
|
|
|
|
return listContainers_impl(baseURL);
|
|
|
|
}
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
ACTOR Future<Version> timeKeeperVersionFromDatetime(std::string datetime, Database db) {
|
|
|
|
state KeyBackedMap<int64_t, Version> versionMap(timeKeeperPrefixRange.begin);
|
|
|
|
state Reference<ReadYourWritesTransaction> tr =
|
|
|
|
Reference<ReadYourWritesTransaction>(new ReadYourWritesTransaction(db));
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
state int64_t time = BackupAgentBase::parseTime(datetime);
|
|
|
|
if (time < 0) {
|
|
|
|
fprintf(stderr, "ERROR: Incorrect date/time or format. Format is %s.\n",
|
|
|
|
BackupAgentBase::timeFormat().c_str());
|
|
|
|
throw backup_error();
|
|
|
|
}
|
2017-12-22 13:15:26 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
state std::vector<std::pair<int64_t, Version>> results =
|
|
|
|
wait(versionMap.getRange(tr, 0, time, 1, false, true));
|
|
|
|
if (results.size() != 1) {
|
|
|
|
// No key less than time was found in the database
|
|
|
|
// Look for a key >= time.
|
|
|
|
wait(store(results, versionMap.getRange(tr, time, std::numeric_limits<int64_t>::max(), 1)));
|
2017-11-17 08:19:56 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
if (results.size() != 1) {
|
|
|
|
fprintf(stderr, "ERROR: Unable to calculate a version for given date/time.\n");
|
|
|
|
throw backup_error();
|
|
|
|
}
|
2017-11-17 08:19:56 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// Adjust version found by the delta between time and the time found and min with 0.
|
|
|
|
auto& result = results[0];
|
|
|
|
return std::max<Version>(0, result.second + (time - result.first) * CLIENT_KNOBS->CORE_VERSIONSPERSECOND);
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr->onError(e));
|
2017-11-15 15:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-21 07:40:04 +08:00
|
|
|
}
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
ACTOR Future<Optional<int64_t>> timeKeeperEpochsFromVersion(Version v, Reference<ReadYourWritesTransaction> tr) {
|
|
|
|
state KeyBackedMap<int64_t, Version> versionMap(timeKeeperPrefixRange.begin);
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// Binary search to find the closest date with a version <= v
|
|
|
|
state int64_t min = 0;
|
|
|
|
state int64_t max = (int64_t)now();
|
|
|
|
state int64_t mid;
|
|
|
|
state std::pair<int64_t, Version> found;
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
loop {
|
|
|
|
mid = (min + max + 1) / 2; // ceiling
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
// Find the highest time < mid
|
|
|
|
state std::vector<std::pair<int64_t, Version>> results =
|
|
|
|
wait(versionMap.getRange(tr, min, mid, 1, false, true));
|
2018-12-19 10:55:44 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
if (results.size() != 1) {
|
|
|
|
if (mid == min) {
|
|
|
|
// There aren't any records having a version < v, so just look for any record having a time < now
|
|
|
|
// and base a result on it
|
|
|
|
wait(store(results, versionMap.getRange(tr, 0, (int64_t)now(), 1)));
|
2018-12-19 10:55:44 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
if (results.size() != 1) {
|
|
|
|
// There aren't any timekeeper records to base a result on so return nothing
|
|
|
|
return Optional<int64_t>();
|
|
|
|
}
|
2018-01-17 20:09:43 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
found = results[0];
|
2018-01-17 20:09:43 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-12-18 20:33:37 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
min = mid;
|
|
|
|
continue;
|
2018-01-17 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
found = results[0];
|
2017-11-15 15:33:17 +08:00
|
|
|
|
2020-10-21 07:40:04 +08:00
|
|
|
if (v < found.second) {
|
|
|
|
max = found.first;
|
|
|
|
} else {
|
|
|
|
if (found.first == min) {
|
|
|
|
break;
|
2018-11-28 01:50:39 +08:00
|
|
|
}
|
2020-10-21 07:40:04 +08:00
|
|
|
min = found.first;
|
2018-01-17 20:09:43 +08:00
|
|
|
}
|
2020-10-21 07:40:04 +08:00
|
|
|
}
|
2018-01-23 15:57:01 +08:00
|
|
|
|
|
|
|
return found.first + (v - found.second) / CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
|
|
|
}
|