@@ -48,7 +48,13 @@ void JsonConstructor::store() {
48
48
m_archive_reader = std::make_unique<ArchiveReader>();
49
49
m_archive_reader->open (m_option.archives_dir , m_option.archive_id );
50
50
m_archive_reader->read_dictionaries_and_metadata ();
51
- if (false == m_option.ordered ) {
51
+
52
+ if (m_option.ordered && false == m_archive_reader->has_log_order ()) {
53
+ SPDLOG_WARN (" This archive is missing ordering information and can not be decompressed in "
54
+ " log order. Falling back to out of order decompression." );
55
+ }
56
+
57
+ if (false == m_option.ordered || false == m_archive_reader->has_log_order ()) {
52
58
FileWriter writer;
53
59
writer.open (
54
60
m_option.output_dir + " /original" ,
@@ -68,15 +74,15 @@ void JsonConstructor::construct_in_order() {
68
74
auto tables = m_archive_reader->read_all_tables ();
69
75
using ReaderPointer = std::shared_ptr<SchemaReader>;
70
76
auto cmp = [](ReaderPointer& left, ReaderPointer& right) {
71
- return left->get_next_timestamp () > right->get_next_timestamp ();
77
+ return left->get_next_log_event_idx () > right->get_next_log_event_idx ();
72
78
};
73
79
std::priority_queue record_queue (tables.begin (), tables.end (), cmp);
74
80
// Clear tables vector so that memory gets deallocated after we have marshalled all records for
75
81
// a given table
76
82
tables.clear ();
77
83
78
- epochtime_t first_timestamp {0 };
79
- epochtime_t last_timestamp {0 };
84
+ int64_t first_idx {0 };
85
+ int64_t last_idx {0 };
80
86
size_t num_records_marshalled{0 };
81
87
auto src_path = std::filesystem::path (m_option.output_dir ) / m_option.archive_id ;
82
88
FileWriter writer;
@@ -97,9 +103,11 @@ void JsonConstructor::construct_in_order() {
97
103
98
104
std::vector<bsoncxx::document::value> results;
99
105
auto finalize_chunk = [&](bool open_new_writer) {
106
+ // Add one to last_idx to match clp's behaviour of having the end index be exclusive
107
+ ++last_idx;
100
108
writer.close ();
101
- std::string new_file_name = src_path.string () + " _" + std::to_string (first_timestamp ) + " _"
102
- + std::to_string (last_timestamp ) + " .jsonl" ;
109
+ std::string new_file_name = src_path.string () + " _" + std::to_string (first_idx ) + " _"
110
+ + std::to_string (last_idx ) + " .jsonl" ;
103
111
auto new_file_path = std::filesystem::path (new_file_name);
104
112
std::error_code ec;
105
113
std::filesystem::rename (src_path, new_file_path, ec);
@@ -119,11 +127,11 @@ void JsonConstructor::construct_in_order() {
119
127
),
120
128
bsoncxx::builder::basic::kvp (
121
129
constants::results_cache::decompression::cBeginMsgIx,
122
- static_cast < int64_t >(first_timestamp)
130
+ first_idx
123
131
),
124
132
bsoncxx::builder::basic::kvp (
125
133
constants::results_cache::decompression::cEndMsgIx,
126
- static_cast < int64_t >(last_timestamp)
134
+ last_idx
127
135
),
128
136
bsoncxx::builder::basic::kvp (
129
137
constants::results_cache::decompression::cIsLastIrChunk,
@@ -140,9 +148,9 @@ void JsonConstructor::construct_in_order() {
140
148
while (false == record_queue.empty ()) {
141
149
ReaderPointer next = record_queue.top ();
142
150
record_queue.pop ();
143
- last_timestamp = next->get_next_timestamp ();
151
+ last_idx = next->get_next_log_event_idx ();
144
152
if (0 == num_records_marshalled) {
145
- first_timestamp = last_timestamp ;
153
+ first_idx = last_idx ;
146
154
}
147
155
next->get_next_message (buffer);
148
156
if (false == next->done ()) {
0 commit comments