Skip to content

Commit

Permalink
Fix ByteSliceReader::Seek
Browse files Browse the repository at this point in the history
  • Loading branch information
yingfeng authored and yuzhichang committed May 30, 2024
1 parent 7f10d32 commit 40911eb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/storage/invertedindex/format/inmem_doc_list_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ bool InMemDocListDecoder::DecodeSkipList(docid_t start_doc_id, docid_t &prev_las
}

bool InMemDocListDecoder::DecodeSkipListWithoutSkipList(docid_t last_doc_id_in_prev_record, u32 offset, docid_t start_doc_id, docid_t &last_doc_id) {
if (finish_decoded_) {
return false;
}
// allocate space
doc_buffer_to_copy_ = new docid_t[MAX_DOC_PER_RECORD];
if (doc_buffer_to_copy_ == nullptr)
doc_buffer_to_copy_ = new docid_t[MAX_DOC_PER_RECORD];

doc_list_reader_.Seek(offset);
if (!doc_list_reader_.Decode(doc_buffer_to_copy_, MAX_DOC_PER_RECORD, decode_count_)) {
return false;
if (doc_list_reader_.Seek(offset)) {
finish_decoded_ = false;
if (!doc_list_reader_.Decode(doc_buffer_to_copy_, MAX_DOC_PER_RECORD, decode_count_)) {
return false;
}
finish_decoded_ = true;
}
last_doc_id = last_doc_id_in_prev_record;
for (SizeT i = 0; i < decode_count_; ++i) {
Expand All @@ -70,7 +71,6 @@ bool InMemDocListDecoder::DecodeSkipListWithoutSkipList(docid_t last_doc_id_in_p
if (start_doc_id > last_doc_id) {
return false;
}
finish_decoded_ = true;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public:
posting_fields_ = posting_byte_slice_->GetPostingFields();
}

void Seek(u32 pos) {
byte_slice_reader_.Seek(pos);
bool Seek(u32 pos) {
SizeT ret = byte_slice_reader_.Seek(pos);
location_cursor_ = 0;
posting_buffer_cursor_ = 0;
if (ret == ByteSliceReader::BYTE_SLICE_EOF)
return false;
return true;
}

u32 Tell() const { return byte_slice_reader_.Tell(); }
Expand Down
7 changes: 6 additions & 1 deletion src/storage/io/byte_slice_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module;

#include <cassert>

module byte_slice_reader;

import stl;
Expand Down Expand Up @@ -111,6 +113,8 @@ SizeT ByteSliceReader::ReadMayCopy(void *&value, SizeT len) {

SizeT ByteSliceReader::Seek(SizeT offset) {
if (offset < global_offset_) {
if (global_offset_ == BYTE_SLICE_EOF)
return BYTE_SLICE_EOF;
// fmt::format("invalid offset value: seek offset = {}, State: list length = {}, offset = {}", offset, GetSize(), global_offset_));
String error_message = "Invalid offset value";
LOG_CRITICAL(error_message);
Expand All @@ -125,6 +129,7 @@ SizeT ByteSliceReader::Seek(SizeT offset) {
if (current_slice_offset_ + len < GetSliceDataSize(current_slice_)) {
current_slice_offset_ += len;
global_offset_ += len;
assert(global_offset_ == offset);
return global_offset_;
} else {
// current byteslice is not long enough, seek to next byteslices
Expand Down Expand Up @@ -154,7 +159,7 @@ SizeT ByteSliceReader::Seek(SizeT offset) {
current_slice_ = ByteSlice::GetEmptySlice();
current_slice_offset_ = 0;
}

assert(global_offset_ == offset);
return global_offset_;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/storage/io/byte_slice_reader.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace infinity {

export class ByteSliceReader {
public:
static const int BYTE_SLICE_EOF = -1;
static const SizeT BYTE_SLICE_EOF = -1;

public:
ByteSliceReader();
Expand Down

0 comments on commit 40911eb

Please sign in to comment.