MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / isNeedToAddEmptyBlock

Method isNeedToAddEmptyBlock

src/IO/ZstdDeflatingAppendableWriteBuffer.cpp:188–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186
187
188bool ZstdDeflatingAppendableWriteBuffer::isNeedToAddEmptyBlock()
189{
190 auto reader = read_buffer_creator();
191 auto fsize = reader->getFileSize();
192 if (fsize > 3)
193 {
194 std::array<char, 3> result{};
195 reader->seek(fsize - 3, SEEK_SET);
196 reader->readStrict(result.data(), 3);
197
198 /// If we don't have correct block in the end, then we need to add it manually.
199 /// NOTE: maybe we can have the same bytes in case of data corruption/unfinished write.
200 /// But in this case file still corrupted and we have to remove it.
201 return result != ZSTD_CORRECT_TERMINATION_LAST_BLOCK;
202 }
203 if (fsize > 0)
204 {
205 throw Exception(
206 ErrorCodes::ZSTD_ENCODER_FAILED,
207 "Trying to write to non-empty file '{}' with tiny size {}. It can lead to data corruption",
208 out->getFileName(),
209 fsize);
210 }
211 return false;
212}
213
214void ZstdDeflatingAppendableWriteBuffer::cancelImpl() noexcept
215{

Callers

nothing calls this directly

Calls 6

ExceptionClass · 0.70
getFileSizeMethod · 0.45
seekMethod · 0.45
readStrictMethod · 0.45
dataMethod · 0.45
getFileNameMethod · 0.45

Tested by

no test coverage detected