snap v2: restore related changes for the simulator
This commit is contained in:
parent
7e04e3c8be
commit
a954cf4e06
|
@ -867,6 +867,19 @@ std::pair<NetworkAddressList, NetworkAddressList> buildNetworkAddresses(const Cl
|
|||
return std::make_pair(publicNetworkAddresses, listenNetworkAddresses);
|
||||
}
|
||||
|
||||
void restoreRoleFilesHelper(std::string dirSrc, std::string dirToMove, std::string role) {
|
||||
std::vector<std::string> returnFiles = platform::listFiles(dirSrc, "");
|
||||
for (const auto & fileEntry: returnFiles) {
|
||||
if (fileEntry != "fdb.cluster" && fileEntry.find(role) != std::string::npos) {
|
||||
//rename files
|
||||
TraceEvent("RenamingSnapFile")
|
||||
.detail("Oldname", dirSrc + "/" + fileEntry)
|
||||
.detail("Newname", dirToMove + "/" + fileEntry);
|
||||
renameFile(dirSrc + "/" + fileEntry, dirToMove + "/" + fileEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
try {
|
||||
platformInit();
|
||||
|
@ -1686,6 +1699,7 @@ int main(int argc, char* argv[]) {
|
|||
std::string absDataFolder = abspath(dataFolder);
|
||||
ini.LoadFile(joinPath(absDataFolder, "restartInfo.ini").c_str());
|
||||
int backupFailed = true;
|
||||
int backupVersion = 1;
|
||||
const char* isRestoringStr = ini.GetValue("RESTORE", "isRestoring", NULL);
|
||||
if (isRestoringStr) {
|
||||
isRestoring = atoi(isRestoringStr);
|
||||
|
@ -1693,64 +1707,142 @@ int main(int argc, char* argv[]) {
|
|||
if (isRestoring && backupFailedStr) {
|
||||
backupFailed = atoi(backupFailedStr);
|
||||
}
|
||||
const char* backupVersionStr = ini.GetValue("RESTORE", "BackupVersion", NULL);
|
||||
if (isRestoring && backupVersionStr) {
|
||||
backupVersion = atoi(backupVersionStr);
|
||||
}
|
||||
}
|
||||
if (isRestoring && !backupFailed) {
|
||||
std::vector<std::string> returnList;
|
||||
std::string ext = "";
|
||||
returnList = platform::listDirectories(absDataFolder);
|
||||
std::string snapStr = ini.GetValue("RESTORE", "RestoreSnapUID");
|
||||
if (backupVersion == 1) {
|
||||
std::vector<std::string> returnList;
|
||||
std::string ext = "";
|
||||
returnList = platform::listDirectories(absDataFolder);
|
||||
std::string snapStr = ini.GetValue("RESTORE", "RestoreSnapUID");
|
||||
|
||||
TraceEvent("RestoringDataFolder").detail("DataFolder", absDataFolder);
|
||||
TraceEvent("RestoreSnapUID").detail("UID", snapStr);
|
||||
TraceEvent("RestoringDataFolder").detail("DataFolder", absDataFolder);
|
||||
TraceEvent("RestoreSnapUID").detail("UID", snapStr);
|
||||
|
||||
// delete all files (except fdb.cluster) in non-snap directories
|
||||
for (int i = 0; i < returnList.size(); i++) {
|
||||
if (returnList[i] == "." || returnList[i] == "..") {
|
||||
continue;
|
||||
}
|
||||
if (returnList[i].find(snapStr) != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
// delete all files (except fdb.cluster) in non-snap directories
|
||||
for (int i = 0; i < returnList.size(); i++) {
|
||||
if (returnList[i] == "." || returnList[i] == "..") {
|
||||
continue;
|
||||
}
|
||||
if (returnList[i].find(snapStr) != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string childf = absDataFolder + "/" + returnList[i];
|
||||
std::vector<std::string> returnFiles = platform::listFiles(childf, ext);
|
||||
for (int j = 0; j < returnFiles.size(); j++) {
|
||||
if (returnFiles[j] != "fdb.cluster" && returnFiles[j] != "fitness") {
|
||||
TraceEvent("DeletingNonSnapfiles")
|
||||
.detail("FileBeingDeleted", childf + "/" + returnFiles[j]);
|
||||
deleteFile(childf + "/" + returnFiles[j]);
|
||||
std::string childf = absDataFolder + "/" + returnList[i];
|
||||
std::vector<std::string> returnFiles = platform::listFiles(childf, ext);
|
||||
for (int j = 0; j < returnFiles.size(); j++) {
|
||||
if (returnFiles[j] != "fdb.cluster" && returnFiles[j] != "fitness") {
|
||||
TraceEvent("DeletingNonSnapfiles")
|
||||
.detail("FileBeingDeleted", childf + "/" + returnFiles[j]);
|
||||
deleteFile(childf + "/" + returnFiles[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// move the contents from snap folder to the original folder,
|
||||
// delete snap folders
|
||||
for (int i = 0; i < returnList.size(); i++) {
|
||||
if (returnList[i] == "." || returnList[i] == "..") {
|
||||
continue;
|
||||
}
|
||||
std::string dirSrc = absDataFolder + "/" + returnList[i];
|
||||
// delete snap directories which are not part of restoreSnapUID
|
||||
if (returnList[i].find(snapStr) == std::string::npos) {
|
||||
if (returnList[i].find("snap") != std::string::npos) {
|
||||
// move the contents from snap folder to the original folder,
|
||||
// delete snap folders
|
||||
for (int i = 0; i < returnList.size(); i++) {
|
||||
if (returnList[i] == "." || returnList[i] == "..") {
|
||||
continue;
|
||||
}
|
||||
std::string dirSrc = absDataFolder + "/" + returnList[i];
|
||||
// delete snap directories which are not part of restoreSnapUID
|
||||
if (returnList[i].find(snapStr) == std::string::npos) {
|
||||
if (returnList[i].find("snap") != std::string::npos) {
|
||||
platform::eraseDirectoryRecursive(dirSrc);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// remove empty/partial snap directories
|
||||
std::vector<std::string> childrenList = platform::listFiles(dirSrc);
|
||||
if (childrenList.size() == 0) {
|
||||
TraceEvent("RemovingEmptySnapDirectory").detail("DirBeingDeleted", dirSrc);
|
||||
platform::eraseDirectoryRecursive(dirSrc);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
std::string origDir = returnList[i].substr(0, 32);
|
||||
std::string dirToRemove = absDataFolder + "/" + origDir;
|
||||
TraceEvent("DeletingOriginalNonSnapDirectory").detail("FileBeingDeleted", dirToRemove);
|
||||
platform::eraseDirectoryRecursive(dirToRemove);
|
||||
renameFile(dirSrc, dirToRemove);
|
||||
TraceEvent("RenamingSnapToOriginalDirectory")
|
||||
.detail("Oldname", dirSrc)
|
||||
.detail("Newname", dirToRemove);
|
||||
}
|
||||
// remove empty/partial snap directories
|
||||
std::vector<std::string> childrenList = platform::listFiles(dirSrc);
|
||||
if (childrenList.size() == 0) {
|
||||
TraceEvent("RemovingEmptySnapDirectory").detail("DirBeingDeleted", dirSrc);
|
||||
platform::eraseDirectoryRecursive(dirSrc);
|
||||
continue;
|
||||
} else if (backupVersion == 2) {
|
||||
std::vector<std::string> returnList;
|
||||
std::string ext = "";
|
||||
returnList = platform::listDirectories(absDataFolder);
|
||||
std::string snapStr = ini.GetValue("RESTORE", "RestoreSnapUID");
|
||||
|
||||
TraceEvent("RestoringDataFolder").detail("DataFolder", absDataFolder);
|
||||
TraceEvent("RestoreSnapUID").detail("UID", snapStr);
|
||||
|
||||
// delete all files (except fdb.cluster) in non-snap directories
|
||||
for (const auto & dirEntry : returnList) {
|
||||
if (dirEntry == "." || dirEntry == "..") {
|
||||
continue;
|
||||
}
|
||||
if (dirEntry.find(snapStr) != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string childf = absDataFolder + "/" + dirEntry;
|
||||
std::vector<std::string> returnFiles = platform::listFiles(childf, ext);
|
||||
for (const auto & fileEntry : returnFiles) {
|
||||
if (fileEntry != "fdb.cluster" && fileEntry != "fitness") {
|
||||
TraceEvent("DeletingNonSnapfiles")
|
||||
.detail("FileBeingDeleted", childf + "/" + fileEntry);
|
||||
deleteFile(childf + "/" + fileEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string origDir = returnList[i].substr(0, 32);
|
||||
std::string dirToRemove = absDataFolder + "/" + origDir;
|
||||
TraceEvent("DeletingOriginalNonSnapDirectory").detail("FileBeingDeleted", dirToRemove);
|
||||
platform::eraseDirectoryRecursive(dirToRemove);
|
||||
renameFile(dirSrc, dirToRemove);
|
||||
TraceEvent("RenamingSnapToOriginalDirectory")
|
||||
.detail("Oldname", dirSrc)
|
||||
.detail("Newname", dirToRemove);
|
||||
// cleanup unwanted and partial directories
|
||||
for (const auto & dirEntry : returnList) {
|
||||
if (dirEntry == "." || dirEntry == "..") {
|
||||
continue;
|
||||
}
|
||||
std::string dirSrc = absDataFolder + "/" + dirEntry;
|
||||
// delete snap directories which are not part of restoreSnapUID
|
||||
if (dirEntry.find(snapStr) == std::string::npos) {
|
||||
if (dirEntry.find("snap") != std::string::npos) {
|
||||
platform::eraseDirectoryRecursive(dirSrc);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// remove empty/partial snap directories
|
||||
std::vector<std::string> childrenList = platform::listFiles(dirSrc);
|
||||
if (childrenList.size() == 0) {
|
||||
TraceEvent("RemovingEmptySnapDirectory").detail("DirBeingDeleted", dirSrc);
|
||||
platform::eraseDirectoryRecursive(dirSrc);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// move snapshotted files to appropriate locations
|
||||
for (const auto & dirEntry : returnList) {
|
||||
if (dirEntry == "." || dirEntry == "..") {
|
||||
continue;
|
||||
}
|
||||
std::string dirSrc = absDataFolder + "/" + dirEntry;
|
||||
std::string origDir = dirEntry.substr(0, 32);
|
||||
std::string dirToMove = absDataFolder + "/" + origDir;
|
||||
if ((dirEntry.find("snap") != std::string::npos) &&
|
||||
(dirEntry.find("tlog") != std::string::npos)) {
|
||||
// restore tlog files
|
||||
restoreRoleFilesHelper(dirSrc, dirToMove, "log");
|
||||
} else if ((dirEntry.find("snap") != std::string::npos) &&
|
||||
(dirEntry.find("storage") != std::string::npos)) {
|
||||
// restore storage files
|
||||
restoreRoleFilesHelper(dirSrc, dirToMove, "storage");
|
||||
} else if ((dirEntry.find("snap") != std::string::npos) &&
|
||||
(dirEntry.find("coord") != std::string::npos)) {
|
||||
// restore coordinator files
|
||||
restoreRoleFilesHelper(dirSrc, dirToMove, "coordination");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue