From 80148a3cbf1c4bc63984cf5d0132b7ead3d2aeb9 Mon Sep 17 00:00:00 2001 From: David Porter Date: Sun, 2 Nov 2025 13:30:21 -0800 Subject: [PATCH 1/5] gen deepcopy Signed-off-by: David Porter --- Makefile | 5 +- common/cache/domainCache.go | 5 +- common/domain/handler.go | 6 +- common/persistence/data_manager_interfaces.go | 3 +- common/types/admin.go | 13 +- common/types/admin_deepcopy.gen.go | 13 ++ common/types/configStore.go | 14 +- common/types/shared.go | 66 +-------- common/types/shared_deepcopy.gen.go | 127 ++++++++++++++++++ common/types/shared_test.go | 25 +++- internal/tools/go.mod | 1 + internal/tools/go.sum | 3 + internal/tools/tools.go | 2 + 13 files changed, 195 insertions(+), 88 deletions(-) create mode 100644 common/types/admin_deepcopy.gen.go create mode 100644 common/types/shared_deepcopy.gen.go diff --git a/Makefile b/Makefile index a722efd313c..2f69974349a 100644 --- a/Makefile +++ b/Makefile @@ -188,6 +188,9 @@ $(BIN)/mockgen: internal/tools/go.mod go.work $(BIN)/mockery: internal/tools/go.mod go.work $(call go_build_tool,github.com/vektra/mockery/v2,mockery) +$(BIN)/deep-copy: internal/tools/go.mod go.work + $(call go_build_tool,github.com/globusdigital/deep-copy) + $(BIN)/enumer: internal/tools/go.mod go.work $(call go_build_tool,github.com/dmarkham/enumer) @@ -549,7 +552,7 @@ bins: $(BINS) ## Build all binaries, and any fast codegen needed (does not refre tools: $(TOOLS) -go-generate: $(BIN)/mockgen $(BIN)/enumer $(BIN)/mockery $(BIN)/gowrap ## Run `go generate` to regen mocks, enums, etc +go-generate: $(BIN)/mockgen $(BIN)/enumer $(BIN)/mockery $(BIN)/gowrap $(BIN)/deep-copy ## Run `go generate` to regen mocks, enums, etc $Q echo "running go generate ./..., this takes a minute or more..." $Q # add our bins to PATH so `go generate` can find them $Q $(BIN_PATH) go generate $(if $(verbose),-v) ./... diff --git a/common/cache/domainCache.go b/common/cache/domainCache.go index 82097ef18c6..568feee3b6b 100644 --- a/common/cache/domainCache.go +++ b/common/cache/domainCache.go @@ -761,7 +761,10 @@ func (entry *DomainCacheEntry) duplicate() *DomainCacheEntry { c := *clusterCfg result.replicationConfig.Clusters = append(result.replicationConfig.Clusters, &c) } - result.replicationConfig.ActiveClusters = entry.replicationConfig.ActiveClusters.DeepCopy() + if entry.replicationConfig.ActiveClusters != nil { + activeClusters := entry.replicationConfig.ActiveClusters.DeepCopy() + result.replicationConfig.ActiveClusters = &activeClusters + } result.configVersion = entry.configVersion result.failoverVersion = entry.failoverVersion result.isGlobalDomain = entry.isGlobalDomain diff --git a/common/domain/handler.go b/common/domain/handler.go index e0cf5473e15..8a3735db634 100644 --- a/common/domain/handler.go +++ b/common/domain/handler.go @@ -839,7 +839,11 @@ func (d *handlerImpl) FailoverDomain( isGlobalDomain := getResponse.IsGlobalDomain gracefulFailoverEndTime := getResponse.FailoverEndTime currentActiveCluster := replicationConfig.ActiveClusterName - currentActiveClusters := replicationConfig.ActiveClusters.DeepCopy() + var currentActiveClusters *types.ActiveClusters + if replicationConfig.ActiveClusters != nil { + currentActiveClustersCopy := replicationConfig.ActiveClusters.DeepCopy() + currentActiveClusters = ¤tActiveClustersCopy + } previousFailoverVersion := getResponse.PreviousFailoverVersion lastUpdatedTime := time.Unix(0, getResponse.LastUpdatedTime) diff --git a/common/persistence/data_manager_interfaces.go b/common/persistence/data_manager_interfaces.go index be1f1a2a971..a074465c76d 100644 --- a/common/persistence/data_manager_interfaces.go +++ b/common/persistence/data_manager_interfaces.go @@ -2151,7 +2151,8 @@ func (r *GetDomainResponse) DeepCopy() *GetDomainResponse { } // Deep copy ActiveClusters if r.ReplicationConfig.ActiveClusters != nil { - result.ReplicationConfig.ActiveClusters = r.ReplicationConfig.ActiveClusters.DeepCopy() + activeClusters := r.ReplicationConfig.ActiveClusters.DeepCopy() + result.ReplicationConfig.ActiveClusters = &activeClusters } } diff --git a/common/types/admin.go b/common/types/admin.go index 217a7e65af9..3e5dc455828 100644 --- a/common/types/admin.go +++ b/common/types/admin.go @@ -428,6 +428,8 @@ type GetDomainAsyncWorkflowConfiguratonResponse struct { Configuration *AsyncWorkflowConfiguration } +//go:generate deep-copy -o ./admin_deepcopy.gen.go -type AsyncWorkflowConfiguration . + type AsyncWorkflowConfiguration struct { Enabled bool PredefinedQueueName string @@ -435,17 +437,6 @@ type AsyncWorkflowConfiguration struct { QueueConfig *DataBlob } -func (c AsyncWorkflowConfiguration) DeepCopy() AsyncWorkflowConfiguration { - res := AsyncWorkflowConfiguration{ - Enabled: c.Enabled, - PredefinedQueueName: c.PredefinedQueueName, - QueueType: c.QueueType, - QueueConfig: c.QueueConfig.DeepCopy(), - } - - return res -} - // ByteSize returns an approximate size of the object in bytes func (c *AsyncWorkflowConfiguration) ByteSize() uint64 { if c == nil { diff --git a/common/types/admin_deepcopy.gen.go b/common/types/admin_deepcopy.gen.go new file mode 100644 index 00000000000..570cf5d6798 --- /dev/null +++ b/common/types/admin_deepcopy.gen.go @@ -0,0 +1,13 @@ +// generated by deep-copy -o ./admin_deepcopy.gen.go -type AsyncWorkflowConfiguration .; DO NOT EDIT. + +package types + +// DeepCopy generates a deep copy of AsyncWorkflowConfiguration +func (o AsyncWorkflowConfiguration) DeepCopy() AsyncWorkflowConfiguration { + var cp AsyncWorkflowConfiguration = o + if o.QueueConfig != nil { + queueConfig := o.QueueConfig.DeepCopy() + cp.QueueConfig = &queueConfig + } + return cp +} diff --git a/common/types/configStore.go b/common/types/configStore.go index 65e60c4e476..459eb48ec63 100644 --- a/common/types/configStore.go +++ b/common/types/configStore.go @@ -44,9 +44,14 @@ func (dcf *DynamicConfigFilter) Copy() *DynamicConfigFilter { if dcf == nil { return nil } + var valueCopy *DataBlob + if dcf.Value != nil { + v := dcf.Value.DeepCopy() + valueCopy = &v + } return &DynamicConfigFilter{ Name: dcf.Name, - Value: dcf.Value.DeepCopy(), + Value: valueCopy, } } @@ -63,8 +68,13 @@ func (dcv *DynamicConfigValue) Copy() *DynamicConfigValue { } } + var valueCopy *DataBlob + if dcv.Value != nil { + v := dcv.Value.DeepCopy() + valueCopy = &v + } return &DynamicConfigValue{ - Value: dcv.Value.DeepCopy(), + Value: valueCopy, Filters: newFilters, } } diff --git a/common/types/shared.go b/common/types/shared.go index 1ff35e137de..4c9da1967b2 100644 --- a/common/types/shared.go +++ b/common/types/shared.go @@ -392,32 +392,6 @@ func (b *BadBinaries) ByteSize() uint64 { } // DeepCopy returns a deep copy of BadBinaries -func (b *BadBinaries) DeepCopy() BadBinaries { - if b == nil { - return BadBinaries{} - } - result := BadBinaries{} - if b.Binaries != nil { - result.Binaries = make(map[string]*BadBinaryInfo, len(b.Binaries)) - for k, v := range b.Binaries { - if v != nil { - copyV := &BadBinaryInfo{ - Reason: v.Reason, - Operator: v.Operator, - } - if v.CreatedTimeNano != nil { - createdTime := *v.CreatedTimeNano - copyV.CreatedTimeNano = &createdTime - } - result.Binaries[k] = copyV - } else { - // Preserve nil entries in the map - result.Binaries[k] = nil - } - } - } - return result -} // BadBinaryInfo is an internal type (TBD...) type BadBinaryInfo struct { @@ -1010,23 +984,6 @@ func (v *DataBlob) GetData() (o []byte) { return } -func (v *DataBlob) DeepCopy() *DataBlob { - if v == nil { - return nil - } - - res := &DataBlob{ - EncodingType: v.EncodingType, - } - - if v.Data != nil { - res.Data = make([]byte, len(v.Data)) - copy(res.Data, v.Data) - } - - return res -} - // ByteSize returns the approximate memory used in bytes func (v *DataBlob) ByteSize() uint64 { if v == nil { @@ -1728,6 +1685,8 @@ func (v *DescribeDomainRequest) GetUUID() (o string) { return } +//go:generate deep-copy -o ./shared_deepcopy.gen.go -type DescribeDomainResponse -type BadBinaries -type DataBlob -type ActiveClusters . + // DescribeDomainResponse is an internal type (TBD...) type DescribeDomainResponse struct { DomainInfo *DomainInfo `json:"domainInfo,omitempty"` @@ -2723,27 +2682,6 @@ func (v ActiveClusterInfo) ByteSize() uint64 { return uint64(unsafe.Sizeof(v)) + uint64(len(v.ActiveClusterName)) } -func (v *ActiveClusters) DeepCopy() *ActiveClusters { - if v == nil { - return nil - } - result := &ActiveClusters{} - if v.AttributeScopes != nil { - result.AttributeScopes = make(map[string]ClusterAttributeScope, len(v.AttributeScopes)) - for scopeType, scope := range v.AttributeScopes { - copiedScope := ClusterAttributeScope{} - if scope.ClusterAttributes != nil { - copiedScope.ClusterAttributes = make(map[string]ActiveClusterInfo, len(scope.ClusterAttributes)) - for attrName, attrInfo := range scope.ClusterAttributes { - copiedScope.ClusterAttributes[attrName] = attrInfo - } - } - result.AttributeScopes[scopeType] = copiedScope - } - } - return result -} - type ClusterAttribute struct { Scope string `json:"scope,omitempty" yaml:"scope,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` diff --git a/common/types/shared_deepcopy.gen.go b/common/types/shared_deepcopy.gen.go new file mode 100644 index 00000000000..9d01fc1e1d7 --- /dev/null +++ b/common/types/shared_deepcopy.gen.go @@ -0,0 +1,127 @@ +// generated by deep-copy -o ./shared_deepcopy.gen.go -type DescribeDomainResponse -type BadBinaries -type DataBlob -type ActiveClusters .; DO NOT EDIT. + +package types + +// DeepCopy generates a deep copy of DescribeDomainResponse +func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { + var cp DescribeDomainResponse = o + if o.DomainInfo != nil { + cp.DomainInfo = new(DomainInfo) + *cp.DomainInfo = *o.DomainInfo + if o.DomainInfo.Status != nil { + cp.DomainInfo.Status = new(DomainStatus) + *cp.DomainInfo.Status = *o.DomainInfo.Status + } + if o.DomainInfo.Data != nil { + cp.DomainInfo.Data = make(map[string]string, len(o.DomainInfo.Data)) + for k4, v4 := range o.DomainInfo.Data { + cp.DomainInfo.Data[k4] = v4 + } + } + } + if o.Configuration != nil { + cp.Configuration = new(DomainConfiguration) + *cp.Configuration = *o.Configuration + if o.Configuration.BadBinaries != nil { + badBinaries := o.Configuration.BadBinaries.DeepCopy() + cp.Configuration.BadBinaries = &badBinaries + } + if o.Configuration.HistoryArchivalStatus != nil { + cp.Configuration.HistoryArchivalStatus = new(ArchivalStatus) + *cp.Configuration.HistoryArchivalStatus = *o.Configuration.HistoryArchivalStatus + } + if o.Configuration.VisibilityArchivalStatus != nil { + cp.Configuration.VisibilityArchivalStatus = new(ArchivalStatus) + *cp.Configuration.VisibilityArchivalStatus = *o.Configuration.VisibilityArchivalStatus + } + if o.Configuration.IsolationGroups != nil { + retV := o.Configuration.IsolationGroups.DeepCopy() + cp.Configuration.IsolationGroups = &retV + } + if o.Configuration.AsyncWorkflowConfig != nil { + retV := o.Configuration.AsyncWorkflowConfig.DeepCopy() + cp.Configuration.AsyncWorkflowConfig = &retV + } + } + if o.ReplicationConfiguration != nil { + cp.ReplicationConfiguration = new(DomainReplicationConfiguration) + *cp.ReplicationConfiguration = *o.ReplicationConfiguration + if o.ReplicationConfiguration.Clusters != nil { + cp.ReplicationConfiguration.Clusters = make([]*ClusterReplicationConfiguration, len(o.ReplicationConfiguration.Clusters)) + copy(cp.ReplicationConfiguration.Clusters, o.ReplicationConfiguration.Clusters) + for i4 := range o.ReplicationConfiguration.Clusters { + if o.ReplicationConfiguration.Clusters[i4] != nil { + cp.ReplicationConfiguration.Clusters[i4] = new(ClusterReplicationConfiguration) + *cp.ReplicationConfiguration.Clusters[i4] = *o.ReplicationConfiguration.Clusters[i4] + } + } + } + if o.ReplicationConfiguration.ActiveClusters != nil { + activeClusters := o.ReplicationConfiguration.ActiveClusters.DeepCopy() + cp.ReplicationConfiguration.ActiveClusters = &activeClusters + } + } + if o.FailoverInfo != nil { + cp.FailoverInfo = new(FailoverInfo) + *cp.FailoverInfo = *o.FailoverInfo + if o.FailoverInfo.PendingShards != nil { + cp.FailoverInfo.PendingShards = make([]int32, len(o.FailoverInfo.PendingShards)) + copy(cp.FailoverInfo.PendingShards, o.FailoverInfo.PendingShards) + } + } + return cp +} + +// DeepCopy generates a deep copy of BadBinaries +func (o BadBinaries) DeepCopy() BadBinaries { + var cp BadBinaries = o + if o.Binaries != nil { + cp.Binaries = make(map[string]*BadBinaryInfo, len(o.Binaries)) + for k2, v2 := range o.Binaries { + var cp_Binaries_v2 *BadBinaryInfo + if v2 != nil { + cp_Binaries_v2 = new(BadBinaryInfo) + *cp_Binaries_v2 = *v2 + if v2.CreatedTimeNano != nil { + cp_Binaries_v2.CreatedTimeNano = new(int64) + *cp_Binaries_v2.CreatedTimeNano = *v2.CreatedTimeNano + } + } + cp.Binaries[k2] = cp_Binaries_v2 + } + } + return cp +} + +// DeepCopy generates a deep copy of DataBlob +func (o DataBlob) DeepCopy() DataBlob { + var cp DataBlob = o + if o.EncodingType != nil { + cp.EncodingType = new(EncodingType) + *cp.EncodingType = *o.EncodingType + } + if o.Data != nil { + cp.Data = make([]byte, len(o.Data)) + copy(cp.Data, o.Data) + } + return cp +} + +// DeepCopy generates a deep copy of ActiveClusters +func (o ActiveClusters) DeepCopy() ActiveClusters { + var cp ActiveClusters = o + if o.AttributeScopes != nil { + cp.AttributeScopes = make(map[string]ClusterAttributeScope, len(o.AttributeScopes)) + for k2, v2 := range o.AttributeScopes { + var cp_AttributeScopes_v2 ClusterAttributeScope + if v2.ClusterAttributes != nil { + cp_AttributeScopes_v2.ClusterAttributes = make(map[string]ActiveClusterInfo, len(v2.ClusterAttributes)) + for k4, v4 := range v2.ClusterAttributes { + cp_AttributeScopes_v2.ClusterAttributes[k4] = v4 + } + } + cp.AttributeScopes[k2] = cp_AttributeScopes_v2 + } + } + return cp +} diff --git a/common/types/shared_test.go b/common/types/shared_test.go index 7bdaf23567b..74e547c77d6 100644 --- a/common/types/shared_test.go +++ b/common/types/shared_test.go @@ -62,9 +62,13 @@ func TestDataBlobDeepCopy(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { + if tc.input == nil { + // Cannot call DeepCopy on nil with value receiver + return + } got := tc.input.DeepCopy() - assert.Equal(t, tc.input, got) - if tc.input != nil && tc.input.Data != nil && identicalByteArray(tc.input.Data, got.Data) { + assert.Equal(t, *tc.input, got) + if tc.input.Data != nil && identicalByteArray(tc.input.Data, got.Data) { t.Error("expected DeepCopy to return a new data slice") } }) @@ -122,8 +126,15 @@ func TestActiveClustersConfigDeepCopy(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { + if tc.input == nil { + // Cannot call DeepCopy on nil with value receiver + if tc.expect != nil { + t.Errorf("expected nil but got %+v", tc.expect) + } + return + } deepCopy := tc.input.DeepCopy() - if diff := cmp.Diff(tc.expect, deepCopy); diff != "" { + if diff := cmp.Diff(*tc.expect, deepCopy); diff != "" { t.Errorf("DeepCopy() mismatch (-want +got):\n%s", diff) } }) @@ -149,7 +160,7 @@ func TestActiveClustersDeepCopyMutationIsolation(t *testing.T) { copied := original.DeepCopy() - assert.Equal(t, original, copied) + assert.Equal(t, *original, copied) scope := original.AttributeScopes["region"] scope.ClusterAttributes["us-west-1"] = ActiveClusterInfo{ @@ -485,13 +496,13 @@ func TestBadBinariesDeepCopy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - copied := tt.input.DeepCopy() - // Test for nil input if tt.input == nil { - assert.Empty(t, copied.Binaries) + // Cannot call DeepCopy on nil with value receiver return } + + copied := tt.input.DeepCopy() // Verify values are equal assert.Equal(t, tt.input.Binaries, copied.Binaries, "values should be equal") diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 06016e100d8..7407cdb83fc 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -7,6 +7,7 @@ toolchain go1.23.4 require ( github.com/daixiang0/gci v0.12.0 github.com/dmarkham/enumer v1.5.8 + github.com/globusdigital/deep-copy v0.5.4 github.com/gogo/protobuf v1.3.2 github.com/hexdigest/gowrap v1.2.5 github.com/mgechev/revive v1.3.2 diff --git a/internal/tools/go.sum b/internal/tools/go.sum index a95619a6621..7bd18e80c75 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -386,6 +386,8 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/globusdigital/deep-copy v0.5.4 h1:W4CHb7ul8VpZN0uj529AvfFH9Rs14MjKSaJHKISxLY0= +github.com/globusdigital/deep-copy v0.5.4/go.mod h1:UDFAJxcRE6lzC16dS/njdFBd3TXL4yeYH47PWkJJgEM= github.com/go-critic/go-critic v0.6.3 h1:abibh5XYBTASawfTQ0rA7dVtQT+6KzpGqb/J+DxRDaw= github.com/go-critic/go-critic v0.6.3/go.mod h1:c6b3ZP1MQ7o6lPR7Rv3lEf7pYQUmAcx8ABHgdZCQt/k= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= @@ -1664,6 +1666,7 @@ golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200107050322-53017a39ae36/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117215004-fe56e6335763/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= diff --git a/internal/tools/tools.go b/internal/tools/tools.go index aa8dfc8204b..29fe6035890 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -28,6 +28,8 @@ import ( _ "github.com/daixiang0/gci" // enumer for generating utility methods for const enums _ "github.com/dmarkham/enumer" + // deep-copy for generating DeepCopy methods + _ "github.com/globusdigital/deep-copy" // protobuf stuff _ "github.com/gogo/protobuf/protoc-gen-gofast" // gowrap for generating decorators for interface From 7b29b601f5bd7d34d3b6be8175e0ae2207179d88 Mon Sep 17 00:00:00 2001 From: David Porter Date: Sun, 2 Nov 2025 13:59:24 -0800 Subject: [PATCH 2/5] Persistence deepcopy Signed-off-by: David Porter --- common/domain/handler.go | 2 +- .../persistence/data_manager_deepcopy.gen.go | 54 +++++++++++ common/persistence/data_manager_interfaces.go | 89 +------------------ .../data_manager_interfaces_test.go | 16 ++-- common/types/shared_test.go | 2 +- 5 files changed, 70 insertions(+), 93 deletions(-) create mode 100644 common/persistence/data_manager_deepcopy.gen.go diff --git a/common/domain/handler.go b/common/domain/handler.go index 8a3735db634..3ff08ffbb1f 100644 --- a/common/domain/handler.go +++ b/common/domain/handler.go @@ -444,7 +444,7 @@ func (d *handlerImpl) UpdateDomain( lastUpdatedTime := time.Unix(0, getResponse.LastUpdatedTime) if !isGlobalDomain { - return d.updateLocalDomain(ctx, updateRequest, getResponse, notificationVersion) + return d.updateLocalDomain(ctx, updateRequest, &getResponse, notificationVersion) } // todo (active-active) refactor the rest of this method to remove all branching for global domain variations // and the split between domain update and failover diff --git a/common/persistence/data_manager_deepcopy.gen.go b/common/persistence/data_manager_deepcopy.gen.go new file mode 100644 index 00000000000..035a0a9ed03 --- /dev/null +++ b/common/persistence/data_manager_deepcopy.gen.go @@ -0,0 +1,54 @@ +// generated by deep-copy -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig .; DO NOT EDIT. + +package persistence + +// DeepCopy generates a deep copy of GetDomainResponse +func (o GetDomainResponse) DeepCopy() GetDomainResponse { + var cp GetDomainResponse = o + if o.Info != nil { + cp.Info = new(DomainInfo) + *cp.Info = *o.Info + if o.Info.Data != nil { + cp.Info.Data = make(map[string]string, len(o.Info.Data)) + for k4, v4 := range o.Info.Data { + cp.Info.Data[k4] = v4 + } + } + } + if o.Config != nil { + cp.Config = new(DomainConfig) + *cp.Config = *o.Config + cp.Config.BadBinaries = o.Config.BadBinaries.DeepCopy() + cp.Config.IsolationGroups = o.Config.IsolationGroups.DeepCopy() + cp.Config.AsyncWorkflowConfig = o.Config.AsyncWorkflowConfig.DeepCopy() + } + if o.ReplicationConfig != nil { + cp.ReplicationConfig = new(DomainReplicationConfig) + *cp.ReplicationConfig = *o.ReplicationConfig + if o.ReplicationConfig.Clusters != nil { + cp.ReplicationConfig.Clusters = make([]*ClusterReplicationConfig, len(o.ReplicationConfig.Clusters)) + copy(cp.ReplicationConfig.Clusters, o.ReplicationConfig.Clusters) + for i4 := range o.ReplicationConfig.Clusters { + if o.ReplicationConfig.Clusters[i4] != nil { + clusterCopy := o.ReplicationConfig.Clusters[i4].DeepCopy() + cp.ReplicationConfig.Clusters[i4] = &clusterCopy + } + } + } + if o.ReplicationConfig.ActiveClusters != nil { + retV := o.ReplicationConfig.ActiveClusters.DeepCopy() + cp.ReplicationConfig.ActiveClusters = &retV + } + } + if o.FailoverEndTime != nil { + cp.FailoverEndTime = new(int64) + *cp.FailoverEndTime = *o.FailoverEndTime + } + return cp +} + +// DeepCopy generates a deep copy of ClusterReplicationConfig +func (o ClusterReplicationConfig) DeepCopy() ClusterReplicationConfig { + var cp ClusterReplicationConfig = o + return cp +} diff --git a/common/persistence/data_manager_interfaces.go b/common/persistence/data_manager_interfaces.go index a074465c76d..fc2488ebab3 100644 --- a/common/persistence/data_manager_interfaces.go +++ b/common/persistence/data_manager_interfaces.go @@ -49,6 +49,9 @@ // execution metered wrapper is special //go:generate gowrap gen -g -p . -i ExecutionManager -t ./wrappers/templates/metered_execution.tmpl -o wrappers/metered/execution_generated.go +// Generate DeepCopy methods +//go:generate deep-copy -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig . + package persistence import ( @@ -2072,92 +2075,6 @@ func (config *ClusterReplicationConfig) deserialize(input map[string]interface{} } // GetCopy return a copy of ClusterReplicationConfig -func (config *ClusterReplicationConfig) GetCopy() *ClusterReplicationConfig { - res := *config - return &res -} - -// DeepCopy returns a deep copy of GetDomainResponse -// todo (david.porter) delete this manual deepcopying since it's annoying to maintain and -// use codegen for generating them instead -func (r *GetDomainResponse) DeepCopy() *GetDomainResponse { - if r == nil { - return nil - } - - result := &GetDomainResponse{ - IsGlobalDomain: r.IsGlobalDomain, - ConfigVersion: r.ConfigVersion, - FailoverVersion: r.FailoverVersion, - FailoverNotificationVersion: r.FailoverNotificationVersion, - PreviousFailoverVersion: r.PreviousFailoverVersion, - LastUpdatedTime: r.LastUpdatedTime, - NotificationVersion: r.NotificationVersion, - } - - // Deep copy FailoverEndTime - if r.FailoverEndTime != nil { - failoverEndTime := *r.FailoverEndTime - result.FailoverEndTime = &failoverEndTime - } - // Deep copy DomainInfo - if r.Info != nil { - result.Info = &DomainInfo{ - ID: r.Info.ID, - Name: r.Info.Name, - Status: r.Info.Status, - Description: r.Info.Description, - OwnerEmail: r.Info.OwnerEmail, - } - if r.Info.Data != nil { - result.Info.Data = make(map[string]string, len(r.Info.Data)) - for k, v := range r.Info.Data { - result.Info.Data[k] = v - } - } - } - - // Deep copy DomainConfig - if r.Config != nil { - result.Config = &DomainConfig{ - Retention: r.Config.Retention, - EmitMetric: r.Config.EmitMetric, - HistoryArchivalStatus: r.Config.HistoryArchivalStatus, - HistoryArchivalURI: r.Config.HistoryArchivalURI, - VisibilityArchivalStatus: r.Config.VisibilityArchivalStatus, - VisibilityArchivalURI: r.Config.VisibilityArchivalURI, - } - // Deep copy BadBinaries - result.Config.BadBinaries = r.Config.BadBinaries.DeepCopy() - // Deep copy IsolationGroups - result.Config.IsolationGroups = r.Config.IsolationGroups.DeepCopy() - // Deep copy AsyncWorkflowConfig - result.Config.AsyncWorkflowConfig = r.Config.AsyncWorkflowConfig.DeepCopy() - } - - // Deep copy DomainReplicationConfig - if r.ReplicationConfig != nil { - result.ReplicationConfig = &DomainReplicationConfig{ - ActiveClusterName: r.ReplicationConfig.ActiveClusterName, - } - // Deep copy Clusters - if r.ReplicationConfig.Clusters != nil { - result.ReplicationConfig.Clusters = make([]*ClusterReplicationConfig, len(r.ReplicationConfig.Clusters)) - for i, cluster := range r.ReplicationConfig.Clusters { - if cluster != nil { - result.ReplicationConfig.Clusters[i] = cluster.GetCopy() - } - } - } - // Deep copy ActiveClusters - if r.ReplicationConfig.ActiveClusters != nil { - activeClusters := r.ReplicationConfig.ActiveClusters.DeepCopy() - result.ReplicationConfig.ActiveClusters = &activeClusters - } - } - - return result -} // DBTimestampToUnixNano converts Milliseconds timestamp to UnixNano func DBTimestampToUnixNano(milliseconds int64) int64 { diff --git a/common/persistence/data_manager_interfaces_test.go b/common/persistence/data_manager_interfaces_test.go index 5b025efec29..e1d35e173f6 100644 --- a/common/persistence/data_manager_interfaces_test.go +++ b/common/persistence/data_manager_interfaces_test.go @@ -39,8 +39,9 @@ func TestClusterReplicationConfigGetCopy(t *testing.T) { config := &ClusterReplicationConfig{ ClusterName: "test", } - assert.Equal(t, config, config.GetCopy()) // deep equal - assert.Equal(t, true, config != config.GetCopy()) + configCopy := config.DeepCopy() + assert.Equal(t, *config, configCopy) // deep equal + assert.Equal(t, true, config != &configCopy) } func TestGetDomainResponseDeepCopy(t *testing.T) { @@ -115,8 +116,13 @@ func TestGetDomainResponseDeepCopy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + if tt.input == nil { + // Cannot call DeepCopy on nil with value receiver + tt.validate(t, tt.input, nil) + return + } copied := tt.input.DeepCopy() - tt.validate(t, tt.input, copied) + tt.validate(t, tt.input, &copied) }) } } @@ -137,10 +143,10 @@ func TestGetDomainResponseDeepCopy_FuzzGenerated(t *testing.T) { require.NotNil(t, copied, "DeepCopy should not return nil for non-nil input") // Verify the copied struct is equal to the original - assert.Equal(t, original, copied, "DeepCopy should produce an equal struct") + assert.Equal(t, *original, copied, "DeepCopy should produce an equal struct") // Verify they are different instances (different memory addresses) - assert.True(t, original != copied, "DeepCopy should create a new instance") + assert.True(t, original != &copied, "DeepCopy should create a new instance") }) } } diff --git a/common/types/shared_test.go b/common/types/shared_test.go index 74e547c77d6..c4b180bc0e1 100644 --- a/common/types/shared_test.go +++ b/common/types/shared_test.go @@ -501,7 +501,7 @@ func TestBadBinariesDeepCopy(t *testing.T) { // Cannot call DeepCopy on nil with value receiver return } - + copied := tt.input.DeepCopy() // Verify values are equal From c64dfd630ea58943b23e8b6d36e9b35cd28ea5be Mon Sep 17 00:00:00 2001 From: David Porter Date: Sun, 2 Nov 2025 15:37:29 -0800 Subject: [PATCH 3/5] WIP Signed-off-by: David Porter --- common/domain/handler.go | 2 +- .../persistence/data_manager_deepcopy.gen.go | 21 +++++++++---------- common/persistence/data_manager_interfaces.go | 2 +- .../data_manager_interfaces_test.go | 10 ++++----- common/types/admin_deepcopy.gen.go | 4 ++-- common/types/shared_deepcopy.gen.go | 6 ++---- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/common/domain/handler.go b/common/domain/handler.go index 3ff08ffbb1f..8a3735db634 100644 --- a/common/domain/handler.go +++ b/common/domain/handler.go @@ -444,7 +444,7 @@ func (d *handlerImpl) UpdateDomain( lastUpdatedTime := time.Unix(0, getResponse.LastUpdatedTime) if !isGlobalDomain { - return d.updateLocalDomain(ctx, updateRequest, &getResponse, notificationVersion) + return d.updateLocalDomain(ctx, updateRequest, getResponse, notificationVersion) } // todo (active-active) refactor the rest of this method to remove all branching for global domain variations // and the split between domain update and failover diff --git a/common/persistence/data_manager_deepcopy.gen.go b/common/persistence/data_manager_deepcopy.gen.go index 035a0a9ed03..6cb6e073785 100644 --- a/common/persistence/data_manager_deepcopy.gen.go +++ b/common/persistence/data_manager_deepcopy.gen.go @@ -1,10 +1,10 @@ -// generated by deep-copy -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig .; DO NOT EDIT. +// generated by deep-copy -pointer-receiver -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig .; DO NOT EDIT. package persistence -// DeepCopy generates a deep copy of GetDomainResponse -func (o GetDomainResponse) DeepCopy() GetDomainResponse { - var cp GetDomainResponse = o +// DeepCopy generates a deep copy of *GetDomainResponse +func (o *GetDomainResponse) DeepCopy() *GetDomainResponse { + var cp GetDomainResponse = *o if o.Info != nil { cp.Info = new(DomainInfo) *cp.Info = *o.Info @@ -30,8 +30,7 @@ func (o GetDomainResponse) DeepCopy() GetDomainResponse { copy(cp.ReplicationConfig.Clusters, o.ReplicationConfig.Clusters) for i4 := range o.ReplicationConfig.Clusters { if o.ReplicationConfig.Clusters[i4] != nil { - clusterCopy := o.ReplicationConfig.Clusters[i4].DeepCopy() - cp.ReplicationConfig.Clusters[i4] = &clusterCopy + cp.ReplicationConfig.Clusters[i4] = o.ReplicationConfig.Clusters[i4].DeepCopy() } } } @@ -44,11 +43,11 @@ func (o GetDomainResponse) DeepCopy() GetDomainResponse { cp.FailoverEndTime = new(int64) *cp.FailoverEndTime = *o.FailoverEndTime } - return cp + return &cp } -// DeepCopy generates a deep copy of ClusterReplicationConfig -func (o ClusterReplicationConfig) DeepCopy() ClusterReplicationConfig { - var cp ClusterReplicationConfig = o - return cp +// DeepCopy generates a deep copy of *ClusterReplicationConfig +func (o *ClusterReplicationConfig) DeepCopy() *ClusterReplicationConfig { + var cp ClusterReplicationConfig = *o + return &cp } diff --git a/common/persistence/data_manager_interfaces.go b/common/persistence/data_manager_interfaces.go index fc2488ebab3..222f0ab8018 100644 --- a/common/persistence/data_manager_interfaces.go +++ b/common/persistence/data_manager_interfaces.go @@ -50,7 +50,7 @@ //go:generate gowrap gen -g -p . -i ExecutionManager -t ./wrappers/templates/metered_execution.tmpl -o wrappers/metered/execution_generated.go // Generate DeepCopy methods -//go:generate deep-copy -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig . +//go:generate deep-copy -pointer-receiver -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig . package persistence diff --git a/common/persistence/data_manager_interfaces_test.go b/common/persistence/data_manager_interfaces_test.go index e1d35e173f6..95e271a5dcc 100644 --- a/common/persistence/data_manager_interfaces_test.go +++ b/common/persistence/data_manager_interfaces_test.go @@ -40,8 +40,8 @@ func TestClusterReplicationConfigGetCopy(t *testing.T) { ClusterName: "test", } configCopy := config.DeepCopy() - assert.Equal(t, *config, configCopy) // deep equal - assert.Equal(t, true, config != &configCopy) + assert.Equal(t, config, configCopy) // deep equal + assert.Equal(t, true, config != configCopy) } func TestGetDomainResponseDeepCopy(t *testing.T) { @@ -122,7 +122,7 @@ func TestGetDomainResponseDeepCopy(t *testing.T) { return } copied := tt.input.DeepCopy() - tt.validate(t, tt.input, &copied) + tt.validate(t, tt.input, copied) }) } } @@ -143,10 +143,10 @@ func TestGetDomainResponseDeepCopy_FuzzGenerated(t *testing.T) { require.NotNil(t, copied, "DeepCopy should not return nil for non-nil input") // Verify the copied struct is equal to the original - assert.Equal(t, *original, copied, "DeepCopy should produce an equal struct") + assert.Equal(t, original, copied, "DeepCopy should produce an equal struct") // Verify they are different instances (different memory addresses) - assert.True(t, original != &copied, "DeepCopy should create a new instance") + assert.True(t, original != copied, "DeepCopy should create a new instance") }) } } diff --git a/common/types/admin_deepcopy.gen.go b/common/types/admin_deepcopy.gen.go index 570cf5d6798..5f510d591bc 100644 --- a/common/types/admin_deepcopy.gen.go +++ b/common/types/admin_deepcopy.gen.go @@ -6,8 +6,8 @@ package types func (o AsyncWorkflowConfiguration) DeepCopy() AsyncWorkflowConfiguration { var cp AsyncWorkflowConfiguration = o if o.QueueConfig != nil { - queueConfig := o.QueueConfig.DeepCopy() - cp.QueueConfig = &queueConfig + retV := o.QueueConfig.DeepCopy() + cp.QueueConfig = &retV } return cp } diff --git a/common/types/shared_deepcopy.gen.go b/common/types/shared_deepcopy.gen.go index 9d01fc1e1d7..c0dbf7900a0 100644 --- a/common/types/shared_deepcopy.gen.go +++ b/common/types/shared_deepcopy.gen.go @@ -23,8 +23,7 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { cp.Configuration = new(DomainConfiguration) *cp.Configuration = *o.Configuration if o.Configuration.BadBinaries != nil { - badBinaries := o.Configuration.BadBinaries.DeepCopy() - cp.Configuration.BadBinaries = &badBinaries + cp.Configuration.BadBinaries = o.Configuration.BadBinaries.DeepCopy() } if o.Configuration.HistoryArchivalStatus != nil { cp.Configuration.HistoryArchivalStatus = new(ArchivalStatus) @@ -57,8 +56,7 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { } } if o.ReplicationConfiguration.ActiveClusters != nil { - activeClusters := o.ReplicationConfiguration.ActiveClusters.DeepCopy() - cp.ReplicationConfiguration.ActiveClusters = &activeClusters + cp.ReplicationConfiguration.ActiveClusters = o.ReplicationConfiguration.ActiveClusters.DeepCopy() } } if o.FailoverInfo != nil { From b69a76eaedf07e9c4b53de70a78cce61568c531a Mon Sep 17 00:00:00 2001 From: David Porter Date: Sun, 2 Nov 2025 15:42:35 -0800 Subject: [PATCH 4/5] WIP Signed-off-by: David Porter --- common/persistence/data_manager_interfaces.go | 7 ++++--- common/types/shared.go | 8 +++++++- common/types/shared_deepcopy.gen.go | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/common/persistence/data_manager_interfaces.go b/common/persistence/data_manager_interfaces.go index 222f0ab8018..61a6ca88a70 100644 --- a/common/persistence/data_manager_interfaces.go +++ b/common/persistence/data_manager_interfaces.go @@ -49,9 +49,6 @@ // execution metered wrapper is special //go:generate gowrap gen -g -p . -i ExecutionManager -t ./wrappers/templates/metered_execution.tmpl -o wrappers/metered/execution_generated.go -// Generate DeepCopy methods -//go:generate deep-copy -pointer-receiver -o ./data_manager_deepcopy.gen.go -type GetDomainResponse -type ClusterReplicationConfig . - package persistence import ( @@ -1162,6 +1159,8 @@ type ( ActiveClusters *types.ActiveClusters } + //go:generate deep-copy -pointer-receiver -o ./data_manager_deepcopy.gen.go -type ClusterReplicationConfig . + // ClusterReplicationConfig describes the cross DC cluster replication configuration ClusterReplicationConfig struct { ClusterName string @@ -1191,6 +1190,8 @@ type ( Name string } + //go:generate deep-copy -pointer-receiver -o ./data_manager_deepcopy.gen.go -type GetDomainResponse . + // GetDomainResponse is the response for GetDomain GetDomainResponse struct { Info *DomainInfo diff --git a/common/types/shared.go b/common/types/shared.go index 4c9da1967b2..a9fd32383c6 100644 --- a/common/types/shared.go +++ b/common/types/shared.go @@ -372,6 +372,8 @@ const ( ArchivalStatusEnabled ) +//go:generate deep-copy -o ./shared_deepcopy.gen.go -type BadBinaries . + // BadBinaries is an internal type (TBD...) type BadBinaries struct { Binaries map[string]*BadBinaryInfo `json:"binaries,omitempty"` @@ -962,6 +964,8 @@ func (v *CurrentBranchChangedError) GetCurrentBranchToken() (o []byte) { return } +//go:generate deep-copy -o ./shared_deepcopy.gen.go -type DataBlob . + // DataBlob is an internal type (TBD...) type DataBlob struct { EncodingType *EncodingType `json:"EncodingType,omitempty"` @@ -1685,7 +1689,7 @@ func (v *DescribeDomainRequest) GetUUID() (o string) { return } -//go:generate deep-copy -o ./shared_deepcopy.gen.go -type DescribeDomainResponse -type BadBinaries -type DataBlob -type ActiveClusters . +//go:generate deep-copy -o ./shared_deepcopy.gen.go -type DescribeDomainResponse . // DescribeDomainResponse is an internal type (TBD...) type DescribeDomainResponse struct { @@ -2481,6 +2485,8 @@ func (v *DomainReplicationConfiguration) ByteSize() uint64 { // }, // } // +//go:generate deep-copy -o ./shared_deepcopy.gen.go -type ActiveClusters . + // TODO(c-warren): Rename to ClusterAttributes type ActiveClusters struct { // ClusterAttributes diff --git a/common/types/shared_deepcopy.gen.go b/common/types/shared_deepcopy.gen.go index c0dbf7900a0..9d01fc1e1d7 100644 --- a/common/types/shared_deepcopy.gen.go +++ b/common/types/shared_deepcopy.gen.go @@ -23,7 +23,8 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { cp.Configuration = new(DomainConfiguration) *cp.Configuration = *o.Configuration if o.Configuration.BadBinaries != nil { - cp.Configuration.BadBinaries = o.Configuration.BadBinaries.DeepCopy() + badBinaries := o.Configuration.BadBinaries.DeepCopy() + cp.Configuration.BadBinaries = &badBinaries } if o.Configuration.HistoryArchivalStatus != nil { cp.Configuration.HistoryArchivalStatus = new(ArchivalStatus) @@ -56,7 +57,8 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { } } if o.ReplicationConfiguration.ActiveClusters != nil { - cp.ReplicationConfiguration.ActiveClusters = o.ReplicationConfiguration.ActiveClusters.DeepCopy() + activeClusters := o.ReplicationConfiguration.ActiveClusters.DeepCopy() + cp.ReplicationConfiguration.ActiveClusters = &activeClusters } } if o.FailoverInfo != nil { From 4dc113ba62a6c9a1b78d061efe64f90049ca1835 Mon Sep 17 00:00:00 2001 From: David Porter Date: Sun, 2 Nov 2025 18:32:42 -0800 Subject: [PATCH 5/5] WIP Signed-off-by: David Porter --- Makefile | 2 +- common/cache/domainCache.go | 3 +- common/domain/handler.go | 3 +- .../persistence/data_manager_deepcopy.gen.go | 8 ++-- common/types/admin_deepcopy.gen.go | 3 +- common/types/configStore.go | 6 +-- common/types/shared.go | 8 +--- common/types/shared_deepcopy.gen.go | 40 +++++++++---------- common/types/shared_test.go | 13 +++--- 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 2f69974349a..1276311c65a 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ $(BUILD)/proto-lint: $(BUILD)/gomod-lint: $(BUILD)/goversion-lint: $(BUILD)/fmt: $(BUILD)/codegen # formatting must occur only after all other go-file-modifications are done -# $(BUILD)/copyright +# $(BUILD)/copyright # $(BUILD)/copyright: $(BUILD)/codegen # must add copyright to generated code, sometimes needs re-formatting $(BUILD)/codegen: $(BUILD)/thrift $(BUILD)/protoc $(BUILD)/thrift: $(BUILD)/go_mod_check diff --git a/common/cache/domainCache.go b/common/cache/domainCache.go index 568feee3b6b..761968e76a7 100644 --- a/common/cache/domainCache.go +++ b/common/cache/domainCache.go @@ -762,8 +762,7 @@ func (entry *DomainCacheEntry) duplicate() *DomainCacheEntry { result.replicationConfig.Clusters = append(result.replicationConfig.Clusters, &c) } if entry.replicationConfig.ActiveClusters != nil { - activeClusters := entry.replicationConfig.ActiveClusters.DeepCopy() - result.replicationConfig.ActiveClusters = &activeClusters + result.replicationConfig.ActiveClusters = entry.replicationConfig.ActiveClusters.DeepCopy() } result.configVersion = entry.configVersion result.failoverVersion = entry.failoverVersion diff --git a/common/domain/handler.go b/common/domain/handler.go index 8a3735db634..cad8556bba3 100644 --- a/common/domain/handler.go +++ b/common/domain/handler.go @@ -841,8 +841,7 @@ func (d *handlerImpl) FailoverDomain( currentActiveCluster := replicationConfig.ActiveClusterName var currentActiveClusters *types.ActiveClusters if replicationConfig.ActiveClusters != nil { - currentActiveClustersCopy := replicationConfig.ActiveClusters.DeepCopy() - currentActiveClusters = ¤tActiveClustersCopy + currentActiveClusters = replicationConfig.ActiveClusters.DeepCopy() } previousFailoverVersion := getResponse.PreviousFailoverVersion lastUpdatedTime := time.Unix(0, getResponse.LastUpdatedTime) diff --git a/common/persistence/data_manager_deepcopy.gen.go b/common/persistence/data_manager_deepcopy.gen.go index 6cb6e073785..28d65f66883 100644 --- a/common/persistence/data_manager_deepcopy.gen.go +++ b/common/persistence/data_manager_deepcopy.gen.go @@ -18,7 +18,10 @@ func (o *GetDomainResponse) DeepCopy() *GetDomainResponse { if o.Config != nil { cp.Config = new(DomainConfig) *cp.Config = *o.Config - cp.Config.BadBinaries = o.Config.BadBinaries.DeepCopy() + { + retV := o.Config.BadBinaries.DeepCopy() + cp.Config.BadBinaries = *retV + } cp.Config.IsolationGroups = o.Config.IsolationGroups.DeepCopy() cp.Config.AsyncWorkflowConfig = o.Config.AsyncWorkflowConfig.DeepCopy() } @@ -35,8 +38,7 @@ func (o *GetDomainResponse) DeepCopy() *GetDomainResponse { } } if o.ReplicationConfig.ActiveClusters != nil { - retV := o.ReplicationConfig.ActiveClusters.DeepCopy() - cp.ReplicationConfig.ActiveClusters = &retV + cp.ReplicationConfig.ActiveClusters = o.ReplicationConfig.ActiveClusters.DeepCopy() } } if o.FailoverEndTime != nil { diff --git a/common/types/admin_deepcopy.gen.go b/common/types/admin_deepcopy.gen.go index 5f510d591bc..535cdb7409d 100644 --- a/common/types/admin_deepcopy.gen.go +++ b/common/types/admin_deepcopy.gen.go @@ -6,8 +6,7 @@ package types func (o AsyncWorkflowConfiguration) DeepCopy() AsyncWorkflowConfiguration { var cp AsyncWorkflowConfiguration = o if o.QueueConfig != nil { - retV := o.QueueConfig.DeepCopy() - cp.QueueConfig = &retV + cp.QueueConfig = o.QueueConfig.DeepCopy() } return cp } diff --git a/common/types/configStore.go b/common/types/configStore.go index 459eb48ec63..33d6bf26ec5 100644 --- a/common/types/configStore.go +++ b/common/types/configStore.go @@ -46,8 +46,7 @@ func (dcf *DynamicConfigFilter) Copy() *DynamicConfigFilter { } var valueCopy *DataBlob if dcf.Value != nil { - v := dcf.Value.DeepCopy() - valueCopy = &v + valueCopy = dcf.Value.DeepCopy() } return &DynamicConfigFilter{ Name: dcf.Name, @@ -70,8 +69,7 @@ func (dcv *DynamicConfigValue) Copy() *DynamicConfigValue { var valueCopy *DataBlob if dcv.Value != nil { - v := dcv.Value.DeepCopy() - valueCopy = &v + valueCopy = dcv.Value.DeepCopy() } return &DynamicConfigValue{ Value: valueCopy, diff --git a/common/types/shared.go b/common/types/shared.go index a9fd32383c6..eab678f4e6e 100644 --- a/common/types/shared.go +++ b/common/types/shared.go @@ -372,8 +372,6 @@ const ( ArchivalStatusEnabled ) -//go:generate deep-copy -o ./shared_deepcopy.gen.go -type BadBinaries . - // BadBinaries is an internal type (TBD...) type BadBinaries struct { Binaries map[string]*BadBinaryInfo `json:"binaries,omitempty"` @@ -964,8 +962,6 @@ func (v *CurrentBranchChangedError) GetCurrentBranchToken() (o []byte) { return } -//go:generate deep-copy -o ./shared_deepcopy.gen.go -type DataBlob . - // DataBlob is an internal type (TBD...) type DataBlob struct { EncodingType *EncodingType `json:"EncodingType,omitempty"` @@ -1689,7 +1685,7 @@ func (v *DescribeDomainRequest) GetUUID() (o string) { return } -//go:generate deep-copy -o ./shared_deepcopy.gen.go -type DescribeDomainResponse . +//go:generate deep-copy -pointer-receiver -o ./shared_deepcopy.gen.go -type DescribeDomainResponse -type BadBinaries -type DataBlob -type ActiveClusters . // DescribeDomainResponse is an internal type (TBD...) type DescribeDomainResponse struct { @@ -2485,8 +2481,6 @@ func (v *DomainReplicationConfiguration) ByteSize() uint64 { // }, // } // -//go:generate deep-copy -o ./shared_deepcopy.gen.go -type ActiveClusters . - // TODO(c-warren): Rename to ClusterAttributes type ActiveClusters struct { // ClusterAttributes diff --git a/common/types/shared_deepcopy.gen.go b/common/types/shared_deepcopy.gen.go index 9d01fc1e1d7..08ddf12e9b1 100644 --- a/common/types/shared_deepcopy.gen.go +++ b/common/types/shared_deepcopy.gen.go @@ -1,10 +1,10 @@ -// generated by deep-copy -o ./shared_deepcopy.gen.go -type DescribeDomainResponse -type BadBinaries -type DataBlob -type ActiveClusters .; DO NOT EDIT. +// generated by deep-copy -pointer-receiver -o ./shared_deepcopy.gen.go -type DescribeDomainResponse -type BadBinaries -type DataBlob -type ActiveClusters .; DO NOT EDIT. package types -// DeepCopy generates a deep copy of DescribeDomainResponse -func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { - var cp DescribeDomainResponse = o +// DeepCopy generates a deep copy of *DescribeDomainResponse +func (o *DescribeDomainResponse) DeepCopy() *DescribeDomainResponse { + var cp DescribeDomainResponse = *o if o.DomainInfo != nil { cp.DomainInfo = new(DomainInfo) *cp.DomainInfo = *o.DomainInfo @@ -23,8 +23,7 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { cp.Configuration = new(DomainConfiguration) *cp.Configuration = *o.Configuration if o.Configuration.BadBinaries != nil { - badBinaries := o.Configuration.BadBinaries.DeepCopy() - cp.Configuration.BadBinaries = &badBinaries + cp.Configuration.BadBinaries = o.Configuration.BadBinaries.DeepCopy() } if o.Configuration.HistoryArchivalStatus != nil { cp.Configuration.HistoryArchivalStatus = new(ArchivalStatus) @@ -57,8 +56,7 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { } } if o.ReplicationConfiguration.ActiveClusters != nil { - activeClusters := o.ReplicationConfiguration.ActiveClusters.DeepCopy() - cp.ReplicationConfiguration.ActiveClusters = &activeClusters + cp.ReplicationConfiguration.ActiveClusters = o.ReplicationConfiguration.ActiveClusters.DeepCopy() } } if o.FailoverInfo != nil { @@ -69,12 +67,12 @@ func (o DescribeDomainResponse) DeepCopy() DescribeDomainResponse { copy(cp.FailoverInfo.PendingShards, o.FailoverInfo.PendingShards) } } - return cp + return &cp } -// DeepCopy generates a deep copy of BadBinaries -func (o BadBinaries) DeepCopy() BadBinaries { - var cp BadBinaries = o +// DeepCopy generates a deep copy of *BadBinaries +func (o *BadBinaries) DeepCopy() *BadBinaries { + var cp BadBinaries = *o if o.Binaries != nil { cp.Binaries = make(map[string]*BadBinaryInfo, len(o.Binaries)) for k2, v2 := range o.Binaries { @@ -90,12 +88,12 @@ func (o BadBinaries) DeepCopy() BadBinaries { cp.Binaries[k2] = cp_Binaries_v2 } } - return cp + return &cp } -// DeepCopy generates a deep copy of DataBlob -func (o DataBlob) DeepCopy() DataBlob { - var cp DataBlob = o +// DeepCopy generates a deep copy of *DataBlob +func (o *DataBlob) DeepCopy() *DataBlob { + var cp DataBlob = *o if o.EncodingType != nil { cp.EncodingType = new(EncodingType) *cp.EncodingType = *o.EncodingType @@ -104,12 +102,12 @@ func (o DataBlob) DeepCopy() DataBlob { cp.Data = make([]byte, len(o.Data)) copy(cp.Data, o.Data) } - return cp + return &cp } -// DeepCopy generates a deep copy of ActiveClusters -func (o ActiveClusters) DeepCopy() ActiveClusters { - var cp ActiveClusters = o +// DeepCopy generates a deep copy of *ActiveClusters +func (o *ActiveClusters) DeepCopy() *ActiveClusters { + var cp ActiveClusters = *o if o.AttributeScopes != nil { cp.AttributeScopes = make(map[string]ClusterAttributeScope, len(o.AttributeScopes)) for k2, v2 := range o.AttributeScopes { @@ -123,5 +121,5 @@ func (o ActiveClusters) DeepCopy() ActiveClusters { cp.AttributeScopes[k2] = cp_AttributeScopes_v2 } } - return cp + return &cp } diff --git a/common/types/shared_test.go b/common/types/shared_test.go index c4b180bc0e1..8d040e384df 100644 --- a/common/types/shared_test.go +++ b/common/types/shared_test.go @@ -63,11 +63,12 @@ func TestDataBlobDeepCopy(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { if tc.input == nil { - // Cannot call DeepCopy on nil with value receiver + // Cannot call DeepCopy on nil with pointer receiver return } got := tc.input.DeepCopy() - assert.Equal(t, *tc.input, got) + assert.Equal(t, tc.input, got) + assert.True(t, tc.input != got, "DeepCopy should return a different pointer") if tc.input.Data != nil && identicalByteArray(tc.input.Data, got.Data) { t.Error("expected DeepCopy to return a new data slice") } @@ -127,16 +128,17 @@ func TestActiveClustersConfigDeepCopy(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { if tc.input == nil { - // Cannot call DeepCopy on nil with value receiver + // Cannot call DeepCopy on nil with pointer receiver if tc.expect != nil { t.Errorf("expected nil but got %+v", tc.expect) } return } deepCopy := tc.input.DeepCopy() - if diff := cmp.Diff(*tc.expect, deepCopy); diff != "" { + if diff := cmp.Diff(tc.expect, deepCopy); diff != "" { t.Errorf("DeepCopy() mismatch (-want +got):\n%s", diff) } + assert.True(t, tc.input != deepCopy, "DeepCopy should return a different pointer") }) } } @@ -160,7 +162,8 @@ func TestActiveClustersDeepCopyMutationIsolation(t *testing.T) { copied := original.DeepCopy() - assert.Equal(t, *original, copied) + assert.Equal(t, original, copied) + assert.True(t, original != copied, "DeepCopy should return a different pointer") scope := original.AttributeScopes["region"] scope.ClusterAttributes["us-west-1"] = ActiveClusterInfo{