You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/11/28 01:20:43 UTC

[GitHub] [rocketmq] RongtongJin commented on a diff in pull request #5601: [ISSUE #5585] Implement SnapshotAbleMetadataManager for ReplicasInfoManager

RongtongJin commented on code in PR #5601:
URL: https://github.com/apache/rocketmq/pull/5601#discussion_r1033050750


##########
controller/src/main/java/org/apache/rocketmq/controller/impl/manager/ReplicasInfoManager.java:
##########
@@ -466,4 +472,61 @@ private void handleCleanBrokerDataEvent(final CleanBrokerDataEvent event) {
     private boolean isContainsBroker(final String brokerName) {
         return this.replicaInfoTable.containsKey(brokerName) && this.syncStateSetInfoTable.containsKey(brokerName);
     }
+
+    @Override
+    public byte[] encodeMetadata() {
+        byte[] replicaInfoTableBytes = this.serializer.serialize(this.replicaInfoTable);
+        byte[] syncStateSetInfoTableBytes = this.serializer.serialize(this.syncStateSetInfoTable);
+
+        int replicaInfoTableLength = replicaInfoTableBytes == null ? 0 : replicaInfoTableBytes.length;
+        int syncStateSetInfoTableLength = syncStateSetInfoTableBytes == null ? 0 : syncStateSetInfoTableBytes.length;
+
+        ByteBuffer buffer = ByteBuffer.allocate(8 + replicaInfoTableLength + syncStateSetInfoTableLength);
+        buffer.putInt(replicaInfoTableLength);
+        buffer.putInt(syncStateSetInfoTableLength);
+        if (replicaInfoTableBytes != null) {
+            buffer.put(replicaInfoTableBytes);
+        }
+        if (syncStateSetInfoTableBytes != null) {
+            buffer.put(syncStateSetInfoTableBytes);
+        }
+        buffer.flip();
+
+        return buffer.array();
+    }

Review Comment:
   It would be better to directly serialize into readable strings, just like topics.json



-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org