56 StreamSpoolCache(
const std::filesystem::path& directory, std::uint64_t maxTotalBytes);
70 bool Next(google::protobuf::Message& record);
71 bool Failed()
const {
return m_failed; }
76 bool Truncated()
const {
return !m_failed && m_recordsRead < m_expectedRecords; }
82 std::ifstream m_stream;
83 std::uint64_t m_recordsRead = 0;
84 std::uint64_t m_expectedRecords = 0;
85 bool m_failed =
false;
101 bool Append(
const google::protobuf::Message& record);
117 void Close(
bool commit);
119 std::ofstream m_stream;
120 std::filesystem::path m_path;
122 std::string m_designName;
123 std::uint64_t m_generation = 0;
124 std::uint64_t m_bytesWritten = 0;
125 std::uint64_t m_recordsWritten = 0;
126 bool m_openForWrite =
false;
127 bool m_committed =
false;
128 bool m_publishSucceeded =
false;
134 bool TryOpenReader(
const std::string& designName, std::uint64_t generation,
Reader& readerOut);
139 bool BeginWrite(
const std::string& designName, std::uint64_t generation,
Writer& writerOut);
142 void Drop(
const std::string& designName);
151 void DropStaleEntry(
const std::string& designName,
const std::filesystem::path& expectedPath);
161 std::filesystem::path path;
162 std::uint64_t generation = 0;
163 std::uint64_t bytes = 0;
164 std::uint64_t records = 0;
165 std::uint64_t lastUsed = 0;
168 void InitializeDirectory(
const std::filesystem::path& directory,
bool ownsDirectory, std::uint64_t maxTotalBytes);
169 std::filesystem::path MakeSpoolPath(
const std::string& designName, std::uint64_t generation, std::uint64_t fillId)
const;
172 bool PublishEntry(
const std::string& designName,
const Entry& entry);
173 void EvictOverBudgetLocked(
const std::string& protectedName);
175 mutable std::mutex m_mutex;
176 std::filesystem::path m_directory;
177 bool m_ownsDirectory =
false;
178 std::uint64_t m_maxTotalBytes = 0;
179 std::uint64_t m_totalBytes = 0;
180 std::uint64_t m_warmOpens = 0;
181 std::uint64_t m_useCounter = 0;
182 std::map<std::string, Entry> m_entriesByName;
183 bool m_usable =
false;