Skip to content
Merged
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 @@ -134,6 +134,12 @@ public TimeseriesMetadata get(TimeSeriesMetadataCacheKey key, Set<String> allSen
cacheHitNum.incrementAndGet();
printCacheLog(true);
} else {
if (config.isDebugOn()) {
DEBUG_LOGGER.info(
"Cache miss: " + key.device + "." + key.measurement + " metadata in file: "
+ key.filePath);
DEBUG_LOGGER.info("Device: " + key.device + " all sensors: " + allSensors);
}
// allow for the parallelism of different devices in different files
synchronized (devices
.computeIfAbsent(key.device + SEPARATOR + key.filePath, WeakReference::new)) {
Expand All @@ -148,26 +154,29 @@ public TimeseriesMetadata get(TimeSeriesMetadataCacheKey key, Set<String> allSen
cacheHitNum.incrementAndGet();
printCacheLog(true);
} else {
printCacheLog(false);
Path path = new Path(key.device, key.measurement);
// bloom filter part
TsFileSequenceReader reader = FileReaderManager.getInstance().get(key.filePath, true);
BloomFilter bloomFilter = reader.readBloomFilter();
if (bloomFilter != null && !bloomFilter
.contains(key.device + IoTDBConstant.PATH_SEPARATOR + key.measurement)) {

if (bloomFilter != null && !bloomFilter.contains(path.getFullPath())) {
if (config.isDebugOn()) {
DEBUG_LOGGER.info("TimeSeries meta data " + key + " is filter by bloomFilter!");
}
return null;
}
printCacheLog(false);
List<TimeseriesMetadata> timeSeriesMetadataList = reader
.readTimeseriesMetadata(key.device, allSensors);
.readTimeseriesMetadata(path, allSensors);
// put TimeSeriesMetadata of all sensors used in this query into cache
lock.writeLock().lock();
try {
timeSeriesMetadataList.forEach(metadata ->
lruCache.put(new TimeSeriesMetadataCacheKey(key.filePath, key.device,
metadata.getMeasurementId()), metadata));
timeSeriesMetadataList.forEach(metadata -> {
TimeSeriesMetadataCacheKey k = new TimeSeriesMetadataCacheKey(key.filePath,
key.device, metadata.getMeasurementId());
if (!lruCache.containsKey(k)) {
lruCache.put(k, metadata);
}
});
timeseriesMetadata = lruCache.get(key);
} finally {
lock.writeLock().unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,40 @@ public TimeseriesMetadata readTimeseriesMetadata(Path path) throws IOException {
return searchResult >= 0 ? timeseriesMetadataList.get(searchResult) : null;
}

/**
* Find the leaf node that contains path, return all the sensors in that leaf node which are also
* in allSensors set
*/
public List<TimeseriesMetadata> readTimeseriesMetadata(Path path, Set<String> allSensors)
throws IOException {
readFileMetadata();
MetadataIndexNode deviceMetadataIndexNode = tsFileMetaData.getMetadataIndex();
Pair<MetadataIndexEntry, Long> metadataIndexPair = getMetadataAndEndOffset(
deviceMetadataIndexNode, path.getDevice(), MetadataIndexNodeType.INTERNAL_DEVICE, true);
if (metadataIndexPair == null) {
return null;
}
ByteBuffer buffer = readData(metadataIndexPair.left.getOffset(), metadataIndexPair.right);
MetadataIndexNode metadataIndexNode = deviceMetadataIndexNode;
if (!metadataIndexNode.getNodeType().equals(MetadataIndexNodeType.LEAF_MEASUREMENT)) {
metadataIndexNode = MetadataIndexNode.deserializeFrom(buffer);
metadataIndexPair = getMetadataAndEndOffset(metadataIndexNode,
path.getMeasurement(), MetadataIndexNodeType.INTERNAL_MEASUREMENT, false);
}
if (metadataIndexPair == null) {
return null;
}
List<TimeseriesMetadata> timeseriesMetadataList = new ArrayList<>();
buffer = readData(metadataIndexPair.left.getOffset(), metadataIndexPair.right);
while (buffer.hasRemaining()) {
TimeseriesMetadata timeseriesMetadata = TimeseriesMetadata.deserializeFrom(buffer);
if (allSensors.contains(timeseriesMetadata.getMeasurementId())) {
timeseriesMetadataList.add(timeseriesMetadata);
}
}
return timeseriesMetadataList;
}

public List<TimeseriesMetadata> readTimeseriesMetadata(String device, Set<String> measurements)
throws IOException {
readFileMetadata();
Expand Down