GeezerVison is showing github.com — [Enhancement] Add ADMIN SHOW AUTOMATED CLUSTER SNAPSHOT status output… · APIJSON/starrocks@8fa8ced
File treeExpand file treeCollapse file tree Open diff view settings fe-grammar/src/main/antlr/com/starrocks/grammar fe-parser/src/main/java/com/starrocks/sql/ast
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/lake/snapshot/ClusterSnapshotJobScheduler.java +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,7 +32,7 @@ public class ClusterSnapshotJobScheduler extends FrontendDaemon implements Snaps | 32 | 32 | // cluster snapshot information used for start | 33 | 33 | protected final RestoredSnapshotInfo restoredSnapshotInfo; | 34 | 34 |
| 35 | | - protected long lastAutomatedJobStartTimeMs; | | 35 | + protected volatile long lastAutomatedJobStartTimeMs; | 36 | 36 | protected volatile ClusterSnapshotJob runningJob; | 37 | 37 |
| 38 | 38 | public ClusterSnapshotJobScheduler(CheckpointController feController, | @@ -80,6 +80,10 @@ public Pair<Long, Long> captureConsistentCheckpointIdBetweenFEAndStarMgr() { | 80 | 80 | return null; | 81 | 81 | } | 82 | 82 |
| | 83 | + public long getLastAutomatedJobStartTimeMs() { | | 84 | + return lastAutomatedJobStartTimeMs; | | 85 | + } | | 86 | + | 83 | 87 | @Override | 84 | 88 | protected void runAfterCatalogReady() { | 85 | 89 | // skip first run when the scheduler start | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/lake/snapshot/ClusterSnapshotMgr.java +51Lines changed: 51 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | import com.google.gson.annotations.SerializedName; | 19 | 19 | import com.starrocks.alter.AlterJobV2; | 20 | 20 | import com.starrocks.common.Config; | | 21 | +import com.starrocks.common.FeConstants; | 21 | 22 | import com.starrocks.common.StarRocksException; | | 23 | +import com.starrocks.common.util.TimeUtils; | 22 | 24 | import com.starrocks.lake.snapshot.ClusterSnapshotJob.ClusterSnapshotJobState; | 23 | 25 | import com.starrocks.persist.ClusterSnapshotLog; | 24 | 26 | import com.starrocks.persist.ImageWriter; | | 33 | 35 | import com.starrocks.sql.ast.AdminAlterAutomatedSnapshotIntervalStmt; | 34 | 36 | import com.starrocks.sql.ast.AdminSetAutomatedSnapshotOffStmt; | 35 | 37 | import com.starrocks.sql.ast.AdminSetAutomatedSnapshotOnStmt; | | 38 | +import com.starrocks.sql.ast.expression.IntervalLiteral; | 36 | 39 | import com.starrocks.staros.StarMgrServer; | 37 | 40 | import com.starrocks.storagevolume.StorageVolume; | 38 | 41 | import com.starrocks.thrift.TClusterSnapshotJobsResponse; | @@ -133,6 +136,54 @@ public long getEffectiveAutomatedSnapshotIntervalSeconds() { | 133 | 136 | return Config.automated_cluster_snapshot_interval_seconds; | 134 | 137 | } | 135 | 138 |
| | 139 | + public long getNextAutomatedSnapshotTimeMs() { | | 140 | + if (!isAutomatedSnapshotOn()) { | | 141 | + return -1L; | | 142 | + } | | 143 | + long intervalSeconds = getEffectiveAutomatedSnapshotIntervalSeconds(); | | 144 | + if (intervalSeconds <= 0) { | | 145 | + return -1L; | | 146 | + } | | 147 | + | | 148 | + long lastStartTimeMs = 0L; | | 149 | + ClusterSnapshotJobScheduler scheduler = clusterSnapshotJobScheduler; | | 150 | + if (scheduler != null) { | | 151 | + lastStartTimeMs = scheduler.getLastAutomatedJobStartTimeMs(); | | 152 | + } | | 153 | + if (lastStartTimeMs <= 0L) { | | 154 | + ClusterSnapshotJob lastFinishedJob = getLastFinishedAutomatedClusterSnapshotJob(); | | 155 | + if (lastFinishedJob != null) { | | 156 | + lastStartTimeMs = lastFinishedJob.getCreatedTimeMs(); | | 157 | + } | | 158 | + } | | 159 | + if (lastStartTimeMs <= 0L) { | | 160 | + return -1L; | | 161 | + } | | 162 | + return lastStartTimeMs + intervalSeconds * 1000L; | | 163 | + } | | 164 | + | | 165 | + public List<List<String>> getAutomatedSnapshotShowResult() { | | 166 | + List<List<String>> rows = Lists.newArrayList(); | | 167 | + if (!isAutomatedSnapshotOn()) { | | 168 | + rows.add(Lists.newArrayList("false", FeConstants.NULL_STRING, FeConstants.NULL_STRING, | | 169 | + FeConstants.NULL_STRING, FeConstants.NULL_STRING)); | | 170 | + return rows; | | 171 | + } | | 172 | + | | 173 | + String interval = IntervalLiteral.formatIntervalSeconds(getEffectiveAutomatedSnapshotIntervalSeconds()); | | 174 | + if (interval == null) { | | 175 | + interval = FeConstants.NULL_STRING; | | 176 | + } | | 177 | + String storageVolume = storageVolumeName == null ? FeConstants.NULL_STRING : storageVolumeName; | | 178 | + ClusterSnapshot snapshot = getAutomatedSnapshot(); | | 179 | + String lastSnapshotTime = snapshot == null ? FeConstants.NULL_STRING | | 180 | + : TimeUtils.longToTimeString(snapshot.getCreatedTimeMs()); | | 181 | + String nextSnapshotTime = TimeUtils.longToTimeString(getNextAutomatedSnapshotTimeMs()); | | 182 | + | | 183 | + rows.add(Lists.newArrayList("true", interval, storageVolume, lastSnapshotTime, nextSnapshotTime)); | | 184 | + return rows; | | 185 | + } | | 186 | + | 136 | 187 | protected void clearFinishedAutomatedClusterSnapshot(String keepSnapshotName) { | 137 | 188 | for (Map.Entry<Long, ClusterSnapshotJob> entry : automatedSnapshotJobs.entrySet()) { | 138 | 189 | ClusterSnapshotJob job = entry.getValue(); | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/qe/RedirectStatus.java +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | import com.starrocks.sql.ast.AdminSetConfigStmt; | 31 | 31 | import com.starrocks.sql.ast.AdminSetPartitionVersionStmt; | 32 | 32 | import com.starrocks.sql.ast.AdminSetReplicaStatusStmt; | | 33 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 33 | 34 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 34 | 35 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 35 | 36 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -715,6 +716,16 @@ public RedirectStatus visitAdminShowConfigStatement(AdminShowConfigStmt statemen | 715 | 716 | return visitShowStatement(statement, context); | 716 | 717 | } | 717 | 718 |
| | 719 | + @Override | | 720 | + public RedirectStatus visitAdminShowAutomatedSnapshotStatement(AdminShowAutomatedSnapshotStmt statement, | | 721 | + Void context) { | | 722 | + if (ConnectContext.get().getSessionVariable().getForwardToLeader()) { | | 723 | + return RedirectStatus.FORWARD_NO_SYNC; | | 724 | + } else { | | 725 | + return RedirectStatus.NO_FORWARD; | | 726 | + } | | 727 | + } | | 728 | + | 718 | 729 | @Override | 719 | 730 | public RedirectStatus visitAdminShowReplicaDistributionStatement(AdminShowReplicaDistributionStmt statement, | 720 | 731 | Void context) { | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 148 | 148 | import com.starrocks.sql.analyzer.AstToStringBuilder; | 149 | 149 | import com.starrocks.sql.analyzer.Authorizer; | 150 | 150 | import com.starrocks.sql.analyzer.SemanticException; | | 151 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 151 | 152 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 152 | 153 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 153 | 154 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -2318,6 +2319,13 @@ public ShowResultSet visitAdminShowConfigStatement(AdminShowConfigStmt statement | 2318 | 2319 | return new ShowResultSet(showResultMetaFactory.getMetadata(statement), results); | 2319 | 2320 | } | 2320 | 2321 |
| | 2322 | + @Override | | 2323 | + public ShowResultSet visitAdminShowAutomatedSnapshotStatement(AdminShowAutomatedSnapshotStmt statement, | | 2324 | + ConnectContext context) { | | 2325 | + return new ShowResultSet(showResultMetaFactory.getMetadata(statement), | | 2326 | + GlobalStateMgr.getCurrentState().getClusterSnapshotMgr().getAutomatedSnapshotShowResult()); | | 2327 | + } | | 2328 | + | 2321 | 2329 | @Override | 2322 | 2330 | public ShowResultSet visitShowSmallFilesStatement(ShowSmallFilesStmt statement, ConnectContext context) { | 2323 | 2331 | List<List<String>> results; | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/qe/ShowResultMetaFactory.java +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 33 | 33 | import com.starrocks.common.proc.RollupProcDir; | 34 | 34 | import com.starrocks.common.proc.SchemaChangeProcDir; | 35 | 35 | import com.starrocks.common.proc.TransProcDir; | | 36 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 36 | 37 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 37 | 38 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 38 | 39 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -771,6 +772,18 @@ public ShowResultSetMetaData visitAdminShowConfigStatement(AdminShowConfigStmt s | 771 | 772 | .build(); | 772 | 773 | } | 773 | 774 |
| | 775 | + @Override | | 776 | + public ShowResultSetMetaData visitAdminShowAutomatedSnapshotStatement(AdminShowAutomatedSnapshotStmt statement, | | 777 | + Void context) { | | 778 | + return ShowResultSetMetaData.builder() | | 779 | + .addColumn(new Column("Enabled", TypeFactory.createVarcharType(5))) | | 780 | + .addColumn(new Column("Interval", TypeFactory.createVarcharType(32))) | | 781 | + .addColumn(new Column("StorageVolume", TypeFactory.createVarcharType(256))) | | 782 | + .addColumn(new Column("LastSnapshotTime", TypeFactory.createVarcharType(20))) | | 783 | + .addColumn(new Column("NextSnapshotTime", TypeFactory.createVarcharType(20))) | | 784 | + .build(); | | 785 | + } | | 786 | + | 774 | 787 | @Override | 775 | 788 | public ShowResultSetMetaData visitShowPluginsStatement(ShowPluginsStmt statement, Void context) { | 776 | 789 | return ShowResultSetMetaData.builder() | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AdminStmtAnalyzer.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | import com.starrocks.sql.ast.AdminSetConfigStmt; | 28 | 28 | import com.starrocks.sql.ast.AdminSetPartitionVersionStmt; | 29 | 29 | import com.starrocks.sql.ast.AdminSetReplicaStatusStmt; | | 30 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 30 | 31 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 31 | 32 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | 32 | 33 | import com.starrocks.sql.ast.AstVisitorExtendInterface; | @@ -110,6 +111,12 @@ public Void visitAdminShowReplicaDistributionStatement( | 110 | 111 | return null; | 111 | 112 | } | 112 | 113 |
| | 114 | + @Override | | 115 | + public Void visitAdminShowAutomatedSnapshotStatement(AdminShowAutomatedSnapshotStmt statement, | | 116 | + ConnectContext session) { | | 117 | + return null; | | 118 | + } | | 119 | + | 113 | 120 | @Override | 114 | 121 | public Void visitAdminShowReplicaStatusStatement(AdminShowReplicaStatusStmt adminShowReplicaStatusStmt, | 115 | 122 | ConnectContext session) { | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Analyzer.java +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | import com.starrocks.sql.ast.AdminSetConfigStmt; | 28 | 28 | import com.starrocks.sql.ast.AdminSetPartitionVersionStmt; | 29 | 29 | import com.starrocks.sql.ast.AdminSetReplicaStatusStmt; | | 30 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 30 | 31 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 31 | 32 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 32 | 33 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -459,6 +460,13 @@ public Void visitAdminShowConfigStatement(AdminShowConfigStmt adminShowConfigStm | 459 | 460 | return null; | 460 | 461 | } | 461 | 462 |
| | 463 | + @Override | | 464 | + public Void visitAdminShowAutomatedSnapshotStatement(AdminShowAutomatedSnapshotStmt statement, | | 465 | + ConnectContext session) { | | 466 | + AdminStmtAnalyzer.analyze(statement, session); | | 467 | + return null; | | 468 | + } | | 469 | + | 462 | 470 | @Override | 463 | 471 | public Void visitDropTableStatement(DropTableStmt statement, ConnectContext session) { | 464 | 472 | DropStmtAnalyzer.analyze(statement, session); | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 61 | 61 | import com.starrocks.sql.ast.AdminRepairTableStmt; | 62 | 62 | import com.starrocks.sql.ast.AdminSetConfigStmt; | 63 | 63 | import com.starrocks.sql.ast.AdminSetReplicaStatusStmt; | | 64 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 64 | 65 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 65 | 66 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 66 | 67 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -2178,6 +2179,20 @@ public Void visitAdminShowConfigStatement(AdminShowConfigStmt statement, Connect | 2178 | 2179 | return null; | 2179 | 2180 | } | 2180 | 2181 |
| | 2182 | + @Override | | 2183 | + public Void visitAdminShowAutomatedSnapshotStatement(AdminShowAutomatedSnapshotStmt statement, | | 2184 | + ConnectContext context) { | | 2185 | + try { | | 2186 | + Authorizer.checkSystemAction(context, PrivilegeType.OPERATE); | | 2187 | + } catch (AccessDeniedException e) { | | 2188 | + AccessDeniedException.reportAccessDenied( | | 2189 | + InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME, | | 2190 | + context.getCurrentUserIdentity(), context.getCurrentRoleIds(), | | 2191 | + PrivilegeType.OPERATE.name(), ObjectType.SYSTEM.name(), null); | | 2192 | + } | | 2193 | + return null; | | 2194 | + } | | 2195 | + | 2181 | 2196 | @Override | 2182 | 2197 | public Void visitAdminShowReplicaDistributionStatement(AdminShowReplicaDistributionStmt statement, | 2183 | 2198 | ConnectContext context) { | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 73 | 73 | import com.starrocks.sql.ast.AdminSetConfigStmt; | 74 | 74 | import com.starrocks.sql.ast.AdminSetPartitionVersionStmt; | 75 | 75 | import com.starrocks.sql.ast.AdminSetReplicaStatusStmt; | | 76 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 76 | 77 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 77 | 78 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 78 | 79 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -2768,6 +2769,12 @@ public ParseNode visitAdminShowConfigStatement( | 2768 | 2769 | return new AdminShowConfigStmt(AdminSetConfigStmt.ConfigType.FRONTEND, null, pos); | 2769 | 2770 | } | 2770 | 2771 |
| | 2772 | + @Override | | 2773 | + public ParseNode visitAdminShowAutomatedSnapshotStatement( | | 2774 | + com.starrocks.sql.parser.StarRocksParser.AdminShowAutomatedSnapshotStatementContext context) { | | 2775 | + return new AdminShowAutomatedSnapshotStmt(createPos(context)); | | 2776 | + } | | 2777 | + | 2771 | 2778 | @Override | 2772 | 2779 | public ParseNode visitAdminShowReplicaDistributionStatement( | 2773 | 2780 | com.starrocks.sql.parser.StarRocksParser.AdminShowReplicaDistributionStatementContext context) { | |
Collapse file Copy file name to clipboardExpand all lines: fe/fe-core/src/test/java/com/starrocks/qe/RedirectStatusTest.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 | import com.starrocks.sql.ast.AdminSetConfigStmt; | 30 | 30 | import com.starrocks.sql.ast.AdminSetPartitionVersionStmt; | 31 | 31 | import com.starrocks.sql.ast.AdminSetReplicaStatusStmt; | | 32 | +import com.starrocks.sql.ast.AdminShowAutomatedSnapshotStmt; | 32 | 33 | import com.starrocks.sql.ast.AdminShowConfigStmt; | 33 | 34 | import com.starrocks.sql.ast.AdminShowReplicaDistributionStmt; | 34 | 35 | import com.starrocks.sql.ast.AdminShowReplicaStatusStmt; | @@ -948,6 +949,12 @@ public void testAdminShowConfigStmt() { | 948 | 949 | Assertions.assertEquals(RedirectStatus.NO_FORWARD, RedirectStatus.getRedirectStatus(stmt)); | 949 | 950 | } | 950 | 951 |
| | 952 | + @Test | | 953 | + public void testAdminShowAutomatedSnapshotStmt() { | | 954 | + AdminShowAutomatedSnapshotStmt stmt = new AdminShowAutomatedSnapshotStmt(); | | 955 | + Assertions.assertEquals(RedirectStatus.NO_FORWARD, RedirectStatus.getRedirectStatus(stmt)); | | 956 | + } | | 957 | + | 951 | 958 | @Test | 952 | 959 | public void testAdminCheckTabletsStmt() { | 953 | 960 | AdminCheckTabletsStmt stmt = new AdminCheckTabletsStmt(java.util.Collections.emptyList(), null, NodePosition.ZERO); | |
|