Skip to content

Commit

Permalink
Merge pull request #259 from yuchen0cc/main
Browse files Browse the repository at this point in the history
Fix bugs in zfile evict and build jump table.
  • Loading branch information
liulanzheng authored Aug 31, 2023
2 parents 9194f47 + 8c7b2e7 commit e10030e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/overlaybd/tar/tar_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ class TarFile : public ForwardFile_Ownership {
virtual ssize_t pwritev(const struct iovec *iov, int iovcnt, off_t offset) override {
return m_file->pwritev(iov, iovcnt, offset + base_offset);
}
virtual int fallocate(int mode, off_t offset, off_t len) override {
return m_file->fallocate(mode, offset + base_offset, len);
}
virtual int fadvise(off_t offset, off_t len, int advice) override {
return m_file->fadvise(offset + base_offset, len, advice);
}

virtual int close() override {
if (is_new_tar()) {
Expand Down
19 changes: 13 additions & 6 deletions src/overlaybd/zfile/zfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class CompressionFile : public VirtualReadOnlyFile {
}

int build(const uint32_t *ibuf, size_t n, off_t offset_begin, uint32_t block_size) {
partial_offset.clear();
deltas.clear();
group_size = (uinttype_max + 1) / block_size;
partial_offset.reserve(n / group_size + 1);
deltas.reserve(n + 1);
Expand All @@ -196,8 +198,8 @@ class CompressionFile : public VirtualReadOnlyFile {
continue;
}
if ((uint64_t)deltas[i - 1] + ibuf[i - 1] >= (uint64_t)uinttype_max) {
LOG_ERRNO_RETURN(ERANGE, -1, "build block[`] length failed `+` > ` (exceed)",
deltas[i-1], ibuf[i-1], (uint64_t)uinttype_max);
LOG_ERROR_RETURN(ERANGE, -1, "build block[`] length failed `+` > ` (exceed)",
i-1, deltas[i-1], ibuf[i-1], (uint64_t)uinttype_max);
}
deltas.push_back(deltas[i - 1] + ibuf[i - 1]);
}
Expand Down Expand Up @@ -255,14 +257,16 @@ class CompressionFile : public VirtualReadOnlyFile {
int reload(size_t idx) {
auto read_size = get_blocks_length(idx, idx + 1);
auto begin_offset = m_zfile->m_jump_table[idx];
LOG_WARN("trim and reload. (idx: `, offset: `, len: `)", idx, begin_offset, read_size);
int trim_res = m_zfile->m_file->trim(begin_offset, read_size);
if (trim_res < 0) {
LOG_ERROR_RETURN(0, -1, "failed to trim block idx: `", idx);
LOG_ERRNO_RETURN(0, -1, "trim block failed. (idx: `, offset: `, len: `)",
idx, begin_offset, read_size);
}
auto readn = m_zfile->m_file->pread(m_buf + m_buf_offset, read_size, begin_offset);
if (readn != (ssize_t)read_size) {
LOG_ERRNO_RETURN(0, -1, "read compressed blocks failed. (offset: `, len: `)",
begin_offset, read_size);
LOG_ERRNO_RETURN(0, -1, "read compressed blocks failed. (idx: `, offset: `, len: `)",
idx, begin_offset, read_size);
}
return 0;
}
Expand Down Expand Up @@ -716,9 +720,12 @@ bool load_jump_table(IFile *file, CompressionFile::HeaderTrailer *pheader_traile
if (ret < (ssize_t)index_bytes) {
LOG_ERRNO_RETURN(0, false, "failed to read index");
}
jump_table.build(ibuf.get(), pht->index_size,
ret = jump_table.build(ibuf.get(), pht->index_size,
CompressionFile::HeaderTrailer::SPACE + pht->opt.dict_size,
pht->opt.block_size);
if (ret != 0) {
LOG_ERRNO_RETURN(0, false, "failed to build jump table");
}
if (pheader_trailer)
*pheader_trailer = *pht;
return true;
Expand Down

0 comments on commit e10030e

Please sign in to comment.