aboutsummaryrefslogtreecommitdiff
path: root/zenstore/CAS.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-10-19 18:42:08 +0200
committerStefan Boberg <[email protected]>2021-10-19 18:42:08 +0200
commit3079a9e9b10c172bdabd3b68b2d44933f0dfda6f (patch)
treeeccc40c8c970524add544db631e1da3679c54cf1 /zenstore/CAS.cpp
parentMerge branch 'main' into gc (diff)
downloadzen-3079a9e9b10c172bdabd3b68b2d44933f0dfda6f.tar.xz
zen-3079a9e9b10c172bdabd3b68b2d44933f0dfda6f.zip
cas: Factored out OpenOrCreateManifest
Diffstat (limited to 'zenstore/CAS.cpp')
-rw-r--r--zenstore/CAS.cpp94
1 files changed, 49 insertions, 45 deletions
diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp
index a71e251e5..7ec91cfa5 100644
--- a/zenstore/CAS.cpp
+++ b/zenstore/CAS.cpp
@@ -118,6 +118,7 @@ private:
StorageScheme m_StorageScheme = StorageScheme::Legacy;
+ bool OpenOrCreateManifest();
void UpdateManifest(bool IsNewStore);
};
@@ -141,72 +142,75 @@ CasImpl::Initialize(const CasStoreConfiguration& InConfig)
std::filesystem::create_directories(m_Config.RootDirectory);
// Open or create manifest
- //
- // The manifest is not currently fully implemented. The goal is to
- // use it for recovery and configuration
+ const bool IsNewStore = OpenOrCreateManifest();
+
+ // Initialize payload storage
+
+ m_TinyStrategy.Initialize("tobs", 16, IsNewStore);
+ m_SmallStrategy.Initialize("sobs", 4096, IsNewStore);
+}
+
+bool
+CasImpl::OpenOrCreateManifest()
+{
bool IsNewStore = false;
- {
- std::filesystem::path ManifestPath = m_Config.RootDirectory;
- ManifestPath /= ".ucas_root";
+ std::filesystem::path ManifestPath = m_Config.RootDirectory;
+ ManifestPath /= ".ucas_root";
- std::error_code Ec;
- BasicFile ManifestFile;
- ManifestFile.Open(ManifestPath.c_str(), /* IsCreate */ false, Ec);
+ std::error_code Ec;
+ BasicFile ManifestFile;
+ ManifestFile.Open(ManifestPath.c_str(), /* IsCreate */ false, Ec);
- bool ManifestIsOk = false;
+ bool ManifestIsOk = false;
- if (Ec)
+ if (Ec)
+ {
+ if (Ec == std::errc::no_such_file_or_directory)
{
- if (Ec == std::errc::no_such_file_or_directory)
- {
- IsNewStore = true;
- }
+ IsNewStore = true;
+ }
+ }
+ else
+ {
+ IoBuffer ManifestBuffer = ManifestFile.ReadAll();
+ ManifestFile.Close();
+
+ if (ManifestBuffer.Size() > 0 && ManifestBuffer.Data<uint8_t>()[0] == '#')
+ {
+ // Old-style manifest, does not contain any useful information, so we may as well update it
}
else
{
- IoBuffer ManifestBuffer = ManifestFile.ReadAll();
- ManifestFile.Close();
+ CbObject Manifest{SharedBuffer(ManifestBuffer)};
+ CbValidateError ValidationResult = ValidateCompactBinary(ManifestBuffer, CbValidateMode::All);
- if (ManifestBuffer.Size() > 0 && ManifestBuffer.Data<uint8_t>()[0] == '#')
+ if (ValidationResult == CbValidateError::None)
{
- // Old-style manifest, does not contain any useful information, so we may as well update it
+ if (Manifest["id"])
+ {
+ ManifestIsOk = true;
+ }
}
else
{
- CbObject Manifest{SharedBuffer(ManifestBuffer)};
- CbValidateError ValidationResult = ValidateCompactBinary(ManifestBuffer, CbValidateMode::All);
-
- if (ValidationResult == CbValidateError::None)
- {
- if (Manifest["id"])
- {
- ManifestIsOk = true;
- }
- }
- else
- {
- ZEN_ERROR("Store manifest validation failed: {:#x}, will generate new manifest to recover", ValidationResult);
- }
-
- if (ManifestIsOk)
- {
- m_ManifestObject = std::move(Manifest);
- }
+ ZEN_ERROR("Store manifest validation failed: {:#x}, will generate new manifest to recover", ValidationResult);
}
- }
- if (!ManifestIsOk)
- {
- UpdateManifest(true);
+ if (ManifestIsOk)
+ {
+ m_ManifestObject = std::move(Manifest);
+ }
}
}
- // Initialize payload storage
+ if (!ManifestIsOk)
+ {
+ UpdateManifest(true);
+ }
- m_TinyStrategy.Initialize("tobs", 16, IsNewStore);
- m_SmallStrategy.Initialize("sobs", 4096, IsNewStore);
+ return IsNewStore;
}
void