aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/admin_cmd.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-11-27 14:32:19 +0100
committerGitHub <[email protected]>2023-11-27 14:32:19 +0100
commit4d95b578350ebfbbf6d54407c9403547b01cac4c (patch)
tree9f8df5d934a6a62fdcebeac94dffe52139d3ea6b /src/zen/cmds/admin_cmd.cpp
parentgc stop command (#569) (diff)
downloadarchived-zen-4d95b578350ebfbbf6d54407c9403547b01cac4c.tar.xz
archived-zen-4d95b578350ebfbbf6d54407c9403547b01cac4c.zip
optimized index snapshot reading/writing (#561)
the previous implementation of in-memory index snapshots serialise data to memory before writing to disk and vice versa when reading. This leads to some memory spikes which end up pushing useful data out of system cache and also cause stalls on I/O operations. this change moves more code to a streaming serialisation approach which scales better from a memory usage perspective and also performs much better
Diffstat (limited to 'src/zen/cmds/admin_cmd.cpp')
-rw-r--r--src/zen/cmds/admin_cmd.cpp32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/zen/cmds/admin_cmd.cpp b/src/zen/cmds/admin_cmd.cpp
index 3422c6880..86a180d54 100644
--- a/src/zen/cmds/admin_cmd.cpp
+++ b/src/zen/cmds/admin_cmd.cpp
@@ -550,21 +550,9 @@ static void
Copy(const std::filesystem::path& Source, const std::filesystem::path& Target)
{
CreateDirectories(Target.parent_path());
- BasicFile SourceFile;
- SourceFile.Open(Source, BasicFile::Mode::kRead);
- BasicFile TargetFile;
- TargetFile.Open(Target, BasicFile::Mode::kTruncate);
- uint64_t Size = SourceFile.FileSize();
- uint64_t Offset = 0;
- std::vector<uint8_t> Buffer(Min(size_t(Size), size_t(65536u)));
- while (Offset < Size)
- {
- uint64_t CopyCount = Min<uint64_t>(Size - Offset, size_t(Buffer.size()));
- SourceFile.Read(Buffer.data(), CopyCount, Offset);
- TargetFile.Write(Buffer.data(), CopyCount, Offset);
- Offset += CopyCount;
- }
- TargetFile.Flush();
+
+ CopyFileOptions Options;
+ CopyFile(Source, Target, Options);
}
static bool
@@ -574,8 +562,11 @@ TryCopy(const std::filesystem::path& Source, const std::filesystem::path& Target
{
return false;
}
- Copy(Source, Target);
- return true;
+
+ CreateDirectories(Target.parent_path());
+
+ CopyFileOptions Options;
+ return CopyFile(Source, Target, Options);
}
int
@@ -630,6 +621,8 @@ CopyStateCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
std::filesystem::path BucketName = BucketPath.filename();
std::filesystem::path TargetBucketPath = TargetNamespacePath / BucketName;
+ // TODO: make these use file naming helpers from cache implementation?
+
std::filesystem::path ManifestPath = BucketPath / "zen_manifest";
std::filesystem::path TargetManifestPath = TargetBucketPath / "zen_manifest";
if (TryCopy(ManifestPath, TargetManifestPath))
@@ -646,6 +639,11 @@ CopyStateCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
std::filesystem::path IndexPath = BucketPath / IndexName;
std::filesystem::path TargetIndexPath = TargetBucketPath / IndexName;
TryCopy(IndexPath, TargetIndexPath);
+
+ std::filesystem::path MetaName = fmt::format("{}.{}", BucketName.string(), "meta");
+ std::filesystem::path MetaPath = BucketPath / MetaName;
+ std::filesystem::path TargetMetaPath = TargetBucketPath / MetaName;
+ TryCopy(MetaPath, TargetMetaPath);
}
}
}