Skip to content

Commit e10030e

Browse files
authored
Merge pull request #259 from yuchen0cc/main
Fix bugs in zfile evict and build jump table.
2 parents 9194f47 + 8c7b2e7 commit e10030e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/overlaybd/tar/tar_file.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ class TarFile : public ForwardFile_Ownership {
158158
virtual ssize_t pwritev(const struct iovec *iov, int iovcnt, off_t offset) override {
159159
return m_file->pwritev(iov, iovcnt, offset + base_offset);
160160
}
161+
virtual int fallocate(int mode, off_t offset, off_t len) override {
162+
return m_file->fallocate(mode, offset + base_offset, len);
163+
}
164+
virtual int fadvise(off_t offset, off_t len, int advice) override {
165+
return m_file->fadvise(offset + base_offset, len, advice);
166+
}
161167

162168
virtual int close() override {
163169
if (is_new_tar()) {

src/overlaybd/zfile/zfile.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class CompressionFile : public VirtualReadOnlyFile {
182182
}
183183

184184
int build(const uint32_t *ibuf, size_t n, off_t offset_begin, uint32_t block_size) {
185+
partial_offset.clear();
186+
deltas.clear();
185187
group_size = (uinttype_max + 1) / block_size;
186188
partial_offset.reserve(n / group_size + 1);
187189
deltas.reserve(n + 1);
@@ -196,8 +198,8 @@ class CompressionFile : public VirtualReadOnlyFile {
196198
continue;
197199
}
198200
if ((uint64_t)deltas[i - 1] + ibuf[i - 1] >= (uint64_t)uinttype_max) {
199-
LOG_ERRNO_RETURN(ERANGE, -1, "build block[`] length failed `+` > ` (exceed)",
200-
deltas[i-1], ibuf[i-1], (uint64_t)uinttype_max);
201+
LOG_ERROR_RETURN(ERANGE, -1, "build block[`] length failed `+` > ` (exceed)",
202+
i-1, deltas[i-1], ibuf[i-1], (uint64_t)uinttype_max);
201203
}
202204
deltas.push_back(deltas[i - 1] + ibuf[i - 1]);
203205
}
@@ -255,14 +257,16 @@ class CompressionFile : public VirtualReadOnlyFile {
255257
int reload(size_t idx) {
256258
auto read_size = get_blocks_length(idx, idx + 1);
257259
auto begin_offset = m_zfile->m_jump_table[idx];
260+
LOG_WARN("trim and reload. (idx: `, offset: `, len: `)", idx, begin_offset, read_size);
258261
int trim_res = m_zfile->m_file->trim(begin_offset, read_size);
259262
if (trim_res < 0) {
260-
LOG_ERROR_RETURN(0, -1, "failed to trim block idx: `", idx);
263+
LOG_ERRNO_RETURN(0, -1, "trim block failed. (idx: `, offset: `, len: `)",
264+
idx, begin_offset, read_size);
261265
}
262266
auto readn = m_zfile->m_file->pread(m_buf + m_buf_offset, read_size, begin_offset);
263267
if (readn != (ssize_t)read_size) {
264-
LOG_ERRNO_RETURN(0, -1, "read compressed blocks failed. (offset: `, len: `)",
265-
begin_offset, read_size);
268+
LOG_ERRNO_RETURN(0, -1, "read compressed blocks failed. (idx: `, offset: `, len: `)",
269+
idx, begin_offset, read_size);
266270
}
267271
return 0;
268272
}
@@ -716,9 +720,12 @@ bool load_jump_table(IFile *file, CompressionFile::HeaderTrailer *pheader_traile
716720
if (ret < (ssize_t)index_bytes) {
717721
LOG_ERRNO_RETURN(0, false, "failed to read index");
718722
}
719-
jump_table.build(ibuf.get(), pht->index_size,
723+
ret = jump_table.build(ibuf.get(), pht->index_size,
720724
CompressionFile::HeaderTrailer::SPACE + pht->opt.dict_size,
721725
pht->opt.block_size);
726+
if (ret != 0) {
727+
LOG_ERRNO_RETURN(0, false, "failed to build jump table");
728+
}
722729
if (pheader_trailer)
723730
*pheader_trailer = *pht;
724731
return true;

0 commit comments

Comments
 (0)