This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.13 by this push:
     new b5747aadc3 [IOTDB-3301] Tag recover bug after IoTDB server restart 
(#6032)
b5747aadc3 is described below

commit b5747aadc3e956194c4ab1bf5702639c096c609d
Author: Hua Xin <[email protected]>
AuthorDate: Tue May 31 19:01:31 2022 +0800

    [IOTDB-3301] Tag recover bug after IoTDB server restart (#6032)
---
 .../org/apache/iotdb/db/metadata/MManager.java     | 10 +++-
 .../iotdb/db/metadata/MManagerBasicTest.java       | 57 +++++++++++++++-------
 2 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java 
b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
index b6c4a6bdb1..c4b333f527 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
@@ -1527,8 +1527,14 @@ public class MManager {
    * @param path timeseries
    * @param offset offset in the tag file
    */
-  public void changeOffset(PartialPath path, long offset) throws 
MetadataException {
-    mtree.getMeasurementMNode(path).setOffset(offset);
+  public void changeOffset(PartialPath path, long offset) throws 
MetadataException, IOException {
+    IMeasurementMNode mNode = mtree.getMeasurementMNode(path);
+    mNode.setOffset(offset);
+    // the timeseries has already been created and now system is recovering, 
using the tag info in
+    // tagFile to recover index directly
+    if (isRecovering) {
+      tagManager.recoverIndex(offset, mNode);
+    }
   }
 
   public void changeAlias(PartialPath path, String alias) throws 
MetadataException {
diff --git 
a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java 
b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
index d677f2524c..d167de0f16 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
@@ -2431,12 +2431,17 @@ public class MManagerBasicTest {
   @Test
   public void testTagIndexRecovery() throws Exception {
     MManager manager = IoTDB.metaManager;
-    PartialPath path = new PartialPath("root.sg.d.s");
+    String tagKey = "description";
+    String tagValue = "oldValue";
     Map<String, String> tags = new HashMap<>();
-    tags.put("description", "oldValue");
+    tags.put(tagKey, tagValue);
+
+    // SCENE 1:create TimeSeries and add tags
+    PartialPath path1 = new PartialPath("root.sg.d.s1");
+
     manager.createTimeseries(
         new CreateTimeSeriesPlan(
-            path,
+            path1,
             TSDataType.valueOf("INT32"),
             TSEncoding.valueOf("RLE"),
             compressionType,
@@ -2444,47 +2449,63 @@ public class MManagerBasicTest {
             tags,
             null,
             null));
+    testTagIndexRecovery(path1, tagKey, tagValue);
 
+    // SCENE 2:first create TimeSeries no tags ,after alter TimeSeries add tags
+    PartialPath path2 = new PartialPath("root.sg.d.s2");
+    manager.createTimeseries(
+        new CreateTimeSeriesPlan(
+            path2,
+            TSDataType.valueOf("INT32"),
+            TSEncoding.valueOf("RLE"),
+            compressionType,
+            null,
+            null,
+            null,
+            null));
+    // alter
+    manager.addTags(tags, path2);
+    testTagIndexRecovery(path2, tagKey, tagValue);
+  }
+
+  private void testTagIndexRecovery(PartialPath path, String tagKey, String 
tagValue)
+      throws Exception {
+    MManager manager = IoTDB.metaManager;
     ShowTimeSeriesPlan showTimeSeriesPlan =
-        new ShowTimeSeriesPlan(
-            new PartialPath("root.sg.d.s"), true, "description", "Value", 0, 
0, false);
+        new ShowTimeSeriesPlan(path, true, tagKey, tagValue, 0, 0, false);
     List<ShowTimeSeriesResult> results =
         manager.showTimeseries(showTimeSeriesPlan, new QueryContext());
 
     assertEquals(1, results.size());
     Map<String, String> resultTag = results.get(0).getTag();
-    assertEquals("oldValue", resultTag.get("description"));
+    assertEquals(tagValue, resultTag.get(tagKey));
 
-    tags.put("description", "newValue");
+    String newValue = "newValue";
+    Map<String, String> tags = new HashMap<>();
+    tags.put(tagKey, newValue);
     manager.upsertTagsAndAttributes(null, tags, null, path);
 
-    showTimeSeriesPlan =
-        new ShowTimeSeriesPlan(
-            new PartialPath("root.sg.d.s"), true, "description", "Value", 0, 
0, false);
+    showTimeSeriesPlan = new ShowTimeSeriesPlan(path, true, tagKey, newValue, 
0, 0, false);
     results = manager.showTimeseries(showTimeSeriesPlan, new QueryContext());
 
     assertEquals(1, results.size());
     resultTag = results.get(0).getTag();
-    assertEquals("newValue", resultTag.get("description"));
+    assertEquals(newValue, resultTag.get(tagKey));
 
     manager.clear();
     manager.init();
 
-    showTimeSeriesPlan =
-        new ShowTimeSeriesPlan(
-            new PartialPath("root.sg.d.s"), true, "description", "oldValue", 
0, 0, false);
+    showTimeSeriesPlan = new ShowTimeSeriesPlan(path, true, tagKey, tagValue, 
0, 0, false);
     results = manager.showTimeseries(showTimeSeriesPlan, new QueryContext());
 
     assertEquals(0, results.size());
 
-    showTimeSeriesPlan =
-        new ShowTimeSeriesPlan(
-            new PartialPath("root.sg.d.s"), true, "description", "Value", 0, 
0, false);
+    showTimeSeriesPlan = new ShowTimeSeriesPlan(path, true, tagKey, newValue, 
0, 0, false);
     results = manager.showTimeseries(showTimeSeriesPlan, new QueryContext());
 
     assertEquals(1, results.size());
     resultTag = results.get(0).getTag();
-    assertEquals("newValue", resultTag.get("description"));
+    assertEquals(newValue, resultTag.get(tagKey));
   }
 
   @Test

Reply via email to