virajjasani commented on code in PR #6046:
URL: https://github.com/apache/hbase/pull/6046#discussion_r1673456730
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureScheduler.java:
##########
@@ -124,11 +134,26 @@ public void yield(final Procedure proc) {
push(proc, false, true);
}
+ private boolean shouldWaitBeforeEnqueuing(TableProcedureInterface proc) {
+ return TableQueue.requireTableExclusiveLock(proc);
+ }
+
@Override
protected void enqueue(final Procedure proc, final boolean addFront) {
if (isMetaProcedure(proc)) {
doAdd(metaRunQueue, getMetaQueue(), proc, addFront);
} else if (isTableProcedure(proc)) {
+ TableProcedureInterface tableProc = (TableProcedureInterface) proc;
+ if (shouldWaitBeforeEnqueuing(tableProc)) {
+ TableProcedureWaitingQueue waitingQueue =
tableProcsWaitingEnqueue.computeIfAbsent(
+ tableProc.getTableName(), k -> new
TableProcedureWaitingQueue(procedureRetriever));
+ if (!waitingQueue.procedureSubmitted(proc)) {
+ // there is a table procedure for this table already enqueued,
waiting
+ LOG.debug("There is already a procedure running for table {}, add {}
to waiting queue",
Review Comment:
nit: `add {} to waiting queue` => `added {} to waiting queue`
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TableProcedureWaitingQueue.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.hadoop.hbase.master.procedure;
+
+import java.util.ArrayDeque;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.function.Function;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.yetus.audience.InterfaceAudience;
+
+import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
+
+/**
+ * To prevent multiple Create/Modify/Disable/Enable table procedures run at
the same time, we will
+ * keep table procedure in this queue first before actually enqueuing it to
+ * MasterProcedureScheduler's tableQueue. See HBASE-28683 for more details
+ */
[email protected]
+class TableProcedureWaitingQueue {
Review Comment:
Nice, this looks promising, let me take detailed look tomorrow
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/TableProcedureWaitingQueue.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.hadoop.hbase.master.procedure;
+
+import java.util.ArrayDeque;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.function.Function;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.yetus.audience.InterfaceAudience;
+
+import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
+
+/**
+ * To prevent multiple Create/Modify/Disable/Enable table procedures run at
the same time, we will
+ * keep table procedure in this queue first before actually enqueuing it to
+ * MasterProcedureScheduler's tableQueue. See HBASE-28683 for more details
+ */
[email protected]
+class TableProcedureWaitingQueue {
+
+ private final Function<Long, Procedure<?>> procedureRetriever;
+
+ // whether there is already a table procedure enqueued in ProcedureScheduler.
+ private Procedure<?> enqueuedProc;
+
+ private final Queue<Procedure<?>> queue = new ArrayDeque<>();
+
+ TableProcedureWaitingQueue(Function<Long, Procedure<?>> procedureRetriever) {
+ this.procedureRetriever = procedureRetriever;
+ }
+
+ private boolean isSubProcedure(Procedure<?> proc) {
+ while (proc.hasParent()) {
+ if (proc.getParentProcId() == enqueuedProc.getProcId()) {
+ return true;
+ }
+ proc =
Preconditions.checkNotNull(procedureRetriever.apply(proc.getParentProcId()),
+ "can not find parent procedure pid=%s", proc.getParentProcId());
+ }
+ return false;
+ }
+
+ /**
+ * Return whether we can enqueue this procedure to ProcedureScheduler.
+ */
Review Comment:
Here we can also mention that if it returns false, it also means that the
proc is queued up for waiting purpose.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]