aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-23 12:53:01 +0200
committerStefan Boberg <[email protected]>2021-05-23 12:53:01 +0200
commit43d5878bfad6313fd6f2a5c55bbfd34a90806bb9 (patch)
tree8ba62c8f7ccb3968a90e40badbc39d8aca5d85d9 /zenserver/cache/structuredcachestore.cpp
parentAdded content type to IoBuffer payloads from http server (diff)
downloadzen-43d5878bfad6313fd6f2a5c55bbfd34a90806bb9.tar.xz
zen-43d5878bfad6313fd6f2a5c55bbfd34a90806bb9.zip
Changed to tsl::robin_map
Also added initial logic around attachment indexing (tactical check-in to continue on other computer)
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index eb3b5d13d..3fd9f5ec4 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -5,6 +5,7 @@
#include <zencore/except.h>
#include <zencore/windows.h>
+#include <zencore/compactbinary.h>
#include <zencore/filesystem.h>
#include <zencore/fmtutils.h>
#include <zencore/iobuffer.h>
@@ -46,12 +47,10 @@ ZenCacheStore::Get(std::string_view InBucket, const zen::IoHash& HashKey, ZenCac
{
Ok = m_DiskLayer.Get(InBucket, HashKey, OutValue);
-#if 0 // This would keep file handles open
- if (ok)
+ if (Ok && (OutValue.Value.Size() <= m_DiskLayerSizeThreshold))
{
- m_memLayer.Put(InBucket, HashKey, OutValue);
+ m_MemLayer.Put(InBucket, HashKey, OutValue);
}
-#endif
}
return Ok;
@@ -60,8 +59,23 @@ ZenCacheStore::Get(std::string_view InBucket, const zen::IoHash& HashKey, ZenCac
void
ZenCacheStore::Put(std::string_view InBucket, const zen::IoHash& HashKey, const ZenCacheValue& Value)
{
- m_MemLayer.Put(InBucket, HashKey, Value);
+ if (Value.Value.Size() <= m_DiskLayerSizeThreshold)
+ {
+ m_MemLayer.Put(InBucket, HashKey, Value);
+ }
+
m_DiskLayer.Put(InBucket, HashKey, Value);
+
+ if (Value.IsCompactBinary)
+ {
+ zen::CbObject Cbo(SharedBuffer(Value.Value));
+
+ std::vector<IoHash> ReferencedChunks;
+
+ Cbo.IterateAttachments([&](CbFieldView AttachmentView) { ReferencedChunks.push_back(AttachmentView.AsHash()); });
+
+ // TODO: store references in index
+ }
}
//////////////////////////////////////////////////////////////////////////
@@ -201,9 +215,9 @@ private:
void BuildPath(zen::WideStringBuilderBase& Path, const zen::IoHash& HashKey);
void PutLargeObject(const zen::IoHash& HashKey, const ZenCacheValue& Value);
- RwLock m_IndexLock;
- std::unordered_map<zen::IoHash, DiskLocation, zen::IoHash::Hasher> m_Index;
- uint64_t m_WriteCursor = 0;
+ RwLock m_IndexLock;
+ tsl::robin_map<zen::IoHash, DiskLocation, zen::IoHash::Hasher> m_Index;
+ uint64_t m_WriteCursor = 0;
};
ZenCacheDiskLayer::CacheBucket::CacheBucket(CasStore& Cas) : m_CasStore(Cas)
@@ -376,7 +390,7 @@ ZenCacheDiskLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheVa
else
{
// TODO: should check if write is idempotent and bail out if it is?
- it->second = Loc;
+ it.value() = Loc;
}
m_SlogFile.Append({.Key = HashKey, .Location = Loc});