aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-03-06 12:39:06 +0100
committerGitHub Enterprise <[email protected]>2026-03-06 12:39:06 +0100
commit5115b419cefd41e8d5cc465c8c7ae5140cde71d4 (patch)
treec97f8d658fa0ec24664264b97327120f2c30bd7f /src/zenstore/include
parentClaude config, some bug fixes (#813) (diff)
downloadzen-5115b419cefd41e8d5cc465c8c7ae5140cde71d4.tar.xz
zen-5115b419cefd41e8d5cc465c8c7ae5140cde71d4.zip
zenstore bug-fixes from static analysis pass (#815)
**Bug fixes across zenstore, zenremotestore, and related subsystems, primarily surfaced by static analysis.** ## Cache subsystem (cachedisklayer.cpp) - Fixed tombstone scoping bug: tombstone flag and missing entry were recorded outside the block where data was removed, causing non-missing entries to be incorrectly tombstoned - Fixed use-after-overwrite: `RemoveMemCachedData`/`RemoveMetaData` were called after `Payload` was overwritten on cache put, leaking stale data - Fixed incorrect retry sleep formula (`100 - (3 - RetriesLeft) * 100` always produced the same or negative value; corrected to `(3 - RetriesLeft) * 100`) - Fixed broken `break` missing from sidecar file read loop, causing reads past valid data - Fixed missing format argument in three `ZEN_WARN`/`ZEN_ERROR` log calls (format string had `{}` placeholders with no corresponding argument, or vice versa) - Fixed elapsed timer being accumulated inside the wrong scope in `HandleRpcGetCacheRecords` - Fixed test asserting against unserialized `RecordPolicy` instead of the deserialized `Loaded` copy - Initialized `AbortFlag`/`PauseFlag` atomics at declaration (UB if read before first write) ## Build store (buildstore.cpp / buildstore.h) - Fixed wrong variable used in warning log: used loop index `ResultIndex` instead of `Index`/`MetaLocationResultIndexes[Index]`, logging wrong hash values - Fixed `sizeof(AccessTimesHeader)` used instead of `sizeof(AccessTimeRecord)` when advancing write offset, corrupting the access times file if the sizes differ - Initialized `m_LastAccessTimeUpdateCount` atomic member (was uninitialized) - Changed map iteration loops to use `const auto&` to avoid unnecessary copies ## Project store (projectstore.cpp / projectstore.h) - Fixed wrong iterator dereferenced in `IterateChunks`: used `ChunkIt->second` (from a different map lookup) instead of `MetaIt->second` - Fixed wrong assert variable: `Sizes[Index]` should be `RawSizes[Index]` - Fixed `MakeTombstone`/`IsTombstone` inconsistency: `MakeTombstone` was zeroing `OpLsn` but `IsTombstone` checks `OpLsn.Number != 0`; tombstone creation now preserves `OpLsn` - Fixed uninitialized `InvalidEntries` counter - Fixed format string mismatch in warning log - Initialized `AbortFlag`/`PauseFlag` atomics; changed map iteration to `const auto&` ## Workspaces (workspaces.cpp) - Fixed missing alias registration when a workspace share is updated: alias was deleted but never re-inserted - Fixed integer overflow in range clamping: `(RequestedOffset + RequestedSize) > Size` could wrap; corrected to `RequestedSize > Size - RequestedOffset` - Changed map iteration loops to `const auto&` ## CAS subsystem (cas.cpp, caslog.cpp, compactcas.cpp, filecas.cpp) - Fixed `IterateChunks` passing original `Payload` buffer instead of the modified `Chunk` buffer (content type was set on the copy but the original was sent to the callback) - Fixed invalid `std::future::get()` call on default-constructed futures - Fixed sign-comparison in `CasLogFile::Replay` loop (`int i` vs `size_t`) - Changed `CasLogFile::IsValid` and `Open` to take `const std::filesystem::path&` instead of by value - Fixed format string in `~CasContainerStrategy` error log ## Remote store (zenremotestore) - Fixed `FolderContent::operator==` always returning true: loop variable `PathCount` was initialized to 0 instead of `Paths.size()` - Fixed `GetChunkIndexForRawHash` looking up from wrong map (`RawHashToSequenceIndex` instead of `ChunkHashToChunkIndex`) - Fixed double-counted `UniqueSequencesFound` stat (incremented in both branches of an if/else) - Fixed `RawSize` sentinel value truncation: `(uint32_t)-1` assigned to a `uint64_t` field; corrected to `(uint64_t)-1` - Initialized uninitialized atomic and struct members across `buildstorageoperations.h`, `chunkblock.h`, and `remoteprojectstore.h`
Diffstat (limited to 'src/zenstore/include')
-rw-r--r--src/zenstore/include/zenstore/buildstore/buildstore.h2
-rw-r--r--src/zenstore/include/zenstore/cache/cachedisklayer.h34
-rw-r--r--src/zenstore/include/zenstore/cache/cacheshared.h6
-rw-r--r--src/zenstore/include/zenstore/cache/structuredcachestore.h12
-rw-r--r--src/zenstore/include/zenstore/caslog.h10
-rw-r--r--src/zenstore/include/zenstore/gc.h6
-rw-r--r--src/zenstore/include/zenstore/projectstore.h10
7 files changed, 38 insertions, 42 deletions
diff --git a/src/zenstore/include/zenstore/buildstore/buildstore.h b/src/zenstore/include/zenstore/buildstore/buildstore.h
index bfc83ba0d..ea2ef7f89 100644
--- a/src/zenstore/include/zenstore/buildstore/buildstore.h
+++ b/src/zenstore/include/zenstore/buildstore/buildstore.h
@@ -223,7 +223,7 @@ private:
uint64_t m_MetaLogFlushPosition = 0;
std::unique_ptr<std::vector<IoHash>> m_TrackedBlobKeys;
- std::atomic<uint64_t> m_LastAccessTimeUpdateCount;
+ std::atomic<uint64_t> m_LastAccessTimeUpdateCount{0};
friend class BuildStoreGcReferenceChecker;
friend class BuildStoreGcReferencePruner;
diff --git a/src/zenstore/include/zenstore/cache/cachedisklayer.h b/src/zenstore/include/zenstore/cache/cachedisklayer.h
index 3d684587d..393e289ac 100644
--- a/src/zenstore/include/zenstore/cache/cachedisklayer.h
+++ b/src/zenstore/include/zenstore/cache/cachedisklayer.h
@@ -153,14 +153,14 @@ public:
struct BucketStats
{
- uint64_t DiskSize;
- uint64_t MemorySize;
- uint64_t DiskHitCount;
- uint64_t DiskMissCount;
- uint64_t DiskWriteCount;
- uint64_t MemoryHitCount;
- uint64_t MemoryMissCount;
- uint64_t MemoryWriteCount;
+ uint64_t DiskSize = 0;
+ uint64_t MemorySize = 0;
+ uint64_t DiskHitCount = 0;
+ uint64_t DiskMissCount = 0;
+ uint64_t DiskWriteCount = 0;
+ uint64_t MemoryHitCount = 0;
+ uint64_t MemoryMissCount = 0;
+ uint64_t MemoryWriteCount = 0;
metrics::RequestStatsSnapshot PutOps;
metrics::RequestStatsSnapshot GetOps;
};
@@ -174,8 +174,8 @@ public:
struct DiskStats
{
std::vector<NamedBucketStats> BucketStats;
- uint64_t DiskSize;
- uint64_t MemorySize;
+ uint64_t DiskSize = 0;
+ uint64_t MemorySize = 0;
};
struct PutResult
@@ -395,12 +395,12 @@ public:
TCasLogFile<DiskIndexEntry> m_SlogFile;
uint64_t m_LogFlushPosition = 0;
- std::atomic<uint64_t> m_DiskHitCount;
- std::atomic<uint64_t> m_DiskMissCount;
- std::atomic<uint64_t> m_DiskWriteCount;
- std::atomic<uint64_t> m_MemoryHitCount;
- std::atomic<uint64_t> m_MemoryMissCount;
- std::atomic<uint64_t> m_MemoryWriteCount;
+ std::atomic<uint64_t> m_DiskHitCount{0};
+ std::atomic<uint64_t> m_DiskMissCount{0};
+ std::atomic<uint64_t> m_DiskWriteCount{0};
+ std::atomic<uint64_t> m_MemoryHitCount{0};
+ std::atomic<uint64_t> m_MemoryMissCount{0};
+ std::atomic<uint64_t> m_MemoryWriteCount{0};
metrics::RequestStats m_PutOps;
metrics::RequestStats m_GetOps;
@@ -540,7 +540,7 @@ private:
Configuration m_Configuration;
std::atomic_uint64_t m_TotalMemCachedSize{};
std::atomic_bool m_IsMemCacheTrimming = false;
- std::atomic<GcClock::Tick> m_NextAllowedTrimTick;
+ std::atomic<GcClock::Tick> m_NextAllowedTrimTick{};
mutable RwLock m_Lock;
BucketMap_t m_Buckets;
std::vector<std::unique_ptr<CacheBucket>> m_DroppedBuckets;
diff --git a/src/zenstore/include/zenstore/cache/cacheshared.h b/src/zenstore/include/zenstore/cache/cacheshared.h
index 791720589..8e9cd7fd7 100644
--- a/src/zenstore/include/zenstore/cache/cacheshared.h
+++ b/src/zenstore/include/zenstore/cache/cacheshared.h
@@ -40,12 +40,12 @@ struct CacheValueDetails
{
struct ValueDetails
{
- uint64_t Size;
- uint64_t RawSize;
+ uint64_t Size = 0;
+ uint64_t RawSize = 0;
IoHash RawHash;
GcClock::Tick LastAccess{};
std::vector<IoHash> Attachments;
- ZenContentType ContentType;
+ ZenContentType ContentType = ZenContentType::kBinary;
};
struct BucketDetails
diff --git a/src/zenstore/include/zenstore/cache/structuredcachestore.h b/src/zenstore/include/zenstore/cache/structuredcachestore.h
index 5a0a8b069..3722a0d31 100644
--- a/src/zenstore/include/zenstore/cache/structuredcachestore.h
+++ b/src/zenstore/include/zenstore/cache/structuredcachestore.h
@@ -70,9 +70,9 @@ public:
struct NamespaceStats
{
- uint64_t HitCount;
- uint64_t MissCount;
- uint64_t WriteCount;
+ uint64_t HitCount = 0;
+ uint64_t MissCount = 0;
+ uint64_t WriteCount = 0;
metrics::RequestStatsSnapshot PutOps;
metrics::RequestStatsSnapshot GetOps;
ZenCacheDiskLayer::DiskStats DiskStats;
@@ -342,11 +342,11 @@ private:
void LogWorker();
RwLock m_LogQueueLock;
std::vector<AccessLogItem> m_LogQueue;
- std::atomic_bool m_ExitLogging;
+ std::atomic_bool m_ExitLogging{false};
Event m_LogEvent;
std::thread m_AsyncLoggingThread;
- std::atomic_bool m_WriteLogEnabled;
- std::atomic_bool m_AccessLogEnabled;
+ std::atomic_bool m_WriteLogEnabled{false};
+ std::atomic_bool m_AccessLogEnabled{false};
friend class CacheStoreReferenceChecker;
};
diff --git a/src/zenstore/include/zenstore/caslog.h b/src/zenstore/include/zenstore/caslog.h
index f3dd32fb1..7967d9dae 100644
--- a/src/zenstore/include/zenstore/caslog.h
+++ b/src/zenstore/include/zenstore/caslog.h
@@ -20,8 +20,8 @@ public:
kTruncate
};
- static bool IsValid(std::filesystem::path FileName, size_t RecordSize);
- void Open(std::filesystem::path FileName, size_t RecordSize, Mode Mode);
+ static bool IsValid(const std::filesystem::path& FileName, size_t RecordSize);
+ void Open(const std::filesystem::path& FileName, size_t RecordSize, Mode Mode);
void Append(const void* DataPointer, uint64_t DataSize);
void Replay(std::function<void(const void*)>&& Handler, uint64_t SkipEntryCount);
void Flush();
@@ -48,7 +48,7 @@ private:
static_assert(sizeof(FileHeader) == 64);
private:
- void Open(std::filesystem::path FileName, size_t RecordSize, BasicFile::Mode Mode);
+ void Open(const std::filesystem::path& FileName, size_t RecordSize, BasicFile::Mode Mode);
BasicFile m_File;
FileHeader m_Header;
@@ -60,8 +60,8 @@ template<typename T>
class TCasLogFile : public CasLogFile
{
public:
- static bool IsValid(std::filesystem::path FileName) { return CasLogFile::IsValid(FileName, sizeof(T)); }
- void Open(std::filesystem::path FileName, Mode Mode) { CasLogFile::Open(FileName, sizeof(T), Mode); }
+ static bool IsValid(const std::filesystem::path& FileName) { return CasLogFile::IsValid(FileName, sizeof(T)); }
+ void Open(const std::filesystem::path& FileName, Mode Mode) { CasLogFile::Open(FileName, sizeof(T), Mode); }
// This should be called before the Replay() is called to do some basic sanity checking
bool Initialize() { return true; }
diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h
index 794f50d96..67cf852f9 100644
--- a/src/zenstore/include/zenstore/gc.h
+++ b/src/zenstore/include/zenstore/gc.h
@@ -443,8 +443,8 @@ struct GcSchedulerState
uint64_t DiskFree = 0;
GcClock::TimePoint LastFullGcTime{};
GcClock::TimePoint LastLightweightGcTime{};
- std::chrono::seconds RemainingTimeUntilLightweightGc;
- std::chrono::seconds RemainingTimeUntilFullGc;
+ std::chrono::seconds RemainingTimeUntilLightweightGc{};
+ std::chrono::seconds RemainingTimeUntilFullGc{};
uint64_t RemainingSpaceUntilFullGC = 0;
std::chrono::milliseconds LastFullGcDuration{};
@@ -562,7 +562,7 @@ private:
GcClock::TimePoint m_LastGcExpireTime{};
IoHash m_LastFullAttachmentRangeMin = IoHash::Zero;
IoHash m_LastFullAttachmentRangeMax = IoHash::Max;
- uint8_t m_AttachmentPassIndex;
+ uint8_t m_AttachmentPassIndex = 0;
std::chrono::milliseconds m_LastFullGcDuration{};
GcStorageSize m_LastFullGCDiff;
diff --git a/src/zenstore/include/zenstore/projectstore.h b/src/zenstore/include/zenstore/projectstore.h
index 33ef996db..6f49cd024 100644
--- a/src/zenstore/include/zenstore/projectstore.h
+++ b/src/zenstore/include/zenstore/projectstore.h
@@ -67,8 +67,8 @@ public:
struct OplogEntryAddress
{
- uint32_t Offset; // note: Multiple of m_OpsAlign!
- uint32_t Size;
+ uint32_t Offset = 0; // note: Multiple of m_OpsAlign!
+ uint32_t Size = 0;
};
struct OplogEntry
@@ -80,11 +80,7 @@ public:
uint32_t Reserved;
inline bool IsTombstone() const { return OpCoreAddress.Offset == 0 && OpCoreAddress.Size == 0 && OpLsn.Number; }
- inline void MakeTombstone()
- {
- OpLsn = {};
- OpCoreAddress.Offset = OpCoreAddress.Size = OpCoreHash = Reserved = 0;
- }
+ inline void MakeTombstone() { OpCoreAddress.Offset = OpCoreAddress.Size = OpCoreHash = Reserved = 0; }
};
static_assert(IsPow2(sizeof(OplogEntry)));