You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Alima777 (via GitHub)" <gi...@apache.org> on 2023/02/06 03:29:32 UTC
[GitHub] [iotdb] Alima777 commented on a diff in pull request #8957: [IOTDB-5449] Allow query scheduler to receive more tasks
Alima777 commented on code in PR #8957:
URL: https://github.com/apache/iotdb/pull/8957#discussion_r1096913283
##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/schedule/queue/IndexedBlockingReserveQueue.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.iotdb.db.mpp.execution.schedule.queue;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * This class is different from <class>IndexedBlockingQueue</class> in that it will reserve space
+ * for polled element in case it will be pushed again.
+ */
+public abstract class IndexedBlockingReserveQueue<E extends IDIndexedAccessible>
+ extends IndexedBlockingQueue<E> {
+
+ // To avoid some elements can't join the queue again that are polled out for running or blocked
+ private int reservedSize;
+
+ public IndexedBlockingReserveQueue(int maxCapacity, E queryHolder) {
+ super(maxCapacity, queryHolder);
+ }
+
+ /**
+ * Get and remove the first element of the queue. Reserve space for this polled element.
+ *
+ * @return the queue head element.
+ */
+ public synchronized E poll() throws InterruptedException {
+ while (isEmpty()) {
+ this.wait();
+ }
+ E output = pollFirst();
+ size--;
+ reservedSize++;
+ return output;
+ }
+
+ public synchronized void push(E element) {
+ if (element == null) {
+ throw new NullPointerException("pushed element is null");
+ }
+ Preconditions.checkState(
+ !contains(element),
+ "The queue has already contained the element: " + element.getDriverTaskId());
+ Preconditions.checkState(
+ size + reservedSize < MAX_CAPACITY, "The system can't allow more query tasks.");
+ pushToQueue(element);
+ size++;
+ this.notifyAll();
+ }
+
+ /**
+ * RePush an element which is polled out for running or blocked before to the queue. In this case,
+ * we don't increase the current size of queue, since we have reserved a place for it.
+ */
+ public synchronized void repush(E element) {
+ if (element == null) {
+ throw new NullPointerException("pushed element is null");
+ }
+ pushToQueue(element);
+ reservedSize--;
Review Comment:
Fixed.
##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/schedule/queue/IndexedBlockingReserveQueue.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.iotdb.db.mpp.execution.schedule.queue;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * This class is different from <class>IndexedBlockingQueue</class> in that it will reserve space
+ * for polled element in case it will be pushed again.
+ */
+public abstract class IndexedBlockingReserveQueue<E extends IDIndexedAccessible>
+ extends IndexedBlockingQueue<E> {
+
+ // To avoid some elements can't join the queue again that are polled out for running or blocked
+ private int reservedSize;
+
+ public IndexedBlockingReserveQueue(int maxCapacity, E queryHolder) {
+ super(maxCapacity, queryHolder);
+ }
+
+ /**
+ * Get and remove the first element of the queue. Reserve space for this polled element.
+ *
+ * @return the queue head element.
+ */
+ public synchronized E poll() throws InterruptedException {
+ while (isEmpty()) {
+ this.wait();
+ }
+ E output = pollFirst();
+ size--;
+ reservedSize++;
+ return output;
+ }
+
+ public synchronized void push(E element) {
+ if (element == null) {
+ throw new NullPointerException("pushed element is null");
+ }
+ Preconditions.checkState(
+ !contains(element),
+ "The queue has already contained the element: " + element.getDriverTaskId());
Review Comment:
Yes, I think so.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org