diff options
| author | Stefan Boberg <[email protected]> | 2023-05-16 21:35:39 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-16 21:35:39 +0200 |
| commit | 81b2757f917e34bb338fad7965ae8a74e160bee4 (patch) | |
| tree | 931ba100471a2369c62a6e41a1b4a7937ed31f6f /src/zenstore/scrubcontext.cpp | |
| parent | added benchmark utility command `bench` (#298) (diff) | |
| download | zen-81b2757f917e34bb338fad7965ae8a74e160bee4.tar.xz zen-81b2757f917e34bb338fad7965ae8a74e160bee4.zip | |
Content scrubbing (#271)
Added zen scrub command which may be triggered via the zen CLI helper. This traverses storage and validates contents either by content hash and/or by structure. If unexpected data is encountered it is invalidated.
Diffstat (limited to 'src/zenstore/scrubcontext.cpp')
| -rw-r--r-- | src/zenstore/scrubcontext.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/zenstore/scrubcontext.cpp b/src/zenstore/scrubcontext.cpp index f35178de6..f5a3784c3 100644 --- a/src/zenstore/scrubcontext.cpp +++ b/src/zenstore/scrubcontext.cpp @@ -6,7 +6,19 @@ namespace zen { -ScrubContext::ScrubContext() +ScrubDeadlineExpiredException::ScrubDeadlineExpiredException() : std::runtime_error("scrubbing deadline expired") +{ +} + +ScrubDeadlineExpiredException::~ScrubDeadlineExpiredException() +{ +} + +////////////////////////////////////////////////////////////////////////// + +ScrubContext::ScrubContext(WorkerThreadPool& InWorkerThreadPool, std::chrono::steady_clock::time_point Deadline) +: m_WorkerThreadPool(InWorkerThreadPool) +, m_Deadline(Deadline) { } @@ -14,4 +26,33 @@ ScrubContext::~ScrubContext() { } -} // namespace zen
\ No newline at end of file +HashKeySet +ScrubContext::BadCids() const +{ + RwLock::SharedLockScope _(m_Lock); + return m_BadCid; +} + +void +ScrubContext::ReportBadCidChunks(std::span<IoHash> BadCasChunks) +{ + RwLock::ExclusiveLockScope _(m_Lock); + m_BadCid.AddHashesToSet(BadCasChunks); +} + +bool +ScrubContext::IsWithinDeadline() const +{ + return std::chrono::steady_clock::now() < m_Deadline; +} + +void +ScrubContext::ThrowIfDeadlineExpired() const +{ + if (IsWithinDeadline()) + return; + + throw ScrubDeadlineExpiredException(); +} + +} // namespace zen |