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

refactor existing domain API for cross DC, refactor existing domain p… #527

Merged
merged 6 commits into from
Feb 1, 2018

Conversation

wxing1292
Copy link
Contributor

@wxing1292 wxing1292 commented Jan 25, 2018

…ersistence layer, refactor existing domain cache

solve #493 #495

…ersistence layer, refactor existing domain cache
var config *persistence.DomainConfig
var result *domainCacheEntry

copyEntry := func(input *domainCacheEntry) *domainCacheEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better if put copyEntry and isCacheExpired outside? (to save some cycles on definition)

Message: fmt.Sprintf("GetDomain operation failed. Error %v", err),
}
}

domainName := request.Name
if len(request.ID) > 0 {
query = m.session.Query(templateGetDomainQuery, request.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this change will lead to an additional call to get domain info. Why we cannot get all info with 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.

Cassandra do not support conditional update to multiple table.
Previously, we were using batch query to atomically update 2 tables, which (in my opinion) is an overkill, and cause a lot of unnecessary load on Cassandra.
This change will use the domains table just for domain uuid -> domain name lookup.
The actual content will be in domain_by_name table.

There will be additional call to Cassandra, but we have cache, and most of time, we do get, not update


func (config *ClusterReplicationConfig) serialize() map[string]interface{} {
output := make(map[string]interface{})
output["cluster_name"] = config.ClusterName
Copy link
Contributor

Choose a reason for hiding this comment

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

make cluster_name a const probably

@coveralls
Copy link

coveralls commented Jan 26, 2018

Coverage Status

Coverage increased (+0.7%) to 68.426% when pulling 5215d47 on cross-dc-API into 051f9de on master.

@@ -749,17 +759,22 @@ struct DescribeDomainRequest {
struct DescribeDomainResponse {
10: optional DomainInfo domainInfo
20: optional DomainConfiguration configuration
30: optional DomainReplicationConfiguration replicationConfiguration
40: optional i64 (js.type = "Long") failoverVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why failoverVersion is not within DomainReplicationConfiguration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the failover cannot be modified by customer and DomainReplicationConfiguration is used for update API


if !applied || err != nil {
// Domain already exist. Delete orphan domain record before returning back to user
if errDelete := m.session.Query(templateDeleteDomainQuery, domainUUID).Exec(); errDelete != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is dangerous to delete the domain on any errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the create API, and existing logic does the same thing, except existing logic have bug dealing with second create call to Cassandra having errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

replicationConfig.ActiveClusterName = m.clusterMetadata.GetOrUseDefaultActiveCluster(replicationConfig.ActiveClusterName)
for index := range replicationClusters {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this out to a helper method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

}, nil
}

func (m *cassandraMetadataPersistence) UpdateDomain(request *UpdateDomainRequest) error {
batch := m.session.NewBatch(gocql.LoggedBatch)
clusterReplicationConfigs := []map[string]interface{}{}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to create some helpers around dealing with replicationConfigs to make the code easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok


type (
// ClusterMetadata provides information about clusters
ClusterMetadata interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Define the interface in dataInterfaces.go and use the same naming convention we use for other persistence API.


type (
// ClusterMetadata provides information about clusters
ClusterMetadata interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I'm not sure if this even belongs in the persistence layer. Let's talk about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the thing is, this originally belongs to common package, until go compiler complains about circular reference between its package and persistence package

@wxing1292 wxing1292 merged commit 1a9baeb into master Feb 1, 2018
@wxing1292 wxing1292 deleted the cross-dc-API branch February 1, 2018 02:39
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