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


##########
cpp/src/writer/tsfile_writer.cc:
##########
@@ -247,6 +253,54 @@ int TsFileWriter::do_check_schema(const std::string 
&device_name,
     return ret;
 }
 
+template <typename MeasurementNamesGetter>
+int TsFileWriter::do_check_schema_aligned(
+    const std::string &device_name, MeasurementNamesGetter &measurement_names,
+    storage::TimeChunkWriter *&time_chunk_writer,
+    common::SimpleVector<storage::ValueChunkWriter *> &value_chunk_writers) {
+    int ret = E_OK;
+    auto dev_it = schemas_.find(device_name);
+    MeasurementSchemaGroup *device_schema = NULL;
+    if (UNLIKELY(dev_it == schemas_.end()) ||
+        IS_NULL(device_schema = dev_it->second)) {
+        return E_DEVICE_NOT_EXIST;
+    }
+    if (IS_NULL(device_schema->time_chunk_writer_)) {
+        device_schema->time_chunk_writer_ = new TimeChunkWriter();
+        device_schema->time_chunk_writer_->init(
+            "", VECTOR, g_config_value_.time_encoding_type_,
+            g_config_value_.time_compress_type_);
+    }
+    time_chunk_writer = device_schema->time_chunk_writer_;
+    MeasurementSchemaMap &msm = device_schema->measurement_schema_map_;
+    uint32_t measurement_count = measurement_names.get_count();
+    for (uint32_t i = 0; i < measurement_count; i++) {
+        auto ms_iter = msm.find(measurement_names.at(i));
+        if (UNLIKELY(ms_iter == msm.end())) {
+            value_chunk_writers.push_back(NULL);
+        } else {
+            // Here we may check data_type against ms_iter. But in Java
+            // libtsfile, no check here.
+            MeasurementSchema *ms = ms_iter->second;
+            if (IS_NULL(ms->value_chunk_writer_)) {
+                ms->value_chunk_writer_ = new ValueChunkWriter;
+                ret = ms->value_chunk_writer_->init(
+                    ms->measurement_name_, ms->data_type_, ms->encoding_,
+                    ms->compression_type_);
+                if (IS_SUCC(ret)) {
+                    value_chunk_writers.push_back(ms->value_chunk_writer_);
+                } else {
+                    std::cout << "get error when chunk init" << std::endl;
+                    value_chunk_writers.push_back(NULL);

Review Comment:
   When initialization of `chunk_writer` fails, it will return an error and 
release some of the already initialized memory.



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