Skip to content

Commit 3d51d22

Browse files
committed
Add clear method to TimestampDictionaryWriter
1 parent 53434a7 commit 3d51d22

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

components/core/src/clp_s/ArchiveWriter.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ void ArchiveWriter::open(ArchiveWriterOption const& option) {
4040
std::string array_dict_path = m_archive_path + constants::cArchiveArrayDictFile;
4141
m_array_dict = std::make_shared<LogTypeDictionaryWriter>();
4242
m_array_dict->open(array_dict_path, m_compression_level, UINT64_MAX);
43-
44-
m_timestamp_dict = std::make_shared<TimestampDictionaryWriter>();
4543
}
4644

4745
void ArchiveWriter::close() {
@@ -90,6 +88,7 @@ void ArchiveWriter::close() {
9088
m_id_to_schema_writer.clear();
9189
m_schema_tree.clear();
9290
m_schema_map.clear();
91+
m_timestamp_dict.clear();
9392
m_encoded_message_size = 0UL;
9493
m_uncompressed_size = 0UL;
9594
m_compressed_size = 0UL;
@@ -101,7 +100,7 @@ size_t ArchiveWriter::write_timestamp_dict() {
101100
ZstdCompressor timestamp_dict_compressor;
102101
timestamp_dict_file_writer.open(timestamp_dict_path, FileWriter::OpenMode::CreateForWriting);
103102
timestamp_dict_compressor.open(timestamp_dict_file_writer, m_compression_level);
104-
m_timestamp_dict->write(timestamp_dict_compressor);
103+
m_timestamp_dict.write(timestamp_dict_compressor);
105104
timestamp_dict_compressor.close();
106105
auto compressed_size = timestamp_dict_file_writer.get_pos();
107106
timestamp_dict_file_writer.close();
@@ -152,7 +151,7 @@ void ArchiveWriter::write_archive_metadata(
152151

153152
// Write timestamp dictionary
154153
compressor.write_numeric_value(ArchiveMetadataPacketType::TimestampDictionary);
155-
m_timestamp_dict->write(compressor);
154+
m_timestamp_dict.write(compressor);
156155

157156
compressor.close();
158157
}
@@ -388,8 +387,8 @@ void ArchiveWriter::update_metadata_db() {
388387
metadata.increment_static_compressed_size(m_compressed_size);
389388
metadata.increment_static_uncompressed_size(m_uncompressed_size);
390389
metadata.expand_time_range(
391-
m_timestamp_dict->get_begin_timestamp(),
392-
m_timestamp_dict->get_end_timestamp()
390+
m_timestamp_dict.get_begin_timestamp(),
391+
m_timestamp_dict.get_end_timestamp()
393392
);
394393

395394
m_metadata_db->add_archive(m_id, metadata);

components/core/src/clp_s/ArchiveWriter.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ArchiveWriter {
121121
std::string const& timestamp,
122122
uint64_t& pattern_id
123123
) {
124-
return m_timestamp_dict->ingest_entry(key, node_id, timestamp, pattern_id);
124+
return m_timestamp_dict.ingest_entry(key, node_id, timestamp, pattern_id);
125125
}
126126

127127
/**
@@ -131,11 +131,11 @@ class ArchiveWriter {
131131
* @param timestamp
132132
*/
133133
void ingest_timestamp_entry(std::string const& key, int32_t node_id, double timestamp) {
134-
m_timestamp_dict->ingest_entry(key, node_id, timestamp);
134+
m_timestamp_dict.ingest_entry(key, node_id, timestamp);
135135
}
136136

137137
void ingest_timestamp_entry(std::string const& key, int32_t node_id, int64_t timestamp) {
138-
m_timestamp_dict->ingest_entry(key, node_id, timestamp);
138+
m_timestamp_dict.ingest_entry(key, node_id, timestamp);
139139
}
140140

141141
/**
@@ -229,7 +229,7 @@ class ArchiveWriter {
229229
std::shared_ptr<VariableDictionaryWriter> m_var_dict;
230230
std::shared_ptr<LogTypeDictionaryWriter> m_log_dict;
231231
std::shared_ptr<LogTypeDictionaryWriter> m_array_dict; // log type dictionary for arrays
232-
std::shared_ptr<TimestampDictionaryWriter> m_timestamp_dict;
232+
TimestampDictionaryWriter m_timestamp_dict;
233233
std::shared_ptr<clp::GlobalMySQLMetadataDB> m_metadata_db;
234234
int m_compression_level{};
235235
bool m_print_archive_stats{};

components/core/src/clp_s/TimestampDictionaryWriter.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,11 @@ epochtime_t TimestampDictionaryWriter::get_end_timestamp() const {
149149

150150
return it->second.get_end_timestamp();
151151
}
152+
153+
void TimestampDictionaryWriter::clear() {
154+
m_next_id = 0;
155+
m_pattern_to_id.clear();
156+
m_column_key_to_range.clear();
157+
m_column_id_to_range.clear();
158+
}
152159
} // namespace clp_s

components/core/src/clp_s/TimestampDictionaryWriter.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CLP_S_TIMESTAMPDICTIONARYWRITER_HPP
22
#define CLP_S_TIMESTAMPDICTIONARYWRITER_HPP
33

4+
#include <map>
45
#include <string>
56
#include <unordered_map>
67
#include <utility>
@@ -77,6 +78,11 @@ class TimestampDictionaryWriter {
7778
*/
7879
epochtime_t get_end_timestamp() const;
7980

81+
/**
82+
* Clears and resets all internal state.
83+
*/
84+
void clear();
85+
8086
private:
8187
/**
8288
* Merges timestamp ranges with the same key name but different node ids.

0 commit comments

Comments
 (0)