Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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) ./...
Expand Down
4 changes: 3 additions & 1 deletion common/cache/domainCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ 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 {
result.replicationConfig.ActiveClusters = entry.replicationConfig.ActiveClusters.DeepCopy()
}
result.configVersion = entry.configVersion
result.failoverVersion = entry.failoverVersion
result.isGlobalDomain = entry.isGlobalDomain
Expand Down
5 changes: 4 additions & 1 deletion common/domain/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,10 @@ 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 {
currentActiveClusters = replicationConfig.ActiveClusters.DeepCopy()
}
previousFailoverVersion := getResponse.PreviousFailoverVersion
lastUpdatedTime := time.Unix(0, getResponse.LastUpdatedTime)

Expand Down
55 changes: 55 additions & 0 deletions common/persistence/data_manager_deepcopy.gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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
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
{
retV := o.Config.BadBinaries.DeepCopy()
cp.Config.BadBinaries = *retV
}
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 {
cp.ReplicationConfig.Clusters[i4] = o.ReplicationConfig.Clusters[i4].DeepCopy()
}
}
}
if o.ReplicationConfig.ActiveClusters != nil {
cp.ReplicationConfig.ActiveClusters = o.ReplicationConfig.ActiveClusters.DeepCopy()
}
}
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
}
89 changes: 4 additions & 85 deletions common/persistence/data_manager_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,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
Expand Down Expand Up @@ -1188,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
Expand Down Expand Up @@ -2072,91 +2076,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 {
result.ReplicationConfig.ActiveClusters = r.ReplicationConfig.ActiveClusters.DeepCopy()
}
}

return result
}

// DBTimestampToUnixNano converts Milliseconds timestamp to UnixNano
func DBTimestampToUnixNano(milliseconds int64) int64 {
Expand Down
10 changes: 8 additions & 2 deletions common/persistence/data_manager_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -115,6 +116,11 @@ 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)
})
Expand Down
13 changes: 2 additions & 11 deletions common/types/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,24 +428,15 @@ type GetDomainAsyncWorkflowConfiguratonResponse struct {
Configuration *AsyncWorkflowConfiguration
}

//go:generate deep-copy -o ./admin_deepcopy.gen.go -type AsyncWorkflowConfiguration .

type AsyncWorkflowConfiguration struct {
Enabled bool
PredefinedQueueName string
QueueType string
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 {
Expand Down
12 changes: 12 additions & 0 deletions common/types/admin_deepcopy.gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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 {
cp.QueueConfig = o.QueueConfig.DeepCopy()
}
return cp
}
12 changes: 10 additions & 2 deletions common/types/configStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ func (dcf *DynamicConfigFilter) Copy() *DynamicConfigFilter {
if dcf == nil {
return nil
}
var valueCopy *DataBlob
if dcf.Value != nil {
valueCopy = dcf.Value.DeepCopy()
}
return &DynamicConfigFilter{
Name: dcf.Name,
Value: dcf.Value.DeepCopy(),
Value: valueCopy,
}
}

Expand All @@ -63,8 +67,12 @@ func (dcv *DynamicConfigValue) Copy() *DynamicConfigValue {
}
}

var valueCopy *DataBlob
if dcv.Value != nil {
valueCopy = dcv.Value.DeepCopy()
}
return &DynamicConfigValue{
Value: dcv.Value.DeepCopy(),
Value: valueCopy,
Filters: newFilters,
}
}
Expand Down
Loading
Loading