Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ public Map<String, TimeseriesMetadata> getTimeseriesMetadata(
try {
if (CACHE_ENABLE && !externalTsFile) {
String deviceName = null;
String devicePrefix = null;
BloomFilter bloomFilter = null;
// an aligned device always has its time column, so check it before the per-column cache
// pass: a file without data for this device then costs one lookup and at most one
Expand All @@ -396,7 +395,7 @@ public Map<String, TimeseriesMetadata> getTimeseriesMetadata(
loadBloomFilterTime += bloomFilterTimeBeforeCachePhase;
if (bloomFilter != null) {
deviceName = device.toString();
devicePrefix = deviceName + IoTDBConstant.PATH_SEPARATOR;
String devicePrefix = deviceName + IoTDBConstant.PATH_SEPARATOR;
if (!bloomFilter.contains(devicePrefix)) {
lookupCount = 1;
return null;
Expand All @@ -420,14 +419,10 @@ public Map<String, TimeseriesMetadata> getTimeseriesMetadata(
filePath, tsFileID, queryContext, debug, bloomFilterIoSizeRecorder, false);
bloomFilterTimeAfterCachePhase = nanoTime() - bloomFilterStartTime;
loadBloomFilterTime += bloomFilterTimeAfterCachePhase;
if (bloomFilter != null) {
devicePrefix = deviceName + IoTDBConstant.PATH_SEPARATOR;
}
}
// the filter and the cache are thread-safe, so a rejected measurement never enters the
// device lock; only the survivors need the locked recheck and the reader
bloomAbsentMeasurements(
tsFileID, device, pending, result, bloomFilter, devicePrefix, debug);
bloomAbsentMeasurements(tsFileID, device, pending, result, bloomFilter, debug);
if (pending.isEmpty()) {
return result;
}
Expand Down Expand Up @@ -494,8 +489,7 @@ public Map<String, TimeseriesMetadata> getTimeseriesMetadata(
lookupCount = 1;
return null;
}
bloomAbsentMeasurements(
tsFileID, device, pending, result, bloomFilter, devicePrefix, debug);
bloomAbsentMeasurements(tsFileID, device, pending, result, bloomFilter, debug);
}
if (pending.isEmpty()) {
return null;
Expand Down Expand Up @@ -575,25 +569,27 @@ private static void bloomAbsentMeasurements(
Set<String> pending,
Map<String, TimeseriesMetadata> result,
BloomFilter bloomFilter,
String devicePrefix,
boolean debug) {
if (bloomFilter == null || pending.isEmpty()) {
return;
}
Iterator<String> iterator = pending.iterator();
while (iterator.hasNext()) {
String measurement = iterator.next();
// the device gate already probed the time column
if (measurement.isEmpty() || bloomFilter.contains(devicePrefix + measurement)) {
continue;
}
iterator.remove();
if (debug) {
DEBUG_LOGGER.info(
StorageEngineMessages.TS_METADATA_FILTERED_BY_BLOOM_FILTER,
new TimeSeriesMetadataCacheKey(tsFileID, device, measurement));
}
result.put(measurement, null);
// The device gate already checked the time column. The reader still needs its metadata.
boolean readTimeColumn = pending.remove("");
if (!pending.isEmpty()) {
bloomFilter.removeNotExistingMeasurements(
device,
pending,
(deviceID, measurement) -> {
if (debug) {
DEBUG_LOGGER.info(
StorageEngineMessages.TS_METADATA_FILTERED_BY_BLOOM_FILTER,
new TimeSeriesMetadataCacheKey(tsFileID, deviceID, measurement));
}
result.put(measurement, null);
});
}
if (readTimeColumn) {
pending.add("");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,21 @@ public void testBloomExcludedMeasurementIsNotRemembered() throws Exception {
try {
String filePath = "target/batch-bloom-excluded.tsfile";
IDeviceID deviceID = Factory.DEFAULT_FACTORY.create("root.device");
Set<String> allSensors = new HashSet<>(Arrays.asList("", "s1"));
Set<String> valueColumns = new HashSet<>(Arrays.asList("s1", "s2"));
Set<String> allSensors = new HashSet<>(valueColumns);
allSensors.add("");

TsFileSequenceReader reader = Mockito.mock(TsFileSequenceReader.class);
fileReaderManager.setReaderForTest(tsFileID, true, reader);
// the device exists, but s1 is not in the file
BloomFilter bloomFilter = BloomFilter.getEmptyBloomFilter(0.05, 1);
// Only the time column is present.
BloomFilter bloomFilter = Mockito.spy(BloomFilter.getEmptyBloomFilter(0.05, 1));
Mockito.doAnswer(
invocation -> {
assertEquals(valueColumns, invocation.getArgument(1));
return invocation.callRealMethod();
})
.when(bloomFilter)
.removeNotExistingMeasurements(Mockito.eq(deviceID), Mockito.anySet(), Mockito.any());
bloomFilter.add(deviceID.toString() + ".");
Mockito.when(reader.readBloomFilter(Mockito.any(LongConsumer.class))).thenReturn(bloomFilter);

Expand All @@ -1012,12 +1021,14 @@ public void testBloomExcludedMeasurementIsNotRemembered() throws Exception {
getTimeseriesMetadata(cache, filePath, tsFileID, deviceID, allSensors, false);
assertNull(first.get("s1"));

// s1 was excluded by the bloom filter, not read, so it is probed again instead of being
// remembered; the second query still needs no reader call
// Both queries probe the missing value columns together. Only the first reads metadata.
Map<String, TimeseriesMetadata> second =
getTimeseriesMetadata(cache, filePath, tsFileID, deviceID, allSensors, false);
assertEquals(allSensors, second.keySet());
assertNull(second.get("s1"));
assertNull(second.get("s2"));
Mockito.verify(bloomFilter, Mockito.times(2))
.removeNotExistingMeasurements(Mockito.eq(deviceID), Mockito.anySet(), Mockito.any());
Mockito.verify(reader, Mockito.times(1))
.readTimeseriesMetadataForMeasurements(
Mockito.eq(deviceID),
Expand Down Expand Up @@ -1122,10 +1133,13 @@ public void testBloomLoadIsExcludedFromItsMetadataLookupPhase() throws Exception
new HashSet<>(Arrays.asList("", "s1")),
false);
now.addAndGet(valueCheckNanos);
return false;
return invocation.callRealMethod();
})
.when(bloomFilter)
.contains(deviceID + ".absent");
.removeNotExistingMeasurements(
Mockito.eq(deviceID),
Mockito.argThat(names -> names.contains("absent")),
Mockito.any());
allSensors.add("absent");
QueryContext mixedQuery = new QueryContext(false, false);
result =
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<thrift.version>0.25.0</thrift.version>
<xz.version>1.9</xz.version>
<zstd-jni.version>1.5.6-3</zstd-jni.version>
<tsfile.version>2.5.1-261120-SNAPSHOT</tsfile.version>
<tsfile.version>2.5.1-261203-SNAPSHOT</tsfile.version>
<i18n.locale>en</i18n.locale>
<tsfile.locale.opt/>
</properties>
Expand Down
Loading