You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/14 11:45:39 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #22171: Refactor migration inventory finished percentage

sandynz commented on code in PR #22171:
URL: https://github.com/apache/shardingsphere/pull/22171#discussion_r1021396365


##########
kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/pojo/MigrationJobItemInfo.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.api.pojo;
+
+import lombok.Getter;
+
+/**
+ * Migration job item info.
+ */
+@Getter
+public final class MigrationJobItemInfo extends InventoryIncrementalJobItemInfo {

Review Comment:
   Looks it's not necessary to create `MigrationJobItemInfo`, we could keep them in `InventoryIncrementalJobItemInfo` for common usage



##########
features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationJobStatusQueryResultSet.java:
##########
@@ -45,24 +45,19 @@ public final class ShowMigrationJobStatusQueryResultSet implements DatabaseDistS
     
     @Override
     public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) {
-        long currentTimeMillis = System.currentTimeMillis();
         List<InventoryIncrementalJobItemInfo> jobItemInfos = JOB_API.getJobItemInfos(((ShowMigrationStatusStatement) sqlStatement).getJobId());
         data = jobItemInfos.stream().map(each -> {
+            MigrationJobItemInfo jobItemInfo = (MigrationJobItemInfo) each;
             Collection<Object> result = new LinkedList<>();
-            result.add(each.getShardingItem());
-            InventoryIncrementalJobItemProgress jobItemProgress = each.getJobItemProgress();
+            result.add(jobItemInfo.getShardingItem());
+            InventoryIncrementalJobItemProgress jobItemProgress = jobItemInfo.getJobItemProgress();

Review Comment:
   It's better to keep use `each` for common methods, it's enough



##########
features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationJobStatusQueryResultSet.java:
##########
@@ -45,24 +45,19 @@ public final class ShowMigrationJobStatusQueryResultSet implements DatabaseDistS
     
     @Override
     public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) {
-        long currentTimeMillis = System.currentTimeMillis();
         List<InventoryIncrementalJobItemInfo> jobItemInfos = JOB_API.getJobItemInfos(((ShowMigrationStatusStatement) sqlStatement).getJobId());
         data = jobItemInfos.stream().map(each -> {
+            MigrationJobItemInfo jobItemInfo = (MigrationJobItemInfo) each;
             Collection<Object> result = new LinkedList<>();
-            result.add(each.getShardingItem());
-            InventoryIncrementalJobItemProgress jobItemProgress = each.getJobItemProgress();
+            result.add(jobItemInfo.getShardingItem());
+            InventoryIncrementalJobItemProgress jobItemProgress = jobItemInfo.getJobItemProgress();
             if (null != jobItemProgress) {
                 result.add(jobItemProgress.getDataSourceName());
                 result.add(jobItemProgress.getStatus());
                 result.add(jobItemProgress.isActive() ? Boolean.TRUE.toString() : Boolean.FALSE.toString());
                 result.add(jobItemProgress.getProcessedRecordsCount());
-                result.add(jobItemProgress.getInventory().getInventoryFinishedPercentage());
-                String incrementalIdleSeconds = "";
-                if (jobItemProgress.getIncremental().getIncrementalLatestActiveTimeMillis() > 0) {
-                    long latestActiveTimeMillis = Math.max(each.getStartTimeMillis(), jobItemProgress.getIncremental().getIncrementalLatestActiveTimeMillis());
-                    incrementalIdleSeconds = String.valueOf(TimeUnit.MILLISECONDS.toSeconds(currentTimeMillis - latestActiveTimeMillis));
-                }
-                result.add(incrementalIdleSeconds);
+                result.add(jobItemInfo.getInventoryFinishedPercentage());
+                result.add(jobItemInfo.getIncrementalIdleSeconds());

Review Comment:
   It's `null != jobItemProgress` in if condition, but it use `jobItemInfo` here, it's not clear enough as before



##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java:
##########
@@ -133,6 +137,32 @@ protected TableBasedPipelineJobInfo getJobInfo(final String jobId) {
         return new TableBasedPipelineJobInfo(jobMetaData, getJobConfiguration(jobConfigPOJO).getSourceTableName());
     }
     
+    @Override
+    public List<InventoryIncrementalJobItemInfo> getJobItemInfos(final String jobId) {

Review Comment:
   Could keep it in `AbstractInventoryIncrementalJobAPIImpl` and extend it for common usage



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org