From be1f11fe159eddde46c768fccfb9a68a809dcc12 Mon Sep 17 00:00:00 2001 From: CalvinNeo Date: Tue, 8 Feb 2022 16:29:43 +0800 Subject: [PATCH 1/5] add type_apply_snapshot_predecode_e2e Signed-off-by: CalvinNeo --- dbms/src/Common/TiFlashMetrics.h | 1 + dbms/src/Storages/Transaction/ApplySnapshot.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/dbms/src/Common/TiFlashMetrics.h b/dbms/src/Common/TiFlashMetrics.h index 5ae7e1f015e..71652226f9d 100644 --- a/dbms/src/Common/TiFlashMetrics.h +++ b/dbms/src/Common/TiFlashMetrics.h @@ -141,6 +141,7 @@ namespace DB Histogram, /* these command usually cost servel seconds, increase the start bucket to 50ms */ \ F(type_ingest_sst, {{"type", "ingest_sst"}}, ExpBuckets{0.05, 2, 10}), \ F(type_apply_snapshot_predecode, {{"type", "snapshot_predecode"}}, ExpBuckets{0.05, 2, 10}), \ + F(type_apply_snapshot_predecode_e2e, {{"type", "snapshot_predecode_e2e"}}, ExpBuckets{0.05, 2, 10}), \ F(type_apply_snapshot_flush, {{"type", "snapshot_flush"}}, ExpBuckets{0.05, 2, 10})) \ M(tiflash_raft_process_keys, "Total number of keys processed in some types of Raft commands", Counter, \ F(type_apply_snapshot, {"type", "apply_snapshot"}), F(type_ingest_sst, {"type", "ingest_sst"})) \ diff --git a/dbms/src/Storages/Transaction/ApplySnapshot.cpp b/dbms/src/Storages/Transaction/ApplySnapshot.cpp index dd9f39c5b84..90bbdbacbe5 100644 --- a/dbms/src/Storages/Transaction/ApplySnapshot.cpp +++ b/dbms/src/Storages/Transaction/ApplySnapshot.cpp @@ -228,6 +228,7 @@ RegionPreDecodeBlockDataPtr KVStore::preHandleSnapshotToBlock( Stopwatch watch; auto & ctx = tmt.getContext(); + SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode_e2e).Observe(watch.elapsedSeconds()); }); SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode).Observe(watch.elapsedSeconds()); }); { @@ -297,6 +298,9 @@ std::vector KVStore::preHandleSSTsToDTFiles( // Use failpoint to change the expected_block_size for some test cases fiu_do_on(FailPoints::force_set_sst_to_dtfile_block_size, { expected_block_size = 3; }); + Stopwatch watch; + SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode_e2e).Observe(watch.elapsedSeconds()); }); + PageIds ids; while (true) { From b8f711014a9760efbd97eeac7e35bbd4403e1f9f Mon Sep 17 00:00:00 2001 From: CalvinNeo Date: Wed, 9 Feb 2022 14:31:06 +0800 Subject: [PATCH 2/5] add metrics Signed-off-by: CalvinNeo --- metrics/grafana/tiflash_summary.json | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/metrics/grafana/tiflash_summary.json b/metrics/grafana/tiflash_summary.json index 2ce7b183811..6bbed97008a 100644 --- a/metrics/grafana/tiflash_summary.json +++ b/metrics/grafana/tiflash_summary.json @@ -5267,6 +5267,72 @@ "yBucketNumber": null, "yBucketSize": null }, + { + "cards": { + "cardPadding": null, + "cardRound": null + }, + "color": { + "cardColor": "#b4ff00", + "colorScale": "sqrt", + "colorScheme": "interpolateSpectral", + "exponent": 0.5, + "min": 0, + "mode": "spectrum" + }, + "dataFormat": "tsbuckets", + "datasource": "${DS_TEST-CLUSTER}", + "description": "Duration of end to end pre-decode when applying region snapshot", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 34 + }, + "heatmap": {}, + "hideZeroBuckets": true, + "highlightCards": true, + "id": 100, + "legend": { + "show": true + }, + "links": [], + "reverseYBuckets": false, + "targets": [ + { + "expr": "sum(delta(tiflash_raft_command_duration_seconds_bucket{tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", type=\"snapshot_predecode_e2e\"}[1m])) by (le)", + "format": "heatmap", + "intervalFactor": 2, + "legendFormat": "{{le}}", + "refId": "B" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Snapshot Predecode End To End Duration", + "tooltip": { + "show": true, + "showHistogram": true + }, + "type": "heatmap", + "xAxis": { + "show": true + }, + "xBucketNumber": null, + "xBucketSize": null, + "yAxis": { + "decimals": 0, + "format": "s", + "logBase": 1, + "max": null, + "min": null, + "show": true, + "splitFactor": null + }, + "yBucketBound": "upper", + "yBucketNumber": null, + "yBucketSize": null + }, { "cards": { "cardPadding": null, From 5fed30997b05803285546235303729f3a3c8b366 Mon Sep 17 00:00:00 2001 From: CalvinNeo Date: Mon, 28 Feb 2022 10:09:19 +0800 Subject: [PATCH 3/5] Rename Signed-off-by: CalvinNeo --- dbms/src/Common/TiFlashMetrics.h | 2 +- .../Storages/DeltaMerge/SSTFilesToDTFilesOutputStream.cpp | 2 +- dbms/src/Storages/Transaction/ApplySnapshot.cpp | 3 +-- metrics/grafana/tiflash_summary.json | 6 +++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dbms/src/Common/TiFlashMetrics.h b/dbms/src/Common/TiFlashMetrics.h index 71652226f9d..eb7f2f45049 100644 --- a/dbms/src/Common/TiFlashMetrics.h +++ b/dbms/src/Common/TiFlashMetrics.h @@ -141,7 +141,7 @@ namespace DB Histogram, /* these command usually cost servel seconds, increase the start bucket to 50ms */ \ F(type_ingest_sst, {{"type", "ingest_sst"}}, ExpBuckets{0.05, 2, 10}), \ F(type_apply_snapshot_predecode, {{"type", "snapshot_predecode"}}, ExpBuckets{0.05, 2, 10}), \ - F(type_apply_snapshot_predecode_e2e, {{"type", "snapshot_predecode_e2e"}}, ExpBuckets{0.05, 2, 10}), \ + F(type_apply_snapshot_predecode_sst2dt, {{"type", "snapshot_predecode_sst2dt"}}, ExpBuckets{0.05, 2, 10}), \ F(type_apply_snapshot_flush, {{"type", "snapshot_flush"}}, ExpBuckets{0.05, 2, 10})) \ M(tiflash_raft_process_keys, "Total number of keys processed in some types of Raft commands", Counter, \ F(type_apply_snapshot, {"type", "apply_snapshot"}), F(type_ingest_sst, {"type", "ingest_sst"})) \ diff --git a/dbms/src/Storages/DeltaMerge/SSTFilesToDTFilesOutputStream.cpp b/dbms/src/Storages/DeltaMerge/SSTFilesToDTFilesOutputStream.cpp index 315d2cfb8e3..6f1f49d9a8b 100644 --- a/dbms/src/Storages/DeltaMerge/SSTFilesToDTFilesOutputStream.cpp +++ b/dbms/src/Storages/DeltaMerge/SSTFilesToDTFilesOutputStream.cpp @@ -79,7 +79,7 @@ void SSTFilesToDTFilesOutputStream::writeSuffix() const auto process_keys = child->getProcessKeys(); if (job_type == FileConvertJobType::ApplySnapshot) { - GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode).Observe(watch.elapsedSeconds()); + GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode_sst2dt).Observe(watch.elapsedSeconds()); // Note that number of keys in different cf will be aggregated into one metrics GET_METRIC(tiflash_raft_process_keys, type_apply_snapshot).Increment(process_keys.total()); } diff --git a/dbms/src/Storages/Transaction/ApplySnapshot.cpp b/dbms/src/Storages/Transaction/ApplySnapshot.cpp index dfa7e079dd7..e2596cf61f3 100644 --- a/dbms/src/Storages/Transaction/ApplySnapshot.cpp +++ b/dbms/src/Storages/Transaction/ApplySnapshot.cpp @@ -255,7 +255,6 @@ RegionPreDecodeBlockDataPtr KVStore::preHandleSnapshotToBlock( Stopwatch watch; auto & ctx = tmt.getContext(); - SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode_e2e).Observe(watch.elapsedSeconds()); }); SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode).Observe(watch.elapsedSeconds()); }); { @@ -332,7 +331,7 @@ std::vector KVStore::preHandleSSTsToDTFiles( fiu_do_on(FailPoints::force_set_sst_to_dtfile_block_size, { expected_block_size = 3; }); Stopwatch watch; - SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode_e2e).Observe(watch.elapsedSeconds()); }); + SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode).Observe(watch.elapsedSeconds()); }); PageIds ids; while (true) diff --git a/metrics/grafana/tiflash_summary.json b/metrics/grafana/tiflash_summary.json index 119688e67e8..60798e07154 100644 --- a/metrics/grafana/tiflash_summary.json +++ b/metrics/grafana/tiflash_summary.json @@ -5286,7 +5286,7 @@ }, "dataFormat": "tsbuckets", "datasource": "${DS_TEST-CLUSTER}", - "description": "Duration of end to end pre-decode when applying region snapshot", + "description": "Duration of SST to DT in pre-decode when applying region snapshot", "gridPos": { "h": 7, "w": 12, @@ -5304,7 +5304,7 @@ "reverseYBuckets": false, "targets": [ { - "expr": "sum(delta(tiflash_raft_command_duration_seconds_bucket{tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", type=\"snapshot_predecode_e2e\"}[1m])) by (le)", + "expr": "sum(delta(tiflash_raft_command_duration_seconds_bucket{tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", type=\"snapshot_predecode_sst2dt\"}[1m])) by (le)", "format": "heatmap", "intervalFactor": 2, "legendFormat": "{{le}}", @@ -5313,7 +5313,7 @@ ], "timeFrom": null, "timeShift": null, - "title": "Snapshot Predecode End To End Duration", + "title": "Snapshot Predecode SST to DT Duration", "tooltip": { "show": true, "showHistogram": true From f876cb00b699a038ac46714f90efe88396bfd372 Mon Sep 17 00:00:00 2001 From: CalvinNeo Date: Tue, 8 Mar 2022 16:07:31 +0800 Subject: [PATCH 4/5] fix Signed-off-by: CalvinNeo --- dbms/src/Storages/Transaction/SchemaBuilder.cpp | 12 ++++++++++++ dbms/src/Storages/Transaction/SchemaGetter.h | 1 + 2 files changed, 13 insertions(+) diff --git a/dbms/src/Storages/Transaction/SchemaBuilder.cpp b/dbms/src/Storages/Transaction/SchemaBuilder.cpp index 84fed766ab7..69b264f9730 100644 --- a/dbms/src/Storages/Transaction/SchemaBuilder.cpp +++ b/dbms/src/Storages/Transaction/SchemaBuilder.cpp @@ -417,6 +417,18 @@ void SchemaBuilder::applyDiff(const SchemaDiff & diff) return; } + if (diff.type == SchemaActionType::CreateTables) { + for (auto && opt : diff.affected_opts) { + AffectedOption aff; + aff.schema_id = opt.schema_id; + aff.table_id = opt.table_id; + aff.old_schema_id = opt.old_schema_id; + aff.old_table_id = opt.old_table_id; + applyDiff(diff); + } + return; + } + auto db_info = getter.getDatabase(diff.schema_id); if (db_info == nullptr) throw TiFlashException("miss database: " + std::to_string(diff.schema_id), Errors::DDL::StaleSchema); diff --git a/dbms/src/Storages/Transaction/SchemaGetter.h b/dbms/src/Storages/Transaction/SchemaGetter.h index 289829da11c..2c95970e6d0 100644 --- a/dbms/src/Storages/Transaction/SchemaGetter.h +++ b/dbms/src/Storages/Transaction/SchemaGetter.h @@ -59,6 +59,7 @@ enum class SchemaActionType : Int8 RebaseAutoRandomBase = 40, AlterIndexVisibility = 41, ExchangeTablePartition = 42, + CreateTables = 60, }; struct AffectedOption From 83e57ace5c1bd03e6afe89865473d725d4f75ea8 Mon Sep 17 00:00:00 2001 From: CalvinNeo Date: Tue, 22 Mar 2022 11:36:21 +0800 Subject: [PATCH 5/5] f Signed-off-by: CalvinNeo --- metrics/grafana/tiflash_summary.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/grafana/tiflash_summary.json b/metrics/grafana/tiflash_summary.json index 7174a114324..807209a56c9 100644 --- a/metrics/grafana/tiflash_summary.json +++ b/metrics/grafana/tiflash_summary.json @@ -6440,7 +6440,7 @@ "reverseYBuckets": false, "targets": [ { - "expr": "sum(delta(tiflash_raft_command_duration_seconds_bucket{tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", type=\"snapshot_predecode_sst2dt\"}[1m])) by (le)", + "expr": "sum(delta(tiflash_raft_command_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", type=\"snapshot_predecode_sst2dt\"}[1m])) by (le)", "format": "heatmap", "intervalFactor": 2, "legendFormat": "{{le}}",