You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/05/17 02:58:31 UTC

[GitHub] [iotdb] cigarl commented on a diff in pull request #5921: [IOTDB-3200] [PartitionInfo] replace bytebuffer with stream

cigarl commented on code in PR #5921:
URL: https://github.com/apache/iotdb/pull/5921#discussion_r874316734


##########
node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java:
##########
@@ -248,75 +245,76 @@ public void createDataPartition(
         .put(timePartitionSlot, Collections.singletonList(regionReplicaSet));
   }
 
-  public void serialize(ByteBuffer buffer) throws IOException, TException {
-    try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
-      for (Entry<
-              String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>>
-          entry : dataPartitionMap.entrySet()) {
-        ReadWriteIOUtils.write(entry.getKey(), byteArrayOutputStream);
-        try (TIOStreamTransport tioStreamTransport =
-            new TIOStreamTransport(byteArrayOutputStream)) {
-          TProtocol protocol = new TBinaryProtocol(tioStreamTransport);
-          for (Entry<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>
-              seriesPartitionSlotMapEntry : entry.getValue().entrySet()) {
-            seriesPartitionSlotMapEntry.getKey().write(protocol);
-            for (Entry<TTimePartitionSlot, List<TRegionReplicaSet>> timePartitionSlotListEntry :
-                seriesPartitionSlotMapEntry.getValue().entrySet()) {
-              timePartitionSlotListEntry.getKey().write(protocol);
-              ReadWriteIOUtils.write(
-                  timePartitionSlotListEntry.getValue().size(), byteArrayOutputStream);
-              timePartitionSlotListEntry
-                  .getValue()
-                  .forEach(
-                      x -> {
-                        try {
-                          x.write(protocol);
-                        } catch (TException e) {
-                          throw new RuntimeException(e);
-                        }
-                      });
-            }
-          }
+  public void serialize(DataOutputStream dataOutputStream, TProtocol protocol)
+      throws IOException, TException {
+    // Map<StorageGroup, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionMessage>>>>
+    dataOutputStream.writeInt(dataPartitionMap.size());
+    for (Entry<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>>
+        entry : dataPartitionMap.entrySet()) {
+      ReadWriteIOUtils.write(entry.getKey(), dataOutputStream);
+      ReadWriteIOUtils.write(entry.getValue().size(), dataOutputStream);
+      for (Entry<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>
+          seriesPartitionSlotMapEntry : entry.getValue().entrySet()) {
+        seriesPartitionSlotMapEntry.getKey().write(protocol);
+        ReadWriteIOUtils.write(seriesPartitionSlotMapEntry.getValue().size(), dataOutputStream);
+        for (Entry<TTimePartitionSlot, List<TRegionReplicaSet>> timePartitionSlotListEntry :
+            seriesPartitionSlotMapEntry.getValue().entrySet()) {
+          timePartitionSlotListEntry.getKey().write(protocol);
+          ReadWriteIOUtils.write(timePartitionSlotListEntry.getValue().size(), dataOutputStream);
+          timePartitionSlotListEntry
+              .getValue()
+              .forEach(
+                  x -> {
+                    try {
+                      x.write(protocol);
+                    } catch (TException e) {
+                      throw new RuntimeException(e);

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

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