javeme commented on code in PR #2312:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2312#discussion_r1328051982


##########
hugegraph-core/src/main/java/org/apache/hugegraph/util/Consumers.java:
##########
@@ -282,7 +281,7 @@ public static void executeOncePerThread(ExecutorService 
executor,
         for (int i = 0; i < totalThreads; i++) {
             tasks.add(task);
         }
-        executor.invokeAll(tasks, invokeTimeout, unit);
+        executor.invokeAll(tasks, invokeTimeout, TimeUnit.SECONDS);

Review Comment:
   also keep invokeTimeout long type?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/EdgesQueryIterator.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.hugegraph.backend.query;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.tx.GraphTransaction;
+import org.apache.hugegraph.type.define.Directions;
+
+public class EdgesQueryIterator implements Iterator<Query> {
+    private final List<Id> labels;
+    private final Directions directions;
+    private final long limit;
+    private final Iterator<Id> sources;
+
+    public EdgesQueryIterator(Iterator<Id> sources,
+                              Directions directions,
+                              List<Id> labels,
+                              long limit) {
+        this.sources = sources;
+        this.labels = labels;
+        this.directions = directions;
+        // Traverse NO_LIMIT ε’Œ Query.NO_LIMIT 不同
+        this.limit = limit < 0 ? Query.NO_LIMIT : limit;
+    }
+
+    @Override
+    public boolean hasNext() {
+        return sources.hasNext();
+    }
+
+    @Override
+    public Query next() {
+        Id sourceId = this.sources.next();
+        ConditionQuery query = GraphTransaction.constructEdgesQuery(sourceId,
+                                                                    
this.directions,
+                                                                    
this.labels);
+        if (this.limit != Query.NO_LIMIT) {
+            query.limit(this.limit);
+            query.capacity(this.limit);
+        } else {
+            query.capacity(Query.NO_CAPACITY);
+        }
+        return query;
+    }
+

Review Comment:
   unused blank line



##########
hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -48,9 +48,10 @@ public final class TaskManager {
                                "server-info-db-worker-%d";
     public static final String TASK_SCHEDULER = "task-scheduler-%d";
 
-    static final long SCHEDULE_PERIOD = 1000L; // unit ms
+    protected static final long SCHEDULE_PERIOD = 1000L; // unit ms
 
     private static final int THREADS = 4;
+    private static final int TX_CLOSE_TIMEOUT = 30;

Review Comment:
   also use long type and move to line 52, and add `unit seconds` comment



##########
hugegraph-rocksdb/src/main/java/org/apache/hugegraph/backend/store/rocksdb/RocksDBStore.java:
##########
@@ -94,6 +94,7 @@ public abstract class RocksDBStore extends 
AbstractBackendStore<RocksDBSessions.
     private static final String TABLE_GENERAL_KEY = "general";
     private static final String DB_OPEN = "db-open-%s";
     private static final long OPEN_TIMEOUT = 600L;
+    private static final int TX_CLOSE_TIMEOUT = 30;

Review Comment:
   they are DB_OPEN_TIMEOUT and DB_CLOSE_TIMEOUT, also use long type



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/EdgesQueryIterator.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.hugegraph.backend.query;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.tx.GraphTransaction;
+import org.apache.hugegraph.type.define.Directions;
+
+public class EdgesQueryIterator implements Iterator<Query> {

Review Comment:
   expect a blank line



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -1004,4 +1015,31 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
             return edges;
         }
     }
+
+    public class EdgesIterator implements Iterator<Iterator<Edge>>, Closeable {
+        private final Iterator<Iterator<Edge>> currentIt;
+
+        public EdgesIterator(EdgesQueryIterator queryIterator) {
+            List<Iterator<Edge>> iteratorList = new ArrayList<>();
+            while (queryIterator.hasNext()) {
+                iteratorList.add(graph().edges(queryIterator.next()));

Review Comment:
   can we split into 2 lines for more readable



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -1004,4 +1015,31 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
             return edges;
         }
     }
+
+    public class EdgesIterator implements Iterator<Iterator<Edge>>, Closeable {
+        private final Iterator<Iterator<Edge>> currentIt;
+
+        public EdgesIterator(EdgesQueryIterator queryIterator) {

Review Comment:
   prefer queryIterator => queries



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -1004,4 +1015,31 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
             return edges;
         }
     }
+
+    public class EdgesIterator implements Iterator<Iterator<Edge>>, Closeable {
+        private final Iterator<Iterator<Edge>> currentIt;

Review Comment:
   currentIter



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/OltpTraverser.java:
##########
@@ -129,11 +142,101 @@ protected <K> long traverse(Iterator<K> iterator, 
Consumer<K> consumer,
         return total;
     }
 
+    protected void traverseIdsByBfs(Iterator<Id> vertices,
+                                    Directions dir,
+                                    Id label,
+                                    long degree,
+                                    long capacity,
+                                    Consumer<EdgeId> consumer) {
+        List<Id> labels =
+                label == null ? Collections.emptyList() : 
Collections.singletonList(label);

Review Comment:
   prefer to put in one line or use this style:
   ```
   List<Id> labels = label == null ? Collections.emptyList() :
                                     Collections.singletonList(label);
   ```



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -1004,4 +1015,31 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
             return edges;
         }
     }
+
+    public class EdgesIterator implements Iterator<Iterator<Edge>>, Closeable {

Review Comment:
   expect a blank line



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/OltpTraverser.java:
##########
@@ -175,4 +278,103 @@ public List<V> getValues(K key) {
             return values;
         }
     }
+
+    public static class ConcurrentVerticesConsumer implements Consumer<EdgeId> 
{
+
+        private final Id sourceV;
+        private final Set<Id> excluded;
+        private final Set<Id> neighbors;
+        private final long limit;
+        private final AtomicInteger count = new AtomicInteger(0);

Review Comment:
   prefer to move to line 296



##########
hugegraph-core/src/main/java/org/apache/hugegraph/util/Consumers.java:
##########
@@ -27,79 +27,100 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Consumer;
 
-import org.apache.hugegraph.config.CoreOptions;
-import org.slf4j.Logger;
-
 import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.config.CoreOptions;
 import org.apache.hugegraph.task.TaskManager.ContextCallable;
+import org.slf4j.Logger;
 
 public final class Consumers<V> {
 
     public static final int THREADS = 4 + CoreOptions.CPUS / 4;
     public static final int QUEUE_WORKER_SIZE = 1000;
     public static final long CONSUMER_WAKE_PERIOD = 1;
+    private static final Object QUEUE_END = new VWrapper<>(null);
 
     private static final Logger LOG = Log.logger(Consumers.class);
 
     private final ExecutorService executor;
     private final Consumer<V> consumer;
-    private final Runnable done;
-
+    private final Runnable doneHandle;
+    private final Consumer<Throwable> exceptionHandle;
     private final int workers;
+    private final List<Future> runningFutures;
     private final int queueSize;
     private final CountDownLatch latch;
-    private final BlockingQueue<V> queue;
-
-    private volatile boolean ending = false;
+    private final BlockingQueue<VWrapper<V>> queue;
     private volatile Throwable exception = null;
 
     public Consumers(ExecutorService executor, Consumer<V> consumer) {
         this(executor, consumer, null);
     }
 
     public Consumers(ExecutorService executor,
-                     Consumer<V> consumer, Runnable done) {
+                     Consumer<V> consumer, Runnable doneHandle) {
+        this(executor, consumer, doneHandle, QUEUE_WORKER_SIZE);
+    }
+
+    public Consumers(ExecutorService executor,
+                     Consumer<V> consumer,
+                     Runnable doneHandle,
+                     int queueSizePerWorker) {
+        this(executor, consumer, doneHandle, null, queueSizePerWorker);
+    }
+
+    public Consumers(ExecutorService executor,
+                     Consumer<V> consumer,
+                     Runnable doneHandle,
+                     Consumer<Throwable> exceptionHandle,
+                     int queueSizePerWorker) {
         this.executor = executor;
         this.consumer = consumer;
-        this.done = done;
+        this.doneHandle = doneHandle;
+        this.exceptionHandle = exceptionHandle;
 
         int workers = THREADS;
         if (this.executor instanceof ThreadPoolExecutor) {
             workers = ((ThreadPoolExecutor) this.executor).getCorePoolSize();
         }
         this.workers = workers;
-        this.queueSize = QUEUE_WORKER_SIZE * workers;
+
+        this.runningFutures = new ArrayList<>(workers);
+        this.queueSize = queueSizePerWorker * workers + 1;
         this.latch = new CountDownLatch(workers);
         this.queue = new ArrayBlockingQueue<>(this.queueSize);
     }
 
     public void start(String name) {
-        this.ending = false;
         this.exception = null;
         if (this.executor == null) {
             return;
         }
         LOG.info("Starting {} workers[{}] with queue size {}...",
                  this.workers, name, this.queueSize);
         for (int i = 0; i < this.workers; i++) {
-            this.executor.submit(new ContextCallable<>(this::runAndDone));
+            this.runningFutures.add(this.executor.submit(new 
ContextCallable<>(this::runAndDone)));

Review Comment:
   can we split into 2 line for more readable?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/util/Consumers.java:
##########
@@ -43,55 +43,55 @@ public final class Consumers<V> {
     public static final int THREADS = 4 + CoreOptions.CPUS / 4;
     public static final int QUEUE_WORKER_SIZE = 1000;
     public static final long CONSUMER_WAKE_PERIOD = 1;
+    private static final Object QUEUE_END = new VWrapper(null);

Review Comment:
   get it, can we remove VWrapper class and keep `BlockingQueue<V> queue`, then 
try to define `V QUEUE_END = (V) new Object();`



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to