diff --git a/pkg/keyspace/keyspace.go b/pkg/keyspace/keyspace.go index 7c4bdf82845..6220166d409 100644 --- a/pkg/keyspace/keyspace.go +++ b/pkg/keyspace/keyspace.go @@ -661,6 +661,9 @@ func (manager *Manager) PatrolKeyspaceAssignment(startKeyspaceID, endKeyspaceID manager.nextPatrolStartID = startKeyspaceID } if endKeyspaceID != 0 && endKeyspaceID < manager.nextPatrolStartID { + log.Info("[keyspace] end keyspace id is smaller than the next patrol start id, skip patrol", + zap.Uint32("end-keyspace-id", endKeyspaceID), + zap.Uint32("next-patrol-start-id", manager.nextPatrolStartID)) return nil } var ( diff --git a/pkg/keyspace/keyspace_test.go b/pkg/keyspace/keyspace_test.go index bbaedef2b54..b06921e48db 100644 --- a/pkg/keyspace/keyspace_test.go +++ b/pkg/keyspace/keyspace_test.go @@ -456,18 +456,24 @@ func (suite *keyspaceTestSuite) TestPatrolKeyspaceAssignmentWithRange() { for i := 1; i < maxEtcdTxnOps*2+1; i++ { re.NotContains(defaultKeyspaceGroup.Keyspaces, uint32(i)) } - // Patrol the keyspace assignment with range [10, 20] - err = suite.manager.PatrolKeyspaceAssignment(10, 20) + // Patrol the keyspace assignment with range [maxEtcdTxnOps/2, maxEtcdTxnOps/2+maxEtcdTxnOps+1] + // to make sure the range crossing the boundary of etcd transaction operation limit. + var ( + startKeyspaceID = uint32(maxEtcdTxnOps / 2) + endKeyspaceID = startKeyspaceID + maxEtcdTxnOps + 1 + ) + err = suite.manager.PatrolKeyspaceAssignment(startKeyspaceID, endKeyspaceID) re.NoError(err) // Check if only the keyspaces within the range are attached to the default group. defaultKeyspaceGroup, err = suite.manager.kgm.GetKeyspaceGroupByID(utils.DefaultKeyspaceGroupID) re.NoError(err) re.NotNil(defaultKeyspaceGroup) for i := 1; i < maxEtcdTxnOps*2+1; i++ { - if i >= 10 && i <= 20 { - re.Contains(defaultKeyspaceGroup.Keyspaces, uint32(i)) + keyspaceID := uint32(i) + if keyspaceID >= startKeyspaceID && keyspaceID <= endKeyspaceID { + re.Contains(defaultKeyspaceGroup.Keyspaces, keyspaceID) } else { - re.NotContains(defaultKeyspaceGroup.Keyspaces, uint32(i)) + re.NotContains(defaultKeyspaceGroup.Keyspaces, keyspaceID) } } }