You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2019/08/08 14:29:23 UTC

[GitHub] [incubator-doris] morningman commented on a change in pull request #1613: Refactor alter job process

morningman commented on a change in pull request #1613: Refactor alter job process
URL: https://github.com/apache/incubator-doris/pull/1613#discussion_r312067204
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/alter/AlterJobV2.java
 ##########
 @@ -0,0 +1,220 @@
+// 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.doris.alter;
+
+import org.apache.doris.common.io.Text;
+import org.apache.doris.common.io.Writable;
+
+import com.google.common.base.Preconditions;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+
+/*
+ * Author: Chenmingyu
+ * Date: Jul 8, 2019
+ */
+
+/*
+ * Version 2 of AlterJob, for replacing the old version of AlterJob.
+ * This base class of RollupJob and SchemaChangeJob
+ */
+public class AlterJobV2 implements Writable {
+    private static final Logger LOG = LogManager.getLogger(AlterJobV2.class);
+
+    public enum JobState {
+        PENDING, // Job is created
+        WAITING_TXN, // New replicas are created and Shadow catalog object is visible for incoming txns,
+                     // waiting for previous txns to be finished
+        RUNNING, // alter tasks are sent to BE, and waiting for them finished.
+        FINISHED, // job is done
+        CANCELLED; // job is cancelled(failed or be cancelled by user)
+
+        public boolean isFinalState() {
+            return this == JobState.FINISHED || this == JobState.CANCELLED;
+        }
+    }
+
+    public enum JobType {
+        ROLLUP, SCHEMA_CHANGE
+    }
+
+    protected JobType type;
+    protected long jobId;
+    protected JobState jobState;
+
+    protected long dbId;
+    protected long tableId;
+    protected String tableName;
+
+    protected String errMsg = "";
+    protected long createTimeMs = -1;
+    protected long finishedTimeMs = -1;
+    protected long timeoutMs = -1;
+
+    public AlterJobV2(long jobId, JobType jobType, long dbId, long tableId, String tableName, long timeoutMs) {
+        this.jobId = jobId;
+        this.type = jobType;
+        this.dbId = dbId;
+        this.tableId = tableId;
+        this.tableName = tableName;
+        this.timeoutMs = timeoutMs;
+
+        this.createTimeMs = System.currentTimeMillis();
+        this.jobState = JobState.PENDING;
+    }
+
+    protected AlterJobV2(JobType type) {
+        this.type = type;
+    }
+
+    public long getJobId() {
+        return jobId;
+    }
+
+    public JobState getJobState() {
+        return jobState;
+    }
+
+    public JobType getType() {
+        return type;
+    }
+
+    public long getDbId() {
+        return dbId;
+    }
+
+    public long getTableId() {
+        return tableId;
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    private boolean isTimeout() {
+        return System.currentTimeMillis() - createTimeMs > timeoutMs;
+    }
+
+    public boolean isDone() {
+        return jobState.isFinalState();
+    }
+
+    /*
+     * The keyword 'synchronized' only protects 2 methods:
+     * run() and cancel()
+     * Only these 2 methods can be visited by different thread(internal working thread and user connection thread)
+     * So using 'synchronized' to make sure only one thread can run the job at one time.
+     */
+    public synchronized void run() {
+        if (isTimeout()) {
+            cancel("Timeout");
+            return;
+        }
+
+        switch (jobState) {
+            case PENDING:
+                runPendingJob();
+                break;
+            case WAITING_TXN:
+                runWaitingTxnJob();
+                break;
+            case RUNNING:
+                runRunningJob();
+                break;
+            default:
+                break;
+        }
+    }
+
+    protected void runPendingJob() {
+        throw new NotImplementedException();
 
 Review comment:
   Yes, I will change it after all test are done

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org