sijie commented on a change in pull request #210: Issue 209: Support rename log
URL: https://github.com/apache/distributedlog/pull/210#discussion_r145556801
 
 

 ##########
 File path: 
distributedlog-core/src/main/java/org/apache/distributedlog/impl/metadata/ZKLogStreamMetadataStore.java
 ##########
 @@ -620,4 +631,271 @@ public void processResult(int rc, String path, Object 
ctx) {
         }
         return promise;
     }
+
+    //
+    // Rename Log
+    //
+
+    @Override
+    public CompletableFuture<Void> renameLog(URI uri, String oldStreamName, 
String newStreamName) {
+        return getLog(
+            uri,
+            oldStreamName,
+            true,
+            false
+        ).thenCompose(metadata -> renameLogMetadata(uri, metadata, 
newStreamName));
+    }
+
+    private CompletableFuture<Void> renameLogMetadata(URI uri,
+                                                      LogMetadataForWriter 
oldMetadata,
+                                                      String newStreamName) {
+
+
+        final LinkedList<Op> createOps = Lists.newLinkedList();
+        final LinkedList<Op> deleteOps = Lists.newLinkedList();
+
+        List<ACL> acls = zooKeeperClient.getDefaultACL();
+
+        // get the root path
+        String oldRootPath = oldMetadata.getLogRootPath();
+        String newRootPath = LogMetadata.getLogRootPath(
+            uri, newStreamName, conf.getUnpartitionedStreamName());
+
+        // 0. the log path
+        deleteOps.addFirst(Op.delete(
+            LogMetadata.getLogStreamPath(uri, oldMetadata.getLogName()), -1));
+
+        // 1. the root path
+        createOps.addLast(Op.create(
+            newRootPath, EMPTY_BYTES, acls, CreateMode.PERSISTENT));
+        deleteOps.addFirst(Op.delete(
+            oldRootPath, -1));
+
+        // 2. max id
+        Versioned<byte[]> maxTxIdData = oldMetadata.getMaxTxIdData();
+        deleteOldPathAndCreateNewPath(
+            oldRootPath, MAX_TXID_PATH, maxTxIdData,
+            newRootPath, DLUtils.serializeTransactionId(0L), acls,
+            createOps, deleteOps
+        );
+
+        // 3. version
+        createOps.addLast(Op.create(
+            newRootPath + VERSION_PATH, intToBytes(LAYOUT_VERSION), acls, 
CreateMode.PERSISTENT));
+        deleteOps.addFirst(Op.delete(
+            oldRootPath + VERSION_PATH, -1));
+
+        // 4. lock path (NOTE: if the stream is locked by a writer, then the 
delete will fail as you can not
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to