Skip to content

Commit

Permalink
migrations/sqlmigrations: add default .meta and .liveness zones
Browse files Browse the repository at this point in the history
Default the .meta zone config to 1h GC TTL and default the .liveness
zone config to 10m GC TTL. The shorter GC TTLs reflect the lack of need
for ever performing historical queries on these ranges coupled with the
desire to keep the meta and liveness ranges smaller.

See cockroachdb#16266
See cockroachdb#14990
  • Loading branch information
petermattis committed Dec 16, 2017
1 parent b511ba5 commit 9beedd5
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 42 deletions.
6 changes: 4 additions & 2 deletions pkg/acceptance/gossip_peerings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ func testGossipRestartFirstNodeNeedsIncomingInner(
t.Fatal(err)
}

if _, _, err := c.ExecCLI(ctx, 0, []string{"zone", "set", ".default", "-f", zoneFile}); err != nil {
t.Fatal(err)
for _, zone := range []string{".default", ".meta", ".liveness"} {
if _, _, err := c.ExecCLI(ctx, 0, []string{"zone", "set", zone, "-f", zoneFile}); err != nil {
t.Fatal(err)
}
}

db := makePGClient(t, c.PGUrl(ctx, 0))
Expand Down
6 changes: 6 additions & 0 deletions pkg/ccl/cliccl/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func Example_cclzone() {
// constraints: [us-east-1a, ssd]
// zone ls
// .default
// .liveness
// .meta
// db.t.p1
// db.t@primary
// zone rm db.t@primary
Expand All @@ -189,11 +191,15 @@ func Example_cclzone() {
// constraints: [us-east-1a, ssd]
// zone ls
// .default
// .liveness
// .meta
// db.t.p1
// zone rm db.t.p0
// CONFIGURE ZONE 0
// zone rm db.t.p1
// CONFIGURE ZONE 1
// zone ls
// .default
// .liveness
// .meta
}
50 changes: 38 additions & 12 deletions pkg/ccl/sqlccl/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {

yamlDefault := fmt.Sprintf("gc: {ttlseconds: %d}", config.DefaultZoneConfig().GC.TTLSeconds)
yamlOverride := "gc: {ttlseconds: 42}"
metaZoneConfig := config.DefaultZoneConfig()
metaZoneConfig.GC.TTLSeconds = 60 * 60
livenessZoneConfig := config.DefaultZoneConfig()
livenessZoneConfig.GC.TTLSeconds = 10 * 60
zoneOverride := config.DefaultZoneConfig()
zoneOverride.GC.TTLSeconds = 42

Expand All @@ -52,6 +56,16 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
CLISpecifier: ".default",
Config: config.DefaultZoneConfig(),
}
livenessRow := sqlutils.ZoneRow{
ID: keys.LivenessRangesID,
CLISpecifier: ".liveness",
Config: livenessZoneConfig,
}
metaRow := sqlutils.ZoneRow{
ID: keys.MetaRangesID,
CLISpecifier: ".meta",
Config: metaZoneConfig,
}
defaultOverrideRow := sqlutils.ZoneRow{
ID: keys.RootNamespaceID,
CLISpecifier: ".default",
Expand Down Expand Up @@ -84,7 +98,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
}

// Ensure the default is reported for all zones at first.
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "RANGE default", defaultRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", defaultRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", defaultRow)
Expand All @@ -95,7 +110,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure a database zone config applies to that database, its tables, and its
// tables' indices and partitions.
sqlutils.SetZoneConfig(t, sqlDB, "DATABASE d", yamlOverride)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow, dbRow)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow, dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", dbRow)
Expand All @@ -105,7 +121,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure a table zone config applies to that table and its indices and
// partitions, but no other zones.
sqlutils.SetZoneConfig(t, sqlDB, "TABLE d.t", yamlOverride)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow, dbRow, tableRow)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow, dbRow, tableRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", tableRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", tableRow)
Expand All @@ -115,7 +132,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure an index zone config applies to that index and its partitions, but
// no other zones.
sqlutils.SetZoneConfig(t, sqlDB, "INDEX d.t@primary", yamlOverride)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow, dbRow, tableRow, primaryRow)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow, dbRow, tableRow, primaryRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", tableRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", primaryRow)
Expand All @@ -125,7 +143,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure a partition zone config applies to that partition, but no other
// zones.
sqlutils.SetZoneConfig(t, sqlDB, "PARTITION p0 OF TABLE d.t", yamlOverride)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow, dbRow, tableRow, primaryRow, p0Row)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow, dbRow, tableRow, primaryRow, p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", tableRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", primaryRow)
Expand All @@ -135,7 +154,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure updating the default zone propagates to zones without an override,
// but not to those with overrides.
sqlutils.SetZoneConfig(t, sqlDB, "RANGE default", yamlOverride)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultOverrideRow, dbRow, tableRow, primaryRow, p0Row)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultOverrideRow, metaRow, livenessRow, dbRow, tableRow, primaryRow, p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", dbRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", tableRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", primaryRow)
Expand All @@ -144,7 +164,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {

// Ensure deleting a database zone leaves child overrides in place.
sqlutils.DeleteZoneConfig(t, sqlDB, "DATABASE d")
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultOverrideRow, tableRow, primaryRow, p0Row)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultOverrideRow, metaRow, livenessRow, tableRow, primaryRow, p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", defaultOverrideRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", tableRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", primaryRow)
Expand All @@ -153,21 +174,24 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {

// Ensure deleting a table zone leaves child overrides in place.
sqlutils.DeleteZoneConfig(t, sqlDB, "TABLE d.t")
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultOverrideRow, primaryRow, p0Row)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultOverrideRow, metaRow, livenessRow, primaryRow, p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", defaultOverrideRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", primaryRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "PARTITION p0 OF TABLE d.t", p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "PARTITION p1 OF TABLE d.t", primaryRow)

