github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/testdata/logic_test/zone_config (about)

     1  # LogicTest: !3node-tenant
     2  # Check that we can alter the default zone config.
     3  
     4  statement ok
     5  ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1
     6  
     7  query IT
     8  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR RANGE default]
     9  ----
    10  0  ALTER RANGE default CONFIGURE ZONE USING
    11     range_min_bytes = 134217728,
    12     range_max_bytes = 536870912,
    13     gc.ttlseconds = 90000,
    14     num_replicas = 1,
    15     constraints = '[]',
    16     lease_preferences = '[]'
    17  
    18  # Check that we can reset the default zone config to defaults.
    19  
    20  statement ok
    21  ALTER RANGE default CONFIGURE ZONE USING DEFAULT
    22  
    23  query IT
    24  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR RANGE default]
    25  ----
    26  0  ALTER RANGE default CONFIGURE ZONE USING
    27     range_min_bytes = 134217728,
    28     range_max_bytes = 536870912,
    29     gc.ttlseconds = 90000,
    30     num_replicas = 3,
    31     constraints = '[]',
    32     lease_preferences = '[]'
    33  
    34  # Make an override for the tests below
    35  
    36  statement ok
    37  ALTER RANGE default CONFIGURE ZONE USING range_min_bytes = 1234567
    38  
    39  statement ok
    40  CREATE TABLE a (id INT PRIMARY KEY)
    41  
    42  # Ensure that SHOW ZONE CONFIGURATION retrieves the default zone (ID 0) if
    43  # no zone was set.
    44  query IT
    45  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
    46  ----
    47  0  ALTER RANGE default CONFIGURE ZONE USING
    48     range_min_bytes = 1234567,
    49     range_max_bytes = 536870912,
    50     gc.ttlseconds = 90000,
    51     num_replicas = 3,
    52     constraints = '[]',
    53     lease_preferences = '[]'
    54  
    55  # Once USING DEFAULT has been used, we get the default config
    56  # but with our own zone config ID.
    57  
    58  statement ok
    59  ALTER TABLE a CONFIGURE ZONE USING DEFAULT
    60  
    61  query IT
    62  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
    63  ----
    64  53  ALTER TABLE a CONFIGURE ZONE USING
    65      range_min_bytes = 1234567,
    66      range_max_bytes = 536870912,
    67      gc.ttlseconds = 90000,
    68      num_replicas = 3,
    69      constraints = '[]',
    70      lease_preferences = '[]'
    71  
    72  # Check that configurations can be adjusted with USING.
    73  statement ok
    74  ALTER TABLE a CONFIGURE ZONE USING
    75    range_min_bytes = 200000 + 1,
    76    range_max_bytes = 300000 + 1,
    77    gc.ttlseconds = 3000 + 600,
    78    num_replicas = floor(1.2)::int,
    79    constraints = '[+region=test]',
    80    lease_preferences = '[[+region=test]]'
    81  
    82  # This should reflect in the metrics.
    83  query T
    84  SELECT feature_name FROM crdb_internal.feature_usage
    85  WHERE feature_name IN (
    86    'sql.schema.zone_config.table.range_min_bytes',
    87    'sql.schema.zone_config.table.range_max_bytes',
    88    'sql.schema.zone_config.table.gc.ttlseconds',
    89    'sql.schema.zone_config.table.num_replicas',
    90    'sql.schema.zone_config.table.constraints'
    91  ) AND usage_count > 0 ORDER BY feature_name
    92  ----
    93  sql.schema.zone_config.table.constraints
    94  sql.schema.zone_config.table.gc.ttlseconds
    95  sql.schema.zone_config.table.num_replicas
    96  sql.schema.zone_config.table.range_max_bytes
    97  sql.schema.zone_config.table.range_min_bytes
    98  
    99  query IT
   100  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
   101  ----
   102  53  ALTER TABLE a CONFIGURE ZONE USING
   103      range_min_bytes = 200001,
   104      range_max_bytes = 300001,
   105      gc.ttlseconds = 3600,
   106      num_replicas = 1,
   107      constraints = '[+region=test]',
   108      lease_preferences = '[[+region=test]]'
   109  
   110  # Check that we can set just one value without altering the others.
   111  statement ok
   112  ALTER TABLE a CONFIGURE ZONE USING range_max_bytes = 400000
   113  
   114  query IT
   115  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
   116  ----
   117  53  ALTER TABLE a CONFIGURE ZONE USING
   118      range_min_bytes = 200001,
   119      range_max_bytes = 400000,
   120      gc.ttlseconds = 3600,
   121      num_replicas = 1,
   122      constraints = '[+region=test]',
   123      lease_preferences = '[[+region=test]]'
   124  
   125  # Check that we can reset the configuration to defaults.
   126  
   127  statement ok
   128  ALTER TABLE a CONFIGURE ZONE USING DEFAULT
   129  
   130  # Note: the range_min_bytes here should reflect the non-standard
   131  # default that was set initially.
   132  query IT
   133  SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
   134  ----
   135  53  ALTER TABLE a CONFIGURE ZONE USING
   136      range_min_bytes = 1234567,
   137      range_max_bytes = 536870912,
   138      gc.ttlseconds = 90000,
   139      num_replicas = 3,
   140      constraints = '[]',
   141      lease_preferences = '[]'
   142  
   143  # Check that we can drop a configuration to get back to inherinting
   144  # the defaults.
   145  statement ok
   146  ALTER TABLE a CONFIGURE ZONE DISCARD
   147  
   148  query I
   149  SELECT zone_id FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
   150  ----
   151  0
   152  
   153  subtest alter_table_telemetry
   154  
   155  query T
   156  SELECT feature_name FROM crdb_internal.feature_usage
   157  WHERE feature_name IN ('sql.schema.alter_range.configure_zone', 'sql.schema.alter_table.configure_zone')
   158  ORDER BY feature_name
   159  ----
   160  sql.schema.alter_range.configure_zone
   161  sql.schema.alter_table.configure_zone