AntiTopQuark commented on code in PR #61199: URL: https://github.com/apache/doris/pull/61199#discussion_r3016436522
########## fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TSOAction.java: ########## @@ -0,0 +1,97 @@ +// 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.doris.httpv2.rest; + +import org.apache.doris.catalog.Env; +import org.apache.doris.httpv2.entity.ResponseEntityBuilder; +import org.apache.doris.tso.TSOTimestamp; + +import com.google.common.collect.Maps; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * TSOAction is used to get TSO (Timestamp Oracle) information via HTTP interface. + * This interface only allows retrieving TSO information without increasing the TSO value. + * + * Example usage: + * GET /api/tso + * Response: + * { + * "window_end_physical_time": 1625097600000, + * "current_tso": 123456789012345678, + * "current_tso_physical_time": 1625097600000, + * "current_tso_logical_counter": 123 + * } + */ +@RestController +public class TSOAction extends RestBaseController { + + private static final Logger LOG = LogManager.getLogger(TSOAction.class); + + /** + * Get current TSO information. + * This interface only returns TSO information without increasing the TSO value. + * + * @param request HTTP request + * @param response HTTP response + * @return ResponseEntity with TSO information including: + * - window_end_physical_time: The end time of the current TSO window + * - current_tso: The current composed TSO timestamp + * - current_tso_physical_time: The physical time part of current TSO + * - current_tso_logical_counter: The logical counter part of current TSO + */ + @RequestMapping(path = "/api/tso", method = RequestMethod.GET) + public Object getTSO(HttpServletRequest request, HttpServletResponse response) { + try { + //check user auth + executeCheckPassword(request, response); + + Env env = Env.getCurrentEnv(); + if (env == null || !env.isReady()) { + LOG.warn("TSO HTTP API: FE is not ready"); + return ResponseEntityBuilder.badRequest("FE is not ready"); + } + if (!env.isMaster()) { + LOG.warn("TSO HTTP API: current FE is not master"); + return ResponseEntityBuilder.badRequest("Current FE is not master"); + } + // Get current TSO information without increasing it + long windowEndPhysicalTime = env.getTSOService().getWindowEndTSO(); Review Comment: This is an intentional design, not an oversight. The `/api/tso` endpoint is intended as a **state observation interface**, not a timestamp issuance interface. The actual path for externally allocating TSO is `getTSO()`, where strict validation is performed on both `enable_tso_feature` and `isInitialized`. Requests will be rejected directly if TSO is not enabled or not calibrated. In contrast, `/api/tso` only reads in-memory snapshots of the current state (`getWindowEndTSO()` / `getCurrentTSO()`) for observation and troubleshooting purposes, and does **not** advance the timestamp. cc @dataroaring -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
