github.com/matrixorigin/matrixone@v0.7.0/proto/logservice.proto (about) 1 /* 2 * Copyright 2021 Matrix Origin 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 syntax = "proto3"; 18 package logservice; 19 option go_package = "github.com/matrixorigin/matrixone/pkg/pb/logservice"; 20 21 import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 22 import "metadata.proto"; 23 24 option (gogoproto.goproto_enum_prefix_all) = false; 25 26 enum UpdateType { 27 LeaseHolderIDUpdate = 0; 28 TruncateLSNUpdate = 1; 29 UserEntryUpdate = 2; 30 TSOUpdate = 3; 31 } 32 33 enum NodeState { 34 NormalState = 0; 35 TimeoutState = 1; 36 } 37 38 message CNStore { 39 string UUID = 1; 40 string ServiceAddress = 2; 41 string SQLAddress = 3; 42 metadata.CNRole Role = 4; 43 uint64 Tick = 5; 44 NodeState State = 6; 45 } 46 47 message DNStore { 48 string UUID = 1; 49 string ServiceAddress = 2; 50 uint64 Tick = 3; 51 NodeState State = 4; 52 53 repeated DNShardInfo Shards = 5 [(gogoproto.nullable) = false]; 54 55 // Server address for logtail push model 56 string LogtailServerAddress = 6; 57 } 58 59 message LogStore { 60 string UUID = 1; 61 string ServiceAddress = 2; 62 uint64 Tick = 3; 63 NodeState State = 4; 64 65 repeated LogReplicaInfo Replicas = 5 [(gogoproto.nullable) = false]; 66 } 67 68 // LogShardInfo contains information a log shard. 69 message LogShardInfo { 70 // ShardID is the ID of a Log shard. 71 uint64 ShardID = 1; 72 // Replicas is a map of ReplicaID to LogStore UUID, it describe the member 73 // replicas of the shard at the given Epoch. 74 map<uint64, string> Replicas = 2; 75 // Epoch is the epoch value of the Shard, member replicas of the Shard can 76 // change across epochs. 77 uint64 Epoch = 3; 78 // LeaderID is the ReplicaID of the leader replica at the given term. When 79 // LeaderID is 0, it means there is no leader or the leader is unknown. 80 uint64 LeaderID = 4; 81 // Term is the Raft term value. 82 uint64 Term = 5; 83 84 // TODO: per shard stats like CPU/memory/network usage can be added here 85 }; 86 87 // LogReplicaInfo contains information of a log replica. 88 message LogReplicaInfo { 89 LogShardInfo LogShardInfo = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; 90 // ReplicaID is the ID of a replica within the Log shard. 91 uint64 ReplicaID = 2; 92 } 93 94 // CNStoreHeartbeat is the periodic message sent tp the HAKeeper by CN stores. 95 message CNStoreHeartbeat { 96 string UUID = 1; 97 string ServiceAddress = 2; 98 string SQLAddress = 3; 99 metadata.CNRole Role = 4; 100 bool TaskServiceCreated = 5; 101 } 102 103 104 // CNAllocateID is the periodic message sent tp the HAKeeper by CN stores. 105 message CNAllocateID { 106 uint64 Batch = 1; 107 } 108 109 // LogStoreHeartbeat is the periodic message sent to the HAKeeper by Log Stores. 110 message LogStoreHeartbeat { 111 // UUID is the uuid of the Log Store. 112 string UUID = 1; 113 114 string RaftAddress = 2; 115 string ServiceAddress = 3; 116 string GossipAddress = 4; 117 118 // Replicas is a list of LogReplicaInfo instances collected on the specified 119 // LogStore. Details in Shards are based on the local knowledge of each 120 // replica running on the current LogStore, it may not be accurate or 121 // update to date due to various reasons. 122 repeated LogReplicaInfo Replicas = 5 [(gogoproto.nullable) = false]; 123 // TaskServiceCreated task service is created at the current log node 124 bool TaskServiceCreated = 6; 125 }; 126 127 // DNShardInfo contains information of a launched DN shard. 128 message DNShardInfo { 129 // ShardID uniquely identifies a DN shard. Each DN shard manages a Primary 130 // Key range or hashed Primary Key value range. 131 uint64 ShardID = 1; 132 // ReplicaID uniquely identifies a DN shard instance. After repairing a 133 // failed DN shard, a new DN shard instance is created with a new ReplicaID 134 // value. 135 uint64 ReplicaID = 2; 136 137 // TODO: per shard stats like CPU/memory/network usage can be added here 138 }; 139 140 // DNStoreHeartbeat is the periodic message sent to the HAKeeper by DN stores. 141 message DNStoreHeartbeat { 142 // UUID is the uuid of the DN Store. 143 string UUID = 1; 144 string ServiceAddress = 2; 145 // Shards is a list of DNShardInfo instances collected on the specified 146 // DN store. 147 repeated DNShardInfo Shards = 3 [(gogoproto.nullable) = false]; 148 bool TaskServiceCreated = 4; 149 150 // Server address for logtail push model 151 string LogtailServerAddress = 5; 152 }; 153 154 message RSMState { 155 uint64 Tso = 1; 156 uint64 Index = 2; 157 uint64 LeaseHolderID = 3; 158 uint64 TruncatedLsn = 4; 159 map<uint64, uint64> LeaseHistory = 5; // log lsn -> truncate lsn 160 } 161 162 enum MethodType { 163 TSO_UPDATE = 0; 164 APPEND = 1; 165 READ = 2; 166 TRUNCATE = 3; 167 GET_TRUNCATE = 4; 168 CONNECT = 5; 169 CONNECT_RO = 6; 170 LOG_HEARTBEAT = 7; 171 CN_HEARTBEAT = 8; 172 DN_HEARTBEAT = 9; 173 CHECK_HAKEEPER = 10; 174 GET_CLUSTER_DETAILS = 11; 175 GET_SHARD_INFO = 12; 176 CN_ALLOCATE_ID = 13; 177 GET_CLUSTER_STATE = 14; 178 }; 179 180 enum RecordType { 181 UserRecord = 0; 182 Internal = 1; 183 LeaseUpdate = 2; 184 LeaseRejected = 3; 185 } 186 187 // LogRecord is what we store into the LogService. 188 message LogRecord { 189 uint64 Lsn = 1; 190 RecordType Type = 2; 191 bytes Data = 3; 192 }; 193 194 message LogRequest { 195 string Name = 1; 196 uint64 ShardID = 2; 197 uint64 Lsn = 3; 198 uint64 MaxSize = 4; 199 uint64 DNShardID = 5; 200 uint64 DNID = 6; 201 } 202 203 message TsoRequest { 204 uint64 Count = 1; 205 } 206 207 message Request { 208 uint64 RequestID = 1; 209 MethodType Method = 2; 210 LogRequest LogRequest = 3 [(gogoproto.nullable) = false]; 211 LogStoreHeartbeat LogHeartbeat = 4; 212 CNStoreHeartbeat CNHeartbeat = 5; 213 DNStoreHeartbeat DNHeartbeat = 6; 214 TsoRequest TsoRequest = 7; 215 CNAllocateID CNAllocateID = 8; 216 }; 217 218 message LogResponse { 219 uint64 ShardID = 1; 220 uint64 Lsn = 2; 221 uint64 LastLsn = 3; 222 } 223 224 message AllocateIDResponse { 225 uint64 FirstID = 1; 226 } 227 228 message Response { 229 uint64 RequestID = 1; 230 MethodType Method = 2; 231 uint32 ErrorCode = 3; 232 string ErrorMessage = 4; 233 bool IsHAKeeper = 5; 234 LogResponse LogResponse = 6 [(gogoproto.nullable) = false]; 235 CommandBatch CommandBatch = 7; 236 TsoResponse TsoResponse = 8; 237 ClusterDetails ClusterDetails = 9; 238 ShardInfoQueryResult ShardInfo = 10; 239 AllocateIDResponse AllocateID = 11; 240 CheckerState CheckerState = 12; 241 }; 242 243 message LogRecordResponse { 244 repeated LogRecord Records = 1 [(gogoproto.nullable) = false]; 245 }; 246 247 message TsoResponse { 248 uint64 Value = 1; 249 } 250 251 // 252 // HAKeeper related pb 253 // 254 255 enum HAKeeperUpdateType { 256 TickUpdate = 0; 257 CNHeartbeatUpdate = 1; 258 DNHeartbeatUpdate = 2; 259 LogHeartbeatUpdate = 3; 260 GetIDUpdate = 4; 261 ScheduleCommandUpdate = 5; 262 SetStateUpdate = 6; 263 InitialClusterUpdate = 7; 264 SetTaskSchedulerStateUpdate = 8; 265 SetTaskTableUserUpdate = 9; 266 } 267 268 // HAKeeperState state transition diagram 269 // HAKeeperCreated 270 // │ 271 // │ cluster init info set 272 // ▼ 273 // HAKeeperBootstrapping 274 // │ 275 // │ init schedule commands received 276 // ▼ 277 // HAKeeperBootstrapCommandsReceived 278 // │ 279 // │ 280 // ┌───────────┴───────────┐ 281 // │ time out │ bootstrap successfully 282 // ▼ ▼ 283 // HAKeeperBootstrapFailed HAKeeperRunning 284 // 285 enum HAKeeperState { 286 HAKeeperCreated = 0; 287 HAKeeperBootstrapping = 1; 288 HAKeeperBootstrapCommandsReceived = 2; 289 HAKeeperBootstrapFailed = 3; 290 HAKeeperRunning = 4; 291 } 292 293 // TaskSchedulerState state transition diagram 294 // TaskSchedulerCreated 295 // │ 296 // │ setTaskTableUser() 297 // ▼ 298 // TaskSchedulerStarted 299 // │ ▲ 300 // │ │ 301 // ▼ │ 302 // TaskSchedulerStopped 303 enum TaskSchedulerState { 304 TaskSchedulerCreated = 0; 305 TaskSchedulerRunning = 1; 306 TaskSchedulerStopped = 2; 307 } 308 309 message TaskTableUser { 310 // Username for task table user 311 string Username = 1; 312 // Password for task table user 313 string Password = 2; 314 } 315 316 // Replica of the shard 317 message Replica { 318 // UUID which store the Replica is located in 319 string UUID = 1; 320 321 uint64 ShardID = 2; 322 uint64 ReplicaID = 3; 323 uint64 Epoch = 4; 324 325 // LogShardID only used for DNShard. 326 uint64 LogShardID = 5; 327 } 328 329 // ConfigChangeType indicates config change command type. 330 enum ConfigChangeType { 331 AddReplica = 0; 332 RemoveReplica = 1; 333 StartReplica = 2; 334 StopReplica = 3; 335 KillZombie = 4; 336 } 337 338 // ConfigChange is the detail of a config change. 339 message ConfigChange { 340 Replica Replica = 1 [(gogoproto.nullable) = false]; 341 ConfigChangeType ChangeType = 2; 342 343 // only used for bootstrap 344 map<uint64, string> InitialMembers = 3; 345 } 346 347 // ShutdownStore would stop store. 348 message ShutdownStore { 349 string StoreID = 1; 350 } 351 352 // ServiceType specifies type of service 353 enum ServiceType { 354 LogService = 0; 355 DNService = 1; 356 CNService = 2; 357 } 358 359 // ScheduleCommand contains a shard schedule command. 360 message ScheduleCommand { 361 // UUID which store the ScheduleCommand is sent to 362 string UUID = 1; 363 bool Bootstrapping = 2; 364 ServiceType ServiceType = 3; 365 ConfigChange ConfigChange = 4; 366 ShutdownStore ShutdownStore = 5; 367 CreateTaskService CreateTaskService = 6; 368 DeleteCNStore DeleteCNStore = 7; 369 } 370 371 // CreateTaskService start task service at current node 372 message CreateTaskService { 373 // User used to connect to the task database. 374 TaskTableUser User = 1 [(gogoproto.nullable) = false]; 375 // TaskDatabase task framework database. 376 string TaskDatabase = 2; 377 } 378 379 // DeleteCNStore deletes CN store from CNState to save hakeeper's memory. 380 message DeleteCNStore { 381 string StoreID = 1; 382 } 383 384 message CommandBatch { 385 uint64 Term = 1; 386 repeated ScheduleCommand Commands = 2 [(gogoproto.nullable) = false]; 387 } 388 389 // CNStoreInfo contains information on a CN store. 390 message CNStoreInfo { 391 uint64 Tick = 1; 392 string ServiceAddress = 2; 393 string SQLAddress = 3; 394 metadata.CNRole Role = 4; 395 396 bool TaskServiceCreated = 5; 397 } 398 399 // CNState contains all CN details known to the HAKeeper. 400 message CNState { 401 // Stores is keyed by CN store UUID. 402 map<string, CNStoreInfo> Stores = 1 [(gogoproto.nullable) = false]; 403 } 404 405 406 // DNStoreInfo contains information on a DN store. 407 message DNStoreInfo { 408 uint64 Tick = 1; 409 string ServiceAddress = 2; 410 repeated DNShardInfo Shards = 3 [(gogoproto.nullable) = false]; 411 412 bool TaskServiceCreated = 4; 413 414 // Server address for logtail push model 415 string LogtailServerAddress = 5; 416 } 417 418 // DNState contains all DN details known to the HAKeeper. 419 message DNState { 420 // Stores is keyed by DN store UUID. 421 map<string, DNStoreInfo> Stores = 1 [(gogoproto.nullable) = false]; 422 } 423 424 message ClusterDetails { 425 repeated DNStore DNStores = 1 [(gogoproto.nullable) = false]; 426 repeated CNStore CNStores = 2 [(gogoproto.nullable) = false]; 427 repeated LogStore LogStores = 3 [(gogoproto.nullable) = false]; 428 } 429 430 // ClusterInfo provides a global view of all shards in the cluster. It 431 // describes the logical sharding of the system, rather than physical 432 // distribution of all replicas that belong to those shards. 433 message ClusterInfo { 434 repeated metadata.DNShardRecord DNShards = 1 [(gogoproto.nullable) = false]; 435 repeated metadata.LogShardRecord LogShards = 2 [(gogoproto.nullable) = false]; 436 } 437 438 message InitialClusterRequest { 439 uint64 NumOfLogShards = 1; 440 uint64 NumOfDNShards = 2; 441 uint64 NumOfLogReplicas = 3; 442 } 443 444 // LogStoreInfo contains information of all replicas found on a Log store. 445 message LogStoreInfo { 446 uint64 Tick = 1; 447 string RaftAddress = 2; 448 string ServiceAddress = 3; 449 string GossipAddress = 4; 450 repeated LogReplicaInfo Replicas = 5 [(gogoproto.nullable) = false]; 451 452 bool TaskServiceCreated = 6; 453 } 454 455 message LogState { 456 // Shards is keyed by ShardID, it contains details aggregated from all Log 457 // stores. Each pb.LogShardInfo here contains data aggregated from 458 // different replicas and thus reflect a more accurate description on each 459 // shard. 460 map<uint64, LogShardInfo> Shards = 1 [(gogoproto.nullable) = false]; 461 // Stores is keyed by log store UUID, it contains details found on each 462 // store. Each LogStoreInfo here reflects what was last reported by each Log 463 // store. 464 map<string, LogStoreInfo> Stores = 2 [(gogoproto.nullable) = false]; 465 } 466 467 // CheckerState contains all HAKeeper state required for making schedule 468 // commands. 469 message CheckerState { 470 uint64 Tick = 1; 471 ClusterInfo ClusterInfo = 2 [(gogoproto.nullable) = false]; 472 DNState DNState = 3 [(gogoproto.nullable) = false]; 473 LogState LogState = 4 [(gogoproto.nullable) = false]; 474 CNState CNState = 5 [(gogoproto.nullable) = false]; 475 HAKeeperState State = 6; 476 TaskSchedulerState TaskSchedulerState = 7; 477 TaskTableUser TaskTableUser = 8 [(gogoproto.nullable) = false]; 478 } 479 480 // HAKeeperRSMState contains state maintained by HAKeeper's RSM. 481 message HAKeeperRSMState { 482 uint64 Tick = 1; 483 uint64 NextID = 2; 484 uint64 Term = 3; 485 HAKeeperState State = 4; 486 TaskSchedulerState TaskSchedulerState = 5; 487 map<string, CommandBatch> ScheduleCommands = 6 [(gogoproto.nullable) = false]; 488 map<string, uint64> LogShards = 7; 489 CNState CNState = 8 [(gogoproto.nullable) = false]; 490 DNState DNState = 9 [(gogoproto.nullable) = false]; 491 LogState LogState = 10 [(gogoproto.nullable) = false]; 492 ClusterInfo ClusterInfo = 11 [(gogoproto.nullable) = false]; 493 TaskTableUser TaskTableUser = 12 [(gogoproto.nullable) = false]; 494 } 495 496 // ReplicaInfo contains details of a replica 497 message ReplicaInfo { 498 string UUID = 1; 499 string ServiceAddress = 2; 500 } 501 502 // ShardInfoQueryResult contains the result of the shard info query. 503 message ShardInfoQueryResult { 504 uint64 ShardID = 1; 505 map<uint64, ReplicaInfo> Replicas = 2 [(gogoproto.nullable) = false]; 506 uint64 Epoch = 3; 507 uint64 LeaderID = 4; 508 uint64 Term = 5; 509 }