neuyilan commented on a change in pull request #1560:
URL: https://github.com/apache/incubator-iotdb/pull/1560#discussion_r460611000



##########
File path: 
cluster/src/main/java/org/apache/iotdb/cluster/log/manage/FilePartitionedSnapshotLogManager.java
##########
@@ -52,21 +54,44 @@ public FilePartitionedSnapshotLogManager(LogApplier 
logApplier, PartitionTable p
 
   @Override
   public void takeSnapshot() throws IOException {
-
     logger.info("Taking snapshots, flushing IoTDB");
     StorageEngine.getInstance().syncCloseAllProcessor();
     logger.info("Taking snapshots, IoTDB is flushed");
-    synchronized (slotSnapshots) {
+    // TODO-cluster https://issues.apache.org/jira/browse/IOTDB-820
+    synchronized (this) {
       collectTimeseriesSchemas();
       snapshotLastLogIndex = getCommitLogIndex();
       snapshotLastLogTerm = getCommitLogTerm();
-      collectTsFiles();
+      collectTsFilesAndFillTimeseriesSchemas();
       logger.info("Snapshot is taken");
     }
   }
 
-  private void collectTsFiles() throws IOException {
+  /**
+   * IMPORTANT, separate the collection timeseries schema from tsfile to avoid 
the following
+   * situations: If the tsfile is empty at this time (only the metadata is 
registered, but the
+   * tsfile has not been written yet), then the timeseries schema snapshot can 
still be generated
+   * and sent to the followers.
+   *
+   * @throws IOException
+   */
+  private void collectTsFilesAndFillTimeseriesSchemas() throws IOException {
+    // 1.collect tsfile
+    collectTsFiles();
+
+    //2.register the measurement
+    for (Map.Entry<Integer, Collection<TimeseriesSchema>> entry : 
slotTimeseries.entrySet()) {
+      int slotNum = entry.getKey();
+      FileSnapshot snapshot = slotSnapshots.computeIfAbsent(slotNum,
+          s -> new FileSnapshot());
+      if (snapshot.getTimeseriesSchemas().isEmpty()) {
+        snapshot.setTimeseriesSchemas(slotTimeseries.getOrDefault(slotNum,
+            Collections.emptySet()));

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.

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


Reply via email to