aboutsummaryrefslogtreecommitdiff
path: root/zenstore/CAS.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-10-19 13:27:13 +0200
committerStefan Boberg <[email protected]>2021-10-19 13:27:13 +0200
commit8e97a98bb73228c6c0bc041d9bf758d2417a62dd (patch)
treed609c141efe65938f14bdce592a923508b12fcb1 /zenstore/CAS.cpp
parentgc: moved GcContect from CAS into gc files (diff)
downloadzen-8e97a98bb73228c6c0bc041d9bf758d2417a62dd.tar.xz
zen-8e97a98bb73228c6c0bc041d9bf758d2417a62dd.zip
cas: added structured manifest support
Diffstat (limited to 'zenstore/CAS.cpp')
-rw-r--r--zenstore/CAS.cpp55
1 files changed, 47 insertions, 8 deletions
diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp
index 807bba3b3..a43759283 100644
--- a/zenstore/CAS.cpp
+++ b/zenstore/CAS.cpp
@@ -14,6 +14,9 @@
#include <zencore/testutils.h>
#include <zencore/thread.h>
#include <zencore/uid.h>
+#include <zencore/compactbinary.h>
+#include <zencore/compactbinarybuilder.h>
+#include <zencore/compactbinaryvalidation.h>
#include <gsl/gsl-lite.hpp>
@@ -105,6 +108,15 @@ private:
CasContainerStrategy m_TinyStrategy;
CasContainerStrategy m_SmallStrategy;
FileCasStrategy m_LargeStrategy;
+ CbObject m_ManifestObject;
+
+ enum class StorageScheme
+ {
+ Legacy = 0,
+ WithCbManifest = 1
+ };
+
+ StorageScheme m_StorageScheme = StorageScheme::Legacy;
};
CasImpl::CasImpl() : m_TinyStrategy(m_Config), m_SmallStrategy(m_Config), m_LargeStrategy(m_Config)
@@ -143,16 +155,43 @@ CasImpl::Initialize(const CasStoreConfiguration& InConfig)
if (Ec)
{
- IsNewStore = true;
+ if (Ec == std::errc::no_such_file_or_directory)
+ {
+ IsNewStore = true;
+
+ CbObjectWriter Cbo;
+
+ Cbo << "id" << zen::Oid::NewOid();
- ExtendableStringBuilder<128> manifest;
- manifest.Append("#CAS_ROOT\n");
- manifest.Append("ID=");
- zen::Oid id = zen::Oid::NewOid();
- id.ToString(manifest);
+ Marker.Open(ManifestPath.c_str(), /* IsCreate */ true);
+ m_ManifestObject = Cbo.Save();
- Marker.Open(ManifestPath.c_str(), /* IsCreate */ true);
- Marker.Write(manifest.c_str(), (DWORD)manifest.Size(), 0);
+ Marker.Write(m_ManifestObject.GetBuffer(), 0);
+ }
+ }
+ else
+ {
+ IoBuffer ManifestBuffer = Marker.ReadAll();
+
+ 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?)
+ m_StorageScheme = StorageScheme::Legacy;
+ }
+ else
+ {
+ CbObject Manifest{SharedBuffer(ManifestBuffer)};
+ CbValidateError ValidationResult = ValidateCompactBinary(ManifestBuffer, CbValidateMode::All);
+
+ if (ValidationResult == CbValidateError::None)
+ {
+ m_ManifestObject = std::move(Manifest);
+ }
+ else
+ {
+ ZEN_ERROR("Store manifest validation failed: {:#x}", ValidationResult);
+ }
+ }
}
}