github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/protos/pb.proto (about) 1 /* 2 * Copyright (C) 2017 Dgraph Labs, Inc. and Contributors 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 18 // Style guide for Protocol Buffer 3. 19 // Use CamelCase (with an initial capital) for message names – for example, 20 // SongServerRequest. Use underscore_separated_names for field names – for 21 // example, song_name. 22 23 syntax = "proto3"; 24 25 package pb; 26 27 import "api.proto"; 28 import "github.com/dgraph-io/badger/pb/pb.proto"; 29 30 /* import "gogoproto/gogo.proto"; */ 31 32 /* option (gogoproto.marshaler_all) = true; */ 33 /* option (gogoproto.sizer_all) = true; */ 34 /* option (gogoproto.unmarshaler_all) = true; */ 35 /* option (gogoproto.goproto_getters_all) = true; */ 36 37 message List { 38 repeated fixed64 uids = 1; 39 } 40 41 message TaskValue { 42 bytes val = 1; 43 Posting.ValType val_type = 2; 44 } 45 46 message SrcFunction { 47 string name = 1; 48 repeated string args = 3; 49 bool isCount = 4; 50 } 51 52 message Query { 53 string attr = 1; 54 repeated string langs = 2; // language list for attribute 55 fixed64 after_uid = 3; // Only return UIDs greater than this. 56 bool do_count = 4; // Are we just getting lengths? 57 58 // Exactly one of uids and terms is populated. 59 List uid_list = 5; 60 61 // Function to generate or filter UIDs. 62 SrcFunction src_func = 6; 63 64 bool reverse = 7; // Whether this is a reverse edge. 65 66 FacetParams facet_param = 8; // which facets to fetch 67 FilterTree facets_filter = 9; // filtering on facets : has Op (and/or/not) tree 68 69 bool expand_all = 10; // expand all language variants. 70 71 uint64 read_ts = 13; 72 int32 cache = 14; 73 } 74 75 message ValueList { 76 repeated TaskValue values = 1; 77 } 78 79 message LangList { 80 repeated string lang = 1; 81 } 82 83 message Result { 84 repeated List uid_matrix = 1; 85 repeated ValueList value_matrix = 2; 86 repeated uint32 counts = 3; 87 bool intersect_dest = 4; 88 repeated FacetsList facet_matrix = 5; 89 repeated LangList lang_matrix = 6; 90 bool list = 7; 91 } 92 93 message Order { 94 string attr = 1; 95 bool desc = 2; 96 repeated string langs = 3; 97 } 98 99 message SortMessage { 100 repeated Order order = 1; 101 repeated List uid_matrix = 2; 102 int32 count = 3; // Return this many elements. 103 int32 offset = 4; // Skip this many elements. 104 105 uint64 read_ts = 13; 106 } 107 108 message SortResult { 109 repeated List uid_matrix = 1; 110 } 111 112 message RaftContext { 113 fixed64 id = 1; 114 uint32 group = 2; 115 string addr = 3; 116 uint64 snapshot_ts = 4; 117 } 118 119 // Member stores information about RAFT group member for a single RAFT node. 120 // Note that each server can be serving multiple RAFT groups. Each group would have 121 // one RAFT node per server serving that group. 122 message Member { 123 fixed64 id = 1; 124 uint32 group_id = 2; 125 string addr = 3; 126 bool leader = 4; 127 bool am_dead = 5; 128 uint64 last_update = 6; 129 130 bool cluster_info_only = 13; 131 } 132 133 message Group { 134 map<uint64, Member> members = 1; // Raft ID is the key. 135 map<string, Tablet> tablets = 2; // Predicate + others are key. 136 uint64 snapshot_ts = 3; // Stores Snapshot transaction ts. 137 uint64 checksum = 4; // Stores a checksum. 138 } 139 140 message License { 141 string user = 1; 142 uint64 maxNodes = 2; 143 int64 expiryTs = 3; 144 bool enabled = 4; 145 } 146 147 message ZeroProposal { 148 map<uint32, uint64> snapshot_ts = 1; // Group ID -> Snapshot Ts. 149 Member member = 2; 150 Tablet tablet = 3; 151 uint64 maxLeaseId = 4; 152 uint64 maxTxnTs = 5; 153 uint64 maxRaftId = 6; 154 api.TxnContext txn = 7; 155 string key = 8; // Used as unique identifier for proposal id. 156 string cid = 9; // Used as unique identifier for the cluster. 157 License license = 10; 158 } 159 160 // MembershipState is used to pack together the current membership state of all the nodes 161 // in the caller server; and the membership updates recorded by the callee server since 162 // the provided lastUpdate. 163 message MembershipState { 164 uint64 counter = 1; // used to find latest membershipState in case of race. 165 map<uint32, Group> groups = 2; 166 map<uint64, Member> zeros = 3; 167 uint64 maxLeaseId = 4; 168 uint64 maxTxnTs = 5; 169 uint64 maxRaftId = 6; 170 repeated Member removed = 7; 171 string cid = 8; // Used to uniquely identify the Dgraph cluster. 172 License license = 9; 173 } 174 175 message ConnectionState { 176 Member member = 1; 177 MembershipState state = 2; 178 uint64 max_pending = 3; // Used to determine the timstamp for reading after bulk load 179 } 180 181 message Tablet { 182 uint32 group_id = 1; // Served by which group. 183 string predicate = 2; 184 bool force = 3; // Used while moving predicate. 185 int64 space = 7; 186 bool remove = 8; 187 bool read_only = 9; // If true, do not ask zero to serve any tablets. 188 } 189 190 message DirectedEdge { 191 fixed64 entity = 1; // Subject or source node / UID. 192 string attr = 2; // Attribute or predicate. Labels the edge. 193 bytes value = 3; // Edge points to a value. 194 Posting.ValType value_type = 4; // The type of the value 195 fixed64 value_id = 5; // Object or destination node / UID. 196 string label = 6; 197 string lang = 7; 198 enum Op { 199 SET = 0; 200 DEL = 1; 201 } 202 Op op = 8; 203 repeated api.Facet facets = 9; 204 } 205 206 message Mutations { 207 uint32 group_id = 1; 208 uint64 start_ts = 2; 209 repeated DirectedEdge edges = 3; 210 repeated SchemaUpdate schema = 4; 211 repeated TypeUpdate types = 6; 212 enum DropOp { 213 NONE = 0; 214 ALL = 1; 215 DATA = 2; 216 TYPE = 3; 217 } 218 DropOp drop_op = 7; 219 string drop_value = 8; 220 } 221 222 message Snapshot { 223 RaftContext context = 1; 224 uint64 index = 2; 225 uint64 read_ts = 3; 226 // done is used to indicate that snapshot stream was a success. 227 bool done = 4; 228 // since_ts stores the ts of the last snapshot to support diff snap updates. 229 uint64 since_ts = 5; 230 } 231 232 message Proposal { 233 Mutations mutations = 2; 234 repeated KV kv = 4; 235 MembershipState state = 5; 236 string clean_predicate = 6; // Delete the predicate which was moved to other group. 237 string key = 7; 238 OracleDelta delta = 8; 239 Snapshot snapshot = 9; // Used to tell the group when to take snapshot. 240 uint64 index = 10; // Used to store Raft index, in raft.Ready. 241 } 242 243 message KVS { 244 repeated pb.KV kv = 1; 245 // done used to indicate if the stream of KVS is over. 246 bool done = 2; 247 } 248 249 // Posting messages. 250 message Posting { 251 fixed64 uid = 1; 252 bytes value = 2; 253 enum ValType { 254 DEFAULT = 0; 255 BINARY = 1; 256 INT = 2; // We treat it as int64. 257 FLOAT = 3; 258 BOOL = 4; 259 DATETIME = 5; 260 GEO = 6; 261 UID = 7; 262 PASSWORD = 8; 263 STRING = 9; 264 OBJECT = 10; 265 } 266 ValType val_type = 3; 267 enum PostingType { 268 REF=0; // UID 269 VALUE=1; // simple, plain value 270 VALUE_LANG=2; // value with specified language 271 } 272 PostingType posting_type = 4; 273 bytes lang_tag = 5; // Only set for VALUE_LANG 274 string label = 6; 275 repeated api.Facet facets = 9; 276 277 // TODO: op is only used temporarily. See if we can remove it from here. 278 uint32 op = 12; 279 uint64 start_ts = 13; // Meant to use only inmemory 280 uint64 commit_ts = 14; // Meant to use only inmemory 281 } 282 283 message UidBlock { 284 uint64 base = 1; 285 // deltas contains the deltas encoded with Varints. We don't store deltas as a list of integers, 286 // because when the PB is brought to memory, Go would always use 8-bytes per integer. Instead, 287 // storing it as a byte slice is a lot cheaper in memory. 288 bytes deltas = 2; 289 // num_uids is the number of UIDs in the block. We are including this because we want to 290 // swtich encoding to groupvarint encoding. Current avaialble open source version implements 291 // encoding and decoding for uint32. We want to wrap it around our logic to use it here. 292 // Default Blocksize is 256 so uint32 would be sufficient. 293 uint32 num_uids = 3; 294 } 295 296 message UidPack { 297 uint32 block_size = 1; 298 repeated UidBlock blocks = 2; 299 } 300 301 message PostingList { 302 UidPack pack = 1; // Encoded list of uids in this posting list. 303 repeated Posting postings = 2; 304 uint64 commit_ts = 3; // More inclination towards smaller values. 305 306 repeated uint64 splits = 4; 307 } 308 309 message FacetParam { 310 string key = 1; 311 string alias = 2; 312 } 313 314 message FacetParams { 315 bool all_keys = 1; // keys should be in sorted order. 316 repeated FacetParam param = 2; 317 } 318 319 message Facets { 320 repeated api.Facet facets = 1; 321 } 322 323 message FacetsList { 324 repeated Facets facets_list = 1; 325 } 326 327 message Function { 328 string name = 1; // Name of the function : eq, le 329 string key = 2; // Facet key over which to run the function. 330 repeated string args = 3; // Arguments of the function. 331 } 332 333 // Op and Children are internal nodes and Func on leaves. 334 message FilterTree { 335 string op = 1; 336 repeated FilterTree children = 2; 337 Function func = 3; 338 } 339 340 // Schema messages. 341 message SchemaRequest { 342 uint32 group_id = 1; 343 repeated string predicates = 2; 344 // fields can be on of type, index, reverse or tokenizer 345 repeated string fields = 3; 346 347 repeated string types = 4; 348 } 349 350 message SchemaNode { 351 string predicate = 1; 352 string type = 2; 353 bool index = 3; 354 repeated string tokenizer = 4; 355 bool reverse = 5; 356 bool count = 6; 357 bool list = 7; 358 bool upsert = 8; 359 bool lang = 9; 360 } 361 362 message SchemaResult { 363 repeated SchemaNode schema = 1 [deprecated=true]; 364 } 365 366 message SchemaUpdate { 367 string predicate = 1; 368 Posting.ValType value_type = 2; 369 enum Directive { 370 NONE = 0; 371 INDEX = 1; 372 REVERSE = 2; 373 DELETE = 3; 374 } 375 Directive directive = 3; 376 repeated string tokenizer = 4; 377 bool count = 5; 378 bool list = 6; 379 bool upsert = 8; 380 bool lang = 9; 381 382 // Fields required for type system. 383 bool non_nullable = 10; 384 bool non_nullable_list = 11; 385 386 // If value_type is OBJECT, then this represents an object type with a 387 // custom name. This field stores said name. 388 string object_type_name = 12; 389 390 // Deleted field: 391 reserved 7; 392 reserved "explicit"; 393 } 394 395 message TypeUpdate { 396 string type_name = 1; 397 repeated SchemaUpdate fields = 2; 398 } 399 400 // Bulk loader proto. 401 message MapEntry { 402 bytes key = 1; 403 404 // Only one should be set. 405 fixed64 uid = 2; 406 Posting posting = 3; 407 } 408 409 message MovePredicatePayload { 410 string predicate = 1; 411 uint32 source_gid = 2; 412 uint32 dest_gid = 3; 413 uint64 txn_ts = 4; 414 } 415 416 message TxnStatus { 417 uint64 start_ts = 1; 418 uint64 commit_ts = 2; 419 } 420 421 message OracleDelta { 422 repeated TxnStatus txns = 1; 423 uint64 max_assigned = 2; 424 map<uint32, uint64> group_checksums = 3; 425 // implement tmax. 426 } 427 428 message TxnTimestamps { 429 repeated uint64 ts = 1; 430 } 431 432 message PeerResponse { 433 bool status = 1; 434 } 435 436 message RaftBatch { 437 RaftContext context = 1; 438 api.Payload payload = 2; 439 } 440 441 service Raft { 442 rpc Heartbeat (api.Payload) returns (stream api.Payload) {} 443 rpc RaftMessage (stream RaftBatch) returns (api.Payload) {} 444 rpc JoinCluster (RaftContext) returns (api.Payload) {} 445 rpc IsPeer (RaftContext) returns (PeerResponse) {} 446 } 447 448 service Zero { 449 // These 3 endpoints are for handling membership. 450 rpc Connect (Member) returns (ConnectionState) {} 451 rpc UpdateMembership (Group) returns (api.Payload) {} 452 rpc StreamMembership (api.Payload) returns (stream MembershipState) {} 453 454 rpc Oracle (api.Payload) returns (stream OracleDelta) {} 455 rpc ShouldServe (Tablet) returns (Tablet) {} 456 rpc AssignUids (Num) returns (AssignedIds) {} 457 rpc Timestamps (Num) returns (AssignedIds) {} 458 rpc CommitOrAbort (api.TxnContext) returns (api.TxnContext) {} 459 rpc TryAbort (TxnTimestamps) returns (OracleDelta) {} 460 } 461 462 service Worker { 463 // Data serving RPCs. 464 rpc Mutate (Mutations) returns (api.TxnContext) {} 465 rpc ServeTask (Query) returns (Result) {} 466 rpc StreamSnapshot (stream Snapshot) returns (stream KVS) {} 467 rpc Sort (SortMessage) returns (SortResult) {} 468 rpc Schema (SchemaRequest) returns (SchemaResult) {} 469 rpc Backup (BackupRequest) returns (Status) {} 470 rpc Export (ExportRequest) returns (Status) {} 471 rpc ReceivePredicate(stream KVS) returns (api.Payload) {} 472 rpc MovePredicate(MovePredicatePayload) returns (api.Payload) {} 473 } 474 475 message Num { 476 uint64 val = 1; 477 bool read_only = 2; 478 bool forwarded = 3; // True if this request was forwarded by a peer. 479 } 480 481 message AssignedIds { 482 uint64 startId = 1; 483 uint64 endId = 2; 484 485 // The following is used for read only transactions. 486 uint64 read_only = 5; 487 } 488 489 message SnapshotMeta { 490 uint64 client_ts = 1; 491 uint32 group_id = 2; 492 } 493 494 // Status describes a general status response. 495 // code: 0 = success, 0 != failure. 496 message Status { 497 int32 code = 1; 498 string msg = 2; 499 } 500 501 message BackupRequest { 502 uint64 read_ts = 1; 503 uint64 since_ts = 2; 504 uint32 group_id = 3; 505 string unix_ts = 4; 506 string destination = 5; 507 string access_key = 6; 508 string secret_key = 7; 509 string session_token = 8; 510 511 // True if no credentials should be used to access the S3 or minio bucket. 512 // For example, when using a bucket with a public policy. 513 bool anonymous = 9; 514 515 // The predicates to backup. All other predicates present in the group (e.g 516 // stale data from a predicate move) will be ignored. 517 repeated string predicates = 10; 518 } 519 520 message ExportRequest { 521 uint32 group_id = 1; // Group id to back up. 522 uint64 read_ts = 2; 523 int64 unix_ts = 3; 524 string format = 4; 525 } 526 527 // A key stored in the format used for writing backups. 528 message BackupKey { 529 enum KeyType { 530 UNKNOWN = 0; 531 DATA = 1; 532 INDEX = 2; 533 REVERSE = 3; 534 COUNT = 4; 535 COUNT_REV = 5; 536 SCHEMA = 6; 537 TYPE = 7; 538 } 539 540 KeyType type = 1; 541 string attr = 2; 542 uint64 uid = 3; 543 uint64 start_uid = 4; 544 string term = 5; 545 uint32 count = 6; 546 } 547 548 // A posting list stored in the format used for writing backups. 549 message BackupPostingList { 550 repeated uint64 uids = 1; 551 repeated Posting postings = 2; 552 uint64 commit_ts = 3; 553 repeated uint64 splits = 4; 554 } 555 556 // vim: noexpandtab sw=2 ts=2