Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix thread pool while iterate result #311

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class StorageClient {
private int timeout = 10000; // ms

/**
* @param ip the ip of metad server
* @param ip the ip of metad server
* @param port the port of meted server
*/
public StorageClient(String ip, int port) {
Expand All @@ -53,7 +53,7 @@ public StorageClient(List<HostAddress> addresses) {

/**
* @param addresses the address of metad server
* @param timeout the timeout of scan vertex or edge
* @param timeout the timeout of scan vertex or edge
*/
public StorageClient(List<HostAddress> addresses, int timeout) {
this.connection = new GraphStorageConnection();
Expand Down Expand Up @@ -761,8 +761,12 @@ private ScanEdgeResultIterator doScanEdge(String spaceName,
* release storage client
*/
public void close() {
pool.close();
connection.close();
if (pool != null) {
pool.close();
}
if (connection != null) {
connection.close();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,6 +32,7 @@ public class ScanEdgeResultIterator extends ScanResultIterator {
private static final Logger LOGGER = LoggerFactory.getLogger(ScanEdgeResultIterator.class);

private final ScanEdgeRequest request;
private ExecutorService threadPool = null;

private ScanEdgeResultIterator(MetaManager metaManager,
StorageConnPool pool,
Expand Down Expand Up @@ -62,6 +65,7 @@ public ScanEdgeResult next() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(addresses.size());
AtomicInteger existSuccess = new AtomicInteger(0);

threadPool = Executors.newFixedThreadPool(addresses.size());
for (HostAddress addr : addresses) {
threadPool.submit(() -> {
ScanEdgeRequest partRequest = new ScanEdgeRequest(request);
Expand Down Expand Up @@ -121,6 +125,7 @@ public ScanEdgeResult next() throws Exception {

try {
countDownLatch.await();
threadPool.shutdown();
} catch (InterruptedException interruptedE) {
LOGGER.error("scan interrupted:", interruptedE);
throw interruptedE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class ScanResultIterator {
protected boolean hasNext = true;

protected final Map<Integer, byte[]> partCursor;
protected final ExecutorService threadPool;

protected final MetaManager metaManager;
protected final StorageConnPool pool;
Expand All @@ -45,8 +44,6 @@ protected ScanResultIterator(MetaManager metaManager, StorageConnPool pool,
this.spaceName = spaceName;
this.labelName = labelName;
this.partSuccess = partSuccess;

this.threadPool = Executors.newFixedThreadPool(addresses.size());
this.partCursor = new HashMap<>(partScanQueue.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -33,6 +35,7 @@ public class ScanVertexResultIterator extends ScanResultIterator {
private static final Logger LOGGER = LoggerFactory.getLogger(ScanVertexResultIterator.class);

private final ScanVertexRequest request;
private ExecutorService threadPool = null;

private ScanVertexResultIterator(MetaManager metaManager,
StorageConnPool pool,
Expand Down Expand Up @@ -64,6 +67,8 @@ public ScanVertexResult next() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(addresses.size());
AtomicInteger existSuccess = new AtomicInteger(0);

threadPool = Executors.newFixedThreadPool(addresses.size());

for (HostAddress addr : addresses) {
threadPool.submit(() -> {
ScanVertexRequest partRequest = new ScanVertexRequest(request);
Expand Down Expand Up @@ -121,6 +126,7 @@ public ScanVertexResult next() throws Exception {

try {
countDownLatch.await();
threadPool.shutdown();
} catch (InterruptedException interruptedE) {
LOGGER.error("scan interrupted:", interruptedE);
throw interruptedE;
Expand Down Expand Up @@ -244,4 +250,4 @@ public ScanVertexResultIterator build() {
partSuccess);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ public static void main(String[] args) {
client.connect();
} catch (Exception e) {
LOGGER.error("storage client connect error, ", e);
client.close();
System.exit(1);
}
scanVertex(client);
scanEdge(client);

client.close();
}

/**
Expand All @@ -53,6 +56,7 @@ public static void scanVertex(StorageClient client) {
result = iterator.next();
} catch (Exception e) {
LOGGER.error("scan error, ", e);
client.close();
System.exit(1);
}
if (result.isEmpty()) {
Expand Down Expand Up @@ -99,6 +103,7 @@ public static void scanEdge(StorageClient client) {
result = iterator.next();
} catch (Exception e) {
LOGGER.error("scan error, ", e);
client.close();
System.exit(1);
}
if (result.isEmpty()) {
Expand Down