Skip to content

Commit 58fa12f

Browse files
authored
fix read from iotdb data. (#520)
1 parent caa77ac commit 58fa12f

File tree

4 files changed

+372
-355
lines changed

4 files changed

+372
-355
lines changed

cpp/src/common/tsfile_common.cc

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace storage {
3030

3131
const char *MAGIC_STRING_TSFILE = "TsFile";
3232
const int MAGIC_STRING_TSFILE_LEN = 6;
33-
const char VERSION_NUM_BYTE = 0x04;//0x03;
33+
const char VERSION_NUM_BYTE = 0x04; // 0x03;
3434
const char CHUNK_GROUP_HEADER_MARKER = 0;
3535
const char CHUNK_HEADER_MARKER = 1;
3636
const char ONLY_ONE_PAGE_CHUNK_HEADER_MARKER = 5;
@@ -104,13 +104,14 @@ int TSMIterator::init() {
104104
chunk_meta_iter_++;
105105
}
106106
if (!tmp.empty()) {
107-
tsm_chunk_meta_info_[chunk_group_meta_iter_.get()
108-
->device_id_] = tmp;
107+
tsm_chunk_meta_info_[chunk_group_meta_iter_.get()->device_id_] =
108+
tmp;
109109
}
110110

111111
chunk_group_meta_iter_++;
112112
}
113-
if (!tsm_chunk_meta_info_.empty() && !tsm_chunk_meta_info_.begin()->second.empty()) {
113+
if (!tsm_chunk_meta_info_.empty() &&
114+
!tsm_chunk_meta_info_.begin()->second.empty()) {
114115
tsm_measurement_iter_ = tsm_chunk_meta_info_.begin()->second.begin();
115116
}
116117
tsm_device_iter_ = tsm_chunk_meta_info_.begin();
@@ -121,7 +122,8 @@ bool TSMIterator::has_next() const {
121122
return tsm_device_iter_ != tsm_chunk_meta_info_.end();
122123
}
123124

124-
int TSMIterator::get_next(std::shared_ptr<IDeviceID> &ret_device_id, String &ret_measurement_name,
125+
int TSMIterator::get_next(std::shared_ptr<IDeviceID> &ret_device_id,
126+
String &ret_measurement_name,
125127
TimeseriesIndex &ret_ts_index) {
126128
int ret = E_OK;
127129
SimpleList<ChunkMeta *> chunk_meta_list_of_this_ts(
@@ -153,7 +155,6 @@ int TSMIterator::get_next(std::shared_ptr<IDeviceID> &ret_device_id, String &ret
153155
ret_ts_index.set_data_type(data_type);
154156
ret_ts_index.init_statistic(data_type);
155157

156-
157158
SimpleList<ChunkMeta *>::Iterator ts_chunk_meta_iter =
158159
chunk_meta_list_of_this_ts.begin();
159160
for (;
@@ -199,9 +200,10 @@ int TsFileMeta::serialize_to(common::ByteStream &out) {
199200
}
200201

201202
common::SerializationUtil::write_var_int(tsfile_properties_.size(), out);
202-
for (const auto& tsfile_property : tsfile_properties_) {
203+
for (const auto &tsfile_property : tsfile_properties_) {
203204
common::SerializationUtil::write_var_str(tsfile_property.first, out);
204-
common::SerializationUtil::write_var_str(tsfile_property.second, out);
205+
common::SerializationUtil::write_var_char_ptr(tsfile_property.second,
206+
out);
205207
}
206208

207209
return out.total_size() - start_idx;
@@ -250,24 +252,26 @@ int TsFileMeta::deserialize_from(common::ByteStream &in) {
250252
int32_t tsfile_properties_size = 0;
251253
common::SerializationUtil::read_var_int(tsfile_properties_size, in);
252254
for (int i = 0; i < tsfile_properties_size; i++) {
253-
std::string key, value;
255+
std::string key, *value;
254256
common::SerializationUtil::read_var_str(key, in);
255-
common::SerializationUtil::read_var_str(value, in);
256-
tsfile_properties_.emplace(key, std::move(value));
257+
common::SerializationUtil::read_var_char_ptr(value, in);
258+
tsfile_properties_.emplace(key, value);
257259
}
258260
return ret;
259261
}
260262

261263
/* ================ MetaIndexNode ================ */
262-
int MetaIndexNode::binary_search_children(std::shared_ptr<IComparable> key, bool exact_search,
263-
std::shared_ptr<IMetaIndexEntry> &ret_index_entry,
264-
int64_t &ret_end_offset) {
264+
int MetaIndexNode::binary_search_children(
265+
std::shared_ptr<IComparable> key, bool exact_search,
266+
std::shared_ptr<IMetaIndexEntry> &ret_index_entry,
267+
int64_t &ret_end_offset) {
265268
#if DEBUG_SE
266269
std::cout << "MetaIndexNode::binary_search_children start, name=" << key
267270
<< ", exact_search=" << exact_search
268271
<< ", children_.size=" << children_.size() << std::endl;
269272
for (int i = 0; i < (int)children_.size(); i++) {
270-
std::cout << "Iterating children: " << children_[i]->get_name() << std::endl;
273+
std::cout << "Iterating children: " << children_[i]->get_name()
274+
<< std::endl;
271275
}
272276
#endif
273277
bool is_aligned = false;
@@ -298,7 +302,7 @@ int MetaIndexNode::binary_search_children(std::shared_ptr<IComparable> key, bool
298302
break;
299303
} else if (cmp > 0) { // children_[m] > name
300304
h = m;
301-
} else { // children_[m] < name
305+
} else { // children_[m] < name
302306
l = m;
303307
}
304308
}

cpp/src/common/tsfile_common.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,8 @@ struct DeviceIDComparable : IComparable {
677677
const auto *other_device =
678678
dynamic_cast<const DeviceIDComparable *>(&other);
679679
if (!other_device) throw std::runtime_error("Incompatible comparison");
680-
return *device_id_ != *other_device->device_id_ && !(*device_id_ < *other_device->device_id_);
680+
return *device_id_ != *other_device->device_id_ &&
681+
!(*device_id_ < *other_device->device_id_);
681682
}
682683

683684
bool operator==(const IComparable &other) const override {
@@ -1066,7 +1067,7 @@ struct TsFileMeta {
10661067
DeviceNodeMap;
10671068
std::map<std::string, std::shared_ptr<MetaIndexNode>>
10681069
table_metadata_index_node_map_;
1069-
std::unordered_map<std::string, std::string> tsfile_properties_;
1070+
std::unordered_map<std::string, std::string *> tsfile_properties_;
10701071
typedef std::unordered_map<std::string, std::shared_ptr<TableSchema>>
10711072
TableSchemasMap;
10721073
TableSchemasMap table_schemas_;
@@ -1104,6 +1105,11 @@ struct TsFileMeta {
11041105
if (bloom_filter_ != nullptr) {
11051106
bloom_filter_->destroy();
11061107
}
1108+
for (auto properties : tsfile_properties_) {
1109+
if (properties.second != nullptr) {
1110+
delete properties.second;
1111+
}
1112+
}
11071113
table_metadata_index_node_map_.clear();
11081114
table_schemas_.clear();
11091115
}

cpp/src/file/tsfile_io_writer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@ int TsFileIOWriter::write_file_index() {
460460
tsfile_meta.table_metadata_index_node_map_ = table_nodes_map;
461461
tsfile_meta.table_schemas_ = schema_->table_schema_map_;
462462
tsfile_meta.tsfile_properties_.insert(
463-
std::make_pair("encryptLevel", encrypt_level_));
463+
std::make_pair("encryptLevel", new std::string(encrypt_level_)));
464464
tsfile_meta.tsfile_properties_.insert(
465-
std::make_pair("encryptType", encrypt_type_));
465+
std::make_pair("encryptType", new std::string(encrypt_type_)));
466466
tsfile_meta.tsfile_properties_.insert(
467-
std::make_pair("encryptKey", encrypt_key_));
467+
std::make_pair("encryptKey", nullptr));
468468
#if DEBUG_SE
469469
auto tsfile_meta_offset = write_stream_.total_size();
470470
#endif

0 commit comments

Comments
 (0)