Skip to content

Commit 5f3321b

Browse files
authored
[feat](TSO) Improve TSO status access (#65850)
### What problem does this PR solve? Issue Number: close #65849 Related PR: #xxx Problem Summary: The /api/tso endpoint only served requests on the master FE, so requests sent to a follower failed instead of reaching the authoritative TSO service. TSO status also needed a queryable system-table interface without adding a dedicated SHOW command. This change forwards /api/tso requests to the master FE by default, adds local=true to inspect the receiving FE without forwarding, and reads all response fields from one TSO status snapshot. It also exposes the master TSO state through information_schema.tso_status using the existing schema-table RPC path.
1 parent f745ddf commit 5f3321b

16 files changed

Lines changed: 790 additions & 13 deletions

File tree

‎be/src/information_schema/schema_scanner.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "information_schema/schema_table_streams_scanner.h"
8383
#include "information_schema/schema_tables_scanner.h"
8484
#include "information_schema/schema_tablets_scanner.h"
85+
#include "information_schema/schema_tso_status_scanner.h"
8586
#include "information_schema/schema_user_privileges_scanner.h"
8687
#include "information_schema/schema_user_scanner.h"
8788
#include "information_schema/schema_variables_scanner.h"
@@ -299,6 +300,8 @@ std::unique_ptr<SchemaScanner> SchemaScanner::create(TSchemaTableType::type type
299300
return SchemaCompactionTasksScanner::create_unique();
300301
case TSchemaTableType::SCH_BACKEND_MS_RPC_TABLE_THROTTLERS:
301302
return SchemaBackendMsRpcTableThrottlersScanner::create_unique();
303+
case TSchemaTableType::SCH_TSO_STATUS:
304+
return SchemaTsoStatusScanner::create_unique();
302305
default:
303306
return SchemaDummyScanner::create_unique();
304307
break;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include "information_schema/schema_tso_status_scanner.h"
19+
20+
#include <gen_cpp/FrontendService_types.h>
21+
22+
#include "core/block/block.h"
23+
#include "core/data_type/data_type_factory.hpp"
24+
#include "runtime/cluster_info.h"
25+
#include "runtime/exec_env.h"
26+
#include "runtime/runtime_state.h"
27+
#include "util/client_cache.h"
28+
#include "util/thrift_rpc_helper.h"
29+
30+
namespace doris {
31+
32+
std::vector<SchemaScanner::ColumnDesc> SchemaTsoStatusScanner::_s_tso_status_columns = {
33+
{"WINDOW_END_PHYSICAL_TIME", TYPE_BIGINT, sizeof(int64_t), true},
34+
{"CURRENT_TSO", TYPE_BIGINT, sizeof(int64_t), true},
35+
{"CURRENT_TSO_PHYSICAL_TIME", TYPE_BIGINT, sizeof(int64_t), true},
36+
{"CURRENT_TSO_LOGICAL_COUNTER", TYPE_BIGINT, sizeof(int64_t), true},
37+
};
38+
39+
SchemaTsoStatusScanner::SchemaTsoStatusScanner()
40+
: SchemaScanner(_s_tso_status_columns, TSchemaTableType::SCH_TSO_STATUS) {}
41+
42+
SchemaTsoStatusScanner::~SchemaTsoStatusScanner() = default;
43+
44+
Status SchemaTsoStatusScanner::start(RuntimeState* state) {
45+
_block_rows_limit = state->batch_size();
46+
_rpc_timeout_ms = state->execution_timeout() * 1000;
47+
return Status::OK();
48+
}
49+
50+
Status SchemaTsoStatusScanner::_get_tso_status_block_from_fe() {
51+
TNetworkAddress master_addr = ExecEnv::GetInstance()->cluster_info()->master_fe_addr;
52+
53+
TSchemaTableRequestParams schema_table_request_params;
54+
TFetchSchemaTableDataRequest request;
55+
request.__set_schema_table_name(TSchemaTableName::TSO_STATUS);
56+
request.__set_schema_table_params(schema_table_request_params);
57+
58+
TFetchSchemaTableDataResult result;
59+
RETURN_IF_ERROR(ThriftRpcHelper::rpc<FrontendServiceClient>(
60+
master_addr.hostname, master_addr.port,
61+
[&request, &result](FrontendServiceConnection& client) {
62+
client->fetchSchemaTableData(result, request);
63+
},
64+
_rpc_timeout_ms));
65+
66+
return _process_tso_status_result(result);
67+
}
68+
69+
Status SchemaTsoStatusScanner::_process_tso_status_result(
70+
const TFetchSchemaTableDataResult& result) {
71+
Status status(Status::create(result.status));
72+
if (!status.ok()) {
73+
LOG(WARNING) << "fetch TSO status from FE failed, errmsg=" << status;
74+
return status;
75+
}
76+
77+
_tso_status_block = Block::create_unique();
78+
for (int i = 0; i < _s_tso_status_columns.size(); ++i) {
79+
auto data_type =
80+
DataTypeFactory::instance().create_data_type(_s_tso_status_columns[i].type, true);
81+
_tso_status_block->insert(ColumnWithTypeAndName(data_type->create_column(), data_type,
82+
_s_tso_status_columns[i].name));
83+
}
84+
85+
_tso_status_block->reserve(result.data_batch.size());
86+
for (const TRow& row : result.data_batch) {
87+
if (row.column_value.size() != _s_tso_status_columns.size()) {
88+
return Status::InternalError<false>(
89+
"TSO status schema does not match between FE and BE");
90+
}
91+
for (int i = 0; i < _s_tso_status_columns.size(); ++i) {
92+
RETURN_IF_ERROR(insert_block_column(row.column_value[i], i, _tso_status_block.get(),
93+
_s_tso_status_columns[i].type));
94+
}
95+
}
96+
_total_rows = static_cast<int>(_tso_status_block->rows());
97+
return Status::OK();
98+
}
99+
100+
Status SchemaTsoStatusScanner::get_next_block_internal(Block* block, bool* eos) {
101+
if (!_is_init) {
102+
return Status::InternalError("Used before initialized.");
103+
}
104+
105+
if (nullptr == block || nullptr == eos) {
106+
return Status::InternalError("input pointer is nullptr.");
107+
}
108+
109+
if (_tso_status_block == nullptr) {
110+
RETURN_IF_ERROR(_get_tso_status_block_from_fe());
111+
}
112+
113+
if (_row_idx == _total_rows) {
114+
*eos = true;
115+
return Status::OK();
116+
}
117+
118+
int current_batch_rows = std::min(_block_rows_limit, _total_rows - _row_idx);
119+
ScopedMutableBlock scoped_mblock(block);
120+
auto& mblock = scoped_mblock.mutable_block();
121+
RETURN_IF_ERROR(mblock.add_rows(_tso_status_block.get(), _row_idx, current_batch_rows));
122+
_row_idx += current_batch_rows;
123+
124+
*eos = _row_idx == _total_rows;
125+
return Status::OK();
126+
}
127+
128+
} // namespace doris
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#pragma once
19+
20+
#include <memory>
21+
#include <vector>
22+
23+
#include "common/status.h"
24+
#include "information_schema/schema_scanner.h"
25+
26+
namespace doris {
27+
28+
class RuntimeState;
29+
class Block;
30+
class TFetchSchemaTableDataResult;
31+
32+
class SchemaTsoStatusScanner : public SchemaScanner {
33+
ENABLE_FACTORY_CREATOR(SchemaTsoStatusScanner);
34+
35+
public:
36+
SchemaTsoStatusScanner();
37+
~SchemaTsoStatusScanner() override;
38+
39+
Status start(RuntimeState* state) override;
40+
Status get_next_block_internal(Block* block, bool* eos) override;
41+
42+
private:
43+
Status _get_tso_status_block_from_fe();
44+
Status _process_tso_status_result(const TFetchSchemaTableDataResult& result);
45+
46+
int _block_rows_limit = 4096;
47+
int _row_idx = 0;
48+
int _total_rows = 0;
49+
std::unique_ptr<Block> _tso_status_block = nullptr;
50+
int _rpc_timeout_ms = 3000;
51+
static std::vector<SchemaScanner::ColumnDesc> _s_tso_status_columns;
52+
};
53+
54+
} // namespace doris

0 commit comments

Comments
 (0)