diff --git a/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality b/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality index 09330ef79091..5947267f270f 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality +++ b/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality @@ -140,6 +140,7 @@ TABLE global ALTER TABLE global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -219,6 +220,7 @@ TABLE global ALTER TABLE global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -337,6 +339,7 @@ TABLE regional_by_table_in_primary_region ALTER TABLE regional_by_table_in_prim range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -450,6 +453,7 @@ TABLE regional_by_table_no_region ALTER TABLE regional_by_table_no_region CONFI range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -555,6 +559,7 @@ TABLE regional_by_table_in_us_east ALTER TABLE regional_by_table_in_us_east CON range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' diff --git a/pkg/config/zonepb/zone.go b/pkg/config/zonepb/zone.go index 49dc7edb8999..98a873e7b3b1 100644 --- a/pkg/config/zonepb/zone.go +++ b/pkg/config/zonepb/zone.go @@ -418,6 +418,12 @@ func (z *ZoneConfig) CopyFromZone(other ZoneConfig, fieldList []tree.Name) { z.RangeMaxBytes = proto.Int64(*other.RangeMaxBytes) } } + if fieldName == "global_reads" { + z.GlobalReads = nil + if other.GlobalReads != nil { + z.GlobalReads = proto.Bool(*other.GlobalReads) + } + } if fieldName == "gc.ttlseconds" { z.GC = nil if other.GC != nil { diff --git a/pkg/config/zonepb/zone.pb.go b/pkg/config/zonepb/zone.pb.go index 7fd3928e0a33..73de4ccdc9d0 100644 --- a/pkg/config/zonepb/zone.pb.go +++ b/pkg/config/zonepb/zone.pb.go @@ -64,7 +64,7 @@ func (x *Constraint_Type) UnmarshalJSON(data []byte) error { return nil } func (Constraint_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{1, 0} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{1, 0} } // GCPolicy defines garbage collection policies which apply to MVCC @@ -84,7 +84,7 @@ func (m *GCPolicy) Reset() { *m = GCPolicy{} } func (m *GCPolicy) String() string { return proto.CompactTextString(m) } func (*GCPolicy) ProtoMessage() {} func (*GCPolicy) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{0} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{0} } func (m *GCPolicy) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -121,7 +121,7 @@ type Constraint struct { func (m *Constraint) Reset() { *m = Constraint{} } func (*Constraint) ProtoMessage() {} func (*Constraint) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{1} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{1} } func (m *Constraint) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -163,7 +163,7 @@ type ConstraintsConjunction struct { func (m *ConstraintsConjunction) Reset() { *m = ConstraintsConjunction{} } func (*ConstraintsConjunction) ProtoMessage() {} func (*ConstraintsConjunction) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{2} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{2} } func (m *ConstraintsConjunction) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -198,7 +198,7 @@ func (m *LeasePreference) Reset() { *m = LeasePreference{} } func (m *LeasePreference) String() string { return proto.CompactTextString(m) } func (*LeasePreference) ProtoMessage() {} func (*LeasePreference) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{3} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{3} } func (m *LeasePreference) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -234,7 +234,14 @@ type ZoneConfig struct { // If GC policy is not set, uses the next highest, non-null policy // in the zone config hierarchy, up to the default policy if necessary. GC *GCPolicy `protobuf:"bytes,4,opt,name=gc" json:"gc,omitempty"` - // NumReplicas specifies the desired number of replicas + // GlobalReads specifies whether transactions operating over the range(s) + // should be configured to provide non-blocking behavior, meaning that reads + // can be served consistently from all replicas and do not block on writes. In + // exchange, writes get pushed into the future and must wait on commit to + // ensure linearizability. For more, see: + // https://github.com/cockroachdb/cockroach/blob/master/docs/RFCS/20200811_non_blocking_txns.md + GlobalReads *bool `protobuf:"varint,12,opt,name=global_reads,json=globalReads" json:"global_reads,omitempty" yaml:"global_reads"` + // NumReplicas specifies the desired number of replicas. NumReplicas *int32 `protobuf:"varint,5,opt,name=num_replicas,json=numReplicas" json:"num_replicas,omitempty" yaml:"num_replicas"` // Constraints constrains which stores the replicas can be stored on. The // order in which the constraints are stored is arbitrary and may change. @@ -276,7 +283,7 @@ func (m *ZoneConfig) Reset() { *m = ZoneConfig{} } func (m *ZoneConfig) String() string { return proto.CompactTextString(m) } func (*ZoneConfig) ProtoMessage() {} func (*ZoneConfig) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{4} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{4} } func (m *ZoneConfig) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -317,7 +324,7 @@ func (m *Subzone) Reset() { *m = Subzone{} } func (m *Subzone) String() string { return proto.CompactTextString(m) } func (*Subzone) ProtoMessage() {} func (*Subzone) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{5} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{5} } func (m *Subzone) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -363,7 +370,7 @@ func (m *SubzoneSpan) Reset() { *m = SubzoneSpan{} } func (m *SubzoneSpan) String() string { return proto.CompactTextString(m) } func (*SubzoneSpan) ProtoMessage() {} func (*SubzoneSpan) Descriptor() ([]byte, []int) { - return fileDescriptor_zone_e0f724a3b706ed21, []int{6} + return fileDescriptor_zone_a3fbc029b2f37fad, []int{6} } func (m *SubzoneSpan) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -553,6 +560,15 @@ func (this *ZoneConfig) Equal(that interface{}) bool { if !this.GC.Equal(that1.GC) { return false } + if this.GlobalReads != nil && that1.GlobalReads != nil { + if *this.GlobalReads != *that1.GlobalReads { + return false + } + } else if this.GlobalReads != nil { + return false + } else if that1.GlobalReads != nil { + return false + } if this.NumReplicas != nil && that1.NumReplicas != nil { if *this.NumReplicas != *that1.NumReplicas { return false @@ -879,6 +895,16 @@ func (m *ZoneConfig) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0 } i++ + if m.GlobalReads != nil { + dAtA[i] = 0x60 + i++ + if *m.GlobalReads { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } return i, nil } @@ -1072,6 +1098,10 @@ func NewPopulatedZoneConfig(r randyZone, easy bool) *ZoneConfig { } this.InheritedConstraints = bool(bool(r.Intn(2) == 0)) this.InheritedLeasePreferences = bool(bool(r.Intn(2) == 0)) + if r.Intn(10) != 0 { + v16 := bool(bool(r.Intn(2) == 0)) + this.GlobalReads = &v16 + } if !easy && r.Intn(10) != 0 { } return this @@ -1081,8 +1111,8 @@ func NewPopulatedSubzone(r randyZone, easy bool) *Subzone { this := &Subzone{} this.IndexID = uint32(r.Uint32()) this.PartitionName = string(randStringZone(r)) - v16 := NewPopulatedZoneConfig(r, easy) - this.Config = *v16 + v17 := NewPopulatedZoneConfig(r, easy) + this.Config = *v17 if !easy && r.Intn(10) != 0 { } return this @@ -1091,16 +1121,16 @@ func NewPopulatedSubzone(r randyZone, easy bool) *Subzone { func NewPopulatedSubzoneSpan(r randyZone, easy bool) *SubzoneSpan { this := &SubzoneSpan{} if r.Intn(10) != 0 { - v17 := r.Intn(100) - this.Key = make(github_com_cockroachdb_cockroach_pkg_roachpb.Key, v17) - for i := 0; i < v17; i++ { + v18 := r.Intn(100) + this.Key = make(github_com_cockroachdb_cockroach_pkg_roachpb.Key, v18) + for i := 0; i < v18; i++ { this.Key[i] = byte(r.Intn(256)) } } if r.Intn(10) != 0 { - v18 := r.Intn(100) - this.EndKey = make(github_com_cockroachdb_cockroach_pkg_roachpb.Key, v18) - for i := 0; i < v18; i++ { + v19 := r.Intn(100) + this.EndKey = make(github_com_cockroachdb_cockroach_pkg_roachpb.Key, v19) + for i := 0; i < v19; i++ { this.EndKey[i] = byte(r.Intn(256)) } } @@ -1132,9 +1162,9 @@ func randUTF8RuneZone(r randyZone) rune { return rune(ru + 61) } func randStringZone(r randyZone) string { - v19 := r.Intn(100) - tmps := make([]rune, v19) - for i := 0; i < v19; i++ { + v20 := r.Intn(100) + tmps := make([]rune, v20) + for i := 0; i < v20; i++ { tmps[i] = randUTF8RuneZone(r) } return string(tmps) @@ -1156,11 +1186,11 @@ func randFieldZone(dAtA []byte, r randyZone, fieldNumber int, wire int) []byte { switch wire { case 0: dAtA = encodeVarintPopulateZone(dAtA, uint64(key)) - v20 := r.Int63() + v21 := r.Int63() if r.Intn(2) == 0 { - v20 *= -1 + v21 *= -1 } - dAtA = encodeVarintPopulateZone(dAtA, uint64(v20)) + dAtA = encodeVarintPopulateZone(dAtA, uint64(v21)) case 1: dAtA = encodeVarintPopulateZone(dAtA, uint64(key)) dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) @@ -1285,6 +1315,9 @@ func (m *ZoneConfig) Size() (n int) { } n += 2 n += 2 + if m.GlobalReads != nil { + n += 2 + } return n } @@ -1996,6 +2029,27 @@ func (m *ZoneConfig) Unmarshal(dAtA []byte) error { } } m.InheritedLeasePreferences = bool(v != 0) + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GlobalReads", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowZone + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + b := bool(v != 0) + m.GlobalReads = &b default: iNdEx = preIndex skippy, err := skipZone(dAtA[iNdEx:]) @@ -2381,63 +2435,65 @@ var ( ErrIntOverflowZone = fmt.Errorf("proto: integer overflow") ) -func init() { proto.RegisterFile("config/zonepb/zone.proto", fileDescriptor_zone_e0f724a3b706ed21) } - -var fileDescriptor_zone_e0f724a3b706ed21 = []byte{ - // 873 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x3d, 0x73, 0xe3, 0x44, - 0x18, 0xf6, 0xda, 0x8e, 0xad, 0x7b, 0xed, 0x24, 0x66, 0xef, 0x48, 0x44, 0x18, 0x2c, 0x23, 0x60, - 0x30, 0x5f, 0x36, 0x13, 0x68, 0xc8, 0x0c, 0xc5, 0xc9, 0x36, 0x87, 0xc8, 0x7d, 0x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34, 0x4c, 0xcf, 0x6d, 0xe7, 0x74, 0xdc, 0xe6, 0x27, - 0x67, 0xd8, 0x3a, 0x24, 0x41, 0xb4, 0xd5, 0x1f, 0x40, 0x99, 0xd0, 0x91, 0xbe, 0xd8, 0xf8, 0xff, - 0x97, 0xab, 0x44, 0xe8, 0xe8, 0x90, 0x04, 0xf8, 0x8d, 0x74, 0x28, 0x78, 0xcd, 0x78, 0xea, 0x8b, - 0xa5, 0xba, 0x90, 0x38, 0x2f, 0x6b, 0x9a, 0x9b, 0xd2, 0xbc, 0xf8, 0xa3, 0x9e, 0xbb, 0x98, 0xd7, - 0xd1, 0x93, 0x79, 0x1d, 0x3d, 0x9d, 0xd7, 0xd1, 0xef, 0xf3, 0x3a, 0xfa, 0xfe, 0xb2, 0x9e, 0x7b, - 0x72, 0x59, 0xcf, 0x3d, 0xbd, 0xac, 0xe7, 0x1e, 0x97, 0xa2, 0x42, 0xfd, 0x1d, 0x00, 0x00, 0xff, - 0xff, 0x1b, 0xf7, 0x5e, 0xb9, 0x83, 0x07, 0x00, 0x00, +func init() { proto.RegisterFile("config/zonepb/zone.proto", fileDescriptor_zone_a3fbc029b2f37fad) } + +var fileDescriptor_zone_a3fbc029b2f37fad = []byte{ + // 903 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x3f, 0x73, 0xe3, 0x44, + 0x14, 0xf7, 0x3a, 0x8e, 0xad, 0x7b, 0x76, 0x12, 0xb3, 0x77, 0x24, 0x22, 0x0c, 0x96, 0x11, 0x30, + 0x98, 0x7f, 0x36, 0x13, 0x68, 0xf0, 0x0c, 0xc5, 0xc9, 0x36, 0x87, 0x48, 0xee, 0xce, 0x28, 0x86, + 0xe2, 0x28, 0x34, 0xb2, 0xb4, 0x51, 0x44, 0xe4, 0x5d, 0x8d, 0x24, 0x43, 0xcc, 0xd0, 0xf1, 0x05, + 0x28, 0x29, 0x28, 0xf2, 0x0d, 0x68, 0xf9, 0x08, 0x29, 0x8f, 0xee, 0x68, 0x3c, 0xe0, 0x34, 0xd4, + 0x69, 0x98, 0xa1, 0x62, 0xb4, 0x92, 0x2d, 0xd9, 0x77, 0x86, 0x40, 0xa5, 0xdd, 0x7d, 0xbf, 0xf7, + 0x7b, 0x6f, 0xdf, 0xfb, 0xed, 0x13, 0x88, 0x26, 0xa3, 0x27, 0x8e, 0xdd, 0xfa, 0x86, 0x51, 0xe2, + 0x0d, 0xf9, 0xa7, 0xe9, 0xf9, 0x2c, 0x64, 0x78, 0xcf, 0x64, 0xe6, 0x99, 0xcf, 0x0c, 0xf3, 0xb4, + 0x19, 0x63, 0x9a, 0x31, 0x66, 0xff, 0x8e, 0xcd, 0x6c, 0xc6, 0x31, 0xad, 0x68, 0x15, 0xc3, 0x65, + 0x15, 0x84, 0x7b, 0x9d, 0x3e, 0x73, 0x1d, 0x73, 0x82, 0xdf, 0x83, 0x72, 0x18, 0xba, 0x7a, 0x40, + 0x4c, 0x46, 0xad, 0x40, 0x44, 0x75, 0xd4, 0xd8, 0x54, 0xf0, 0xe5, 0x54, 0xca, 0xcd, 0xa6, 0x12, + 0x0c, 0x06, 0x47, 0xc7, 0xb1, 0x45, 0x83, 0x30, 0x74, 0x93, 0x75, 0x5b, 0xf8, 0xf9, 0x42, 0x42, + 0x7f, 0x5c, 0x48, 0x48, 0xfe, 0x05, 0x01, 0x74, 0x18, 0x0d, 0x42, 0xdf, 0x70, 0x68, 0x88, 0x15, + 0x28, 0x84, 0x13, 0x8f, 0x70, 0x9a, 0xed, 0x83, 0x46, 0x73, 0x4d, 0x5e, 0xcd, 0xd4, 0xa5, 0x39, + 0x98, 0x78, 0x44, 0x29, 0x44, 0x01, 0x35, 0xee, 0x8b, 0x77, 0x61, 0xe3, 0x8c, 0x4c, 0xc4, 0x7c, + 0x1d, 0x35, 0x6e, 0x25, 0x86, 0xe8, 0x00, 0xef, 0xc3, 0xe6, 0x57, 0x86, 0x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 0x4d, 0x93, 0x8d, + 0x5a, 0x8b, 0x38, 0xd6, 0x30, 0x5d, 0xb7, 0xbc, 0x33, 0xbb, 0xc5, 0x57, 0xde, 0xb0, 0x79, 0x48, + 0x26, 0xf1, 0x1f, 0xe1, 0x3e, 0x94, 0x08, 0xb5, 0xf4, 0xf9, 0xdf, 0xe2, 0xff, 0x72, 0x15, 0x09, + 0xb5, 0x0e, 0xc9, 0x04, 0xbf, 0x91, 0x3e, 0x28, 0x5e, 0x33, 0x7e, 0xf5, 0xf9, 0x40, 0x9e, 0x3f, + 0x0f, 0x5e, 0xd6, 0xf4, 0x6e, 0x4a, 0xe3, 0xf2, 0xf7, 0x5a, 0xee, 0x72, 0x56, 0x43, 0x8f, 0x67, + 0x35, 0xf4, 0x64, 0x56, 0x43, 0xbf, 0xcd, 0x6a, 0xe8, 0xfb, 0xab, 0x5a, 0xee, 0xf1, 0x55, 0x2d, + 0xf7, 0xe4, 0xaa, 0x96, 0x7b, 0x54, 0x8c, 0x0b, 0xf5, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd4, + 0x0a, 0x17, 0x49, 0xbf, 0x07, 0x00, 0x00, } diff --git a/pkg/config/zonepb/zone.proto b/pkg/config/zonepb/zone.proto index 93200a9c9684..0943f319eb57 100644 --- a/pkg/config/zonepb/zone.proto +++ b/pkg/config/zonepb/zone.proto @@ -97,7 +97,15 @@ message ZoneConfig { // in the zone config hierarchy, up to the default policy if necessary. optional GCPolicy gc = 4 [(gogoproto.customname) = "GC"]; - // NumReplicas specifies the desired number of replicas + // GlobalReads specifies whether transactions operating over the range(s) + // should be configured to provide non-blocking behavior, meaning that reads + // can be served consistently from all replicas and do not block on writes. In + // exchange, writes get pushed into the future and must wait on commit to + // ensure linearizability. For more, see: + // https://github.com/cockroachdb/cockroach/blob/master/docs/RFCS/20200811_non_blocking_txns.md + optional bool global_reads = 12 [(gogoproto.moretags) = "yaml:\"global_reads\""]; + + // NumReplicas specifies the desired number of replicas. optional int32 num_replicas = 5 [(gogoproto.moretags) = "yaml:\"num_replicas\""]; // Constraints constrains which stores the replicas can be stored on. The diff --git a/pkg/config/zonepb/zone_test.go b/pkg/config/zonepb/zone_test.go index 86f01ae6f67b..17afe597a598 100644 --- a/pkg/config/zonepb/zone_test.go +++ b/pkg/config/zonepb/zone_test.go @@ -394,6 +394,7 @@ func TestZoneConfigMarshalYAML(t *testing.T) { GC: &GCPolicy{ TTLSeconds: 1, }, + GlobalReads: proto.Bool(true), NumReplicas: proto.Int32(1), } @@ -407,6 +408,7 @@ func TestZoneConfigMarshalYAML(t *testing.T) { range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: [] lease_preferences: [] @@ -428,6 +430,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: [+duck=foo] lease_preferences: [] @@ -458,6 +461,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: [foo, +duck=foo, -duck=foo] lease_preferences: [] @@ -480,6 +484,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: {+duck=foo: 3} lease_preferences: [] @@ -511,6 +516,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: {'foo,+duck=foo,-duck=foo': 3} lease_preferences: [] @@ -548,6 +554,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: {'+duck=bar1,+duck=bar2': 1, +duck=foo: 2} lease_preferences: [] @@ -559,6 +566,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: [] lease_preferences: [] @@ -580,6 +588,7 @@ lease_preferences: [] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: [] lease_preferences: [[+duck=foo]] @@ -626,6 +635,7 @@ lease_preferences: [[+duck=foo]] range_max_bytes: 1 gc: ttlseconds: 1 +global_reads: true num_replicas: 1 constraints: [+duck=foo] lease_preferences: [[+duck=bar1, +duck=bar2], [-duck=foo]] diff --git a/pkg/config/zonepb/zone_yaml.go b/pkg/config/zonepb/zone_yaml.go index f513f9b8652c..24087bd156f2 100644 --- a/pkg/config/zonepb/zone_yaml.go +++ b/pkg/config/zonepb/zone_yaml.go @@ -202,6 +202,7 @@ type marshalableZoneConfig struct { RangeMinBytes *int64 `json:"range_min_bytes" yaml:"range_min_bytes"` RangeMaxBytes *int64 `json:"range_max_bytes" yaml:"range_max_bytes"` GC *GCPolicy `json:"gc"` + GlobalReads *bool `json:"global_reads" yaml:"global_reads"` NumReplicas *int32 `json:"num_replicas" yaml:"num_replicas"` Constraints ConstraintsList `json:"constraints" yaml:"constraints,flow"` LeasePreferences []LeasePreference `json:"lease_preferences" yaml:"lease_preferences,flow"` @@ -222,6 +223,9 @@ func zoneConfigToMarshalable(c ZoneConfig) marshalableZoneConfig { tempGC := *c.GC m.GC = &tempGC } + if c.GlobalReads != nil { + m.GlobalReads = proto.Bool(*c.GlobalReads) + } if c.NumReplicas != nil && *c.NumReplicas != 0 { m.NumReplicas = proto.Int32(*c.NumReplicas) } @@ -250,6 +254,9 @@ func zoneConfigFromMarshalable(m marshalableZoneConfig, c ZoneConfig) ZoneConfig tempGC := *m.GC c.GC = &tempGC } + if m.GlobalReads != nil { + c.GlobalReads = proto.Bool(*m.GlobalReads) + } if m.NumReplicas != nil { c.NumReplicas = proto.Int32(*m.NumReplicas) } diff --git a/pkg/kv/kvserver/replica.go b/pkg/kv/kvserver/replica.go index 131a5cc5bb4d..a4c6dfa78ec7 100644 --- a/pkg/kv/kvserver/replica.go +++ b/pkg/kv/kvserver/replica.go @@ -678,6 +678,10 @@ func (r *Replica) SetZoneConfig(zone *zonepb.ZoneConfig) { r.mu.largestPreviousMaxRangeSizeBytes = 0 } + + // TODO(nvanbenschoten): use the new zone.GlobalReads field to configure + // closed timestamp lead/lag, once we have per-range closed timestamp + // trackers. } r.mu.zone = zone } diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal b/pkg/sql/logictest/testdata/logic_test/crdb_internal index d9bb780acdf2..201a98407e54 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal @@ -282,7 +282,7 @@ SELECT zone_id, target FROM crdb_internal.zones ORDER BY 1 query T SELECT quote_literal(raw_config_yaml) FROM crdb_internal.zones WHERE zone_id = 0 ---- -e'range_min_bytes: 134217728\nrange_max_bytes: 536870912\ngc:\n ttlseconds: 90000\nnum_replicas: 3\nconstraints: []\nlease_preferences: []\n' +e'range_min_bytes: 134217728\nrange_max_bytes: 536870912\ngc:\n ttlseconds: 90000\nglobal_reads: null\nnum_replicas: 3\nconstraints: []\nlease_preferences: []\n' query T SELECT raw_config_sql FROM crdb_internal.zones WHERE zone_id = 0 diff --git a/pkg/sql/logictest/testdata/logic_test/multiregion b/pkg/sql/logictest/testdata/logic_test/multiregion index 80d625a12479..44740e7b06c3 100644 --- a/pkg/sql/logictest/testdata/logic_test/multiregion +++ b/pkg/sql/logictest/testdata/logic_test/multiregion @@ -307,6 +307,7 @@ TABLE global_table ALTER TABLE global_table CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -582,6 +583,7 @@ TABLE t_global ALTER TABLE t_global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -663,6 +665,7 @@ TABLE t_global ALTER TABLE t_global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -716,6 +719,7 @@ TABLE t_global ALTER TABLE t_global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' diff --git a/pkg/sql/logictest/testdata/logic_test/zone_config b/pkg/sql/logictest/testdata/logic_test/zone_config index 3b124047e981..e56ec11a573b 100644 --- a/pkg/sql/logictest/testdata/logic_test/zone_config +++ b/pkg/sql/logictest/testdata/logic_test/zone_config @@ -75,6 +75,7 @@ ALTER TABLE a CONFIGURE ZONE USING range_min_bytes = 200000 + 1, range_max_bytes = 300000 + 1, gc.ttlseconds = 3000 + 600, + global_reads = true, num_replicas = floor(1.2)::int, constraints = '[+region=test]', lease_preferences = '[[+region=test]]' @@ -86,12 +87,14 @@ WHERE feature_name IN ( 'sql.schema.zone_config.table.range_min_bytes', 'sql.schema.zone_config.table.range_max_bytes', 'sql.schema.zone_config.table.gc.ttlseconds', + 'sql.schema.zone_config.table.global_reads', 'sql.schema.zone_config.table.num_replicas', 'sql.schema.zone_config.table.constraints' ) AND usage_count > 0 ORDER BY feature_name ---- sql.schema.zone_config.table.constraints sql.schema.zone_config.table.gc.ttlseconds +sql.schema.zone_config.table.global_reads sql.schema.zone_config.table.num_replicas sql.schema.zone_config.table.range_max_bytes sql.schema.zone_config.table.range_min_bytes @@ -103,6 +106,7 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a] range_min_bytes = 200001, range_max_bytes = 300001, gc.ttlseconds = 3600, + global_reads = true, num_replicas = 1, constraints = '[+region=test]', lease_preferences = '[[+region=test]]' @@ -118,6 +122,7 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a] range_min_bytes = 200001, range_max_bytes = 400000, gc.ttlseconds = 3600, + global_reads = true, num_replicas = 1, constraints = '[+region=test]', lease_preferences = '[[+region=test]]' @@ -154,6 +159,7 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a] range_min_bytes = 200001, range_max_bytes = 400000, gc.ttlseconds = 3600, + global_reads = true, num_replicas = 1, constraints = '[+region=test]', lease_preferences = '[[+region=test]]' diff --git a/pkg/sql/region_util.go b/pkg/sql/region_util.go index d5ad4b9976d3..63b13ef038c5 100644 --- a/pkg/sql/region_util.go +++ b/pkg/sql/region_util.go @@ -214,7 +214,9 @@ func zoneConfigFromTableLocalityConfig( switch l := localityConfig.Locality.(type) { case *descpb.TableDescriptor_LocalityConfig_Global_: - // Inherit everything from the database. + // Enable non-blocking transactions. + ret.GlobalReads = proto.Bool(true) + // Inherit constraints and leaseholders from the database. ret.InheritedConstraints = true ret.InheritedLeasePreferences = true case *descpb.TableDescriptor_LocalityConfig_RegionalByTable_: diff --git a/pkg/sql/region_util_test.go b/pkg/sql/region_util_test.go index 8778c88645a7..9d67daee9c30 100644 --- a/pkg/sql/region_util_test.go +++ b/pkg/sql/region_util_test.go @@ -205,6 +205,7 @@ func TestZoneConfigFromTableLocalityConfig(t *testing.T) { SurvivalGoal: descpb.SurvivalGoal_ZONE_FAILURE, }, expected: &zonepb.ZoneConfig{ + GlobalReads: proto.Bool(true), NumReplicas: proto.Int32(4), InheritedConstraints: true, InheritedLeasePreferences: true, @@ -228,6 +229,7 @@ func TestZoneConfigFromTableLocalityConfig(t *testing.T) { SurvivalGoal: descpb.SurvivalGoal_REGION_FAILURE, }, expected: &zonepb.ZoneConfig{ + GlobalReads: proto.Bool(true), NumReplicas: proto.Int32(4), InheritedConstraints: true, InheritedLeasePreferences: true, @@ -434,7 +436,7 @@ func TestZoneConfigFromRegionConfigForPartition(t *testing.T) { }, }, { - desc: "4-region global table with region survivability", + desc: "4-region table with region survivability", region: descpb.DatabaseDescriptor_RegionConfig_Region{ Name: "region_a", }, diff --git a/pkg/sql/set_zone_config.go b/pkg/sql/set_zone_config.go index bf8fe6322feb..e13f6950e8a5 100644 --- a/pkg/sql/set_zone_config.go +++ b/pkg/sql/set_zone_config.go @@ -67,6 +67,7 @@ var supportedZoneConfigOptions = map[tree.Name]struct { "range_min_bytes": {types.Int, func(c *zonepb.ZoneConfig, d tree.Datum) { c.RangeMinBytes = proto.Int64(int64(tree.MustBeDInt(d))) }}, "range_max_bytes": {types.Int, func(c *zonepb.ZoneConfig, d tree.Datum) { c.RangeMaxBytes = proto.Int64(int64(tree.MustBeDInt(d))) }}, "num_replicas": {types.Int, func(c *zonepb.ZoneConfig, d tree.Datum) { c.NumReplicas = proto.Int32(int32(tree.MustBeDInt(d))) }}, + "global_reads": {types.Bool, func(c *zonepb.ZoneConfig, d tree.Datum) { c.GlobalReads = proto.Bool(bool(tree.MustBeDBool(d))) }}, "gc.ttlseconds": {types.Int, func(c *zonepb.ZoneConfig, d tree.Datum) { c.GC = &zonepb.GCPolicy{TTLSeconds: int32(tree.MustBeDInt(d))} }}, diff --git a/pkg/sql/show_zone_config.go b/pkg/sql/show_zone_config.go index f624115c81d7..f3d15915de38 100644 --- a/pkg/sql/show_zone_config.go +++ b/pkg/sql/show_zone_config.go @@ -184,36 +184,43 @@ func zoneConfigToSQL(zs *tree.ZoneSpecifier, zone *zonepb.ZoneConfig) (string, e prefs = strings.TrimSpace(prefs) useComma := false + maybeWriteComma := func(f *tree.FmtCtx) { + if useComma { + f.Printf(",\n") + } + useComma = true + } + f := tree.NewFmtCtx(tree.FmtParsable) f.WriteString("ALTER ") f.FormatNode(zs) f.WriteString(" CONFIGURE ZONE USING\n") if zone.RangeMinBytes != nil { + maybeWriteComma(f) f.Printf("\trange_min_bytes = %d", *zone.RangeMinBytes) - useComma = true } if zone.RangeMaxBytes != nil { - writeComma(f, useComma) + maybeWriteComma(f) f.Printf("\trange_max_bytes = %d", *zone.RangeMaxBytes) - useComma = true } if zone.GC != nil { - writeComma(f, useComma) + maybeWriteComma(f) f.Printf("\tgc.ttlseconds = %d", zone.GC.TTLSeconds) - useComma = true + } + if zone.GlobalReads != nil { + maybeWriteComma(f) + f.Printf("\tglobal_reads = %t", *zone.GlobalReads) } if zone.NumReplicas != nil { - writeComma(f, useComma) + maybeWriteComma(f) f.Printf("\tnum_replicas = %d", *zone.NumReplicas) - useComma = true } if !zone.InheritedConstraints { - writeComma(f, useComma) + maybeWriteComma(f) f.Printf("\tconstraints = %s", lex.EscapeSQLString(constraints)) - useComma = true } if !zone.InheritedLeasePreferences { - writeComma(f, useComma) + maybeWriteComma(f) f.Printf("\tlease_preferences = %s", lex.EscapeSQLString(prefs)) } return f.String(), nil @@ -317,13 +324,6 @@ func generateZoneConfigIntrospectionValues( return nil } -// Writes a comma followed by a newline if useComma is true. -func writeComma(f *tree.FmtCtx, useComma bool) { - if useComma { - f.Printf(",\n") - } -} - func yamlMarshalFlow(v interface{}) (string, error) { var buf bytes.Buffer e := yaml.NewEncoder(&buf)