diff options
Diffstat (limited to 'zenstore')
| -rw-r--r-- | zenstore/basicfile.cpp | 17 | ||||
| -rw-r--r-- | zenstore/cas.cpp | 2 | ||||
| -rw-r--r-- | zenstore/caslog.cpp | 8 | ||||
| -rw-r--r-- | zenstore/compactcas.cpp | 2 | ||||
| -rw-r--r-- | zenstore/compactcas.h | 11 | ||||
| -rw-r--r-- | zenstore/filecas.cpp | 26 | ||||
| -rw-r--r-- | zenstore/gc.cpp | 8 | ||||
| -rw-r--r-- | zenstore/include/zenstore/cas.h | 4 | ||||
| -rw-r--r-- | zenstore/include/zenstore/caslog.h | 2 | ||||
| -rw-r--r-- | zenstore/include/zenstore/gc.h | 2 |
10 files changed, 34 insertions, 48 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp index 80d9a2204..dcd9a8575 100644 --- a/zenstore/basicfile.cpp +++ b/zenstore/basicfile.cpp @@ -15,6 +15,7 @@ # include <fcntl.h> # include <sys/file.h> # include <sys/stat.h> +# include <unistd.h> #endif #include <fmt/format.h> @@ -22,8 +23,6 @@ namespace zen { -using namespace fmt::literals; - BasicFile::~BasicFile() { Close(); @@ -37,7 +36,7 @@ BasicFile::Open(std::filesystem::path FileName, bool IsCreate) if (Ec) { - throw std::system_error(Ec, "failed to open file '{}'"_format(FileName)); + throw std::system_error(Ec, fmt::format("failed to open file '{}'", FileName)); } } @@ -132,7 +131,7 @@ BasicFile::Read(void* Data, uint64_t BytesToRead, uint64_t FileOffset) if (!Success) { - ThrowLastError("Failed to read from file '{}'"_format(zen::PathFromHandle(m_FileHandle))); + ThrowLastError(fmt::format("Failed to read from file '{}'", zen::PathFromHandle(m_FileHandle))); } BytesToRead -= NumberOfBytesToRead; @@ -238,7 +237,7 @@ BasicFile::Write(const void* Data, uint64_t Size, uint64_t Offset) if (Ec) { - throw std::system_error(Ec, "Failed to write to file '{}'"_format(zen::PathFromHandle(m_FileHandle))); + throw std::system_error(Ec, fmt::format("Failed to write to file '{}'", zen::PathFromHandle(m_FileHandle))); } } @@ -334,11 +333,9 @@ LockFile::LockFile() LockFile::~LockFile() { -#if ZEN_PLATFORM_LINUX +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC int Fd = int(intptr_t(m_FileHandle)); flock(Fd, LOCK_UN | LOCK_NB); -#elif ZEN_PLATFORM_MAC -# error check flock() support #endif } @@ -368,7 +365,7 @@ LockFile::Create(std::filesystem::path FileName, CbObject Payload, std::error_co return; } -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC int Fd = open(FileName.c_str(), O_RDWR | O_CREAT, 0666); if (Fd < 0) { @@ -385,8 +382,6 @@ LockFile::Create(std::filesystem::path FileName, CbObject Payload, std::error_co } void* FileHandle = (void*)uintptr_t(Fd); -#else -# error check flock() support #endif m_FileHandle = FileHandle; diff --git a/zenstore/cas.cpp b/zenstore/cas.cpp index 1fd01ff0c..7b58111db 100644 --- a/zenstore/cas.cpp +++ b/zenstore/cas.cpp @@ -201,7 +201,7 @@ CasImpl::OpenOrCreateManifest() } else { - ZEN_ERROR("Store manifest validation failed: {:#x}, will generate new manifest to recover", ValidationResult); + ZEN_ERROR("Store manifest validation failed: {:#x}, will generate new manifest to recover", uint32_t(ValidationResult)); } if (ManifestIsOk) diff --git a/zenstore/caslog.cpp b/zenstore/caslog.cpp index dc4891e9f..055e3feda 100644 --- a/zenstore/caslog.cpp +++ b/zenstore/caslog.cpp @@ -24,8 +24,6 @@ namespace zen { -using namespace fmt::literals; - uint32_t CasLogFile::FileHeader::ComputeChecksum() { @@ -50,7 +48,7 @@ CasLogFile::Open(std::filesystem::path FileName, size_t RecordSize, bool IsCreat if (Ec) { - throw std::system_error(Ec, "Failed to open log file '{}'"_format(FileName)); + throw std::system_error(Ec, fmt::format("Failed to open log file '{}'", FileName)); } uint64_t AppendOffset = 0; @@ -76,7 +74,7 @@ CasLogFile::Open(std::filesystem::path FileName, size_t RecordSize, bool IsCreat if ((0 != memcmp(Header.Magic, FileHeader::MagicSequence, sizeof Header.Magic)) || (Header.Checksum != Header.ComputeChecksum())) { - throw std::runtime_error("Mangled log header (invalid header magic) in '{}'"_format(FileName)); + throw std::runtime_error(fmt::format("Mangled log header (invalid header magic) in '{}'", FileName)); } AppendOffset = m_File.FileSize(); @@ -153,7 +151,7 @@ CasLogFile::Append(const void* DataPointer, uint64_t DataSize) if (Ec) { - throw std::system_error(Ec, "Failed to write to log file '{}'"_format(PathFromHandle(m_File.Handle()))); + throw std::system_error(Ec, fmt::format("Failed to write to log file '{}'", PathFromHandle(m_File.Handle()))); } } diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index aa60ec37b..3bf0c70df 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -31,8 +31,6 @@ namespace zen { -using namespace fmt::literals; - CasContainerStrategy::CasContainerStrategy(const CasStoreConfiguration& Config, CasGc& Gc) : GcStorage(Gc) , m_Config(Config) diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h index 974f45a0c..c039feec9 100644 --- a/zenstore/compactcas.h +++ b/zenstore/compactcas.h @@ -14,14 +14,17 @@ #include <zenstore/caslog.h> #include <zenstore/gc.h> -namespace spdlog { -class logger; -} - #if ZEN_PLATFORM_WINDOWS # include <zencore/windows.h> #endif +#include <atomic> +#include <unordered_map> + +namespace spdlog { +class logger; +} + namespace zen { ////////////////////////////////////////////////////////////////////////// diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 76b921994..533c99569 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -35,8 +35,6 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { -using namespace fmt::literals; - FileCasStrategy::ShardingHelper::ShardingHelper(const std::filesystem::path& RootPath, const IoHash& ChunkHash) { ShardedPath.Append(RootPath.c_str()); @@ -241,7 +239,7 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) if (FAILED(hRes)) { - ThrowSystemException(hRes, "Failed to open shard directory '{}'"_format(FilePath)); + ThrowSystemException(hRes, fmt::format("Failed to open shard directory '{}'", FilePath)); } // Retry rename/move @@ -271,7 +269,7 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) ChunkHash); DeletePayloadFileOnClose(); -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC std::filesystem::path SourcePath = PathFromHandle(FileRef.FileHandle); std::filesystem::path DestPath = Name.ShardedPath.c_str(); int Ret = link(SourcePath.c_str(), DestPath.c_str()); @@ -311,8 +309,6 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) { return CasStore::InsertResult{.New = true}; } -#else -# error check link/unlink for this platform #endif // ZEN_PLATFORM_* } @@ -345,13 +341,11 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize } PayloadFile.Close(); -#elif ZEN_PLATFORM_LINUX +#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC if (access(Name.ShardedPath.c_str(), F_OK) == 0) { return CasStore::InsertResult{.New = false}; } -#else -# error Check access() for this platform #endif RwLock::ExclusiveLockScope _(LockForHash(ChunkHash)); @@ -390,7 +384,7 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize if (FAILED(hRes)) { - ThrowSystemException(hRes, "Failed to open shard file '{}'"_format(Name.ShardedPath.ToUtf8())); + ThrowSystemException(hRes, fmt::format("Failed to open shard file '{}'", Name.ShardedPath.ToUtf8())); } #else // Attempt to exclusively create the file. @@ -413,10 +407,10 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize break; } } - ThrowLastError("Failed creating shard directory '{}'"_format(Name.ShardedPath)); + ThrowLastError(fmt::format("Failed creating shard directory '{}'", Name.ShardedPath)); default: - ThrowLastError("Unexpected error occurred opening shard file '{}'"_format(Name.ShardedPath)); + ThrowLastError(fmt::format("Unexpected error occurred opening shard file '{}'", Name.ShardedPath)); } } @@ -573,7 +567,7 @@ FileCasStrategy::IterateChunks(std::function<void(const IoHash& Hash, BasicFile& } } - virtual bool VisitDirectory([[maybe_unused]] const std::filesystem::path& Parent, [[maybe_unused]] const path_view& DirectoryName) + virtual bool VisitDirectory([[maybe_unused]] const std::filesystem::path& Parent, [[maybe_unused]] const path_view& DirectoryName) override { return true; } @@ -727,8 +721,6 @@ FileCasStrategy::CollectGarbage(GcContext& GcCtx) TEST_CASE("cas.file.move") { - using namespace fmt::literals; - // specifying an absolute path here can be helpful when using procmon to dig into things ScopedTemporaryDirectory TempDir; // {"d:\\filecas_testdir"}; @@ -773,7 +765,7 @@ TEST_CASE("cas.file.move") *reinterpret_cast<int*>(Payload.MutableData()) = i; PayloadHashes.push_back(IoHash::HashBuffer(Payload)); - std::filesystem::path PayloadPath{TempDir.Path() / "payload_{}_{}"_format(w, i)}; + std::filesystem::path PayloadPath{TempDir.Path() / fmt::format("payload_{}_{}", w, i)}; WriteFile(PayloadPath, Payload); } } @@ -785,7 +777,7 @@ TEST_CASE("cas.file.move") for (int i = 0; i < kItemCount; ++i) { - std::filesystem::path PayloadPath{TempDir.Path() / "payload_{}_{}"_format(w, i)}; + std::filesystem::path PayloadPath{TempDir.Path() / fmt::format("payload_{}_{}", w, i)}; IoBuffer Payload = IoBufferBuilder::MakeFromTemporaryFile(PayloadPath); Buffers.push_back(Payload); Sync.arrive_and_wait(); diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index d23e0c466..0e93f1c3d 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -393,7 +393,7 @@ GcScheduler::Initialize(const GcSchedulerConfig& Config) } m_NextGcTime = NextGcTime(m_LastGcTime); - m_GcThread = std::jthread(&GcScheduler::SchedulerThread, this); + m_GcThread = std::thread(&GcScheduler::SchedulerThread, this); } void @@ -403,6 +403,8 @@ GcScheduler::Shutdown() { m_Status = static_cast<uint32_t>(GcSchedulerStatus::kStopped); m_GcSignal.notify_one(); + + m_GcThread.join(); } } @@ -427,8 +429,6 @@ GcScheduler::Trigger(const GcScheduler::TriggerParams& Params) void GcScheduler::SchedulerThread() { - using namespace fmt::literals; - std::chrono::seconds WaitTime = m_Config.MonitorInterval; for (;;) @@ -472,7 +472,7 @@ GcScheduler::SchedulerThread() NiceBytes(Space.Free), NiceBytes(Space.Total), m_Config.Interval.count() - ? "{} until next GC"_format(NiceTimeSpanMs(uint64_t(std::chrono::milliseconds(RemaingTime).count()))) + ? fmt::format("{} until next GC", NiceTimeSpanMs(uint64_t(std::chrono::milliseconds(RemaingTime).count()))) : std::string("next scheduled GC no set")); // TODO: Trigger GC if max disk usage water mark is reached diff --git a/zenstore/include/zenstore/cas.h b/zenstore/include/zenstore/cas.h index 9371e4de0..1823fd630 100644 --- a/zenstore/include/zenstore/cas.h +++ b/zenstore/include/zenstore/cas.h @@ -49,7 +49,7 @@ public: [[nodiscard]] inline bool IsEmpty() const { return m_ChunkSet.empty(); } [[nodiscard]] inline size_t GetSize() const { return m_ChunkSet.size(); } - inline void FilterChunks(std::span<const IoHash> Candidates, std::invocable<const IoHash&> auto MatchFunc) + inline void FilterChunks(std::span<const IoHash> Candidates, Invocable<const IoHash&> auto MatchFunc) { for (const IoHash& Candidate : Candidates) { @@ -60,7 +60,7 @@ public: } } - inline void FilterChunks(std::span<const IoHash> Candidates, std::invocable<const IoHash&, bool> auto MatchFunc) + inline void FilterChunks(std::span<const IoHash> Candidates, Invocable<const IoHash&, bool> auto MatchFunc) { for (const IoHash& Candidate : Candidates) { diff --git a/zenstore/include/zenstore/caslog.h b/zenstore/include/zenstore/caslog.h index 1ecb721f7..1bd11800c 100644 --- a/zenstore/include/zenstore/caslog.h +++ b/zenstore/include/zenstore/caslog.h @@ -66,7 +66,7 @@ public: // This should be called before the Replay() is called to do some basic sanity checking bool Initialize() { return true; } - void Replay(std::invocable<const T&> auto Handler) + void Replay(Invocable<const T&> auto Handler) { CasLogFile::Replay([&](const void* VoidPtr) { const T& Record = *reinterpret_cast<const T*>(VoidPtr); diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h index 1540b66c2..b8ba338f0 100644 --- a/zenstore/include/zenstore/gc.h +++ b/zenstore/include/zenstore/gc.h @@ -204,7 +204,7 @@ private: GcClock::TimePoint m_LastGcTime{}; GcClock::TimePoint m_NextGcTime{}; std::atomic_uint32_t m_Status{}; - std::jthread m_GcThread; + std::thread m_GcThread; std::mutex m_GcMutex; std::condition_variable m_GcSignal; std::optional<TriggerParams> m_TriggerParams; |