coderzc commented on code in PR #269:
URL: 
https://github.com/apache/incubator-hugegraph-computer/pull/269#discussion_r1364763128


##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * 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.computer.core.snapshot;
+
+import io.minio.DownloadObjectArgs;
+import io.minio.ListObjectsArgs;
+import io.minio.MinioClient;
+import io.minio.RemoveObjectsArgs;
+import io.minio.Result;
+import io.minio.UploadObjectArgs;
+import io.minio.messages.DeleteError;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hugegraph.computer.core.common.ComputerContext;
+import org.apache.hugegraph.computer.core.common.ContainerInfo;
+import org.apache.hugegraph.computer.core.common.exception.ComputerException;
+import org.apache.hugegraph.computer.core.config.ComputerOptions;
+import org.apache.hugegraph.computer.core.config.Config;
+import org.apache.hugegraph.computer.core.graph.partition.Partitioner;
+import org.apache.hugegraph.computer.core.manager.Manager;
+import org.apache.hugegraph.computer.core.network.buffer.FileRegionBuffer;
+import org.apache.hugegraph.computer.core.network.message.MessageType;
+import org.apache.hugegraph.computer.core.receiver.MessageRecvManager;
+import org.apache.hugegraph.computer.core.sender.MessageSendManager;
+import org.apache.hugegraph.util.Log;
+import org.slf4j.Logger;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+public class SnapshotManager implements Manager {
+
+    private static final Logger LOG = Log.logger(SnapshotManager.class);
+    public static final String NAME = "worker_snapshot";
+
+    private final MessageSendManager sendManager;
+    private final MessageRecvManager recvManager;
+
+    private final ContainerInfo workerInfo;
+    private final Partitioner partitioner;
+    private final int partitionCount;
+    private final boolean loadSnapshot;
+    private final boolean writeSnapshot;
+    private final String snapshotName;
+
+    private MinioClient minioClient;
+    private String bucketName;
+
+    public SnapshotManager(ComputerContext context, MessageSendManager 
sendManager,
+                           MessageRecvManager recvManager, ContainerInfo 
workerInfo) {
+        this.loadSnapshot = 
context.config().get(ComputerOptions.SNAPSHOT_LOAD);
+        this.writeSnapshot = 
context.config().get(ComputerOptions.SNAPSHOT_WRITE);
+
+        this.sendManager = sendManager;
+        this.recvManager = recvManager;
+        this.recvManager.setSnapshotManager(this);
+
+        this.workerInfo = workerInfo;
+        this.partitioner = 
context.config().createObject(ComputerOptions.WORKER_PARTITIONER);
+        this.partitionCount = 
context.config().get(ComputerOptions.JOB_PARTITIONS_COUNT);
+        this.snapshotName = 
context.config().get(ComputerOptions.SNAPSHOT_NAME);
+    }
+
+    @Override
+    public String name() {
+        return NAME;
+    }
+
+    @Override
+    public void init(Config config) {
+        String endpoint = config.get(ComputerOptions.SNAPSHOT_MINIO_ENDPOINT);
+        String accessKey = 
config.get(ComputerOptions.SNAPSHOT_MINIO_ACCESS_KEY);
+        String secretKey = 
config.get(ComputerOptions.SNAPSHOT_MINIO_SECRET_KEY);
+        this.bucketName = 
config.get(ComputerOptions.SNAPSHOT_MINIO_BUCKET_NAME);
+        if (StringUtils.isNotEmpty(endpoint)) {
+            this.minioClient = MinioClient.builder()
+                                          .endpoint(endpoint)
+                                          .credentials(accessKey, secretKey)
+                                          .build();
+        }
+    }
+
+    @Override
+    public void close(Config config) {
+        // pass
+    }
+
+    public boolean loadSnapshot() {
+        return this.loadSnapshot;
+    }
+
+    public boolean writeSnapshot() {
+        return this.writeSnapshot;
+    }
+
+    public void upload(MessageType messageType, int partitionId, List<String> 
outputFiles) {
+        if (this.loadSnapshot()) {
+            LOG.info("No later {} snapshots have to be uploaded",
+                      messageType.name().toLowerCase(Locale.ROOT));
+            return;
+        }
+        this.uploadObjects(messageType, partitionId, outputFiles);
+    }
+
+    public void load() {
+        int id = this.workerInfo.id();
+        for (int partitionId = 0; partitionId < this.partitionCount; 
partitionId++) {
+            if (this.partitioner.workerId(partitionId) == id) {
+                // TODO: Do not need to send control message to all workers
+                this.sendManager.startSend(MessageType.VERTEX);

Review Comment:
   Why we need to send control message?



##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * 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.computer.core.snapshot;
+
+import io.minio.DownloadObjectArgs;
+import io.minio.ListObjectsArgs;
+import io.minio.MinioClient;
+import io.minio.RemoveObjectsArgs;
+import io.minio.Result;
+import io.minio.UploadObjectArgs;
+import io.minio.messages.DeleteError;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hugegraph.computer.core.common.ComputerContext;
+import org.apache.hugegraph.computer.core.common.ContainerInfo;
+import org.apache.hugegraph.computer.core.common.exception.ComputerException;
+import org.apache.hugegraph.computer.core.config.ComputerOptions;
+import org.apache.hugegraph.computer.core.config.Config;
+import org.apache.hugegraph.computer.core.graph.partition.Partitioner;
+import org.apache.hugegraph.computer.core.manager.Manager;
+import org.apache.hugegraph.computer.core.network.buffer.FileRegionBuffer;
+import org.apache.hugegraph.computer.core.network.message.MessageType;
+import org.apache.hugegraph.computer.core.receiver.MessageRecvManager;
+import org.apache.hugegraph.computer.core.sender.MessageSendManager;
+import org.apache.hugegraph.util.Log;
+import org.slf4j.Logger;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+public class SnapshotManager implements Manager {
+
+    private static final Logger LOG = Log.logger(SnapshotManager.class);
+    public static final String NAME = "worker_snapshot";
+
+    private final MessageSendManager sendManager;
+    private final MessageRecvManager recvManager;
+
+    private final ContainerInfo workerInfo;
+    private final Partitioner partitioner;
+    private final int partitionCount;
+    private final boolean loadSnapshot;
+    private final boolean writeSnapshot;
+    private final String snapshotName;
+
+    private MinioClient minioClient;
+    private String bucketName;
+
+    public SnapshotManager(ComputerContext context, MessageSendManager 
sendManager,
+                           MessageRecvManager recvManager, ContainerInfo 
workerInfo) {
+        this.loadSnapshot = 
context.config().get(ComputerOptions.SNAPSHOT_LOAD);
+        this.writeSnapshot = 
context.config().get(ComputerOptions.SNAPSHOT_WRITE);
+
+        this.sendManager = sendManager;
+        this.recvManager = recvManager;
+        this.recvManager.setSnapshotManager(this);
+
+        this.workerInfo = workerInfo;
+        this.partitioner = 
context.config().createObject(ComputerOptions.WORKER_PARTITIONER);
+        this.partitionCount = 
context.config().get(ComputerOptions.JOB_PARTITIONS_COUNT);
+        this.snapshotName = 
context.config().get(ComputerOptions.SNAPSHOT_NAME);
+    }
+
+    @Override
+    public String name() {
+        return NAME;
+    }
+
+    @Override
+    public void init(Config config) {
+        String endpoint = config.get(ComputerOptions.SNAPSHOT_MINIO_ENDPOINT);
+        String accessKey = 
config.get(ComputerOptions.SNAPSHOT_MINIO_ACCESS_KEY);
+        String secretKey = 
config.get(ComputerOptions.SNAPSHOT_MINIO_SECRET_KEY);
+        this.bucketName = 
config.get(ComputerOptions.SNAPSHOT_MINIO_BUCKET_NAME);
+        if (StringUtils.isNotEmpty(endpoint)) {
+            this.minioClient = MinioClient.builder()
+                                          .endpoint(endpoint)
+                                          .credentials(accessKey, secretKey)
+                                          .build();
+        }
+    }
+
+    @Override
+    public void close(Config config) {
+        // pass
+    }
+
+    public boolean loadSnapshot() {
+        return this.loadSnapshot;
+    }
+
+    public boolean writeSnapshot() {
+        return this.writeSnapshot;
+    }
+
+    public void upload(MessageType messageType, int partitionId, List<String> 
outputFiles) {
+        if (this.loadSnapshot()) {
+            LOG.info("No later {} snapshots have to be uploaded",
+                      messageType.name().toLowerCase(Locale.ROOT));
+            return;
+        }
+        this.uploadObjects(messageType, partitionId, outputFiles);
+    }
+
+    public void load() {
+        int id = this.workerInfo.id();
+        for (int partitionId = 0; partitionId < this.partitionCount; 
partitionId++) {
+            if (this.partitioner.workerId(partitionId) == id) {
+                // TODO: Do not need to send control message to all workers
+                this.sendManager.startSend(MessageType.VERTEX);

Review Comment:
   Why we need to send control message?



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