You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2019/07/02 20:07:15 UTC

[GitHub] [incubator-ratis] joshelser commented on a change in pull request #25: RATIS-588 LogStream StateMachine export

joshelser commented on a change in pull request #25: RATIS-588 LogStream StateMachine export
URL: https://github.com/apache/incubator-ratis/pull/25#discussion_r299652999
 
 

 ##########
 File path: ratis-logservice/src/main/java/org/apache/ratis/logservice/client/LogServiceClient.java
 ##########
 @@ -149,20 +169,58 @@ public void close() throws Exception {
      * @param logInfo
      * @return
      */
-    private RaftClient getRaftClient(LogInfo logInfo) {
+    private RaftClient getRaftClient(LogInfo logInfo) throws IOException {
+
         RaftProperties properties = new RaftProperties();
         return RaftClient.newBuilder().setRaftGroup(logInfo.getRaftGroup()).setProperties(properties).build();
 
     }
 
+    private LogInfo getLogInfo(LogName logName) throws IOException {
+        RaftClientReply reply = client.sendReadOnly(
+            () -> MetaServiceProtoUtil.toGetLogRequestProto(logName).toByteString());
+        GetLogReplyProto message = GetLogReplyProto.parseFrom(reply.getMessage().getContent());
+        if (message.hasException()) {
+            throw MetaServiceProtoUtil.toMetaServiceException(message.getException());
+        }
+        return MetaServiceProtoUtil.toLogInfo(message.getLog());
+    }
+
     /**
-     * Archives the given log out of the state machine and into a configurable long-term storage. A log must be
-     * in {@link State#CLOSED} to archive it.
+     * Archives the given log out of the state machine and into a configurable long-term storage.
+     * A log must be in {@link State#CLOSED} to archive it.
+     * Archiving of the log will happen asynchronously from the client,
+     * The call will return immediately after adding a request for archiving log
+     * to the respective quorum
      *
-     * @param name The name of the log to archive.
+     * Client can check the status of Archiving by calling getState() Method
+     *
+     * @param logName The name of the log to archive.
      */
-    void archiveLog(LogName name) throws IOException {
-      // TODO: write me
+    public void archiveLog(LogName logName) throws IOException {
+        exportLog(logName, null, 0);
+    }
+
+    /**
+     * Export the given log out of the state machine and into a provided location on the configured storage
+     * A log must be in {@link State#CLOSED} to export it.
+     * exporting of the log will happen asynchronously from the client,
+     * The call will return immediately after adding a request for archiving log
+     * to the respective quorum
+     *
+     * Client can check the status of export by calling getState() Method
+     *
+     * @param logName The name of the log to archive.
+     */
+    public void exportLog(LogName logName, String location, long recordId) throws IOException {
+        RaftClientReply archiveLogReply = getRaftClient(getLogInfo(logName)).sendReadOnly(
 
 Review comment:
   Why getting a new `RaftClient` here? We have a `client` instance of it, right?
   
   If it's intentional to use a new Client, make sure to close it in a try/finally.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services