JackieTien97 commented on code in PR #815:
URL: https://github.com/apache/tsfile/pull/815#discussion_r3213127504


##########
cpp/src/reader/tsfile_reader.cc:
##########
@@ -25,6 +25,69 @@
 using namespace common;
 using namespace storage;
 
+namespace {
+
+struct DeviceMetaEntry {
+    std::shared_ptr<IDeviceID> device_id;
+    int64_t start_offset;
+    int64_t end_offset;
+};
+
+int get_all_device_entries(std::vector<DeviceMetaEntry>& entries,
+                           std::shared_ptr<MetaIndexNode> index_node,
+                           ReadFile* read_file, PageArena& pa) {
+    int ret = E_OK;
+    if (index_node == nullptr) {
+        return ret;
+    }
+    if (index_node->node_type_ == LEAF_DEVICE) {
+        for (size_t i = 0; i < index_node->children_.size(); i++) {
+            DeviceMetaEntry entry;
+            entry.device_id = index_node->children_[i]->get_device_id();
+            entry.start_offset = index_node->children_[i]->get_offset();
+            entry.end_offset =
+                (i + 1 < index_node->children_.size())
+                    ? index_node->children_[i + 1]->get_offset()
+                    : index_node->end_offset_;
+            entries.push_back(entry);
+        }
+    } else {
+        for (size_t idx = 0; idx < index_node->children_.size(); idx++) {
+            auto meta_index_entry = index_node->children_[idx];
+            int start_offset = meta_index_entry->get_offset();
+            int end_offset = index_node->end_offset_;

Review Comment:
   **Bug: `int64_t` truncated to `int`**
   
   `get_offset()` returns `int64_t` and `end_offset_` is `int64_t`. Assigning 
them to `int` (32-bit) silently truncates for files >2 GB — the read offset 
passed to `read_file->read()` will be wrong.
   
   Both should be `int64_t`:
   ```cpp
   int64_t start_offset = meta_index_entry->get_offset();
   int64_t end_offset = index_node->end_offset_;
   ```



##########
cpp/src/file/tsfile_io_reader.cc:
##########
@@ -155,6 +155,70 @@ int 
TsFileIOReader::get_device_timeseries_meta_without_chunk_meta(
     return ret;
 }
 
+int TsFileIOReader::get_device_timeseries_meta_by_offset(
+    int64_t start_offset, int64_t end_offset,
+    std::vector<ITimeseriesIndex*>& timeseries_indexs, PageArena& pa) {
+    int ret = E_OK;
+    load_tsfile_meta_if_necessary();
+
+    std::vector<std::pair<std::shared_ptr<IMetaIndexEntry>, int64_t>>
+        meta_index_entry_list;
+    bool is_aligned = false;
+    TimeseriesIndex* time_timeseries_index = nullptr;
+
+    ASSERT(start_offset < end_offset);
+    const int32_t read_size = end_offset - start_offset;

Review Comment:
   Nit: `end_offset - start_offset` is `int64_t` arithmetic, implicitly 
narrowed to `int32_t`. For a single measurement index node the size is unlikely 
to exceed 2 GB so this is fine in practice, and it matches the `int32_t 
buf_size` parameter of `ReadFile::read()`. Just noting for awareness.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to