761417898 commented on code in PR #192:
URL: https://github.com/apache/tsfile/pull/192#discussion_r1712923522


##########
cpp/src/file/tsfile_io_writer.cc:
##########
@@ -83,19 +83,35 @@ int TsFileIOWriter::start_file() {
     return ret;
 }
 
-int TsFileIOWriter::start_flush_chunk_group(const std::string &device_name) {
+int TsFileIOWriter::start_flush_chunk_group(const std::string &device_name,
+                                            bool is_aligned) {
     int ret = E_OK;
     if (RET_FAIL(write_byte(CHUNK_GROUP_HEADER_MARKER))) {
     } else if (RET_FAIL(write_string(device_name))) {
     } else {
         cur_device_name_ = device_name;
         ASSERT(cur_chunk_group_meta_ == nullptr);
-        void *buf = meta_allocator_.alloc(sizeof(*cur_chunk_group_meta_));
-        if (IS_NULL(buf)) {
-            ret = E_OOM;
-        } else {
-            cur_chunk_group_meta_ = new (buf) ChunkGroupMeta(&meta_allocator_);
-            ret = cur_chunk_group_meta_->init(device_name, meta_allocator_);
+        chunk_group_meta_has_inited_ = false;
+        for (auto iter = chunk_group_meta_list_.begin();
+             iter != chunk_group_meta_list_.end(); iter++) {
+            common::String cur_device_name((char *)cur_device_name_.c_str(),
+                                           cur_device_name_.size());
+            if (is_aligned &&
+                iter.get()->device_name_.equal_to(cur_device_name)) {
+                chunk_group_meta_has_inited_ = true;
+                cur_chunk_group_meta_ = iter.get();
+                break;
+            }
+        }
+        if (!chunk_group_meta_has_inited_) {
+            void *buf = meta_allocator_.alloc(sizeof(*cur_chunk_group_meta_));
+            if (IS_NULL(buf)) {
+                ret = E_OOM;
+            } else {
+                cur_chunk_group_meta_ =
+                    new (buf) ChunkGroupMeta(&meta_allocator_);
+                ret = cur_chunk_group_meta_->init(device_name, 
meta_allocator_);
+            }
         }

Review Comment:
   "The name `chunk_group_meta_has_inited_` was a bit confusing, so I changed 
it to `is_newly_alloc_aligned_cgm` and updated the related logic."



-- 
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