Skip to content

Commit bd3109e

Browse files
authored
Fix tag index query for pre-deleted timeseries (#18751)
1 parent d74b274 commit bd3109e

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

  • iotdb-core/datanode/src

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/tag/TagManager.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ private void getNext() throws IOException {
325325
nextMatched = null;
326326
while (allMatchedNodes.hasNext()) {
327327
final IMeasurementMNode<?> node = allMatchedNodes.next();
328+
if (node.isPreDeleted()) {
329+
continue;
330+
}
328331
if (plan.isPrefixMatch()
329332
? pathPattern.prefixMatchFullPath(node.getPartialPath())
330333
: pathPattern.matchFullPath(node.getPartialPath())) {

‎iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/schemaregion/tag/TagManagerTest.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
*/
1919
package org.apache.iotdb.db.schemaengine.schemaregion.tag;
2020

21+
import org.apache.iotdb.commons.path.PartialPath;
22+
import org.apache.iotdb.commons.schema.filter.impl.TagFilter;
2123
import org.apache.iotdb.commons.schema.node.role.IMeasurementMNode;
2224
import org.apache.iotdb.commons.schema.node.utils.IMNodeFactory;
2325
import org.apache.iotdb.db.schemaengine.rescon.MemSchemaEngineStatistics;
2426
import org.apache.iotdb.db.schemaengine.rescon.MemSchemaRegionStatistics;
2527
import org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.mem.mnode.IMemMNode;
2628
import org.apache.iotdb.db.schemaengine.schemaregion.mtree.loader.MNodeFactoryLoader;
29+
import org.apache.iotdb.db.schemaengine.schemaregion.read.req.IShowTimeSeriesPlan;
30+
import org.apache.iotdb.db.schemaengine.schemaregion.read.resp.info.ITimeSeriesSchemaInfo;
31+
import org.apache.iotdb.db.schemaengine.schemaregion.read.resp.reader.ISchemaReader;
2732

2833
import org.apache.tsfile.enums.TSDataType;
2934
import org.apache.tsfile.external.commons.io.FileUtils;
@@ -34,6 +39,7 @@
3439
import org.junit.After;
3540
import org.junit.Assert;
3641
import org.junit.Test;
42+
import org.mockito.Mockito;
3743

3844
import java.io.File;
3945
import java.nio.file.Files;
@@ -188,6 +194,24 @@ public void concurrentAddAndRemoveIndexEventuallyReleasesAllMemory() throws Exce
188194
Assert.assertEquals(0, regionStatistics.getRegionMemoryUsage());
189195
}
190196

197+
@Test
198+
public void preDeletedMeasurementIsSkippedByIndexReader() throws Exception {
199+
initTagManager();
200+
final IMeasurementMNode<?> node = newMeasurementMNode("s0");
201+
node.setPreDeleted(true);
202+
tagManager.addIndex("key", "value", node);
203+
204+
final IShowTimeSeriesPlan plan = Mockito.mock(IShowTimeSeriesPlan.class);
205+
Mockito.when(plan.getSchemaFilter()).thenReturn(new TagFilter("key", "value", false));
206+
Mockito.when(plan.getPath()).thenReturn(new PartialPath("s0"));
207+
208+
final ISchemaReader<ITimeSeriesSchemaInfo> reader =
209+
tagManager.getTimeSeriesReaderWithIndex(plan);
210+
Assert.assertFalse(reader.hasNext());
211+
Assert.assertTrue(reader.isSuccess());
212+
reader.close();
213+
}
214+
191215
private void initTagManager() throws Exception {
192216
tempDir = Files.createTempDirectory("tag-manager").toFile();
193217
regionStatistics = new MemSchemaRegionStatistics(0, new MemSchemaEngineStatistics());

0 commit comments

Comments
 (0)