github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/jobs/jobspb/jobs.proto (about)

     1  // Copyright 2017 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  syntax = "proto3";
    12  package cockroach.sql.jobs.jobspb;
    13  option go_package = "jobspb";
    14  
    15  import "errorspb/errors.proto";
    16  import "gogoproto/gogo.proto";
    17  import "roachpb/api.proto";
    18  import "roachpb/data.proto";
    19  import "roachpb/io-formats.proto";
    20  import "sql/sqlbase/structured.proto";
    21  import "util/hlc/timestamp.proto";
    22  
    23  message Lease {
    24    option (gogoproto.equal) = true;
    25  
    26    // The ID of the node that holds the lease.
    27    uint32 node_id = 1 [
    28      (gogoproto.customname) = "NodeID",
    29      (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.NodeID"
    30    ];
    31    // The epoch of the lease holder's node liveness entry.
    32    int64 epoch = 2;
    33  }
    34  
    35  message BackupDetails {
    36    util.hlc.Timestamp start_time = 1 [(gogoproto.nullable) = false];
    37    util.hlc.Timestamp end_time = 2 [(gogoproto.nullable) = false];
    38    // URI is the URI for the main backup destination. For partitioned backups,
    39    // the main BACKUP manifest and files with no other specified destination are
    40    // written to this location. For regular backups, all files are written to
    41    // this location.
    42    string uri = 3 [(gogoproto.customname) = "URI"];
    43    // URIsByLocalityKV is a map of locality KVs to store URIs, used for
    44    // partitioned backups.
    45    map<string, string> uris_by_locality_kv = 5 [(gogoproto.customname) = "URIsByLocalityKV"];
    46    bytes backup_manifest = 4;
    47    roachpb.FileEncryptionOptions encryption = 6;
    48  
    49    // ProtectedTimestampRecord is the ID of the protected timestamp record
    50    // corresponding to this job. While the job ought to clean up the record
    51    // when it enters a terminal state, there may be cases where it cannot or
    52    // does not run the code to do so. To deal with this there is a background
    53    // reconcilliation loop to ensure that protected timestamps are cleaned up.
    54    bytes protected_timestamp_record = 7 [
    55      (gogoproto.customname) = "ProtectedTimestampRecord",
    56      (gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/util/uuid.UUID"
    57    ];
    58  }
    59  
    60  message BackupProgress {
    61  
    62  }
    63  
    64  message RestoreDetails {
    65    message TableRewrite {
    66      uint32 table_id = 1 [
    67        (gogoproto.customname) = "TableID",
    68        (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"
    69      ];
    70      uint32 parent_id = 2 [
    71        (gogoproto.customname) = "ParentID",
    72        (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"
    73      ];
    74    }
    75    message BackupLocalityInfo {
    76      map<string, string> uris_by_original_locality_kv = 1 [(gogoproto.customname) = "URIsByOriginalLocalityKV"];
    77    }
    78    reserved 1;
    79    util.hlc.Timestamp end_time = 4 [(gogoproto.nullable) = false];
    80    map<uint32, TableRewrite> table_rewrites = 2 [
    81      (gogoproto.castkey) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"
    82    ];
    83    // URIs contains one URI for each backup (full or incremental) corresponding
    84    // to the location of the main BACKUP manifest. For partitioned backups, each
    85    // backup may also have files in other stores.
    86    repeated string uris = 3 [(gogoproto.customname) = "URIs"];
    87    repeated BackupLocalityInfo backup_locality_info = 7 [(gogoproto.nullable) = false];
    88    repeated sqlbase.TableDescriptor table_descs = 5;
    89    string override_db = 6 [(gogoproto.customname) = "OverrideDB"];
    90    bool prepare_completed = 8;
    91    bool stats_inserted = 9;
    92    bool tables_published = 10;
    93    int32 descriptor_coverage = 11 [
    94      (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/tree.DescriptorCoverage"
    95    ];
    96    roachpb.FileEncryptionOptions encryption = 12;
    97  }
    98  
    99  message RestoreProgress {
   100    bytes high_water = 1;
   101  }
   102  
   103  message ImportDetails {
   104    message Table {
   105      sqlbase.TableDescriptor desc = 1;
   106      string name = 18;
   107      int64 seq_val = 19;
   108      bool is_new = 20;
   109      repeated string target_cols = 21;
   110      reserved 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17;
   111    }
   112    repeated Table tables = 1 [(gogoproto.nullable) = false];
   113    repeated string uris = 2 [(gogoproto.customname) = "URIs"];
   114    roachpb.IOFileFormat format = 3 [(gogoproto.nullable) = false];
   115  
   116    int64 sst_size = 4 [(gogoproto.customname) = "SSTSize"];
   117    int64 oversample = 9;
   118    bool skip_fks = 10 [(gogoproto.customname) = "SkipFKs"];
   119    int64 walltime = 5;
   120    uint32 parent_id = 6 [
   121      (gogoproto.customname) = "ParentID",
   122      (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"
   123    ];
   124    string backup_path = 7;
   125  
   126    // samples is a sampling of cockroach KV keys generated from the input data.
   127    // It is populated with the sampling phase's results. These must be
   128    // used if a job is resumed to guarantee that AddSSTable will not attempt
   129    // to add ranges with an old split point within them.
   130    repeated bytes samples = 8;
   131  
   132    // ingest_directly means the Import job directly ingests the data as readers
   133    // produce it instead of sampling it and then setting up a distsql shuffle and
   134    // sort that produced sorted, non-overlapping data to ingest. When ingesting
   135    // directly, many other fields like samples, oversample, sst_size are ignored.
   136    bool ingest_directly = 11;
   137  
   138    bool prepare_complete = 12;
   139    bool tables_published = 13;
   140  
   141    // ProtectedTimestampRecord is the ID of the protected timestamp record
   142    // corresponding to this job. While the job ought to clean up the record
   143    // when it enters a terminal state, there may be cases where it cannot or
   144    // does not run the code to do so. To deal with this there is a background
   145    // reconcilliation loop to ensure that protected timestamps are cleaned up.
   146    bytes protected_timestamp_record = 22 [
   147      (gogoproto.customname) = "ProtectedTimestampRecord",
   148      (gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/util/uuid.UUID"
   149    ];
   150  }
   151  
   152  message ImportProgress {
   153    repeated float sampling_progress = 1;
   154    repeated float read_progress = 2;
   155    repeated float write_progress = 3;
   156    // The spans of split keys which have had their SSTable's generated.
   157    // This allows us to skip the shuffle stage for already-completed
   158    // spans when resuming an import job.
   159    repeated roachpb.Span span_progress = 4 [(gogoproto.nullable) = false];
   160  
   161    // In direct-ingest import, once the KVs for i'th row of an input file have
   162    // been flushed, we can advance the count here and then on resume skip over
   163    // that many rows without needing to convert/process them at all.
   164    repeated int64 resume_pos = 5; // Only set by direct import.
   165  }
   166  
   167  message ResumeSpanList {
   168    repeated roachpb.Span resume_spans = 1 [(gogoproto.nullable) = false];
   169  }
   170  
   171  enum Status {
   172    DRAINING_NAMES = 0;
   173    WAIT_FOR_GC_INTERVAL = 1;
   174    ROCKSDB_COMPACTION = 2;
   175    DONE = 10;
   176  }
   177  
   178  message DroppedTableDetails {
   179    string name = 1;
   180    uint32 ID = 2 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"];
   181    Status status = 3;
   182  }
   183  
   184  // SchemaChangeGCDetails should resemble one of the following:
   185  //
   186  // 1. Index (non-interleaved) deletions: One or more deletions of an index on a
   187  // table.
   188  //      details.Indexes -> the indexes to GC. These indexes must be
   189  //      non-interleaved.
   190  //      details.ParentID -> the table with the indexes.
   191  //
   192  // 2. Table deletions: The deletion of a single table.
   193  //      details.Tables -> the tables to be deleted.
   194  //
   195  // 3. Database deletions: The deletion of a database and therefore all its tables.
   196  //      details.Tables -> the IDs of the tables to GC.
   197  //      details.ParentID -> the ID of the database to drop.
   198  message SchemaChangeGCDetails {
   199    message DroppedIndex {
   200      int64 index_id = 1 [(gogoproto.customname) = "IndexID",
   201                         (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.IndexID"];
   202      int64 drop_time = 2;
   203    }
   204  
   205    message DroppedID {
   206      int64 id = 1 [(gogoproto.customname) = "ID",
   207                   (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"];
   208      int64 drop_time = 2;
   209    }
   210  
   211    // Indexes to GC.
   212    repeated DroppedIndex indexes = 1 [(gogoproto.nullable) = false];
   213  
   214    // Entire tables to GC.
   215    repeated DroppedID tables = 2 [(gogoproto.nullable) = false];
   216  
   217    // If dropping indexes, the table ID which has those indexes. If dropping a
   218    // database, the database ID.
   219    int64 parent_id = 3 [(gogoproto.customname) = "ParentID",
   220                        (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"];
   221  }
   222  
   223  message SchemaChangeDetails {
   224    reserved 1;
   225    // A schema change can involve running multiple processors backfilling
   226    // or deleting data. They occasionally checkpoint Spans so that the
   227    // processing can resume in the event of a node failure. The spans are
   228    // non-overlapping contiguous areas of the KV space that still need to
   229    // be processed. The index represents the index of a mutation in a
   230    // mutation list containing mutations for the same mutationID.
   231    repeated ResumeSpanList resume_span_list = 2 [(gogoproto.nullable) = false];
   232    repeated DroppedTableDetails dropped_tables = 3 [(gogoproto.nullable) = false];
   233    // The descriptor ID of the dropped database which created this job.
   234    uint32 dropped_database_id = 4 [
   235      (gogoproto.customname) = "DroppedDatabaseID",
   236      (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"
   237    ];
   238    uint32 table_id = 5 [(gogoproto.customname) = "TableID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"];
   239    uint32 mutation_id = 6 [(gogoproto.customname) = "MutationID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.MutationID"];
   240    // The format version of the schema change job details. This is used to
   241    // distinguish between jobs as they existed in 19.2 and earlier versions
   242    // (controlled and updated by a SchemaChanger) and jobs as they exist in 20.1
   243    // (scheduled and run by the job registry).
   244    uint32 format_version = 7 [(gogoproto.casttype) = "SchemaChangeDetailsFormatVersion"];
   245  }
   246  
   247  message SchemaChangeProgress {
   248  
   249  }
   250  
   251  message SchemaChangeGCProgress {
   252    enum Status {
   253      // Waiting for the index/table to expire.
   254      WAITING_FOR_GC = 0;
   255      // The GC TTL has expired. This element is marked for imminent deletion
   256      DELETING = 1;
   257      // This element has been deleted. The job is done when all elements are in
   258      // this state.
   259      DELETED = 2;
   260    }
   261  
   262    message IndexProgress {
   263      int64 index_id = 1 [(gogoproto.customname) = "IndexID",
   264                         (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.IndexID"];
   265      Status status = 2;
   266    }
   267  
   268    message TableProgress {
   269      int64 id = 1 [(gogoproto.customname) = "ID",
   270                   (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"];
   271      Status status = 2;
   272    }
   273  
   274    // Indexes to GC.
   275    repeated IndexProgress indexes = 1 [(gogoproto.nullable) = false];
   276  
   277    // Entire tables to GC.
   278    repeated TableProgress tables = 2 [(gogoproto.nullable) = false];
   279  }
   280  
   281  message ChangefeedTarget {
   282    string statement_time_name = 1;
   283  
   284    // TODO(dan): Add partition name, ranges of primary keys.
   285  }
   286  
   287  message ChangefeedDetails {
   288    // Targets contains the user-specified tables and databases to watch, mapping
   289    // the descriptor id to the name at the time of changefeed creating. There is
   290    // a 1:1 correspondance between unique targets in the original sql query and
   291    // entries in this map.
   292    //
   293    // - A watched table is stored here under its table id
   294    // - TODO(dan): A watched database is stored here under its database id
   295    // - TODO(dan): A db.* expansion is treated identicially to watching the
   296    //   database
   297    //
   298    // Note that the TODOs mean this field currently is guaranteed to only hold
   299    // table ids and a cluster version check will be added when this changes.
   300    //
   301    // The names at resolution time are included so that table and database
   302    // renames can be detected. They are also used to construct an error message
   303    // if the descriptor id no longer exists when the jobs is unpaused (which can
   304    // happen if it was dropped or truncated).
   305    map<uint32, ChangefeedTarget> targets = 6 [
   306      (gogoproto.castkey) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID",
   307      (gogoproto.casttype) = "ChangefeedTargets",
   308      (gogoproto.nullable) = false
   309    ];
   310    string sink_uri = 3 [(gogoproto.customname) = "SinkURI"];
   311    map<string, string> opts = 4;
   312    util.hlc.Timestamp statement_time = 7 [(gogoproto.nullable) = false];
   313  
   314    reserved 1, 2, 5;
   315  }
   316  
   317  message ResolvedSpan {
   318    roachpb.Span span = 1 [(gogoproto.nullable) = false];
   319    util.hlc.Timestamp timestamp = 2 [(gogoproto.nullable) = false];
   320    bool boundary_reached = 3;
   321  }
   322  
   323  message ChangefeedProgress {
   324    reserved 1;
   325    repeated ResolvedSpan resolved_spans = 2 [(gogoproto.nullable) = false];
   326  
   327    // ProtectedTimestampRecord is the ID of the protected timestamp record
   328    // corresponding to this job. While the job ought to clean up the record
   329    // when it enters a terminal state, there may be cases where it cannot or
   330    // does not run the code to do so. To deal with this there is a background
   331    // reconcilliation loop to ensure that protected timestamps are cleaned up.
   332    //
   333    // A record is created with the job if the job requires an initial backfill.
   334    // Furthermore, once subsequent backfills begin, record will be created and
   335    // released accordingly.
   336    bytes protected_timestamp_record = 3 [
   337      (gogoproto.customname) = "ProtectedTimestampRecord",
   338      (gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/util/uuid.UUID",
   339      (gogoproto.nullable) = false
   340    ];
   341  }
   342  
   343  // CreateStatsDetails are used for the CreateStats job, which is triggered
   344  // whenever the `CREATE STATISTICS` SQL statement is run. The CreateStats job
   345  // collects table statistics, which contain info such as the number of rows in
   346  // the table or the number of distinct values in a column.
   347  message CreateStatsDetails {
   348    message ColStat {
   349      repeated uint32 column_ids = 1 [
   350        (gogoproto.customname) = "ColumnIDs",
   351        (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ColumnID"
   352      ];
   353  
   354      // Indicates whether this column stat should include a histogram.
   355      bool has_histogram = 2;
   356    }
   357    string name = 1;
   358    sqlbase.TableDescriptor table = 2 [(gogoproto.nullable) = false];
   359    repeated ColStat column_stats = 3 [(gogoproto.nullable) = false];
   360    string statement = 4;
   361    util.hlc.Timestamp as_of = 5;
   362    double max_fraction_idle = 7;
   363  
   364    // Fully qualified table name.
   365    string fq_table_name = 6 [(gogoproto.customname) = "FQTableName"];
   366  }
   367  
   368  message CreateStatsProgress {
   369  
   370  }
   371  
   372  message Payload {
   373    string description = 1;
   374    // If empty, the description is assumed to be the statement.
   375    string statement = 16;
   376    string username = 2;
   377    // For consistency with the SQL timestamp type, which has microsecond
   378    // precision, we avoid the timestamp.Timestamp WKT, which has nanosecond
   379    // precision, and use microsecond integers directly.
   380    int64 started_micros = 3;
   381    int64 finished_micros = 4;
   382    reserved 5;
   383    repeated uint32 descriptor_ids = 6 [
   384      (gogoproto.customname) = "DescriptorIDs",
   385      (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ID"
   386    ];
   387    reserved 7;
   388    // TODO (lucy): Deprecate the string error field and move to using the encoded
   389    // errors everywhere.
   390    string error = 8;
   391    repeated errorspb.EncodedError resume_errors = 17;
   392    repeated errorspb.EncodedError cleanup_errors = 18;
   393    // FinalResumeError is set when an error occurs that requires the job to be
   394    // reverted. The error is recorded so it can be handled while reverting, if
   395    // needed.
   396    errorspb.EncodedError final_resume_error = 19;
   397    Lease lease = 9;
   398    // Noncancelable is used to denote when a job cannot be canceled. This field
   399    // will not be respected in mixed version clusters where some nodes have
   400    // a version < 20.1, so it can only be used in cases where all nodes having
   401    // versions >= 20.1 is guaranteed.
   402    bool noncancelable = 20;
   403    oneof details {
   404      BackupDetails backup = 10;
   405      RestoreDetails restore = 11;
   406      SchemaChangeDetails schemaChange = 12;
   407      ImportDetails import = 13;
   408      ChangefeedDetails changefeed = 14;
   409      CreateStatsDetails createStats = 15;
   410      SchemaChangeGCDetails schemaChangeGC = 21;
   411    }
   412  }
   413  
   414  message Progress {
   415    oneof progress {
   416      float fraction_completed = 1;
   417      util.hlc.Timestamp high_water = 3;
   418    }
   419    int64 modified_micros = 2;
   420    string running_status = 4;
   421  
   422    oneof details {
   423      BackupProgress backup = 10;
   424      RestoreProgress restore = 11;
   425      SchemaChangeProgress schemaChange = 12;
   426      ImportProgress import = 13;
   427      ChangefeedProgress changefeed = 14;
   428      CreateStatsProgress createStats = 15;
   429      SchemaChangeGCProgress schemaChangeGC = 16;
   430    }
   431  }
   432  
   433  enum Type {
   434    option (gogoproto.goproto_enum_prefix) = false;
   435    option (gogoproto.goproto_enum_stringer) = false;
   436  
   437    UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "TypeUnspecified"];
   438    BACKUP = 1 [(gogoproto.enumvalue_customname) = "TypeBackup"];
   439    RESTORE = 2 [(gogoproto.enumvalue_customname) = "TypeRestore"];
   440    SCHEMA_CHANGE = 3 [(gogoproto.enumvalue_customname) = "TypeSchemaChange"];
   441    IMPORT = 4 [(gogoproto.enumvalue_customname) = "TypeImport"];
   442    CHANGEFEED = 5 [(gogoproto.enumvalue_customname) = "TypeChangefeed"];
   443    CREATE_STATS = 6 [(gogoproto.enumvalue_customname) = "TypeCreateStats"];
   444    AUTO_CREATE_STATS = 7 [(gogoproto.enumvalue_customname) = "TypeAutoCreateStats"];
   445    SCHEMA_CHANGE_GC = 8 [(gogoproto.enumvalue_customname) = "TypeSchemaChangeGC"];
   446  }
   447  
   448  message Job {
   449    int64 id = 1;
   450    // Keep progress first as it may bre more relevant to see when looking at a
   451    // running job.
   452    Progress progress = 2;
   453    Payload payload = 3;
   454  }