Skip to content

Commit fdd2f80

Browse files
active-active prototyping
1 parent 2c2a590 commit fdd2f80

File tree

97 files changed

+1213
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1213
-291
lines changed

Diff for: common/activecluster/manager.go

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// The MIT License (MIT)
2+
3+
// Copyright (c) 2017-2020 Uber Technologies Inc.
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
package activecluster
24+
25+
import (
26+
"context"
27+
"errors"
28+
29+
"github.com/uber/cadence/common/cache"
30+
"github.com/uber/cadence/common/cluster"
31+
"github.com/uber/cadence/common/log"
32+
"github.com/uber/cadence/common/log/tag"
33+
"github.com/uber/cadence/common/metrics"
34+
"github.com/uber/cadence/common/types"
35+
)
36+
37+
type DomainIDToDomainFn func(id string) (*cache.DomainCacheEntry, error)
38+
39+
type manager struct {
40+
domainIDToDomainFn DomainIDToDomainFn
41+
clusterMetadata cluster.Metadata
42+
metricsCl metrics.Client
43+
logger log.Logger
44+
}
45+
46+
func NewManager(
47+
domainIDToDomainFn DomainIDToDomainFn,
48+
clusterMetadata cluster.Metadata,
49+
metricsCl metrics.Client,
50+
logger log.Logger,
51+
) Manager {
52+
return &manager{
53+
domainIDToDomainFn: domainIDToDomainFn,
54+
clusterMetadata: clusterMetadata,
55+
metricsCl: metricsCl,
56+
logger: logger.WithTags(tag.ComponentActiveRegionManager),
57+
}
58+
}
59+
60+
func (m *manager) Start() {
61+
// TODO: implement this
62+
}
63+
64+
func (m *manager) Stop() {
65+
// TODO: implement this
66+
}
67+
68+
func (m *manager) LookupExternalEntity(ctx context.Context, entityType, entityKey string) (*LookupResult, error) {
69+
// TODO: implement this
70+
return nil, errors.New("not implemented")
71+
}
72+
73+
func (m *manager) LookupExternalEntityOfNewWorkflow(ctx context.Context, req *types.HistoryStartWorkflowExecutionRequest) (*LookupResult, error) {
74+
d, err := m.domainIDToDomainFn(req.DomainUUID)
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
if !d.GetReplicationConfig().IsActiveActive() {
80+
// Not an active-active domain. return ActiveClusterName from domain entry
81+
return &LookupResult{
82+
Region: d.GetReplicationConfig().ActiveClusterName,
83+
ClusterName: d.GetReplicationConfig().ActiveClusterName,
84+
FailoverVersion: d.GetFailoverVersion(),
85+
}, nil
86+
}
87+
88+
wfID := req.StartRequest.WorkflowID
89+
return helperToBeRemoved(wfID)
90+
}
91+
92+
func (m *manager) LookupWorkflow(ctx context.Context, domainID, wfID, rID string) (*LookupResult, error) {
93+
d, err := m.domainIDToDomainFn(domainID)
94+
if err != nil {
95+
return nil, err
96+
}
97+
98+
if !d.GetReplicationConfig().IsActiveActive() {
99+
// Not an active-active domain. return ActiveClusterName from domain entry
100+
return &LookupResult{
101+
Region: d.GetReplicationConfig().ActiveClusterName,
102+
ClusterName: d.GetReplicationConfig().ActiveClusterName,
103+
FailoverVersion: d.GetFailoverVersion(),
104+
}, nil
105+
}
106+
107+
return helperToBeRemoved(wfID)
108+
}
109+
110+
func helperToBeRemoved(wfID string) (*LookupResult, error) {
111+
// TODO: Remove below fake implementation and implement properly
112+
// - lookup active region given <domain id, wf id, run id> from executions table RowType=ActiveCluster.
113+
// - cache this info
114+
// - add metrics for cache hit/miss
115+
// - return cluster name
116+
if wfID == "wf1" {
117+
return &LookupResult{
118+
Region: "cluster0",
119+
ClusterName: "cluster0",
120+
FailoverVersion: 1,
121+
}, nil
122+
}
123+
if wfID == "wf2" {
124+
return &LookupResult{
125+
Region: "cluster1",
126+
ClusterName: "cluster1",
127+
FailoverVersion: 2,
128+
}, nil
129+
}
130+
131+
return nil, errors.New("not implemented")
132+
}

Diff for: common/activecluster/manager_mock.go

+134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: common/activecluster/types.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// The MIT License (MIT)
2+
3+
// Copyright (c) 2017-2020 Uber Technologies Inc.
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
package activecluster
24+
25+
import (
26+
"context"
27+
28+
"github.com/uber/cadence/common"
29+
"github.com/uber/cadence/common/types"
30+
)
31+
32+
//go:generate mockgen -package $GOPACKAGE -destination manager_mock.go -self_package github.com/uber/cadence/common/activecluster github.com/uber/cadence/common/activecluster Manager
33+
34+
type LookupResult struct {
35+
Region string
36+
ClusterName string
37+
FailoverVersion int64
38+
}
39+
40+
type Manager interface {
41+
common.Daemon
42+
43+
// LookupExternalEntity returns active cluster, cluster name and failover version of given external entity.
44+
// Only active-active global domains can have external entities.
45+
// For each entity type, there must be a corresponding watcher populating EntityActiveRegion table.
46+
// LookupExternalEntity will return the active cluster name and failover version by checking EntityActiveRegion table.
47+
LookupExternalEntity(ctx context.Context, entityType, entityKey string) (*LookupResult, error)
48+
49+
// LookupExternalEntityOfNewWorkflow returns active cluster, cluster name and failover version of given new workflow.
50+
// Exactly same as LookupExternalEntity except it extracts entityType and entityKey from the start request.
51+
LookupExternalEntityOfNewWorkflow(ctx context.Context, req *types.HistoryStartWorkflowExecutionRequest) (*LookupResult, error)
52+
53+
// LookupWorkflow returns active cluster, cluster name and failover version of given workflow.
54+
// 1. If domain is local:
55+
// Returns current cluster name and domain entry's failover version.
56+
// 2. If domain is active-passive global:
57+
// Returns domain entry's ActiveClusterName and domain entry's failover version.
58+
// 3. If domain is active-active global:
59+
// Returns corresponding active cluster name and failover version by checking workflow's activeness metadata and EntityActiveRegion lookup table.
60+
LookupWorkflow(ctx context.Context, domainID, wfID, rID string) (*LookupResult, error)
61+
}

0 commit comments

Comments
 (0)