// Ensure deleting an index zone leaves child overrides in place.
sqlutils.DeleteZoneConfig(t, sqlDB, "INDEX d.t@primary")
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultOverrideRow, p0Row)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultOverrideRow, metaRow, livenessRow, p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "INDEX d.t@primary", defaultOverrideRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "PARTITION p0 OF TABLE d.t", p0Row)

// Ensure deleting a partition zone works.
sqlutils.DeleteZoneConfig(t, sqlDB, "PARTITION p0 OF TABLE d.t")
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultOverrideRow)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultOverrideRow, metaRow, livenessRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "PARTITION p0 OF TABLE d.t", defaultOverrideRow)

// Ensure deleting non-overridden zones is not an error.
Expand All @@ -178,7 +202,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure updating the default zone config applies to zones that have had
// overrides added and removed.
sqlutils.SetZoneConfig(t, sqlDB, "RANGE default", yamlDefault)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "RANGE default", defaultRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "DATABASE d", defaultRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", defaultRow)
Expand All @@ -189,7 +214,8 @@ func TestValidIndexPartitionSetShowZones(t *testing.T) {
// Ensure subzones can be created even when no table zone exists.
sqlutils.SetZoneConfig(t, sqlDB, "PARTITION p0 OF TABLE d.t", yamlOverride)
sqlutils.SetZoneConfig(t, sqlDB, "PARTITION p1 OF TABLE d.t", yamlOverride)
sqlutils.VerifyAllZoneConfigs(t, sqlDB, defaultRow, p0Row, p1Row)
sqlutils.VerifyAllZoneConfigs(t, sqlDB,
defaultRow, metaRow, livenessRow, p0Row, p1Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "TABLE d.t", defaultRow)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "PARTITION p0 OF TABLE d.t", p0Row)
sqlutils.VerifyZoneConfigForTarget(t, sqlDB, "PARTITION p1 OF TABLE d.t", p1Row)
Expand Down
36 changes: 33 additions & 3 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ func Example_zone() {
c.Run("zone ls")
c.Run("zone set system --file=./testdata/zone_attrs.yaml")
c.Run("zone ls")
c.Run("zone get .liveness")
c.Run("zone get .meta")
c.Run("zone get system.nonexistent")
c.Run("zone get system.descriptor")
Expand All @@ -507,6 +508,7 @@ func Example_zone() {
c.Run("zone rm system")
c.Run("zone ls")
c.Run("zone rm .default")
c.Run("zone set .liveness --file=./testdata/zone_range_max_bytes.yaml")
c.Run("zone set .meta --file=./testdata/zone_range_max_bytes.yaml")
c.Run("zone set .system --file=./testdata/zone_range_max_bytes.yaml")
c.Run("zone set .timeseries --file=./testdata/zone_range_max_bytes.yaml")
Expand All @@ -516,11 +518,13 @@ func Example_zone() {
c.Run("zone get system")
c.Run("zone set .default --disable-replication")
c.Run("zone get system")
c.Run("zone rm .liveness")
c.Run("zone rm .meta")
c.Run("zone rm .system")
c.Run("zone ls")
c.Run("zone rm .timeseries")
c.Run("zone ls")
c.Run("zone rm .liveness")
c.Run("zone rm .meta")
c.Run("zone rm .system")
c.Run("zone rm .timeseries")
Expand All @@ -529,6 +533,8 @@ func Example_zone() {
// Output:
// zone ls
// .default
// .liveness
// .meta
// zone set system --file=./testdata/zone_attrs.yaml
// range_min_bytes: 1048576
// range_max_bytes: 67108864
Expand All @@ -538,13 +544,23 @@ func Example_zone() {
// constraints: [us-east-1a, ssd]
// zone ls
// .default
// .liveness
// .meta
// system
// zone get .liveness
// .liveness
// range_min_bytes: 1048576
// range_max_bytes: 67108864
// gc:
// ttlseconds: 600
// num_replicas: 1
// constraints: []
// zone get .meta
// .default
// .meta
// range_min_bytes: 1048576
// range_max_bytes: 67108864
// gc:
// ttlseconds: 90000
// ttlseconds: 3600
// num_replicas: 1
// constraints: []
// zone get system.nonexistent
Expand Down Expand Up @@ -582,13 +598,22 @@ func Example_zone() {
// CONFIGURE ZONE 1
// zone ls
// .default
// .liveness
// .meta
// zone rm .default
// pq: cannot remove default zone
// zone set .liveness --file=./testdata/zone_range_max_bytes.yaml
// range_min_bytes: 1048576
// range_max_bytes: 134217728
// gc:
// ttlseconds: 600
// num_replicas: 3
// constraints: []
// zone set .meta --file=./testdata/zone_range_max_bytes.yaml
// range_min_bytes: 1048576
// range_max_bytes: 134217728
// gc:
// ttlseconds: 90000
// ttlseconds: 3600
// num_replicas: 3
// constraints: []
// zone set .system --file=./testdata/zone_range_max_bytes.yaml
Expand All @@ -615,6 +640,7 @@ func Example_zone() {
// constraints: []
// zone ls
// .default
// .liveness
// .meta
// .system
// .timeseries
Expand Down Expand Up @@ -648,6 +674,8 @@ func Example_zone() {
// ttlseconds: 90000
// num_replicas: 1
// constraints: []
// zone rm .liveness
// CONFIGURE ZONE 1
// zone rm .meta
// CONFIGURE ZONE 1
// zone rm .system
Expand All @@ -659,6 +687,8 @@ func Example_zone() {
// CONFIGURE ZONE 1
// zone ls
// .default
// zone rm .liveness
// CONFIGURE ZONE 0
// zone rm .meta
// CONFIGURE ZONE 0
// zone rm .system
Expand Down
10 changes: 7 additions & 3 deletions pkg/config/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ func (s SystemConfig) GetZoneConfigForKey(key roachpb.RKey) (ZoneConfig, error)
// Special-case known system ranges to their special zone configs.
if key.Equal(roachpb.RKeyMin) || bytes.HasPrefix(key, keys.Meta1Prefix) || bytes.HasPrefix(key, keys.Meta2Prefix) {
objectID = keys.MetaRangesID
} else if bytes.HasPrefix(key, keys.TimeseriesPrefix) {
objectID = keys.TimeseriesRangesID
} else if bytes.HasPrefix(key, keys.SystemPrefix) {
objectID = keys.SystemRangesID
if bytes.HasPrefix(key, keys.NodeLivenessPrefix) {
objectID = keys.LivenessRangesID
} else if bytes.HasPrefix(key, keys.TimeseriesPrefix) {
objectID = keys.TimeseriesRangesID
} else {
objectID = keys.SystemRangesID
}
}

return s.getZoneConfigForID(objectID, keySuffix)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func TestGetZoneConfigForKey(t *testing.T) {
{roachpb.RKey(keys.SystemPrefix), keys.SystemRangesID},
{roachpb.RKey(keys.SystemPrefix.Next()), keys.SystemRangesID},
{roachpb.RKey(keys.MigrationLease), keys.SystemRangesID},
{roachpb.RKey(keys.NodeLivenessPrefix), keys.SystemRangesID},
{roachpb.RKey(keys.NodeLivenessPrefix), keys.LivenessRangesID},
{roachpb.RKey(keys.DescIDGenerator), keys.SystemRangesID},
{roachpb.RKey(keys.NodeIDGenerator), keys.SystemRangesID},
{roachpb.RKey(keys.RangeIDGenerator), keys.SystemRangesID},
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
// can be targeted by zone configs.
const (
DefaultZoneName = "default"
LivenessZoneName = "liveness"
MetaZoneName = "meta"
SystemZoneName = "system"
TimeseriesZoneName = "timeseries"
Expand All @@ -40,6 +41,7 @@ const (
// install an entry into the system.zones table.
var NamedZones = map[string]uint32{
DefaultZoneName: keys.RootNamespaceID,
LivenessZoneName: keys.LivenessRangesID,
MetaZoneName: keys.MetaRangesID,
SystemZoneName: keys.SystemRangesID,
TimeseriesZoneName: keys.TimeseriesRangesID,
Expand Down
1 change: 1 addition & 0 deletions pkg/keys/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ const (
WebSessionsTableID = 19
TableStatisticsTableID = 20
LocationsTableID = 21
LivenessRangesID = 22
)
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ id cli_specifier config_yaml config_proto

statement ok
INSERT INTO system.zones (id, config) VALUES
(16, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)),
(17, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)),
(18, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)),
(51, (SELECT config_proto FROM crdb_internal.zones WHERE id = 0)),
Expand All @@ -178,6 +177,7 @@ SELECT id, cli_specifier FROM crdb_internal.zones ORDER BY id
16 .meta
17 .system
18 .timeseries
22 .liveness
51 testdb
52 testdb.foo

Expand Down
7 changes: 4 additions & 3 deletions pkg/sql/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func TestQueryCounts(t *testing.T) {
// Initialize accum while accounting for system migrations that may have run
// DDL statements.
accum := queryCounter{
insertCount: 2, // version setting population migration and root user addition.
selectCount: 2, // non-zero due to migrations
insertCount: 4, // non-zero due to migrations
ddlCount: s.MustGetSQLCounter(sql.MetaDdl.Name),
miscCount: s.MustGetSQLCounter(sql.MetaMisc.Name),
}
Expand Down Expand Up @@ -188,7 +189,7 @@ func TestAbortCountConflictingWrites(t *testing.T) {
if err := checkCounterEQ(s, sql.MetaTxnCommit, 0); err != nil {
t.Error(err)
}
if err := checkCounterEQ(s, sql.MetaInsert, 3); err != nil {
if err := checkCounterEQ(s, sql.MetaInsert, 5); err != nil {
t.Error(err)
}
}
Expand Down Expand Up @@ -216,7 +217,7 @@ func TestAbortCountErrorDuringTransaction(t *testing.T) {
if err := checkCounterEQ(s, sql.MetaTxnBegin, 1); err != nil {
t.Error(err)
}
if err := checkCounterEQ(s, sql.MetaSelect, 1); err != nil {
if err := checkCounterEQ(s, sql.MetaSelect, 3); err != nil {
t.Error(err)
}

Expand Down
Loading

0 comments on commit 9beedd5

Please sign in to comment.