aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-09-08 10:54:31 +0200
committerGitHub <[email protected]>2022-09-08 01:54:31 -0700
commit033e742c5102df67c000e2b281152fd37f59afb3 (patch)
treea395e3b22d94b890148745eeff796550f8e3a411
parent0.1.4-pre27 (diff)
downloadzen-033e742c5102df67c000e2b281152fd37f59afb3.tar.xz
zen-033e742c5102df67c000e2b281152fd37f59afb3.zip
Remove legacy code (#161)
* changelog * remove obsolete legacy code
-rw-r--r--CHANGELOG.md2
-rw-r--r--zenserver/cache/structuredcachestore.h22
-rw-r--r--zenstore/blockstore.cpp211
-rw-r--r--zenstore/include/zenstore/blockstore.h10
4 files changed, 11 insertions, 234 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0951e703a..ecbb3a108 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,5 @@
##
-- Change: Bumped ZEN_SCHEMA_VERSION - this will invalidate intire local cache when deployed
+- Change: Bumped ZEN_SCHEMA_VERSION - this will invalidate entire local cache when deployed
- Change: Make CAS storage an hidden implementation detail of CidStore, we no longer hash and do mapping to compressed hash when storing cache values
- Feature: Extended zen print command to also handle CbPackage and CompressedBuffer format payloads
- Feature: Added /prj/{project}/oplog/{log}/{op} endpoint to allow retrieval of an op entry by LSN. Supports returning CbObject or CbPackage format payloads
diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h
index b81e44835..8812556c1 100644
--- a/zenserver/cache/structuredcachestore.h
+++ b/zenserver/cache/structuredcachestore.h
@@ -291,18 +291,16 @@ private:
std::atomic_uint64_t m_TotalSize{};
- void BuildPath(PathBuilderBase& Path, const IoHash& HashKey);
- void PutStandaloneCacheValue(const IoHash& HashKey, const ZenCacheValue& Value);
- bool GetStandaloneCacheValue(const DiskLocation& Loc, const IoHash& HashKey, ZenCacheValue& OutValue);
- void PutInlineCacheValue(const IoHash& HashKey, const ZenCacheValue& Value);
- bool GetInlineCacheValue(const DiskLocation& Loc, ZenCacheValue& OutValue);
- void MakeIndexSnapshot();
- uint64_t ReadIndexFile();
- uint64_t ReadLog(uint64_t LogPosition);
- uint64_t MigrateLegacyData(bool CleanSource);
- void OpenLog(const std::filesystem::path& BucketDir, const bool IsNew);
- static bool Delete(std::filesystem::path BucketDir);
- void SaveManifest();
+ void BuildPath(PathBuilderBase& Path, const IoHash& HashKey);
+ void PutStandaloneCacheValue(const IoHash& HashKey, const ZenCacheValue& Value);
+ bool GetStandaloneCacheValue(const DiskLocation& Loc, const IoHash& HashKey, ZenCacheValue& OutValue);
+ void PutInlineCacheValue(const IoHash& HashKey, const ZenCacheValue& Value);
+ bool GetInlineCacheValue(const DiskLocation& Loc, ZenCacheValue& OutValue);
+ void MakeIndexSnapshot();
+ uint64_t ReadIndexFile();
+ uint64_t ReadLog(uint64_t LogPosition);
+ void OpenLog(const std::filesystem::path& BucketDir, const bool IsNew);
+ void SaveManifest();
// These locks are here to avoid contention on file creation, therefore it's sufficient
// that we take the same lock for the same hash
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index 88592d785..38371124d 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -718,217 +718,6 @@ BlockStore::IterateChunks(const std::vector<BlockStoreLocation>& ChunkLocations,
}
}
-bool
-BlockStore::Split(const std::vector<BlockStoreLocation>& ChunkLocations,
- const std::filesystem::path& SourceBlockFilePath,
- const std::filesystem::path& BlocksBasePath,
- uint64_t MaxBlockSize,
- uint64_t MaxBlockCount,
- size_t PayloadAlignment,
- bool CleanSource,
- const SplitCallback& Callback)
-{
- std::error_code Error;
- DiskSpace Space = DiskSpaceInfo(BlocksBasePath.parent_path(), Error);
- if (Error)
- {
- ZEN_ERROR("get disk space in {} FAILED, reason: '{}'", BlocksBasePath, Error.message());
- return false;
- }
-
- if (Space.Free < MaxBlockSize)
- {
- ZEN_ERROR("legacy store migration from '{}' FAILED, required disk space {}, free {}",
- BlocksBasePath,
- MaxBlockSize,
- NiceBytes(Space.Free));
- return false;
- }
-
- size_t TotalSize = 0;
- for (const BlockStoreLocation& Location : ChunkLocations)
- {
- TotalSize += Location.Size;
- }
- size_t ChunkCount = ChunkLocations.size();
- uint64_t RequiredDiskSpace = TotalSize + ((PayloadAlignment - 1) * ChunkCount);
- uint64_t MaxRequiredBlockCount = RoundUp(RequiredDiskSpace, MaxBlockSize) / MaxBlockSize;
- if (MaxRequiredBlockCount > MaxBlockCount)
- {
- ZEN_ERROR("legacy store migration from '{}' FAILED, required block count {}, possible {}",
- BlocksBasePath,
- MaxRequiredBlockCount,
- MaxBlockCount);
- return false;
- }
-
- constexpr const uint64_t DiskReserve = 1ul << 28;
-
- if (CleanSource)
- {
- if (Space.Free < (MaxBlockSize + DiskReserve))
- {
- ZEN_INFO("legacy store migration from '{}' aborted, not enough disk space available {} ({})",
- BlocksBasePath,
- NiceBytes(MaxBlockSize + DiskReserve),
- NiceBytes(Space.Free));
- return false;
- }
- }
- else
- {
- if (Space.Free < (RequiredDiskSpace + DiskReserve))
- {
- ZEN_INFO("legacy store migration from '{}' aborted, not enough disk space available {} ({})",
- BlocksBasePath,
- NiceBytes(RequiredDiskSpace + DiskReserve),
- NiceBytes(Space.Free));
- return false;
- }
- }
-
- uint32_t WriteBlockIndex = 0;
- while (std::filesystem::exists(BlockStore::GetBlockPath(BlocksBasePath, WriteBlockIndex)))
- {
- ++WriteBlockIndex;
- }
-
- BasicFile BlockFile;
- BlockFile.Open(SourceBlockFilePath, CleanSource ? BasicFile::Mode::kWrite : BasicFile::Mode::kRead);
-
- if (CleanSource && (MaxRequiredBlockCount < 2))
- {
- MovedChunksArray Chunks;
- Chunks.reserve(ChunkCount);
- for (size_t Index = 0; Index < ChunkCount; ++Index)
- {
- const BlockStoreLocation& ChunkLocation = ChunkLocations[Index];
- Chunks.push_back({Index, {.BlockIndex = WriteBlockIndex, .Offset = ChunkLocation.Offset, .Size = ChunkLocation.Size}});
- }
- std::filesystem::path BlockPath = BlockStore::GetBlockPath(BlocksBasePath, WriteBlockIndex);
- CreateDirectories(BlockPath.parent_path());
- BlockFile.Close();
- std::filesystem::rename(SourceBlockFilePath, BlockPath);
- Callback(Chunks);
- return true;
- }
-
- ChunkIndexArray ChunkIndexes;
- ChunkIndexes.reserve(ChunkCount);
- for (size_t Index = 0; Index < ChunkCount; ++Index)
- {
- ChunkIndexes.push_back(Index);
- }
-
- std::sort(begin(ChunkIndexes), end(ChunkIndexes), [&](size_t Lhs, size_t Rhs) {
- const BlockStoreLocation& LhsLocation = ChunkLocations[Lhs];
- const BlockStoreLocation& RhsLocation = ChunkLocations[Rhs];
- return LhsLocation.Offset < RhsLocation.Offset;
- });
-
- uint64_t BlockSize = 0;
- uint64_t BlockOffset = 0;
- std::vector<BlockStoreLocation> NewLocations;
- struct BlockData
- {
- MovedChunksArray Chunks;
- uint64_t BlockOffset;
- uint64_t BlockSize;
- uint32_t BlockIndex;
- };
-
- std::vector<BlockData> BlockRanges;
- MovedChunksArray Chunks;
- BlockRanges.reserve(MaxRequiredBlockCount);
- for (const size_t& ChunkIndex : ChunkIndexes)
- {
- const BlockStoreLocation& LegacyChunkLocation = ChunkLocations[ChunkIndex];
-
- uint64_t ChunkOffset = LegacyChunkLocation.Offset;
- uint64_t ChunkSize = LegacyChunkLocation.Size;
- uint64_t ChunkEnd = ChunkOffset + ChunkSize;
-
- if (BlockSize == 0)
- {
- BlockOffset = ChunkOffset;
- }
- if ((ChunkEnd - BlockOffset) > MaxBlockSize)
- {
- BlockData BlockRange{.BlockOffset = BlockOffset, .BlockSize = BlockSize, .BlockIndex = WriteBlockIndex};
- BlockRange.Chunks.swap(Chunks);
- BlockRanges.push_back(BlockRange);
-
- WriteBlockIndex++;
- while (std::filesystem::exists(BlockStore::GetBlockPath(BlocksBasePath, WriteBlockIndex)))
- {
- ++WriteBlockIndex;
- }
- BlockOffset = ChunkOffset;
- BlockSize = 0;
- }
- BlockSize = RoundUp(BlockSize, PayloadAlignment);
- BlockStoreLocation ChunkLocation = {.BlockIndex = WriteBlockIndex, .Offset = ChunkOffset - BlockOffset, .Size = ChunkSize};
- Chunks.push_back({ChunkIndex, ChunkLocation});
- BlockSize = ChunkEnd - BlockOffset;
- }
- if (BlockSize > 0)
- {
- BlockRanges.push_back(
- {.Chunks = std::move(Chunks), .BlockOffset = BlockOffset, .BlockSize = BlockSize, .BlockIndex = WriteBlockIndex});
- }
-
- Stopwatch WriteBlockTimer;
-
- std::reverse(BlockRanges.begin(), BlockRanges.end());
- std::vector<std::uint8_t> Buffer(1 << 28);
- for (size_t Idx = 0; Idx < BlockRanges.size(); ++Idx)
- {
- const BlockData& BlockRange = BlockRanges[Idx];
- if (Idx > 0)
- {
- uint64_t Remaining = BlockRange.BlockOffset + BlockRange.BlockSize;
- uint64_t Completed = BlockOffset + BlockSize - Remaining;
- uint64_t ETA = (WriteBlockTimer.GetElapsedTimeMs() * Remaining) / Completed;
-
- ZEN_INFO("migrating store '{}' {}/{} blocks, remaining {} ({}) ETA: {}",
- BlocksBasePath,
- Idx,
- BlockRanges.size(),
- NiceBytes(BlockRange.BlockOffset + BlockRange.BlockSize),
- NiceBytes(BlockOffset + BlockSize),
- NiceTimeSpanMs(ETA));
- }
-
- std::filesystem::path BlockPath = BlockStore::GetBlockPath(BlocksBasePath, BlockRange.BlockIndex);
- BlockStoreFile ChunkBlock(BlockPath);
- ChunkBlock.Create(BlockRange.BlockSize);
- uint64_t Offset = 0;
- while (Offset < BlockRange.BlockSize)
- {
- uint64_t Size = BlockRange.BlockSize - Offset;
- if (Size > Buffer.size())
- {
- Size = Buffer.size();
- }
- BlockFile.Read(Buffer.data(), Size, BlockRange.BlockOffset + Offset);
- ChunkBlock.Write(Buffer.data(), Size, Offset);
- Offset += Size;
- }
- ChunkBlock.Truncate(Offset);
- ChunkBlock.Flush();
-
- Callback(BlockRange.Chunks);
-
- if (CleanSource)
- {
- BlockFile.SetFileSize(BlockRange.BlockOffset);
- }
- }
- BlockFile.Close();
-
- return true;
-}
-
const char*
BlockStore::GetBlockFileExtension()
{
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h
index fe435cdff..db32efb9f 100644
--- a/zenstore/include/zenstore/blockstore.h
+++ b/zenstore/include/zenstore/blockstore.h
@@ -123,7 +123,6 @@ public:
typedef std::function<uint64_t()> ClaimDiskReserveCallback;
typedef std::function<void(size_t ChunkIndex, const void* Data, uint64_t Size)> IterateChunksSmallSizeCallback;
typedef std::function<void(size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size)> IterateChunksLargeSizeCallback;
- typedef std::function<void(const MovedChunksArray& MovedChunks)> SplitCallback;
typedef std::function<void(const BlockStoreLocation& Location)> WriteChunkCallback;
void Initialize(const std::filesystem::path& BlocksBasePath,
@@ -151,15 +150,6 @@ public:
const IterateChunksSmallSizeCallback& SmallSizeCallback,
const IterateChunksLargeSizeCallback& LargeSizeCallback);
- static bool Split(const std::vector<BlockStoreLocation>& ChunkLocations,
- const std::filesystem::path& SourceBlockFilePath,
- const std::filesystem::path& BlocksBasePath,
- uint64_t MaxBlockSize,
- uint64_t MaxBlockCount,
- size_t PayloadAlignment,
- bool CleanSource,
- const SplitCallback& Callback);
-
static const char* GetBlockFileExtension();
static std::filesystem::path GetBlockPath(const std::filesystem::path& BlocksBasePath, const uint32_t BlockIndex);