From 17c7ce2874c5a2aa3449adaf7a5c24e6198f2707 Mon Sep 17 00:00:00 2001 From: Bin Shi Date: Tue, 13 Jun 2023 16:29:01 -0700 Subject: [PATCH] Fix potential inconsistency caused by non-atomic applying the keyspace movement change in the persistent store. Signed-off-by: Bin Shi --- pkg/tso/keyspace_group_manager.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/tso/keyspace_group_manager.go b/pkg/tso/keyspace_group_manager.go index 9eaea2bf48e..798a61046f4 100644 --- a/pkg/tso/keyspace_group_manager.go +++ b/pkg/tso/keyspace_group_manager.go @@ -563,7 +563,14 @@ func (kgm *KeyspaceGroupManager) updateKeyspaceGroupMembership( i++ j++ } else if i < oldLen && j < newLen && oldKeyspaces[i] < newKeyspaces[j] || j == newLen { - delete(kgm.keyspaceLookupTable, oldKeyspaces[i]) + // kgm.keyspaceLookupTable is a global lookup table for all keyspace groups, storing the + // keyspace group ID for each keyspace. If the keyspace group of this keyspace in this + // lookup table isn't the current keyspace group, it means the keyspace has been moved + // to another keyspace group which has already declared the ownership of the keyspace, + // and we shouldn't delete and overwrite the ownership. + if curGroupID, ok := kgm.keyspaceLookupTable[oldKeyspaces[i]]; ok && curGroupID == groupID { + delete(kgm.keyspaceLookupTable, oldKeyspaces[i]) + } i++ } else { newGroup.KeyspaceLookupTable[newKeyspaces[j]] = struct{}{}