Fix a backup container unit test
Write a valid range file instead of random data so that checking its content is fine.
This commit is contained in:
parent
7d59e53349
commit
ba261eda36
|
@ -1373,7 +1373,7 @@ public:
|
|||
wait(bc->readKeyspaceSnapshot(snapshot.get()));
|
||||
restorable.ranges = std::move(results.first);
|
||||
restorable.keyRanges = std::move(results.second);
|
||||
if (false && g_network->isSimulated()) { // TODO: Reenable sanity check
|
||||
if (g_network->isSimulated()) {
|
||||
// Sanity check key ranges
|
||||
state std::map<std::string, KeyRange>::iterator rit;
|
||||
for (rit = restorable.keyRanges.begin(); rit != restorable.keyRanges.end(); rit++) {
|
||||
|
@ -2097,6 +2097,8 @@ ACTOR Future<Optional<int64_t>> timeKeeperEpochsFromVersion(Version v, Reference
|
|||
return found.first + (v - found.second) / CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
||||
}
|
||||
|
||||
namespace backup_test {
|
||||
|
||||
int chooseFileSize(std::vector<int> &sizes) {
|
||||
int size = 1000;
|
||||
if(!sizes.empty()) {
|
||||
|
@ -2134,7 +2136,30 @@ Version nextVersion(Version v) {
|
|||
return v + increment;
|
||||
}
|
||||
|
||||
ACTOR Future<Void> testBackupContainer(std::string url) {
|
||||
// Write a snapshot file with only begin & end key
|
||||
ACTOR static Future<Void> testWriteSnapshotFile(Reference<IBackupFile> file, Key begin, Key end, uint32_t blockSize) {
|
||||
ASSERT(blockSize > 3 * sizeof(uint32_t) + begin.size() + end.size());
|
||||
|
||||
uint32_t fileVersion = BACKUP_AGENT_SNAPSHOT_FILE_VERSION;
|
||||
// write Header
|
||||
wait(file->append((uint8_t*)&fileVersion, sizeof(fileVersion)));
|
||||
|
||||
// write begin key length and key
|
||||
wait(file->appendStringRefWithLen(begin));
|
||||
|
||||
// write end key length and key
|
||||
wait(file->appendStringRefWithLen(end));
|
||||
|
||||
int bytesLeft = blockSize - file->size();
|
||||
if (bytesLeft > 0) {
|
||||
Value paddings = fileBackup::makePadding(bytesLeft);
|
||||
wait(file->append(paddings.begin(), bytesLeft));
|
||||
}
|
||||
wait(file->finish());
|
||||
return Void();
|
||||
}
|
||||
|
||||
ACTOR static Future<Void> testBackupContainer(std::string url) {
|
||||
printf("BackupContainerTest URL %s\n", url.c_str());
|
||||
|
||||
state Reference<IBackupContainer> c = IBackupContainer::openContainer(url);
|
||||
|
@ -2163,6 +2188,8 @@ ACTOR Future<Void> testBackupContainer(std::string url) {
|
|||
loop {
|
||||
state Version logStart = v;
|
||||
state int kvfiles = deterministicRandom()->randomInt(0, 3);
|
||||
state Key begin = LiteralStringRef("");
|
||||
state Key end = LiteralStringRef("");
|
||||
|
||||
while(kvfiles > 0) {
|
||||
if(snapshots.empty()) {
|
||||
|
@ -2173,15 +2200,17 @@ ACTOR Future<Void> testBackupContainer(std::string url) {
|
|||
v = nextVersion(v);
|
||||
}
|
||||
}
|
||||
Reference<IBackupFile> range = wait(c->writeRangeFile(snapshots.rbegin()->first, 0, v, 10));
|
||||
Reference<IBackupFile> range = wait(c->writeRangeFile(snapshots.rbegin()->first, 0, v, 16));
|
||||
++nRangeFiles;
|
||||
v = nextVersion(v);
|
||||
snapshots.rbegin()->second.push_back(range->getFileName());
|
||||
snapshotBeginEndKeys.rbegin()->second.emplace_back(LiteralStringRef(""), LiteralStringRef(""));
|
||||
snapshotBeginEndKeys.rbegin()->second.emplace_back(begin, end);
|
||||
|
||||
int size = chooseFileSize(fileSizes);
|
||||
snapshotSizes.rbegin()->second += size;
|
||||
writes.push_back(writeAndVerifyFile(c, range, size));
|
||||
// Write in actual range file format, instead of random data.
|
||||
// writes.push_back(writeAndVerifyFile(c, range, size));
|
||||
wait(testWriteSnapshotFile(range, begin, end, 16));
|
||||
|
||||
if(deterministicRandom()->random01() < .2) {
|
||||
writes.push_back(c->writeKeyspaceSnapshotFile(
|
||||
|
@ -2377,4 +2406,6 @@ TEST_CASE("/backup/continuous") {
|
|||
ASSERT(BackupContainerFileSystem::getPartitionedLogsContinuousEndVersion(files, 250) == 399);
|
||||
|
||||
return Void();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace backup_test
|
||||
|
|
Loading…
Reference in New Issue