Skip to content

Commit

Permalink
watch prev
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 14, 2023
1 parent 7044b63 commit 4609029
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
}
var watchChannel chan []*meta_storagepb.Event
if !c.ruConfig.isSingleGroupByKeyspace {
// Use WithPrevKV() to get the previous key-value pair when get Delete Event.
watchChannel, err = c.provider.Watch(ctx, pd.GroupSettingsPathPrefixBytes, pd.WithRev(revision), pd.WithPrefix(), pd.WithPrevKV())
}
watchRetryTimer := time.NewTimer(watchRetryInterval)
Expand Down Expand Up @@ -293,10 +294,13 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
if err := proto.Unmarshal(item.PrevKv.Value, group); err != nil {
continue

Check warning on line 295 in client/resource_group/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

client/resource_group/controller/controller.go#L293-L295

Added lines #L293 - L295 were not covered by tests
}
log.Info("delete resource group", zap.String("name", group.Name))
if _, ok := c.groupsController.LoadAndDelete(group.Name); ok {
resourceGroupStatusGauge.DeleteLabelValues(group.Name)

Check warning on line 298 in client/resource_group/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

client/resource_group/controller/controller.go#L297-L298

Added lines #L297 - L298 were not covered by tests
}
} else {
// Prev-kv is compacted means there must have been a delete event before this event,
// which means that this is just a duplicated event, so we can just ignore it.
log.Info("previous key-value pair has been compacted", zap.String("previous key", string(item.Kv.Key)))
}
}
}
Expand Down

0 comments on commit 4609029

Please sign in to comment.