This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git
The following commit(s) were added to refs/heads/develop by this push:
new fe06607c CPP.fix multi-flush SEGSEGV. (#170)
fe06607c is described below
commit fe06607c00b3961719b25e717d45a79958e135f1
Author: Colin Lee <[email protected]>
AuthorDate: Fri Jul 12 09:30:04 2024 +0800
CPP.fix multi-flush SEGSEGV. (#170)
---
cpp/src/cwrapper/TsFile-cwrapper.cc | 10 ++++++++--
cpp/src/writer/tsfile_writer.cc | 1 +
cpp/test/writer/tsfile_writer_test.cc | 31 ++++++++++++++++++++++++++++++-
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/cpp/src/cwrapper/TsFile-cwrapper.cc
b/cpp/src/cwrapper/TsFile-cwrapper.cc
index df38ce72..d70c5199 100644
--- a/cpp/src/cwrapper/TsFile-cwrapper.cc
+++ b/cpp/src/cwrapper/TsFile-cwrapper.cc
@@ -157,7 +157,11 @@ CTsFileReader ts_reader_open(const char* pathname,
ErrorCode* err_code) {
CTsFileWriter ts_writer_open(const char* pathname, ErrorCode* err_code) {
init_tsfile_config();
TsFileWriter* writer = new TsFileWriter();
- int ret = writer->open(pathname, O_CREAT | O_RDWR, 0644);
+ int flags = O_WRONLY | O_CREAT | O_TRUNC;
+#ifdef _WIN32
+ flags |= O_BINARY;
+#endif
+ int ret = writer->open(pathname, flags, 0644);
if (ret != E_OK) {
delete writer;
*err_code = ret;
@@ -598,7 +602,9 @@ QueryDataRet ts_reader_query(CTsFileReader reader, const
char* table_name,
ret->data = qds;
ret->column_names = (char**)malloc(column_num * sizeof(char*));
ret->column_num = column_num;
- memcpy(ret->column_names, columns_name, column_num * sizeof(char*));
+ for (int i = 0; i < column_num; i++) {
+ ret->column_names[i] = strdup(columns_name[i]);
+ }
storage::QueryExpression::destory(query_expression);
return ret;
}
diff --git a/cpp/src/writer/tsfile_writer.cc b/cpp/src/writer/tsfile_writer.cc
index 7d5db9f0..2ec90a63 100644
--- a/cpp/src/writer/tsfile_writer.cc
+++ b/cpp/src/writer/tsfile_writer.cc
@@ -489,6 +489,7 @@ int TsFileWriter::flush_chunk_group(MeasurementSchemaGroup
*chunk_group) {
return ret;
} else {
chunk_writer->destroy();
+ chunk_writer = nullptr;
}
}
return ret;
diff --git a/cpp/test/writer/tsfile_writer_test.cc
b/cpp/test/writer/tsfile_writer_test.cc
index a3004c8d..4f52e197 100644
--- a/cpp/test/writer/tsfile_writer_test.cc
+++ b/cpp/test/writer/tsfile_writer_test.cc
@@ -38,7 +38,7 @@ class TsFileWriterTest : public ::testing::Test {
tsfile_writer_ = new TsFileWriter();
libtsfile_init();
file_name_ = std::string("tsfile_writer_test_") +
- generate_random_string(10) + std::string(".dat");
+ generate_random_string(10) + std::string(".tsfile");
remove(file_name_.c_str());
int flags = O_WRONLY | O_CREAT | O_TRUNC;
#ifdef _WIN32
@@ -214,3 +214,32 @@ TEST_F(TsFileWriterTest, FlushWithoutWriteAfterRegisterTS)
{
ASSERT_EQ(writer.close(), E_OK);
}
*/
+
+TEST_F(TsFileWriterTest, MultiFlush) {
+ std::string device_path = "device1";
+ std::string measurement_name = "temperature";
+ common::TSDataType data_type = common::TSDataType::INT32;
+ common::TSEncoding encoding = common::TSEncoding::PLAIN;
+ common::CompressionType compression_type =
+ common::CompressionType::UNCOMPRESSED;
+ ASSERT_EQ(tsfile_writer_->register_timeseries(device_path,
measurement_name,
+ data_type, encoding,
+ compression_type),
+ E_OK);
+ for (int i = 1; i < 2000; i++) {
+ TsRecord record(i, device_path);
+ DataPoint point(measurement_name, i);
+ record.append_data_point(point);
+ ASSERT_EQ(tsfile_writer_->write_record(record), E_OK);
+ }
+ ASSERT_EQ(tsfile_writer_->flush(), E_OK);
+
+ for (int i = 2000; i < 4000; i++) {
+ TsRecord record(i, device_path);
+ DataPoint point(measurement_name, i);
+ record.append_data_point(point);
+ ASSERT_EQ(tsfile_writer_->write_record(record), E_OK);
+ }
+ ASSERT_EQ(tsfile_writer_->flush(), E_OK);
+ tsfile_writer_->close();
+}