Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple domain cache entry from cluster metadata #4847

Conversation

vytautas-karpavicius
Copy link
Contributor

@vytautas-karpavicius vytautas-karpavicius commented May 26, 2022

What changed?

  • Decoupled cache.DomainCacheEntry from cluster.Metadata

Why?
cluster.Metadata was used solely to check whether domain is active. This can be done by simply passing current cluster as a parameter. Decoupling domain entry simplifies code & testing.

How did you test it?
Existing tests and new units tests covering moved out functions.

Potential risks

Release notes

Documentation Changes

@vytautas-karpavicius vytautas-karpavicius requested a review from a team May 26, 2022 10:36
@vytautas-karpavicius vytautas-karpavicius marked this pull request as ready for review May 26, 2022 10:37
@coveralls
Copy link

coveralls commented May 26, 2022

Pull Request Test Coverage Report for Build 0181050a-5e52-478c-a51f-e740fe09b1ee

  • 92 of 98 (93.88%) changed or added relevant lines in 10 files are covered.
  • 86 unchanged lines in 15 files lost coverage.
  • Overall coverage increased (+0.02%) to 56.855%

Changes Missing Coverage Covered Lines Changed/Added Lines %
service/history/historyEngine.go 20 22 90.91%
service/history/shard/context.go 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
common/cache/domainCache.go 1 88.48%
common/task/weightedRoundRobinTaskScheduler.go 1 89.64%
service/history/execution/mutable_state_task_refresher.go 1 73.42%
common/peerprovider/ringpopprovider/config.go 2 81.58%
common/task/fifoTaskScheduler.go 2 85.57%
common/util.go 2 51.17%
service/history/task/transfer_active_task_executor.go 2 71.55%
common/cache/lru.go 3 90.73%
common/persistence/nosql/nosqlplugin/cassandra/workflow.go 3 57.59%
service/history/queue/cross_cluster_queue_processor_base.go 4 66.73%
Totals Coverage Status
Change from base Build 0181050a-15f3-4383-9621-b7e299cb4edd: 0.02%
Covered Lines: 83941
Relevant Lines: 147641

💛 - Coveralls

@@ -157,7 +150,6 @@ func NewDomainCache(
cacheNameToID: &atomic.Value{},
cacheByID: &atomic.Value{},
domainManager: domainManager,
clusterMetadata: clusterMetadata,
timeSource: clock.NewRealTimeSource(),
metricsClient: metricsClient,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you are here... can you replace metricsClient with scope?

Something like this: scope := c.metricsClient.Scope(metrics.DomainCacheScope)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

func newDomainCacheEntry(
clusterMetadata cluster.Metadata,
) *DomainCacheEntry {
func newDomainCacheEntry() *DomainCacheEntry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this function is noop? Consider to remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, no longer needed


return &DomainCacheEntry{
clusterMetadata: clusterMetadata,
initialized: false,
initialized: false,
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's for tests only, maybe it is worth to add *testing.T as a first arg and/or move to test file?

@@ -127,7 +122,6 @@ type (

// DomainCacheEntry contains the info and config for a domain
DomainCacheEntry struct {
clusterMetadata cluster.Metadata
sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to keep mutex public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not. Made private.


// IsActive return whether the domain is active, i.e. non global domain or global domain which active cluster is the current cluster
// If domain is not active, it also returns an error
func IsActive(domain *cache.DomainCacheEntry, cluster cluster.Metadata) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of thoughts to consider:

  • Cluster metadata is not strictly needed here, only cluster name
  • I would go with struct method: DomainCacheEntry.IsActiveIn(cluster string)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, I like it much better this way! 👍

return true, nil
}

func GetActiveDomainByID(cache cache.DomainCache, cluster cluster.Metadata, id string) (*cache.DomainCacheEntry, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: id -> domainID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -791,7 +792,7 @@ func (r *mutableStateTaskGeneratorImpl) GenerateFromCrossClusterTask(
var targetCluster string

sourceDomainEntry := r.mutableState.GetDomainEntry()
if !sourceDomainEntry.IsDomainActive() && !sourceDomainEntry.IsDomainPendingActive() {
if isActive, _ := domain.IsActive(sourceDomainEntry, r.clusterMetadata); !isActive && !sourceDomainEntry.IsDomainPendingActive() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are skipping err check here because you need implementation details?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need error here. Both GetNotActiveErr and IsActive are now combined into one function. The error part is not relevant here.

newEntry.notificationVersion = record.NotificationVersion
newEntry.initialized = true
return newEntry
return &DomainCacheEntry{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so much better

@vytautas-karpavicius vytautas-karpavicius merged commit d6ae278 into uber:master May 27, 2022
@vytautas-karpavicius vytautas-karpavicius deleted the decouple-cluster-metadata branch May 27, 2022 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants