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

Commit

Permalink
update is_multi_zone field in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
datoug committed Jun 12, 2017
1 parent b7cadd7 commit f8b1f90
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clients/metadata/metadata_cassandra.go
Expand Up @@ -371,6 +371,7 @@ const (

sqlUpdateDstByUUID = `UPDATE ` + tableDestinations + ` SET ` +
columnDestination + `=` + sqlDstType +
`, ` + columnIsMultiZone + ` = ? ` +
` WHERE ` + columnUUID + `=?`

sqlUpdateDstDLQCursors = `UPDATE ` + tableDestinations + ` SET ` +
Expand All @@ -380,6 +381,7 @@ const (

sqlUpdateDstByPath = `UPDATE ` + tableDestinationsByPath + ` SET ` +
columnDestination + `=` + sqlDstType +
`, ` + columnIsMultiZone + ` = ? ` +
` WHERE ` + columnPath + `=? and ` + columnDirectoryUUID + `=?`

sqlDeleteDst = `DELETE FROM ` + tableDestinationsByPath +
Expand Down Expand Up @@ -746,6 +748,7 @@ func (s *CassandraMetadataService) UpdateDestination(ctx thrift.Context, updateR
updateRequest.GetChecksumOption(),
isMultiZone,
marshalDstZoneConfigs(updateRequest.GetZoneConfigs()),
isMultiZone,
updateRequest.GetDestinationUUID())

batch.Query(
Expand All @@ -760,6 +763,7 @@ func (s *CassandraMetadataService) UpdateDestination(ctx thrift.Context, updateR
updateRequest.GetChecksumOption(),
isMultiZone,
marshalDstZoneConfigs(updateRequest.GetZoneConfigs()),
isMultiZone,
existing.GetPath(),
directoryUUID)

Expand Down Expand Up @@ -829,6 +833,7 @@ func (s *CassandraMetadataService) DeleteDestination(ctx thrift.Context, deleteR
existing.GetChecksumOption(),
existing.GetIsMultiZone(),
marshalDstZoneConfigs(existing.GetZoneConfigs()),
existing.GetIsMultiZone(),
existing.GetDestinationUUID())
batch.Query(sqlDeleteDst, directoryUUID, existing.GetPath())
if err = s.session.ExecuteBatch(batch); err != nil {
Expand Down Expand Up @@ -1705,6 +1710,7 @@ func (s *CassandraMetadataService) DeleteConsumerGroup(ctx thrift.Context, reque
dlqDstDesc.GetChecksumOption(),
dlqDstDesc.IsMultiZone,
marshalDstZoneConfigs(dlqDstDesc.ZoneConfigs),
dlqDstDesc.IsMultiZone,
dlqDstDesc.GetDestinationUUID())
}

Expand Down
28 changes: 28 additions & 0 deletions services/controllerhost/controllerhost_test.go
Expand Up @@ -1108,6 +1108,10 @@ func (s *McpSuite) TestMultiZoneDestConfigUpdate() {
Path: common.StringPtr(destPath),
IsMultiZone: common.BoolPtr(false),
}
listReq := &shared.ListDestinationsByUUIDRequest{
MultiZoneOnly: common.BoolPtr(true),
ValidateAgainstPathTable: common.BoolPtr(true),
}

// issue create request
destDesc, err := s.mcp.CreateDestination(nil, createReq)
Expand All @@ -1124,6 +1128,9 @@ func (s *McpSuite) TestMultiZoneDestConfigUpdate() {
s.NotNil(destDesc)
s.Equal(destPath, destDesc.GetPath())
s.False(destDesc.GetIsMultiZone())
listRes, err := s.mClient.ListDestinationsByUUID(nil, listReq)
s.NoError(err)
s.False(ListDestResultContains(listRes, destUUID))

/*********update to a multi-zone destination, expect to fail because path exists in remote but uuid is different*****************/
var zoneConfigs []*shared.DestinationZoneConfig
Expand Down Expand Up @@ -1153,6 +1160,9 @@ func (s *McpSuite) TestMultiZoneDestConfigUpdate() {
s.Error(err)
assert.IsType(s.T(), &shared.BadRequestError{}, err)
s.Nil(destDesc)
listRes, err = s.mClient.ListDestinationsByUUID(nil, listReq)
s.NoError(err)
s.False(ListDestResultContains(listRes, destUUID))

/*********update to a multi-zone destination, expect to fail because ReadDestinationInRemoteZone returns an random error*****************/
// ReadDestinationInRemoteZone returns a random error
Expand All @@ -1165,6 +1175,9 @@ func (s *McpSuite) TestMultiZoneDestConfigUpdate() {
destDesc, err = s.mcp.UpdateDestination(nil, updateReq)
s.Error(err)
s.Nil(destDesc)
listRes, err = s.mClient.ListDestinationsByUUID(nil, listReq)
s.NoError(err)
s.False(ListDestResultContains(listRes, destUUID))

/*********update to a multi-zone destination, expect to succeed (same uuid exists in remote already)*****************/
// uuid exists in remote already
Expand Down Expand Up @@ -1197,6 +1210,9 @@ func (s *McpSuite) TestMultiZoneDestConfigUpdate() {
s.Equal(destPath, destDesc.GetPath())
s.True(common.AreDestinationZoneConfigsEqual(zoneConfigs, destDesc.GetZoneConfigs()))
s.True(destDesc.GetIsMultiZone())
listRes, err = s.mClient.ListDestinationsByUUID(nil, listReq)
s.NoError(err)
s.True(ListDestResultContains(listRes, destUUID))

/*********update to a multi-zone destination, expect to succeed (path doesn't exist in remote)*****************/
zoneConfigs[0].AllowConsume = common.BoolPtr(!zoneConfigs[0].GetAllowConsume()) // flip some config
Expand Down Expand Up @@ -1229,6 +1245,18 @@ func (s *McpSuite) TestMultiZoneDestConfigUpdate() {
s.Equal(destPath, destDesc.GetPath())
s.True(common.AreDestinationZoneConfigsEqual(zoneConfigs, destDesc.GetZoneConfigs()))
s.True(destDesc.GetIsMultiZone())
listRes, err = s.mClient.ListDestinationsByUUID(nil, listReq)
s.NoError(err)
s.True(ListDestResultContains(listRes, destUUID))
}

func ListDestResultContains(result *shared.ListDestinationsResult_, uuid string) bool {
for _, dest := range result.GetDestinations() {
if dest.GetDestinationUUID() == uuid {
return true
}
}
return false
}

func (s *McpSuite) TestCreateConsumerGroup() {
Expand Down

0 comments on commit f8b1f90

Please sign in to comment.