From 4609029852399ff14a78949b9b757234115d9d33 Mon Sep 17 00:00:00 2001 From: husharp Date: Thu, 14 Sep 2023 14:54:24 +0800 Subject: [PATCH] watch prev Signed-off-by: husharp --- client/resource_group/controller/controller.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/resource_group/controller/controller.go b/client/resource_group/controller/controller.go index ff7c39df19f..27380cc4c12 100755 --- a/client/resource_group/controller/controller.go +++ b/client/resource_group/controller/controller.go @@ -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) @@ -293,10 +294,13 @@ func (c *ResourceGroupsController) Start(ctx context.Context) { if err := proto.Unmarshal(item.PrevKv.Value, group); err != nil { continue } - log.Info("delete resource group", zap.String("name", group.Name)) if _, ok := c.groupsController.LoadAndDelete(group.Name); ok { resourceGroupStatusGauge.DeleteLabelValues(group.Name) } + } 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))) } } }