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

Method isNeedToAddEmptyBlock

src/IO/ZstdDeflatingAppendableWriteBuffer.cpp:176–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176bool ZstdDeflatingAppendableWriteBuffer::isNeedToAddEmptyBlock()
177{
178 ReadBufferFromFile reader(out.getFileName());
179 auto fsize = reader.getFileSize();
180 if (fsize > 3)
181 {
182 std::array<char, 3> result;
183 reader.seek(fsize - 3, SEEK_SET);
184 reader.readStrict(result.data(), 3);
185
186 /// If we don't have correct block in the end, then we need to add it manually.
187 /// NOTE: maybe we can have the same bytes in case of data corruption/unfinished write.
188 /// But in this case file still corrupted and we have to remove it.
189 return result != ZSTD_CORRECT_TERMINATION_LAST_BLOCK;
190 }
191 else if (fsize > 0)
192 {
193 throw Exception(
194 ErrorCodes::ZSTD_ENCODER_FAILED,
195 "Trying to write to non-empty file '{}' with tiny size {}. It can lead to data corruption",
196 out.getFileName(), fsize);
197 }
198 return false;
199}
200
201}

Callers

nothing calls this directly

Calls 6

readStrictMethod · 0.80
ExceptionClass · 0.50
getFileNameMethod · 0.45
getFileSizeMethod · 0.45
seekMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected