Skip to content

Commit

Permalink
Fixed the cache invalidation logic when delete time series
Browse files Browse the repository at this point in the history
  • Loading branch information
Caideyipi authored Oct 22, 2024
1 parent 8bf2294 commit dc96146
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ public void deleteTimeSeriesAndAutoDeleteDeviceTest() throws Exception {
}
}

@Test
public void deleteTimeSeriesAndInvalidationTest() throws Exception {
try (final Connection connection = EnvFactory.getEnv().getConnection();
final Statement statement = connection.createStatement()) {
statement.execute("insert into root.sg.d1 (c1, c2) values (1, 1)");
statement.execute("delete timeSeries root.sg.d1.**");
try (final ResultSet resultSet = statement.executeQuery("select c1, c2 from root.sg.d1")) {
Assert.assertEquals(1, resultSet.getMetaData().getColumnCount());
Assert.assertFalse(resultSet.next());
}
}
}

@Test
public void deleteTimeSeriesCrossSchemaRegionTest() throws Exception {
String[] retArray1 = new String[] {"4,4,4,4"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ void invalidateLastCache(final PartialPath devicePath, final String measurement)
}

// WARNING: This is not guaranteed to affect table model's cache
void invalidateCache(final PartialPath devicePath) {
void invalidateCache(
final @Nonnull PartialPath devicePath, final boolean isMultiLevelWildcardMeasurement) {
if (!devicePath.hasWildcard()) {
final IDeviceID deviceID = devicePath.getIDeviceID();
dualKeyCache.invalidate(new TableId(null, deviceID.getTableName()), deviceID);
Expand All @@ -458,7 +459,9 @@ void invalidateCache(final PartialPath devicePath) {
},
cachedDeviceID -> {
try {
return new PartialPath(cachedDeviceID).matchFullPath(devicePath);
return isMultiLevelWildcardMeasurement
? devicePath.matchPrefixPath(new PartialPath(cachedDeviceID))
: devicePath.matchFullPath(new PartialPath(cachedDeviceID));
} catch (final IllegalPathException e) {
logger.warn(
"Illegal deviceID {} found in cache when invalidating by path {}, invalidate it anyway",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathPatternUtil;
import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
import org.apache.iotdb.db.exception.metadata.view.InsertNonWritableViewException;
import org.apache.iotdb.db.queryengine.common.schematree.ClusterSchemaTree;
Expand Down Expand Up @@ -433,7 +434,13 @@ public void updateLastCache(
public void invalidate(final List<MeasurementPath> partialPathList) {
// Currently invalidate by device
partialPathList.forEach(
measurementPath -> tableDeviceSchemaCache.invalidateCache(measurementPath.getDevicePath()));
measurementPath -> {
final boolean isMultiLevelWildcardMeasurement =
PathPatternUtil.isMultiLevelMatchWildcard(measurementPath.getMeasurement());
tableDeviceSchemaCache.invalidateCache(
isMultiLevelWildcardMeasurement ? measurementPath : measurementPath.getDevicePath(),
isMultiLevelWildcardMeasurement);
});
}

public void cleanUp() {
Expand Down

0 comments on commit dc96146

Please sign in to comment.