diff options
| author | Martin Ridgers <[email protected]> | 2024-09-12 13:11:56 +0200 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2024-09-19 15:26:13 +0200 |
| commit | 1107d22721223de03ac2ab33f641ad1bfec1f156 (patch) | |
| tree | b0e8e1a3f28e335885357b7404ef7d17ed0edab8 /src | |
| parent | Added brief section on building for macOS with multiple users (diff) | |
| download | zen-1107d22721223de03ac2ab33f641ad1bfec1f156.tar.xz zen-1107d22721223de03ac2ab33f641ad1bfec1f156.zip | |
Optional paged results when iterating oplog entries
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 24 | ||||
| -rw-r--r-- | src/zenserver/projectstore/projectstore.h | 10 |
2 files changed, 28 insertions, 6 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index a34f2f4d5..d47b4e50b 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -2032,14 +2032,14 @@ ProjectStore::Oplog::IterateFileMap( } void -ProjectStore::Oplog::IterateOplog(std::function<void(CbObjectView)>&& Handler) +ProjectStore::Oplog::IterateOplog(std::function<void(CbObjectView)>&& Handler, const Paging& EntryPaging) { RwLock::SharedLockScope _(m_OplogLock); - IterateOplogLocked(std::move(Handler)); + IterateOplogLocked(std::move(Handler), EntryPaging); } void -ProjectStore::Oplog::IterateOplogLocked(std::function<void(CbObjectView)>&& Handler) +ProjectStore::Oplog::IterateOplogLocked(std::function<void(CbObjectView)>&& Handler, const Paging& EntryPaging) { ZEN_TRACE_CPU("Store::Oplog::IterateOplogLocked"); if (!m_Storage) @@ -2062,7 +2062,23 @@ ProjectStore::Oplog::IterateOplogLocked(std::function<void(CbObjectView)>&& Hand return Lhs.Offset < Rhs.Offset; }); - m_Storage->ReplayLogEntries(Entries, [&](CbObjectView Op) { Handler(Op); }); + std::span<OplogEntryAddress> EntrySpan; + if (EntryPaging.Start >= 0 || EntryPaging.Count >= 0) + { + int32_t Indices[2] = {EntryPaging.Start, EntryPaging.Start + EntryPaging.Count}; + for (int32_t& Index : Indices) + { + Index = std::max<int32_t>(0, Index); + Index = std::min<int32_t>(Index, int32_t(Entries.size())); + } + EntrySpan = decltype(EntrySpan)(Entries.begin() + Indices[0], Indices[1] - Indices[0]); + } + else + { + EntrySpan = Entries; + } + + m_Storage->ReplayLogEntries(EntrySpan, [&](CbObjectView Op) { Handler(Op); }); } static constexpr uint32_t OplogMetaDataExpectedMagic = 0x6f'74'6d'62; // 'omta'; diff --git a/src/zenserver/projectstore/projectstore.h b/src/zenserver/projectstore/projectstore.h index 7d969874d..c001293a9 100644 --- a/src/zenserver/projectstore/projectstore.h +++ b/src/zenserver/projectstore/projectstore.h @@ -95,12 +95,18 @@ public: uint64_t ChunkSize; }; + struct Paging + { + int32_t Start = -1; + int32_t Count = -1; + }; + std::vector<ChunkInfo> GetAllChunksInfo(); void IterateChunkMap(std::function<void(const Oid&, const IoHash& Hash)>&& Fn); void IterateFileMap(std::function<void(const Oid&, const std::string_view& ServerPath, const std::string_view& ClientPath)>&& Fn); - void IterateOplog(std::function<void(CbObjectView)>&& Fn); + void IterateOplog(std::function<void(CbObjectView)>&& Fn, const Paging& EntryPaging = {}); void IterateOplogWithKey(std::function<void(uint32_t, const Oid&, CbObjectView)>&& Fn); - void IterateOplogLocked(std::function<void(CbObjectView)>&& Fn); + void IterateOplogLocked(std::function<void(CbObjectView)>&& Fn, const Paging& EntryPaging = {}); size_t GetOplogEntryCount() const; std::optional<CbObject> GetOpByKey(const Oid& Key); |