MCPcopy Create free account
hub / github.com/ByConity/ByConity / processPartitionPieceTaskImpl

Method processPartitionPieceTaskImpl

programs/copier/ClusterCopier.cpp:1249–1649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1247
1248
1249TaskStatus ClusterCopier::processPartitionPieceTaskImpl(
1250 const ConnectionTimeouts & timeouts, ShardPartition & task_partition,
1251 const size_t current_piece_number, bool is_unprioritized_task)
1252{
1253 TaskShard & task_shard = task_partition.task_shard;
1254 TaskTable & task_table = task_shard.task_table;
1255 ClusterPartition & cluster_partition = task_table.getClusterPartition(task_partition.name);
1256 ShardPartitionPiece & partition_piece = task_partition.pieces[current_piece_number];
1257
1258 const size_t number_of_splits = task_table.number_of_splits;
1259 const String primary_key_comma_separated = task_table.primary_key_comma_separated;
1260
1261 /// We need to update table definitions for each partition, it could be changed after ALTER
1262 createShardInternalTables(timeouts, task_shard, true);
1263
1264 auto split_table_for_current_piece = task_shard.list_of_split_tables_on_shard[current_piece_number];
1265
1266 auto zookeeper = getContext()->getZooKeeper();
1267
1268 const String piece_is_dirty_flag_path = partition_piece.getPartitionPieceIsDirtyPath();
1269 const String piece_is_dirty_cleaned_path = partition_piece.getPartitionPieceIsCleanedPath();
1270 const String current_task_piece_is_active_path = partition_piece.getActiveWorkerPath();
1271 const String current_task_piece_status_path = partition_piece.getShardStatusPath();
1272
1273 /// Auxiliary functions:
1274
1275 /// Creates is_dirty node to initialize DROP PARTITION
1276 auto create_is_dirty_node = [&] (const CleanStateClock & clock)
1277 {
1278 if (clock.is_stale())
1279 LOG_INFO(log, "Clean state clock is stale while setting dirty flag, cowardly bailing");
1280 else if (!clock.is_clean())
1281 LOG_INFO(log, "Thank you, Captain Obvious");
1282 else if (clock.discovery_version)
1283 {
1284 LOG_INFO(log, "Updating clean state clock");
1285 zookeeper->set(piece_is_dirty_flag_path, host_id, clock.discovery_version.value());
1286 }
1287 else
1288 {
1289 LOG_INFO(log, "Creating clean state clock");
1290 zookeeper->create(piece_is_dirty_flag_path, host_id, zkutil::CreateMode::Persistent);
1291 }
1292 };
1293
1294 /// Returns SELECT query filtering current partition and applying user filter
1295 auto get_select_query = [&] (const DatabaseAndTableName & from_table, const String & fields, bool enable_splitting, String limit = "")
1296 {
1297 String query;
1298 query += "SELECT " + fields + " FROM " + getQuotedTable(from_table);
1299
1300 if (enable_splitting && experimental_use_sample_offset)
1301 query += " SAMPLE 1/" + toString(number_of_splits) + " OFFSET " + toString(current_piece_number) + "/" + toString(number_of_splits);
1302
1303 /// TODO: Bad, it is better to rewrite with ASTLiteral(partition_key_field)
1304 query += " WHERE (" + queryToString(task_table.engine_push_partition_key_ast) + " = (" + task_partition.name + " AS partition_key))";
1305
1306 if (enable_splitting && !experimental_use_sample_offset)

Callers

nothing calls this directly

Calls 15

getQuotedTableFunction · 0.85
queryToStringFunction · 0.85
parseQueryFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
fromStringFunction · 0.85
is_staleMethod · 0.80
is_cleanMethod · 0.80

Tested by

no test coverage detected