github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/execinfrapb/data.proto (about)

     1  // Copyright 2016 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  //
    11  // Data structures and basic infrastructure for distributed SQL APIs. See
    12  // docs/RFCS/distributed_sql.md.
    13  // All the concepts here are "physical plan" concepts.
    14  
    15  syntax = "proto2";
    16  // Beware! This package name must not be changed, even though it doesn't match
    17  // the Go package name, because it defines the Protobuf message names which
    18  // can't be changed without breaking backward compatibility.
    19  package cockroach.sql.distsqlrun;
    20  option go_package = "execinfrapb";
    21  
    22  import "jobs/jobspb/jobs.proto";
    23  import "roachpb/api.proto";
    24  import "roachpb/data.proto";
    25  import "roachpb/errors.proto";
    26  import "errorspb/errors.proto";
    27  import "sql/pgwire/pgerror/errors.proto";
    28  import "sql/sqlbase/structured.proto";
    29  import "sql/sqlbase/encoded_datum.proto";
    30  import "sql/types/types.proto";
    31  import "util/tracing/recorded_span.proto";
    32  import "gogoproto/gogo.proto";
    33  
    34  // Error is a generic representation including a string message.
    35  message Error {
    36    option (gogoproto.goproto_stringer) = false;
    37  
    38    reserved 1,2;
    39  
    40    // full_error contains a structured errors with possibly multiple
    41    // wrapping layers implementing the errors.Cause() interface.
    42    optional errorspb.EncodedError full_error = 3;
    43  }
    44  
    45  message Expression {
    46    // Don't generate a typedecl, so we can add the LocalExpr field.
    47    option (gogoproto.typedecl) = false;
    48    option (gogoproto.goproto_stringer) = false;
    49  
    50    // TODO(radu): TBD how this will be used
    51    optional string version = 1 [(gogoproto.nullable) = false];
    52  
    53    // SQL expressions are passed as a string, with ordinal references
    54    // (@1, @2, @3 ..) used for "input" variables.
    55    optional string expr = 2 [(gogoproto.nullable) = false];
    56  }
    57  
    58  // Ordering defines an order - specifically a list of column indices and
    59  // directions. See sqlbase.ColumnOrdering.
    60  message Ordering {
    61    option (gogoproto.equal) = true;
    62  
    63    message Column {
    64      option (gogoproto.equal) = true;
    65  
    66      // The direction of the desired ordering for a column.
    67      enum Direction {
    68        ASC = 0;
    69        DESC = 1;
    70      }
    71      optional uint32 col_idx = 1 [(gogoproto.nullable) = false];
    72      optional Direction direction = 2 [(gogoproto.nullable) = false];
    73    }
    74    repeated Column columns = 1 [(gogoproto.nullable) = false];
    75  }
    76  
    77  // StreamEndpointSpec describes one of the endpoints (input or output) of a physical
    78  // stream.
    79  message StreamEndpointSpec {
    80    enum Type {
    81      // Stream that is part of the local flow.
    82      LOCAL = 0;
    83      // Stream that has the other endpoint on a different node.
    84      REMOTE = 1;
    85      // Special stream used when in "sync flow" mode. In this mode, we return
    86      // results directly as part of the RPC call that set up the flow. This saves
    87      // overhead (extra RPCs) compared to the normal mode where the RPC just sets
    88      // up the flow. This type can only be used with outbound endpoints.
    89      SYNC_RESPONSE = 2;
    90    }
    91    optional Type type = 1 [(gogoproto.nullable) = false];
    92  
    93    // The ID of this stream.
    94    //
    95    // For LOCAL streams, both ends of the stream are part of the flow on this
    96    // machine (and there must be a corresponding endpoint with the same ID).
    97    //
    98    // For REMOTE streams, this ID is used in the ProducerHeader when connecting to
    99    // the other host.
   100    //
   101    // For SYNC_RESPONSE streams, the ID is unused.
   102    optional int32 stream_id = 2 [(gogoproto.nullable) = false,
   103                                  (gogoproto.customname) = "StreamID",
   104                                  (gogoproto.casttype) = "StreamID"];
   105    // Node ID of the target host, only used for outgoing REMOTE streams.
   106    optional int32 target_node_id = 4 [(gogoproto.nullable) = false,
   107                                       (gogoproto.customname) = "TargetNodeID",
   108                                       (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.NodeID"];
   109    reserved 3;
   110  }
   111  
   112  // InputSyncSpec is the specification for an input synchronizer; it decides how
   113  // to interleave rows from multiple input streams.
   114  message InputSyncSpec {
   115    enum Type {
   116      // Rows from the input streams are interleaved arbitrarily.
   117      UNORDERED = 0;
   118      // The input streams are guaranteed to be ordered according to the column
   119      // ordering field; rows from the streams are interleaved to preserve that
   120      // ordering.
   121      ORDERED = 1;
   122    }
   123    optional Type type = 1 [(gogoproto.nullable) = false];
   124  
   125    optional Ordering ordering = 2 [(gogoproto.nullable) = false];
   126  
   127    repeated StreamEndpointSpec streams = 3 [(gogoproto.nullable) = false];
   128  
   129    // Schema for the streams entering this synchronizer.
   130    repeated sql.sem.types.T column_types = 4;
   131  }
   132  
   133  // OutputRouterSpec is the specification for the output router of a processor;
   134  // it decides how to send results to multiple output streams.
   135  message OutputRouterSpec {
   136    enum Type {
   137      // Single output stream.
   138      PASS_THROUGH = 0;
   139      // Each row is sent to all output streams.
   140      MIRROR = 1;
   141      // Each row is sent to one stream, chosen by hashing certain columns of
   142      // the row (specified by the hash_columns field).
   143      BY_HASH = 2;
   144      // Each row is sent to one stream, chosen according to preset boundaries
   145      // for the values of certain columns of the row.
   146      BY_RANGE = 3;
   147    }
   148    optional Type type = 1 [(gogoproto.nullable) = false];
   149    repeated StreamEndpointSpec streams = 2 [(gogoproto.nullable) = false];
   150  
   151    // Only used for the BY_HASH type; these are the indexes of the columns we are
   152    // hashing.
   153    repeated uint32 hash_columns = 3;
   154  
   155    message RangeRouterSpec {
   156      message ColumnEncoding {
   157        // column is the index of a column to encode.
   158        optional uint32 column = 1 [(gogoproto.nullable) = false];
   159        // encoding specifies how a particular column is to be encoded for
   160        // generating the sort key for a row. This needs to correspond to the way
   161        // the Span.{start,end} keys have been generated.
   162        optional sqlbase.DatumEncoding encoding = 2 [(gogoproto.nullable) = false];
   163      }
   164      // Span matches bytes in [start, end).
   165      message Span {
   166        optional bytes start = 1;
   167        optional bytes end = 2;
   168        // stream is the index of the destination stream.
   169        optional int32 stream = 3 [(gogoproto.nullable) = false];
   170      }
   171  
   172      // spans is a slice of Span. Input matching a span will be routed to its
   173      // specified stream.
   174      repeated Span spans = 1 [(gogoproto.nullable) = false];
   175      // default_dest, if not nil, is the index of the stream to send rows that do
   176      // not match any span. If nil, a row that does not match a span will produce
   177      // an error in the router.
   178      optional int32 default_dest = 2;
   179      // encodings is a slice of columns and encodings. Each will be appended to a
   180      // []byte, which is used as input to the spans. Columns from the input rows
   181      // potentially need to be recoded to match the encoding used for the spans.
   182      repeated ColumnEncoding encodings = 3 [(gogoproto.nullable) = false];
   183    }
   184    optional RangeRouterSpec range_router_spec = 4 [(gogoproto.nullable) = false];
   185  
   186    // disable_buffering disables output buffering. Generally buffering should be
   187    // enabled to prevent deadlocks. However some plans are known not to deadlock,
   188    // and so can set this flag to prevent unbounded buffering causing OOMs.
   189    optional bool disable_buffering = 5 [(gogoproto.nullable) = false];
   190  }
   191  
   192  message DatumInfo {
   193    optional sqlbase.DatumEncoding encoding = 1 [(gogoproto.nullable) = false];
   194    optional sql.sem.types.T type = 2;
   195  }
   196  
   197  // ProducerHeader is a message that is sent once at the beginning of a stream.
   198  message ProducerHeader {
   199    optional bytes flow_id = 1 [(gogoproto.nullable) = false,
   200                                (gogoproto.customname) = "FlowID",
   201                                (gogoproto.customtype) = "FlowID"];
   202  
   203    optional int32 stream_id = 2 [(gogoproto.nullable) = false,
   204                                  (gogoproto.customname) = "StreamID",
   205                                  (gogoproto.casttype) = "StreamID"];
   206  }
   207  
   208  // ProducerData is a message that can be sent multiple times as part of a stream
   209  // from a producer to a consumer. It contains 0 or more rows and/or 0 or more
   210  // metadata messages.
   211  message ProducerData {
   212    // A bunch of rows, encoded. Each datum is encoded according to the
   213    // corresponding DatumInfo.
   214    optional bytes raw_bytes = 1;
   215  
   216    // In the special case when the stream contains empty rows, the count is
   217    // passed instead.
   218    optional int32 num_empty_rows = 3 [(gogoproto.nullable) = false];
   219  
   220    // A bunch of metadata messages.
   221    repeated RemoteProducerMetadata metadata = 2 [(gogoproto.nullable) = false];
   222  }
   223  
   224  message ProducerMessage {
   225    optional ProducerHeader header = 1;
   226  
   227    // Typing information. There will be one DatumInfo for each element in a row.
   228    // This field has to be populated on, or before, a ProducerMessage with data
   229    // in it, and can only be populated once. It can be nil if only zero length
   230    // rows will be sent.
   231    // TODO(andrei): It'd be nice if the typing information for streams would be
   232    // configured statically at plan creation time, instead of being discovered
   233    // dynamically through the first rows that flow.
   234    repeated DatumInfo typing = 2 [(gogoproto.nullable) = false];
   235  
   236    optional ProducerData data = 3 [(gogoproto.nullable) = false];
   237  }
   238  
   239  // RemoteProducerMetadata represents records that a producer wants to pass to
   240  // a consumer, other than data rows. It's named RemoteProducerMetadata to not
   241  // clash with ProducerMetadata, which is used internally within a node and has
   242  // a different go error instead of a proto error inside.
   243  message RemoteProducerMetadata {
   244    message RangeInfos {
   245      repeated roachpb.RangeInfo range_info = 1 [(gogoproto.nullable) = false];
   246    }
   247    message TraceData {
   248      repeated util.tracing.RecordedSpan collected_spans = 1 [(gogoproto.nullable) = false];
   249    }
   250    // RowNum is used to count the rows sent from a processor. It is used in tests
   251    // to check that metadata is propagated correctly.
   252    message RowNum {
   253      // The ID of the processor that is producing rows.
   254      optional string sender_id = 1 [(gogoproto.nullable) = false,
   255                                     (gogoproto.customname) = "SenderID"];
   256      // A running count of the number of rows emitted from the sender so far.
   257      optional int32 row_num = 2 [(gogoproto.nullable) = false];
   258      // When set, indicates that the row count contains the expected number of
   259      // RowNum messages with this ID.
   260      optional bool last_msg = 3 [(gogoproto.nullable) = false];
   261    }
   262    message SamplerProgress {
   263      // The number of rows processed by the sampler processor since the last
   264      // update.
   265      optional uint64 rows_processed = 1 [(gogoproto.nullable) = false];
   266      // Indicates that sample collection for histograms should be disabled,
   267      // likely because the sampler processor ran out of memory.
   268      optional bool histogram_disabled = 2 [(gogoproto.nullable) = false];
   269    }
   270    message BulkProcessorProgress {
   271       repeated roachpb.Span completed_spans = 1 [(gogoproto.nullable) = false];
   272       map<int32, float> completed_fraction = 2;
   273       map<int32, int64> resume_pos = 3;
   274    }
   275    // Metrics are unconditionally emitted by table readers.
   276    message Metrics {
   277      // Total number of bytes read while executing a statement.
   278      optional int64 bytes_read = 1 [(gogoproto.nullable) = false];
   279      // Total number of rows read while executing a statement.
   280      optional int64 rows_read = 2 [(gogoproto.nullable) = false];
   281    }
   282    oneof value {
   283      RangeInfos range_info = 1;
   284      Error error = 2;
   285      TraceData trace_data = 3;
   286      roachpb.LeafTxnFinalState leaf_txn_final_state = 4;
   287      RowNum row_num = 5;
   288      SamplerProgress sampler_progress = 7;
   289      Metrics metrics = 8;
   290      BulkProcessorProgress bulk_processor_progress = 9;
   291    }
   292    reserved 6;
   293  }
   294  
   295  // DistSQLVersionGossipInfo represents the DistSQL server version information
   296  // that gets gossiped for each node. This is used by planners to avoid planning
   297  // on nodes with incompatible version during rolling cluster updates.
   298  //
   299  // For the meaning of the fields, see the corresponding constants in
   300  // distsqlrun/server.go.
   301  message DistSQLVersionGossipInfo {
   302    optional uint32 version = 1 [(gogoproto.nullable) = false,
   303                                 (gogoproto.casttype) = "DistSQLVersion"];
   304  
   305    optional uint32 min_accepted_version = 2 [(gogoproto.nullable) = false,
   306                                              (gogoproto.casttype) = "DistSQLVersion"];
   307  }
   308  
   309  // DistSQLDrainingInfo represents the DistSQL draining state that gets gossiped
   310  // for each node. This is used by planners to avoid planning on nodes that are
   311  // known to be draining.
   312  message DistSQLDrainingInfo {
   313    optional bool draining = 1 [(gogoproto.nullable) = false];
   314  }