The result from getSortedAffectedKeysToLock is used  by TotalOrderInterceptor and OptimisticLockingInterceptor to acquire the locks.
In both places the keys that are not local are being ignored, so this logic here is redundant IMO. I'd alos keep the filtering-out logic in the calling code, as it needs to perform a locality check anyway to determine if the key is on a primary owner or on a secondary owner.