Skip to content

Commit a1d7fd1

Browse files
authored
*: Refine some comments of handling DDL and startup (#10439)
ref #6233 Signed-off-by: JaySon-Huang <tshent@qq.com>
1 parent ff34ccc commit a1d7fd1

File tree

13 files changed

+141
-100
lines changed

13 files changed

+141
-100
lines changed

dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ void DAGStorageInterpreter::executeImpl(
375375
auto remote_requests = buildRemoteRequests(dag_context.scan_context_map[table_scan.getTableScanExecutorID()]);
376376
if (dag_context.is_disaggregated_task && !remote_requests.empty())
377377
{
378-
// This means RN is sending requests with stale region info, we simply reject the request
379-
// and ask RN to send requests again with correct region info. When RN updates region info,
380-
// RN may be sending requests to other WN.
378+
// This means compute node is sending requests with stale region info, we simply reject the request
379+
// and ask compute node to send requests again with correct region info. When compute node updates region info,
380+
// compute node may be sending requests to other WN.
381381

382382
RegionException::UnavailableRegions region_ids;
383383
for (const auto & info : context.getDAGContext()->retry_regions)
@@ -487,9 +487,9 @@ void DAGStorageInterpreter::executeImpl(DAGPipeline & pipeline)
487487
auto remote_requests = buildRemoteRequests(dag_context.scan_context_map[table_scan.getTableScanExecutorID()]);
488488
if (dag_context.is_disaggregated_task && !remote_requests.empty())
489489
{
490-
// This means RN is sending requests with stale region info, we simply reject the request
491-
// and ask RN to send requests again with correct region info. When RN updates region info,
492-
// RN may be sending requests to other WN.
490+
// This means compute node is sending requests with stale region info, we simply reject the request
491+
// and ask compute node to send requests again with correct region info. When compute node updates region info,
492+
// compute node may be sending requests to other write node.
493493

494494
RegionException::UnavailableRegions region_ids;
495495
for (const auto & info : context.getDAGContext()->retry_regions)
@@ -878,7 +878,7 @@ LearnerReadSnapshot DAGStorageInterpreter::doBatchCopLearnerRead()
878878
}
879879
catch (const LockException & e)
880880
{
881-
// When this is a disaggregated read task on WN issued by RN, we need RN
881+
// When this is a disaggregated read task on write node issued by compute node, we need compute node
882882
// to take care of retrying.
883883
if (context.getDAGContext()->is_disaggregated_task)
884884
throw;
@@ -890,7 +890,7 @@ LearnerReadSnapshot DAGStorageInterpreter::doBatchCopLearnerRead()
890890
}
891891
catch (const RegionException & e)
892892
{
893-
// When this is a disaggregated read task on WN issued by RN, we need RN
893+
// When this is a disaggregated read task on write node issued by compute node, we need compute node
894894
// to take care of retrying.
895895
if (context.getDAGContext()->is_disaggregated_task)
896896
throw;

dbms/src/Flash/Planner/Plans/PhysicalTableScan.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void PhysicalTableScan::buildBlockInputStreamImpl(DAGPipeline & pipeline, Contex
101101

102102
if (context.getSharedContextDisagg()->isDisaggregatedComputeMode())
103103
{
104+
// Interact between compute node and write node.
104105
StorageDisaggregatedInterpreter disaggregated_tiflash_interpreter(
105106
context,
106107
tidb_table_scan,
@@ -124,6 +125,7 @@ void PhysicalTableScan::buildPipeline(
124125
// For building PipelineExec in compile time.
125126
if (context.getSharedContextDisagg()->isDisaggregatedComputeMode())
126127
{
128+
// Interact between compute node and write node.
127129
StorageDisaggregatedInterpreter disaggregated_tiflash_interpreter(
128130
context,
129131
tidb_table_scan,

dbms/src/Server/Server.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ try
11381138
SessionCleaner session_cleaner(*global_context);
11391139
auto & tmt_context = global_context->getTMTContext();
11401140

1141+
// Start the proxy service, including the grpc service for raft and http status service
11411142
proxy_machine.startProxyService(tmt_context, store_ident);
11421143
if (proxy_machine.isProxyRunnable())
11431144
{
@@ -1162,6 +1163,8 @@ try
11621163
syncSchemaWithTiDB(storage_config, bg_init_stores, terminate_signals_counter, global_context, log);
11631164
bg_init_stores.waitUntilFinish();
11641165
}
1166+
1167+
// Start read index workers and wait region apply index catch up with TiKV before serving requests.
11651168
proxy_machine.waitProxyServiceReady(tmt_context, terminate_signals_counter);
11661169
}
11671170
}
@@ -1224,13 +1227,13 @@ try
12241227
GRPCCompletionQueuePool::global_instance = std::make_unique<GRPCCompletionQueuePool>(size);
12251228
}
12261229

1227-
/// startup grpc server to serve raft and/or flash services.
1230+
/// startup flash service for handling coprocessor and MPP requests.
12281231
FlashGrpcServerHolder flash_grpc_server_holder(this->context(), this->config(), raft_config, log);
12291232

12301233
SCOPE_EXIT({
12311234
// Stop LAC for AutoScaler managed CN before FlashGrpcServerHolder is destructed.
12321235
// Because AutoScaler it will kill tiflash process when port of flash_server_addr is down.
1233-
// And we want to make sure LAC is cleanedup.
1236+
// And we want to make sure LAC is cleaned up.
12341237
// The effects are there will be no resource control during [lac.safeStop(), FlashGrpcServer destruct done],
12351238
// but it's basically ok, that duration is small(normally 100-200ms).
12361239
if (is_disagg_compute_mode && disagg_opt.use_autoscaler && LocalAdmissionController::global_instance)

dbms/src/Storages/KVStore/ProxyStateMachine.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct TiFlashProxyConfig
114114
private:
115115
TiFlashProxyConfig()
116116
{
117-
// For test, bootstrap no proxy.
117+
// For test, bootstrap without proxy.
118118
}
119119
// TiFlash Proxy will set the default value of "flash.proxy.addr", so we don't need to set here.
120120
void addExtraArgs(const std::string & k, const std::string & v) { val_map["--" + k] = v; }
@@ -331,6 +331,10 @@ struct ProxyStateMachine
331331
tiflash_instance_wrap.tmt = &tmt_context;
332332
LOG_INFO(log, "Let tiflash proxy start all services");
333333
// Set tiflash instance status to running, then wait for proxy enter running status
334+
// It means that in tiflash-proxy
335+
// * rpc server for handling raft command is started
336+
// * http status server is started
337+
// https://github.com/pingcap/tidb-engine-ext/blob/74d6916e0aee34783cf3835b6fb93d40f32bb889/proxy_components/proxy_server/src/run.rs#L241-L265
334338
tiflash_instance_wrap.status = EngineStoreServerStatus::Running;
335339
while (tiflash_instance_wrap.proxy_helper->getProxyStatus() == RaftProxyStatus::Idle)
336340
std::this_thread::sleep_for(std::chrono::milliseconds(200));

dbms/src/Storages/KVStore/Read/ReadIndex.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ void WaitCheckRegionReadyImpl(
307307
total_regions_cnt);
308308
}
309309

310+
/**
311+
* For the region_ids stored in `kvstore`
312+
* 1. fetch the latest commit-index from TiKV
313+
* 2. wait until the tiflash-proxy apply raft logs for regions has catchup (applied to the commit-index)
314+
*/
310315
void WaitCheckRegionReady(KVStore & kvstore, const std::atomic_size_t & terminate_signals_counter)
311316
{
312317
const auto & config = kvstore.getConfigRef();

dbms/src/TiDB/Schema/DatabaseInfoCache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace DB
2424
{
2525

26+
// DatabaseInfoCache is a thread-safe cache for DatabaseID -> TiDB::DBInfo
2627
class DatabaseInfoCache
2728
{
2829
public:

dbms/src/TiDB/Schema/SchemaBuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void SchemaBuilder<Getter, NameMapper>::applyDiff(const SchemaDiff & diff)
370370
{
371371
// >= SchemaActionType::MaxRecognizedType
372372
// log down the Int8 value directly
373-
LOG_ERROR(log, "Unsupported change type: {}, diff_version={}", fmt::underlying(diff.type), diff.version);
373+
LOG_WARNING(log, "Unsupported change type: {}, diff_version={}", fmt::underlying(diff.type), diff.version);
374374
}
375375

376376
break;
@@ -1138,7 +1138,7 @@ void SchemaBuilder<Getter, NameMapper>::applyCreateStorageInstance(
11381138
// Else the storage instance does not exist, create it.
11391139

11401140
// We need to create a Storage instance to handle its raft log and snapshot when it
1141-
// is "dropped" but not physically removed in TiDB. To handle it porperly, we get a
1141+
// is "dropped" but not physically removed in TiDB. To handle it properly, we get a
11421142
// tso from PD to create the table. The tso must be newer than what "DROP TABLE" DDL
11431143
// is executed. So when the gc-safepoint is larger than tombstone_ts, the table can
11441144
// be safe to physically drop on TiFlash.
@@ -1434,7 +1434,7 @@ void SchemaBuilder<Getter, NameMapper>::syncAllSchema()
14341434
}
14351435
sync_all_schema_wait_group->wait();
14361436

1437-
// `applyRenameLogicalTable` is not atmoic when renaming a partitioned table
1437+
// `applyRenameLogicalTable` is not atomic when renaming a partitioned table
14381438
// to new database. There could be a chance that the logical table .sql have
14391439
// been moved to the new database while some partitions' sql are not moved.
14401440
// Try to detect such situation and fix it.
@@ -1526,7 +1526,7 @@ void SchemaBuilder<Getter, NameMapper>::tryFixPartitionsBelongingDatabase()
15261526
auto it = part_to_db_id.find(*opt_tbl_id);
15271527
if (it == part_to_db_id.end())
15281528
{
1529-
// this is not a physical_table_id of a partition, ignore sliently
1529+
// this is not a physical_table_id of a partition, ignore silently
15301530
continue;
15311531
}
15321532
// Get the `new_database_id` from `table_id_map`
@@ -1769,8 +1769,8 @@ String SchemaBuilder<Getter, NameMapper>::tryGetDatabaseDisplayNameFromLocal(Dat
17691769
{
17701770
// This method is called in the `applyDiff` loop. The `applyDiff` loop should apply the all the DDL operations before
17711771
// the database get dropped, so the database info should be cached in `databases`.
1772-
// But for corner cases that the database is dropped on some unkonwn cases, we just return a display database name
1773-
// according to the keyspace_id and database_id because display name ususally is not critical.
1772+
// But for corner cases that the database is dropped on some unknown cases, we just return a display database name
1773+
// according to the keyspace_id and database_id because display name usually is not critical.
17741774
if (auto new_db_info = databases.getDBInfo(database_id); likely(new_db_info != nullptr))
17751775
{
17761776
return name_mapper.displayDatabaseName(*new_db_info);

dbms/src/TiDB/Schema/SchemaBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ struct SchemaBuilder
3131
private:
3232
NameMapper name_mapper;
3333

34+
// Snapshot reader of schema info from TiKV
3435
Getter & getter;
3536

3637
Context & context;
3738

39+
// Cache of DatabaseID -> DatabaseInfo in this keyspace
3840
DatabaseInfoCache & databases;
39-
41+
// Cache of TableIDMap in this keyspace
4042
TableIDMap & table_id_map;
4143

4244
const KeyspaceID keyspace_id;

dbms/src/TiDB/Schema/SchemaGetter.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace DB
2929
{
3030
// The enum results are completely the same as the DDL Action listed in the "parser/model/ddl.go" of TiDB codebase, which must be keeping in sync.
31-
// https://github.com/pingcap/tidb/blob/84492a9a1e5bff0b4a4256955ab8231975c2dde1/pkg/meta/model/job.go#L35-L36
31+
// https://github.com/pingcap/tidb/blob/35094ab95c393e6d55b00a215d24e859880ec1f5/pkg/meta/model/job.go#L36-L120
3232
enum class SchemaActionType : Int8
3333
{
3434
None = 0,
@@ -105,11 +105,14 @@ enum class SchemaActionType : Int8
105105
ActionRemovePartitioning = 72,
106106
ActionAddColumnarIndex = 73,
107107
ActionModifyEngineAttribute = 74,
108+
ActionAlterTableMode = 75,
109+
ActionRefreshMeta = 76,
110+
ActionModifySchemaReadOnly = 77,
108111

109112
// If we support new type from TiDB.
110113
// MaxRecognizedType also needs to be changed.
111114
// It should always be equal to the maximum supported type + 1
112-
MaxRecognizedType = 75,
115+
MaxRecognizedType = 78,
113116
};
114117

115118
struct AffectedOption

dbms/src/TiDB/Schema/SchemaSyncer.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@
1616

1717
#include <Interpreters/Context_fwd.h>
1818
#include <Storages/KVStore/Types.h>
19+
#include <TiDB/Schema/TiDB_fwd.h>
1920
#include <common/logger_useful.h>
2021

2122
#include <memory>
22-
#include <vector>
23-
24-
namespace TiDB
25-
{
26-
struct DBInfo;
27-
using DBInfoPtr = std::shared_ptr<DBInfo>;
28-
struct TableInfo;
29-
using TableInfoPtr = std::shared_ptr<TableInfo>;
30-
} // namespace TiDB
3123

3224
namespace DB
3325
{
@@ -48,17 +40,25 @@ class SchemaSyncer
4840
*/
4941
virtual bool syncTableSchema(Context & context, TableID physical_table_id) = 0;
5042

51-
virtual void reset() = 0;
52-
53-
virtual TiDB::DBInfoPtr getDBInfoByName(const String & database_name) = 0;
54-
43+
/*
44+
* When the table is physically dropped from the TiFlash node, use this method to unregister
45+
* the TableID mapping.
46+
*/
5547
virtual void removeTableID(TableID table_id) = 0;
5648

5749
/**
5850
* Drop all schema of a given keyspace.
5951
* When a keyspace is removed, drop all its databases and tables.
6052
*/
6153
virtual void dropAllSchema(Context & context) = 0;
54+
55+
/*
56+
* Clear all states.
57+
* just for testing restart
58+
*/
59+
virtual void reset() = 0;
60+
61+
virtual TiDB::DBInfoPtr getDBInfoByName(const String & database_name) = 0;
6262
};
6363

6464
using SchemaSyncerPtr = std::shared_ptr<SchemaSyncer>;

0 commit comments

Comments
 (0)