Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

support updating zone configs for multi-zone dest and cg #218

Merged
merged 6 commits into from
Jun 8, 2017
Merged

Conversation

datoug
Copy link
Contributor

@datoug datoug commented Jun 2, 2017

This patch adds support for upgrading a regular destination or consumer group to a multi-zone one.
related thrift change in: uber-archive/cherami-thrift#23

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 332d4ea on mz_upgrade into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 15995f0 on mz_upgrade into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 15995f0 on mz_upgrade into ** on master**.

Copy link
Contributor

@kirg kirg left a comment

Choose a reason for hiding this comment

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

The changes look okay to me .. just some minor comments.

Also, as discussed, you might want to do the cross-zone validations in CreateDestination too. Do you want to add a "TODO" in code perhaps, if you are planning to take care of this at a later point?

if !updateRequest.IsSetZoneConfigs() {
updateRequest.ZoneConfigs = existing.GetZoneConfigs()
} else {
isMultiZone = true
Copy link
Contributor

Choose a reason for hiding this comment

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

So if zone-configs are specified, then this is assumed to be multi-zone? Couldn't we set (one) zone-config for a non-multi-zone destination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, we disallow single zone config in CLI part. Zone config(s) are designed for multi-zone only.

if req.IsSetZoneConfigs() && !common.AreCgZoneConfigsEqual(cgDesc.GetZoneConfigs(), req.GetZoneConfigs()) {
isChanged = true
cgDesc.ZoneConfigs = req.GetZoneConfigs()
cgDesc.IsMultiZone = common.BoolPtr(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the same assumption here .. if even one zone-config is set, then it is multi-zone?

common/util.go Outdated
zone := l.GetZone()
foundMatch := false
for _, r := range right {
if r.GetZone() == zone {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do a case-insensitive compare here?

Copy link
Contributor

Choose a reason for hiding this comment

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

btw, another way to do this would obviously be to do run through one of the slices and put it into a map; and then run through the other while looking up against the map. but i guess the zone-config list would be really small to make a difference between O(n^2) vs O(n)?

common/util.go Outdated
zone := l.GetZone()
foundMatch := false
for _, r := range right {
if r.GetZone() == zone {
Copy link
Contributor

Choose a reason for hiding this comment

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

case-insensitive compare?

})
if err == nil {
// path exists in remote. If uuid is different, then fail the validation
if remoteDest.GetDestinationUUID() != updateRequest.GetDestinationUUID() {
Copy link
Contributor

Choose a reason for hiding this comment

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

do you want to add a TODO .. that perhaps we could support this scenario eventually (of tying in two destinations with different UUIDs across zones)?

// path exists in remote. If uuid is different, then fail the validation
if remoteDest.GetDestinationUUID() != updateRequest.GetDestinationUUID() {
logger.WithField(common.TagZoneName, common.FmtZoneName(zoneConfig.GetZone())).Error(`destination exists in remote but UUID is different`)
return false, 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 might be good to return an error (instead of 'nil').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually in caller we check if there's any error. If not (and validation fails), we return BadRequestError

Copy link
Contributor

Choose a reason for hiding this comment

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

i do see that .. but this is bug-prone. typically/canonically, the code should always check the error-code and only if it is non-nil look at the 'value' returned.

// cg exists in remote. If uuid is different, then fail the validation
if remoteCg.GetDestinationUUID() != cgDesc.GetDestinationUUID() || remoteCg.GetConsumerGroupUUID() != cgDesc.GetConsumerGroupUUID() {
logger.WithField(common.TagZoneName, common.FmtZoneName(zoneConfig.GetZone())).Error(`cg exists in remote but UUID is different`)
return false, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return an error, instead of 'nil'?

@@ -1251,3 +1279,97 @@ func (mcp *Mcp) CreateRemoteZoneConsumerGroupExtent(ctx thrift.Context, createRe
lclLg.Info("CreateRemoteZoneConsumerGroupExtent: Extent added to consumer group")
return nil
}

// ValidateDestZoneConfigUpdateRequest validates the zone configs for a UpdateDestinationRequest
func (mcp *Mcp) ValidateDestZoneConfigUpdateRequest(ctx thrift.Context, logger bark.Logger, updateRequest *shared.UpdateDestinationRequest) (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.

I presume you want to name this to not have "update" in it's name .. since you will be probably calling the exact same function from the CreateDestination path too.

}

// ValidateCgZoneConfigUpdateRequest validates the zone configs for a UpdateConsumerGroupRequest
func (mcp *Mcp) ValidateCgZoneConfigUpdateRequest(ctx thrift.Context, logger bark.Logger, updateRequest *shared.UpdateConsumerGroupRequest) (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.

as with 'ValidateDestZoneConfigUpdateRequest', this could get called from the CreateDestination path too, right?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1556cbe on mz_upgrade into ** on master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1556cbe on mz_upgrade into ** on master**.

@datoug datoug merged commit d67f58e into master Jun 8, 2017
@datoug datoug deleted the mz_upgrade branch June 8, 2017 20:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants