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
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<properties>
<java.version>17</java.version>
<tsfile.version>2.3.0</tsfile.version>
<tsfile.version>2.5.0</tsfile.version>
<caffeine.version>3.2.0</caffeine.version>
<springdoc.version>2.8.0</springdoc.version>
<google-java-format.version>1.22.0</google-java-format.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ public Cache<String, ScanTask> scanTaskCache(TsFileProperties tsFileProperties)
* <p>The health checker is a pure Java class with no Spring dependencies, so it is registered as
* a bean here to allow injection into Spring-managed services.
*
* @param tsFileProperties configuration supplying the chunk cap for the data-area traversal
* @return a new TsFileHealthChecker instance
*/
@Bean
public TsFileHealthChecker tsFileHealthChecker() {
logger.info("Initializing TsFileHealthChecker bean");
return new TsFileHealthChecker();
public TsFileHealthChecker tsFileHealthChecker(TsFileProperties tsFileProperties) {
int maxChunks = tsFileProperties.getScan().getMaxChunks();
logger.info("Initializing TsFileHealthChecker bean with maxChunks={}", maxChunks);
return new TsFileHealthChecker(maxChunks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ public static class ScanProperties {
/** Time-to-live in minutes for cached scan results. */
private int cacheTtlMinutes = 60;

/**
* 单个文件允许建立紧凑 chunk 索引的最大 chunk 数。
*
* <p>超过该阈值时不报错、不 OOM,而是降级为只做结构与元数据检查,跳过数据区全量遍历,并在 {@code ScanResult} 的错误列表中以 {@link
* org.apache.tsfile.viewer.dto.ScanErrorType#DATA_VALIDATION_SKIPPED} 标注。默认 5,000,000。
*/
private int maxChunks = 5_000_000;

public int getMaxConcurrent() {
return maxConcurrent;
}
Expand Down Expand Up @@ -274,5 +282,13 @@ public int getCacheTtlMinutes() {
public void setCacheTtlMinutes(int cacheTtlMinutes) {
this.cacheTtlMinutes = cacheTtlMinutes;
}

public int getMaxChunks() {
return maxChunks;
}

public void setMaxChunks(int maxChunks) {
this.maxChunks = maxChunks;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@
package org.apache.tsfile.viewer.controller;

import java.io.IOException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.apache.tsfile.viewer.dto.ChunkDTO;
import org.apache.tsfile.viewer.dto.DeviceMeasurementsDTO;
import org.apache.tsfile.viewer.dto.DeviceRefDTO;
import org.apache.tsfile.viewer.dto.MeasurementDTO;
import org.apache.tsfile.viewer.dto.PageDTO;
import org.apache.tsfile.viewer.dto.RowGroupDTO;
import org.apache.tsfile.viewer.dto.TsFileMetadataDTO;
import org.apache.tsfile.viewer.exception.AccessDeniedException;
import org.apache.tsfile.viewer.exception.TsFileNotFoundException;
Expand All @@ -40,7 +48,9 @@
* <p>Provides endpoints for:
*
* <ul>
* <li>GET /api/meta/{fileId} - Get complete TsFile metadata
* <li>GET /api/meta/{fileId} - Get the metadata summary
* <li>GET /api/meta/{fileId}/row-groups - Get a page of RowGroups
* <li>GET /api/meta/{fileId}/chunks - Get a page of Chunks
* </ul>
*
* <p>Validates: Requirement 8.3 (Metadata endpoint)
Expand All @@ -58,13 +68,14 @@ public MetadataController(MetadataService metadataService) {
}

/**
* Gets complete metadata for a TsFile.
* Gets the metadata summary for a TsFile.
*
* <p>Returns metadata including version, time range, device/measurement counts, and detailed
* lists of measurements, RowGroups, and Chunks.
* <p>Returns version, time range, device/measurement counts and schema details. The {@code
* rowGroups} and {@code chunks} fields are kept for contract compatibility but are always empty;
* details come from the paging endpoints below.
*
* @param fileId the file identifier
* @return TsFileMetadataDTO with complete metadata
* @return TsFileMetadataDTO with summary metadata
*/
@GetMapping("/{fileId}")
public ResponseEntity<TsFileMetadataDTO> getMetadata(@PathVariable String fileId)
Expand All @@ -74,4 +85,101 @@ public ResponseEntity<TsFileMetadataDTO> getMetadata(@PathVariable String fileId
TsFileMetadataDTO metadata = metadataService.getMetadata(fileId);
return ResponseEntity.ok(metadata);
}

/**
* Gets one page of devices, optionally scoped to a table and filtered by a substring.
*
* <p>Cheap enough for pickers: it is derived from the cached device index, not from a table
* query.
*
* @param fileId the file identifier
* @param tableName only devices of this table
* @param query case-insensitive substring the device name must contain
* @param offset zero-based offset, negative values are treated as 0
* @param limit page size, defaults to 50 and is capped at 200
* @return page of devices
*/
@GetMapping("/{fileId}/devices")
public ResponseEntity<PageDTO<DeviceRefDTO>> getDevices(
@PathVariable String fileId,
@RequestParam(required = false) String tableName,
@RequestParam(required = false) String query,
@RequestParam(required = false) Integer offset,
@RequestParam(required = false) Integer limit)
throws TsFileNotFoundException, AccessDeniedException, IOException {
int effectiveOffset = PageDTO.normalizeOffset(offset);
int effectiveLimit = PageDTO.normalizeLimit(limit);

PageDTO<DeviceRefDTO> page =
metadataService.getDevicesPage(fileId, tableName, query, effectiveOffset, effectiveLimit);
return ResponseEntity.ok(page);
}

/**
* Gets the measurements carried by one device.
*
* <p>Tree model files nest measurements under devices, so a client showing a device picker needs
* the measurement choices of the selected device instead of the whole file's union.
*
* @param fileId the file identifier
* @param device device name as returned by the RowGroup paging endpoint
* @return measurements of that device, empty when the device is not part of the file
*/
@GetMapping("/{fileId}/devices/{device}/measurements")
public ResponseEntity<DeviceMeasurementsDTO> getDeviceMeasurements(
@PathVariable String fileId, @PathVariable String device)
throws TsFileNotFoundException, AccessDeniedException, IOException {
logger.debug("Getting measurements of device={} for fileId={}", device, fileId);

List<MeasurementDTO> measurements = metadataService.getDeviceMeasurements(fileId, device);
return ResponseEntity.ok(new DeviceMeasurementsDTO(device, measurements));
}

/**
* Gets one page of RowGroups of a TsFile.
*
* @param fileId the file identifier
* @param offset zero-based offset, negative values are treated as 0
* @param limit page size, defaults to 50 and is capped at 200
* @return page of RowGroups
*/
@GetMapping("/{fileId}/row-groups")
public ResponseEntity<PageDTO<RowGroupDTO>> getRowGroups(
@PathVariable String fileId,
@RequestParam(name = "offset", required = false) Integer offset,
@RequestParam(name = "limit", required = false) Integer limit)
throws TsFileNotFoundException, AccessDeniedException, IOException {
int pageOffset = PageDTO.normalizeOffset(offset);
int pageLimit = PageDTO.normalizeLimit(limit);

logger.debug(
"Getting RowGroup page for fileId={}, offset={}, limit={}", fileId, pageOffset, pageLimit);

PageDTO<RowGroupDTO> page = metadataService.getRowGroupsPage(fileId, pageOffset, pageLimit);
return ResponseEntity.ok(page);
}

/**
* Gets one page of Chunks of a TsFile.
*
* @param fileId the file identifier
* @param offset zero-based offset, negative values are treated as 0
* @param limit page size, defaults to 50 and is capped at 200
* @return page of Chunks
*/
@GetMapping("/{fileId}/chunks")
public ResponseEntity<PageDTO<ChunkDTO>> getChunks(
@PathVariable String fileId,
@RequestParam(name = "offset", required = false) Integer offset,
@RequestParam(name = "limit", required = false) Integer limit)
throws TsFileNotFoundException, AccessDeniedException, IOException {
int pageOffset = PageDTO.normalizeOffset(offset);
int pageLimit = PageDTO.normalizeLimit(limit);

logger.debug(
"Getting chunk page for fileId={}, offset={}, limit={}", fileId, pageOffset, pageLimit);

PageDTO<ChunkDTO> page = metadataService.getChunksPage(fileId, pageOffset, pageLimit);
return ResponseEntity.ok(page);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.tsfile.viewer.dto;

import java.util.List;

/**
* Measurements carried by a single device.
*
* <p>Tree model files nest measurements under devices, so the measurement options a client offers
* must be scoped to the selected device rather than to the whole file.
*/
public class DeviceMeasurementsDTO {

private String device;
private List<MeasurementDTO> measurements;

public DeviceMeasurementsDTO() {}

public DeviceMeasurementsDTO(String device, List<MeasurementDTO> measurements) {
this.device = device;
this.measurements = measurements;
}

public String getDevice() {
return device;
}

public void setDevice(String device) {
this.device = device;
}

public List<MeasurementDTO> getMeasurements() {
return measurements;
}

public void setMeasurements(List<MeasurementDTO> measurements) {
this.measurements = measurements;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.tsfile.viewer.dto;

import java.util.List;

/**
* A device reference for pickers: its identifier, owning table and TAG values.
*
* <p>Derived from the device identifier itself, which is {@code tableName.tag1.tag2...}, so it
* needs no row scan.
*/
public class DeviceRefDTO {

private String device;
private String tableName;
private List<String> tagValues;

public DeviceRefDTO() {}

public DeviceRefDTO(String device, String tableName, List<String> tagValues) {
this.device = device;
this.tableName = tableName;
this.tagValues = tagValues;
}

public String getDevice() {
return device;
}

public void setDevice(String device) {
this.device = device;
}

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public List<String> getTagValues() {
return tagValues;
}

public void setTagValues(List<String> tagValues) {
this.tagValues = tagValues;
}
}
Loading
Loading