|
20 | 20 | #include <gen_cpp/AgentService_types.h>
|
21 | 21 | #include <gtest/gtest-message.h>
|
22 | 22 | #include <gtest/gtest-test-part.h>
|
| 23 | +#include <gtest/gtest.h> |
23 | 24 | #include <stdlib.h>
|
24 | 25 | #include <unistd.h>
|
25 | 26 |
|
|
39 | 40 | #include "io/fs/local_file_system.h"
|
40 | 41 | #include "olap/data_dir.h"
|
41 | 42 | #include "olap/iterators.h"
|
| 43 | +#include "olap/olap_common.h" |
42 | 44 | #include "olap/olap_define.h"
|
43 | 45 | #include "olap/options.h"
|
44 | 46 | #include "olap/rowset/beta_rowset.h"
|
| 47 | +#include "olap/rowset/rowset_fwd.h" |
45 | 48 | #include "olap/rowset/segment_v2/segment.h"
|
46 | 49 | #include "olap/rowset_builder.h"
|
47 | 50 | #include "olap/schema.h"
|
|
55 | 58 | #include "runtime/descriptor_helper.h"
|
56 | 59 | #include "runtime/descriptors.h"
|
57 | 60 | #include "runtime/exec_env.h"
|
| 61 | +#include "testutil/desc_tbl_builder.h" |
58 | 62 | #include "vec/columns/column.h"
|
| 63 | +#include "vec/columns/column_map.h" |
| 64 | +#include "vec/columns/column_struct.h" |
59 | 65 | #include "vec/core/block.h"
|
60 | 66 | #include "vec/core/column_with_type_and_name.h"
|
61 | 67 | #include "vec/runtime/vdatetime_value.h"
|
@@ -1047,4 +1053,195 @@ TEST_F(TestDeltaWriter, vec_sequence_col_concurrent_write) {
|
1047 | 1053 | res = engine_ref->tablet_manager()->drop_tablet(request.tablet_id, request.replica_id, false);
|
1048 | 1054 | ASSERT_TRUE(res.ok());
|
1049 | 1055 | }
|
| 1056 | + |
| 1057 | +TEST_F(TestDeltaWriter, write_sigle_block_statistics_segment_meta_pb) { |
| 1058 | + std::unique_ptr<RuntimeProfile> profile; |
| 1059 | + profile = std::make_unique<RuntimeProfile>("CreateTablet"); |
| 1060 | + TCreateTabletReq request; |
| 1061 | + create_tablet_request(10010, 270068330, &request); |
| 1062 | + Status res = engine_ref->create_tablet(request, profile.get()); |
| 1063 | + EXPECT_EQ(Status::OK(), res); |
| 1064 | + |
| 1065 | + TDescriptorTable tdesc_tbl = create_descriptor_tablet(); |
| 1066 | + ObjectPool obj_pool; |
| 1067 | + DescriptorTbl* desc_tbl = nullptr; |
| 1068 | + static_cast<void>(DescriptorTbl::create(&obj_pool, tdesc_tbl, &desc_tbl)); |
| 1069 | + TupleDescriptor* tuple_desc = desc_tbl->get_tuple_descriptor(0); |
| 1070 | + auto param = std::make_shared<OlapTableSchemaParam>(); |
| 1071 | + |
| 1072 | + PUniqueId load_id; |
| 1073 | + load_id.set_hi(0); |
| 1074 | + load_id.set_lo(0); |
| 1075 | + WriteRequest write_req; |
| 1076 | + write_req.tablet_id = 10010; |
| 1077 | + write_req.schema_hash = 270068330; |
| 1078 | + write_req.txn_id = 20002; |
| 1079 | + write_req.partition_id = 30003; |
| 1080 | + write_req.load_id = load_id; |
| 1081 | + write_req.tuple_desc = tuple_desc; |
| 1082 | + write_req.slots = &(tuple_desc->slots()); |
| 1083 | + write_req.is_high_priority = true; |
| 1084 | + write_req.table_schema_param = param; |
| 1085 | + |
| 1086 | + // test vec delta writer |
| 1087 | + profile = std::make_unique<RuntimeProfile>("LoadChannels"); |
| 1088 | + auto delta_writer = |
| 1089 | + std::make_unique<DeltaWriter>(*engine_ref, write_req, profile.get(), TUniqueId {}); |
| 1090 | + EXPECT_NE(delta_writer, nullptr); |
| 1091 | + |
| 1092 | + vectorized::Block block; |
| 1093 | + for (const auto& slot_desc : tuple_desc->slots()) { |
| 1094 | + block.insert(vectorized::ColumnWithTypeAndName(slot_desc->get_empty_mutable_column(), |
| 1095 | + slot_desc->type(), slot_desc->col_name())); |
| 1096 | + } |
| 1097 | + |
| 1098 | + auto columns = block.mutate_columns(); |
| 1099 | + { |
| 1100 | + int8_t k1 = -127; |
| 1101 | + columns[0]->insert_data((const char*)&k1, sizeof(k1)); |
| 1102 | + |
| 1103 | + int16_t k2 = -32767; |
| 1104 | + columns[1]->insert_data((const char*)&k2, sizeof(k2)); |
| 1105 | + |
| 1106 | + int32_t k3 = -2147483647; |
| 1107 | + columns[2]->insert_data((const char*)&k3, sizeof(k3)); |
| 1108 | + |
| 1109 | + int64_t k4 = -9223372036854775807L; |
| 1110 | + columns[3]->insert_data((const char*)&k4, sizeof(k4)); |
| 1111 | + |
| 1112 | + int128_t k5 = -90000; |
| 1113 | + columns[4]->insert_data((const char*)&k5, sizeof(k5)); |
| 1114 | + |
| 1115 | + VecDateTimeValue k6; |
| 1116 | + k6.from_date_str("2048-11-10", 10); |
| 1117 | + auto k6_int = k6.to_int64(); |
| 1118 | + columns[5]->insert_data((const char*)&k6_int, sizeof(k6_int)); |
| 1119 | + |
| 1120 | + VecDateTimeValue k7; |
| 1121 | + k7.from_date_str("2636-08-16 19:39:43", 19); |
| 1122 | + auto k7_int = k7.to_int64(); |
| 1123 | + columns[6]->insert_data((const char*)&k7_int, sizeof(k7_int)); |
| 1124 | + |
| 1125 | + columns[7]->insert_data("abcd", 4); |
| 1126 | + columns[8]->insert_data("abcde", 5); |
| 1127 | + |
| 1128 | + DecimalV2Value decimal_value; |
| 1129 | + decimal_value.assign_from_double(1.1); |
| 1130 | + columns[9]->insert_data((const char*)&decimal_value, sizeof(decimal_value)); |
| 1131 | + |
| 1132 | + DateV2Value<DateV2ValueType> date_v2; |
| 1133 | + date_v2.from_date_str("2048-11-10", 10); |
| 1134 | + auto date_v2_int = date_v2.to_date_int_val(); |
| 1135 | + columns[10]->insert_data((const char*)&date_v2_int, sizeof(date_v2_int)); |
| 1136 | + |
| 1137 | + int8_t v1 = -127; |
| 1138 | + columns[11]->insert_data((const char*)&v1, sizeof(v1)); |
| 1139 | + |
| 1140 | + int16_t v2 = -32767; |
| 1141 | + columns[12]->insert_data((const char*)&v2, sizeof(v2)); |
| 1142 | + |
| 1143 | + int32_t v3 = -2147483647; |
| 1144 | + columns[13]->insert_data((const char*)&v3, sizeof(v3)); |
| 1145 | + |
| 1146 | + int64_t v4 = -9223372036854775807L; |
| 1147 | + columns[14]->insert_data((const char*)&v4, sizeof(v4)); |
| 1148 | + |
| 1149 | + int128_t v5 = -90000; |
| 1150 | + columns[15]->insert_data((const char*)&v5, sizeof(v5)); |
| 1151 | + |
| 1152 | + VecDateTimeValue v6; |
| 1153 | + v6.from_date_str("2048-11-10", 10); |
| 1154 | + auto v6_int = v6.to_int64(); |
| 1155 | + columns[16]->insert_data((const char*)&v6_int, sizeof(v6_int)); |
| 1156 | + |
| 1157 | + VecDateTimeValue v7; |
| 1158 | + v7.from_date_str("2636-08-16 19:39:43", 19); |
| 1159 | + auto v7_int = v7.to_int64(); |
| 1160 | + columns[17]->insert_data((const char*)&v7_int, sizeof(v7_int)); |
| 1161 | + |
| 1162 | + columns[18]->insert_data("abcd", 4); |
| 1163 | + columns[19]->insert_data("abcde", 5); |
| 1164 | + |
| 1165 | + decimal_value.assign_from_double(1.1); |
| 1166 | + columns[20]->insert_data((const char*)&decimal_value, sizeof(decimal_value)); |
| 1167 | + |
| 1168 | + date_v2.from_date_str("2048-11-10", 10); |
| 1169 | + date_v2_int = date_v2.to_date_int_val(); |
| 1170 | + columns[21]->insert_data((const char*)&date_v2_int, sizeof(date_v2_int)); |
| 1171 | + |
| 1172 | + res = delta_writer->write(&block, {0}); |
| 1173 | + ASSERT_TRUE(res.ok()); |
| 1174 | + } |
| 1175 | + |
| 1176 | + res = delta_writer->close(); |
| 1177 | + EXPECT_EQ(Status::OK(), res); |
| 1178 | + res = delta_writer->build_rowset(); |
| 1179 | + EXPECT_EQ(Status::OK(), res); |
| 1180 | + res = delta_writer->commit_txn(PSlaveTabletNodes()); |
| 1181 | + EXPECT_EQ(Status::OK(), res); |
| 1182 | + |
| 1183 | + // publish version success |
| 1184 | + TabletSharedPtr tablet = engine_ref->tablet_manager()->get_tablet(write_req.tablet_id); |
| 1185 | + std::cout << "before publish, tablet row nums:" << tablet->num_rows() << std::endl; |
| 1186 | + OlapMeta* meta = tablet->data_dir()->get_meta(); |
| 1187 | + Version version; |
| 1188 | + version.first = tablet->get_rowset_with_max_version()->end_version() + 1; |
| 1189 | + version.second = tablet->get_rowset_with_max_version()->end_version() + 1; |
| 1190 | + std::cout << "start to add rowset version:" << version.first << "-" << version.second |
| 1191 | + << std::endl; |
| 1192 | + std::map<TabletInfo, RowsetSharedPtr> tablet_related_rs; |
| 1193 | + engine_ref->txn_manager()->get_txn_related_tablets(write_req.txn_id, write_req.partition_id, |
| 1194 | + &tablet_related_rs); |
| 1195 | + for (auto& tablet_rs : tablet_related_rs) { |
| 1196 | + std::cout << "start to publish txn" << std::endl; |
| 1197 | + RowsetSharedPtr rowset = tablet_rs.second; |
| 1198 | + TabletPublishStatistics stats; |
| 1199 | + std::shared_ptr<TabletTxnInfo> extend_tablet_txn_info_lifetime = nullptr; |
| 1200 | + res = engine_ref->txn_manager()->publish_txn( |
| 1201 | + meta, write_req.partition_id, write_req.txn_id, write_req.tablet_id, |
| 1202 | + tablet_rs.first.tablet_uid, version, &stats, extend_tablet_txn_info_lifetime); |
| 1203 | + ASSERT_TRUE(res.ok()); |
| 1204 | + std::cout << "start to add inc rowset:" << rowset->rowset_id() |
| 1205 | + << ", num rows:" << rowset->num_rows() << ", version:" << rowset->version().first |
| 1206 | + << "-" << rowset->version().second << std::endl; |
| 1207 | + res = tablet->add_inc_rowset(rowset); |
| 1208 | + ASSERT_TRUE(res.ok()); |
| 1209 | + } |
| 1210 | + ASSERT_EQ(1, tablet->num_rows()); |
| 1211 | + |
| 1212 | + std::vector<RowsetSharedPtr> all_rowsets; |
| 1213 | + res = tablet->capture_consistent_rowsets_unlocked( |
| 1214 | + Version(0, tablet->get_rowset_with_max_version()->end_version()), &all_rowsets); |
| 1215 | + EXPECT_EQ(Status::OK(), res); |
| 1216 | + |
| 1217 | + auto total_column_data_size = 0; |
| 1218 | + auto total_segoemt_data_footprint = 0; |
| 1219 | + |
| 1220 | + for (auto& rs : all_rowsets) { |
| 1221 | + std::vector<segment_v2::SegmentSharedPtr> segments; |
| 1222 | + Status res = ((BetaRowset*)rs.get())->load_segments(&segments); |
| 1223 | + |
| 1224 | + for (const auto& segment : segments) { |
| 1225 | + std::shared_ptr<SegmentFooterPB> footer_pb_shared; |
| 1226 | + |
| 1227 | + res = segment->get_segment_footer(footer_pb_shared, nullptr); |
| 1228 | + EXPECT_EQ(Status::OK(), res); |
| 1229 | + |
| 1230 | + auto seg_footprint = footer_pb_shared->data_footprint(); |
| 1231 | + |
| 1232 | + for (const auto& column : footer_pb_shared->columns()) { |
| 1233 | + auto column_data_size = column.estimate_total_data_size(); |
| 1234 | + total_column_data_size += column_data_size; |
| 1235 | + } |
| 1236 | + |
| 1237 | + total_segoemt_data_footprint += seg_footprint; |
| 1238 | + } |
| 1239 | + } |
| 1240 | + |
| 1241 | + EXPECT_EQ(total_column_data_size, total_segoemt_data_footprint); |
| 1242 | + |
| 1243 | + res = engine_ref->tablet_manager()->drop_tablet(request.tablet_id, request.replica_id, false); |
| 1244 | + EXPECT_EQ(Status::OK(), res); |
| 1245 | +} |
| 1246 | + |
1050 | 1247 | } // namespace doris
|
0 commit comments