github.com/matrixorigin/matrixone@v1.2.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 string LockServiceAddress = 4; 43 reserved 5; 44 metadata.CNRole Role = 6; 45 uint64 Tick = 7; 46 NodeState State = 8; 47 map<string, metadata.LabelList> Labels = 9 [(gogoproto.nullable) = false]; 48 metadata.WorkState WorkState = 10; 49 string QueryAddress = 11; 50 ConfigData ConfigData = 12; 51 Resource Resource = 13 [(gogoproto.nullable) = false]; 52 int64 UpTime = 14; 53 } 54 55 message TNStore { 56 string UUID = 1; 57 string ServiceAddress = 2; 58 uint64 Tick = 3; 59 NodeState State = 4; 60 61 repeated TNShardInfo Shards = 5 [(gogoproto.nullable) = false]; 62 63 // Server address for logtail push model 64 string LogtailServerAddress = 6; 65 // LockServiceAddress lock service address for lock table allocator 66 string LockServiceAddress = 7; 67 reserved 8; 68 ConfigData ConfigData = 9; 69 // QueryAddress is the address of the queryservice on tn 70 string QueryAddress = 10; 71 } 72 73 message LogStore { 74 string UUID = 1; 75 string ServiceAddress = 2; 76 uint64 Tick = 3; 77 NodeState State = 4; 78 79 repeated LogReplicaInfo Replicas = 5 [(gogoproto.nullable) = false]; 80 ConfigData ConfigData = 6; 81 } 82 83 // LogShardInfo contains information a log shard. 84 message LogShardInfo { 85 // ShardID is the ID of a Log shard. 86 uint64 ShardID = 1; 87 // Replicas is a map of ReplicaID to LogStore UUID, it describe the member 88 // replicas of the shard at the given Epoch. 89 map<uint64, string> Replicas = 2; 90 // Epoch is the epoch value of the Shard, member replicas of the Shard can 91 // change across epochs. 92 uint64 Epoch = 3; 93 // LeaderID is the ReplicaID of the leader replica at the given term. When 94 // LeaderID is 0, it means there is no leader or the leader is unknown. 95 uint64 LeaderID = 4; 96 // Term is the Raft term value. 97 uint64 Term = 5; 98 99 // TODO: per shard stats like CPU/memory/network usage can be added here 100 }; 101 102 // LogReplicaInfo contains information of a log replica. 103 message LogReplicaInfo { 104 LogShardInfo LogShardInfo = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; 105 // ReplicaID is the ID of a replica within the Log shard. 106 uint64 ReplicaID = 2; 107 } 108 109 message Resource { 110 uint64 CPUTotal = 1; 111 double CPUAvailable = 2; 112 uint64 MemTotal = 3; 113 uint64 MemAvailable = 4; 114 } 115 116 // CNStoreHeartbeat is the periodic message sent tp the HAKeeper by CN stores. 117 message CNStoreHeartbeat { 118 string UUID = 1; 119 string ServiceAddress = 2; 120 string SQLAddress = 3; 121 string LockServiceAddress = 4; 122 reserved 5; 123 metadata.CNRole Role = 6; 124 bool TaskServiceCreated = 7; 125 string QueryAddress = 8; 126 string InitWorkState = 9; 127 string GossipAddress = 10; 128 bool GossipJoined = 11; 129 ConfigData ConfigData = 12; 130 Resource Resource = 13 [(gogoproto.nullable) = false]; 131 } 132 133 // CNAllocateID is the periodic message sent tp the HAKeeper by CN stores. 134 message CNAllocateID { 135 string key = 1; 136 uint64 Batch = 2; 137 } 138 139 // LogStoreHeartbeat is the periodic message sent to the HAKeeper by Log Stores. 140 message LogStoreHeartbeat { 141 // UUID is the uuid of the Log Store. 142 string UUID = 1; 143 144 string RaftAddress = 2; 145 string ServiceAddress = 3; 146 string GossipAddress = 4; 147 148 // Replicas is a list of LogReplicaInfo instances collected on the specified 149 // LogStore. Details in Shards are based on the local knowledge of each 150 // replica running on the current LogStore, it may not be accurate or 151 // update to date due to various reasons. 152 repeated LogReplicaInfo Replicas = 5 [(gogoproto.nullable) = false]; 153 // TaskServiceCreated task service is created at the current log node 154 bool TaskServiceCreated = 6; 155 156 ConfigData ConfigData = 7; 157 }; 158 159 // TNShardInfo contains information of a launched TN shard. 160 message TNShardInfo { 161 // ShardID uniquely identifies a TN shard. Each TN shard manages a Primary 162 // Key range or hashed Primary Key value range. 163 uint64 ShardID = 1; 164 // ReplicaID uniquely identifies a TN shard instance. After repairing a 165 // failed TN shard, a new TN shard instance is created with a new ReplicaID 166 // value. 167 uint64 ReplicaID = 2; 168 169 // TODO: per shard stats like CPU/memory/network usage can be added here 170 }; 171 172 // TNStoreHeartbeat is the periodic message sent to the HAKeeper by TN stores. 173 message TNStoreHeartbeat { 174 // UUID is the uuid of the TN Store. 175 string UUID = 1; 176 string ServiceAddress = 2; 177 // Shards is a list of TNShardInfo instances collected on the specified 178 // TN store. 179 repeated TNShardInfo Shards = 3 [(gogoproto.nullable) = false]; 180 bool TaskServiceCreated = 4; 181 // Server address for logtail push model 182 string LogtailServerAddress = 5; 183 // LockServiceAddress lock service address for lock table allocator 184 string LockServiceAddress = 6; 185 reserved 7; 186 ConfigData ConfigData = 8; 187 // QueryAddress is the address of queryservice on tn 188 string QueryAddress = 9; 189 }; 190 191 message RSMState { 192 uint64 Tso = 1; 193 uint64 Index = 2; 194 uint64 LeaseHolderID = 3; 195 uint64 TruncatedLsn = 4; 196 map<uint64, uint64> LeaseHistory = 5; // log lsn -> truncate lsn 197 } 198 199 enum MethodType { 200 TSO_UPDATE = 0; 201 APPEND = 1; 202 READ = 2; 203 TRUNCATE = 3; 204 GET_TRUNCATE = 4; 205 CONNECT = 5; 206 CONNECT_RO = 6; 207 LOG_HEARTBEAT = 7; 208 CN_HEARTBEAT = 8; 209 TN_HEARTBEAT = 9; 210 CHECK_HAKEEPER = 10; 211 GET_CLUSTER_DETAILS = 11; 212 GET_SHARD_INFO = 12; 213 CN_ALLOCATE_ID = 13; 214 GET_CLUSTER_STATE = 14; 215 UPDATE_CN_LABEL = 15; 216 UPDATE_CN_WORK_STATE = 16; 217 PATCH_CN_STORE = 17; 218 DELETE_CN_STORE = 18; 219 PROXY_HEARTBEAT = 19; 220 }; 221 222 enum RecordType { 223 UserRecord = 0; 224 Internal = 1; 225 LeaseUpdate = 2; 226 LeaseRejected = 3; 227 } 228 229 // LogRecord is what we store into the LogService. 230 message LogRecord { 231 uint64 Lsn = 1; 232 RecordType Type = 2; 233 bytes Data = 3; 234 }; 235 236 message LogRequest { 237 string Name = 1; 238 uint64 ShardID = 2; 239 uint64 Lsn = 3; 240 uint64 MaxSize = 4; 241 uint64 TNShardID = 5; 242 uint64 TNID = 6; 243 } 244 245 message TsoRequest { 246 uint64 Count = 1; 247 } 248 249 enum CNLabelOp { 250 SetLabel = 0; 251 DeleteLabel = 1; 252 } 253 254 message CNStoreLabel { 255 // UUID is the uuid of the CN store. 256 string UUID = 1; 257 // Operation is the CN label operation. 258 // TODO(volgariver6): Unused field. 259 CNLabelOp Operation = 2; 260 // Labels is the labels of the CN store. 261 map<string, metadata.LabelList> Labels = 3 [(gogoproto.nullable) = false]; 262 } 263 264 message CNWorkState { 265 // UUID is the uuid of the CN store. 266 string UUID = 1; 267 // State is the CN work state. 268 metadata.WorkState State = 2; 269 } 270 271 message CNStateLabel { 272 // UUID is the uuid of the CN store. 273 string UUID = 1; 274 // State is the CN work state. 275 metadata.WorkState State = 2; 276 // Labels is the labels of the CN store. 277 map<string, metadata.LabelList> Labels = 3 [(gogoproto.nullable) = false]; 278 } 279 280 message Request { 281 uint64 RequestID = 1; 282 MethodType Method = 2; 283 LogRequest LogRequest = 3 [(gogoproto.nullable) = false]; 284 LogStoreHeartbeat LogHeartbeat = 4; 285 CNStoreHeartbeat CNHeartbeat = 5; 286 TNStoreHeartbeat TNHeartbeat = 6; 287 TsoRequest TsoRequest = 7; 288 CNAllocateID CNAllocateID = 8; 289 CNStoreLabel CNStoreLabel = 9; 290 CNWorkState CNWorkState = 10; 291 CNStateLabel CNStateLabel = 11; 292 DeleteCNStore DeleteCNStore = 12; 293 ProxyHeartbeat ProxyHeartbeat = 13; 294 }; 295 296 message LogResponse { 297 uint64 ShardID = 1; 298 uint64 Lsn = 2; 299 uint64 LastLsn = 3; 300 } 301 302 message AllocateIDResponse { 303 uint64 FirstID = 1; 304 } 305 306 message Response { 307 uint64 RequestID = 1; 308 MethodType Method = 2; 309 uint32 ErrorCode = 3; 310 string ErrorMessage = 4; 311 bool IsHAKeeper = 5; 312 LogResponse LogResponse = 6 [(gogoproto.nullable) = false]; 313 CommandBatch CommandBatch = 7; 314 TsoResponse TsoResponse = 8; 315 ClusterDetails ClusterDetails = 9; 316 ShardInfoQueryResult ShardInfo = 10; 317 AllocateIDResponse AllocateID = 11; 318 CheckerState CheckerState = 12; 319 }; 320 321 message LogRecordResponse { 322 repeated LogRecord Records = 1 [(gogoproto.nullable) = false]; 323 }; 324 325 message TsoResponse { 326 uint64 Value = 1; 327 } 328 329 // 330 // HAKeeper related pb 331 // 332 333 enum HAKeeperUpdateType { 334 TickUpdate = 0; 335 CNHeartbeatUpdate = 1; 336 TNHeartbeatUpdate = 2; 337 LogHeartbeatUpdate = 3; 338 GetIDUpdate = 4; 339 ScheduleCommandUpdate = 5; 340 SetStateUpdate = 6; 341 InitialClusterUpdate = 7; 342 SetTaskSchedulerStateUpdate = 8; 343 SetTaskTableUserUpdate = 9; 344 UpdateCNLabel = 10; 345 UpdateCNWorkState = 11; 346 PatchCNStore = 12; 347 RemoveCNStore = 13; 348 ProxyHeartbeatUpdate = 14; 349 } 350 351 // HAKeeperState state transition diagram 352 // HAKeeperCreated 353 // │ 354 // │ cluster init info set 355 // ▼ 356 // HAKeeperBootstrapping 357 // │ 358 // │ init schedule commands received 359 // ▼ 360 // HAKeeperBootstrapCommandsReceived 361 // │ 362 // │ 363 // ┌───────────┴───────────┐ 364 // │ time out │ bootstrap successfully 365 // ▼ ▼ 366 // HAKeeperBootstrapFailed HAKeeperRunning 367 // 368 enum HAKeeperState { 369 HAKeeperCreated = 0; 370 HAKeeperBootstrapping = 1; 371 HAKeeperBootstrapCommandsReceived = 2; 372 HAKeeperBootstrapFailed = 3; 373 HAKeeperRunning = 4; 374 } 375 376 // TaskSchedulerState state transition diagram 377 // TaskSchedulerCreated 378 // │ 379 // │ setTaskTableUser() 380 // ▼ 381 // TaskSchedulerStarted 382 // │ ▲ 383 // │ │ 384 // ▼ │ 385 // TaskSchedulerStopped 386 enum TaskSchedulerState { 387 TaskSchedulerCreated = 0; 388 TaskSchedulerRunning = 1; 389 TaskSchedulerStopped = 2; 390 } 391 392 message TaskTableUser { 393 // Username for task table user 394 string Username = 1; 395 // Password for task table user 396 string Password = 2; 397 } 398 399 // Replica of the shard 400 message Replica { 401 // UUID which store the Replica is located in 402 string UUID = 1; 403 404 uint64 ShardID = 2; 405 uint64 ReplicaID = 3; 406 uint64 Epoch = 4; 407 408 // LogShardID only used for TNShard. 409 uint64 LogShardID = 5; 410 } 411 412 // ConfigChangeType indicates config change command type. 413 enum ConfigChangeType { 414 AddReplica = 0; 415 RemoveReplica = 1; 416 StartReplica = 2; 417 StopReplica = 3; 418 KillZombie = 4; 419 } 420 421 // ConfigChange is the detail of a config change. 422 message ConfigChange { 423 Replica Replica = 1 [(gogoproto.nullable) = false]; 424 ConfigChangeType ChangeType = 2; 425 426 // only used for bootstrap 427 map<uint64, string> InitialMembers = 3; 428 } 429 430 // ShutdownStore would stop store. 431 message ShutdownStore { 432 string StoreID = 1; 433 } 434 435 // ServiceType specifies type of service 436 enum ServiceType { 437 LogService = 0; 438 TNService = 1; 439 CNService = 2; 440 ProxyService = 3; 441 } 442 443 // ScheduleCommand contains a shard schedule command. 444 message ScheduleCommand { 445 // UUID which store the ScheduleCommand is sent to 446 string UUID = 1; 447 bool Bootstrapping = 2; 448 ServiceType ServiceType = 3; 449 ConfigChange ConfigChange = 4; 450 ShutdownStore ShutdownStore = 5; 451 CreateTaskService CreateTaskService = 6; 452 DeleteCNStore DeleteCNStore = 7; 453 JoinGossipCluster JoinGossipCluster = 8; 454 DeleteProxyStore DeleteProxyStore = 9; 455 } 456 457 message JoinGossipCluster { 458 repeated string Existing = 1; 459 } 460 461 // CreateTaskService start task service at current node 462 message CreateTaskService { 463 // User used to connect to the task database. 464 TaskTableUser User = 1 [(gogoproto.nullable) = false]; 465 // TaskDatabase task framework database. 466 string TaskDatabase = 2; 467 } 468 469 // DeleteCNStore deletes CN store from CNState to save hakeeper's memory. 470 message DeleteCNStore { 471 string StoreID = 1; 472 } 473 474 // DeleteProxyStore deletes Proxy store from ProxyState to save hakeeper's memory. 475 message DeleteProxyStore { 476 string StoreID = 1; 477 } 478 479 message CommandBatch { 480 uint64 Term = 1; 481 repeated ScheduleCommand Commands = 2 [(gogoproto.nullable) = false]; 482 } 483 484 // CNStoreInfo contains information on a CN store. 485 message CNStoreInfo { 486 uint64 Tick = 1; 487 string ServiceAddress = 2; 488 string SQLAddress = 3; 489 string LockServiceAddress = 4; 490 reserved 5; 491 metadata.CNRole Role = 6; 492 bool TaskServiceCreated = 7; 493 map<string, metadata.LabelList> Labels = 8 [(gogoproto.nullable) = false]; 494 metadata.WorkState WorkState = 9; 495 string QueryAddress = 10; 496 string GossipAddress = 11; 497 bool GossipJoined = 12; 498 ConfigData ConfigData = 13; 499 Resource Resource = 14 [(gogoproto.nullable) = false]; 500 int64 UpTime = 15; 501 } 502 503 // CNState contains all CN details known to the HAKeeper. 504 message CNState { 505 // Stores is keyed by CN store UUID. 506 map<string, CNStoreInfo> Stores = 1 [(gogoproto.nullable) = false]; 507 } 508 509 510 // TNStoreInfo contains information on a TN store. 511 message TNStoreInfo { 512 uint64 Tick = 1; 513 string ServiceAddress = 2; 514 repeated TNShardInfo Shards = 3 [(gogoproto.nullable) = false]; 515 516 bool TaskServiceCreated = 4; 517 518 // Server address for logtail push model 519 string LogtailServerAddress = 5; 520 // LockServiceAddress lock service address for lock table allocator 521 string LockServiceAddress = 6; 522 reserved 7; 523 ConfigData ConfigData = 8; 524 // QueryAddress is the address of queryservice on tn 525 string QueryAddress = 9; 526 } 527 528 // TNState contains all TN details known to the HAKeeper. 529 message TNState { 530 // Stores is keyed by TN store UUID. 531 map<string, TNStoreInfo> Stores = 1 [(gogoproto.nullable) = false]; 532 } 533 534 message ProxyStore { 535 string UUID = 1; 536 uint64 Tick = 2; 537 string ListenAddress = 3; 538 ConfigData ConfigData = 4; 539 } 540 541 message ProxyState { 542 map<string, ProxyStore> Stores = 1 [(gogoproto.nullable) = false]; 543 } 544 545 message ProxyHeartbeat { 546 string UUID = 1; 547 string ListenAddress = 2; 548 ConfigData ConfigData = 3; 549 }; 550 551 message ClusterDetails { 552 repeated TNStore TNStores = 1 [(gogoproto.nullable) = false]; 553 repeated CNStore CNStores = 2 [(gogoproto.nullable) = false]; 554 repeated LogStore LogStores = 3 [(gogoproto.nullable) = false]; 555 repeated ProxyStore ProxyStores = 4 [(gogoproto.nullable) = false]; 556 repeated DeletedStore DeletedStores = 5 [(gogoproto.nullable) = false]; 557 } 558 559 // ClusterInfo provides a global view of all shards in the cluster. It 560 // describes the logical sharding of the system, rather than physical 561 // distribution of all replicas that belong to those shards. 562 message ClusterInfo { 563 repeated metadata.TNShardRecord TNShards = 1 [(gogoproto.nullable) = false]; 564 repeated metadata.LogShardRecord LogShards = 2 [(gogoproto.nullable) = false]; 565 } 566 567 message InitialClusterRequest { 568 uint64 NumOfLogShards = 1; 569 uint64 NumOfTNShards = 2; 570 uint64 NumOfLogReplicas = 3; 571 uint64 NextID = 4; 572 map<string, uint64> NextIDByKey = 5; 573 } 574 575 // LogStoreInfo contains information of all replicas found on a Log store. 576 message LogStoreInfo { 577 uint64 Tick = 1; 578 string RaftAddress = 2; 579 string ServiceAddress = 3; 580 string GossipAddress = 4; 581 repeated LogReplicaInfo Replicas = 5 [(gogoproto.nullable) = false]; 582 583 bool TaskServiceCreated = 6; 584 ConfigData ConfigData = 7; 585 } 586 587 message LogState { 588 // Shards is keyed by ShardID, it contains details aggregated from all Log 589 // stores. Each pb.LogShardInfo here contains data aggregated from 590 // different replicas and thus reflect a more accurate description on each 591 // shard. 592 map<uint64, LogShardInfo> Shards = 1 [(gogoproto.nullable) = false]; 593 // Stores is keyed by log store UUID, it contains details found on each 594 // store. Each LogStoreInfo here reflects what was last reported by each Log 595 // store. 596 map<string, LogStoreInfo> Stores = 2 [(gogoproto.nullable) = false]; 597 } 598 599 // CheckerState contains all HAKeeper state required for making schedule 600 // commands. 601 message CheckerState { 602 uint64 Tick = 1; 603 ClusterInfo ClusterInfo = 2 [(gogoproto.nullable) = false]; 604 TNState TNState = 3 [(gogoproto.nullable) = false]; 605 LogState LogState = 4 [(gogoproto.nullable) = false]; 606 CNState CNState = 5 [(gogoproto.nullable) = false]; 607 HAKeeperState State = 6; 608 TaskSchedulerState TaskSchedulerState = 7; 609 TaskTableUser TaskTableUser = 8 [(gogoproto.nullable) = false]; 610 uint64 NextId = 9; 611 map<string, uint64> NextIDByKey = 10; 612 ProxyState ProxyState = 11 [(gogoproto.nullable) = false]; 613 Resource Resource = 12 [(gogoproto.nullable) = false]; 614 } 615 616 message DeletedStore { 617 string UUID = 1; 618 // StoreType indicates the type of the store: CN, TN or proxy. 619 string StoreType = 2; 620 string Address = 3; 621 int64 UpTime = 4; 622 int64 DownTime = 5; 623 } 624 625 // HAKeeperRSMState contains state maintained by HAKeeper's RSM. 626 message HAKeeperRSMState { 627 uint64 Index = 1; 628 uint64 Tick = 2; 629 // NextID is a shared, global ID. 630 uint64 NextID = 3; 631 // NextIDByKey is IDs isolated by keys. 632 map<string, uint64> NextIDByKey = 4; 633 uint64 Term = 5; 634 HAKeeperState State = 6; 635 TaskSchedulerState TaskSchedulerState = 7; 636 map<string, CommandBatch> ScheduleCommands = 8 [(gogoproto.nullable) = false]; 637 map<string, uint64> LogShards = 9; 638 CNState CNState = 10 [(gogoproto.nullable) = false]; 639 TNState TNState = 11 [(gogoproto.nullable) = false]; 640 LogState LogState = 12 [(gogoproto.nullable) = false]; 641 ClusterInfo ClusterInfo = 13 [(gogoproto.nullable) = false]; 642 TaskTableUser TaskTableUser = 14 [(gogoproto.nullable) = false]; 643 ProxyState ProxyState = 15 [(gogoproto.nullable) = false]; 644 repeated DeletedStore DeletedStores = 16 [(gogoproto.nullable) = false]; 645 } 646 647 // ReplicaInfo contains details of a replica 648 message ReplicaInfo { 649 string UUID = 1; 650 string ServiceAddress = 2; 651 } 652 653 // ShardInfoQueryResult contains the result of the shard info query. 654 message ShardInfoQueryResult { 655 uint64 ShardID = 1; 656 map<uint64, ReplicaInfo> Replicas = 2 [(gogoproto.nullable) = false]; 657 uint64 Epoch = 3; 658 uint64 LeaderID = 4; 659 uint64 Term = 5; 660 } 661 662 // BackupData is the information that needs to backup, including NextID and 663 // NextIDByKey in HAKeeperRSMState. 664 message BackupData { 665 // NextID is a shared, global ID. 666 uint64 NextID = 1; 667 // NextIDByKey is IDs isolated by keys. 668 map<string, uint64> NextIDByKey = 2; 669 } 670 671 message ConfigItem{ 672 // Name is the name of config item 673 string Name = 1; 674 // CurrentValue is the current value of config item 675 string CurrentValue = 2; 676 // DefaultValue is the default value of config item 677 string DefaultValue = 3; 678 // Internal denotes the config item is internal or not 679 string Internal = 4; 680 } 681 682 // ConfigData is the content of config on cn,tn,log and proxy 683 message ConfigData{ 684 // Content is the key value of the config 685 map<string, ConfigItem> Content = 1; 686 }