boolean lockKeysAndPrimary(EntryEventImpl event) {
    if (!needWriteLock(event)) {
      return false;
    }

    if (cache.isCacheAtShutdownAll()) {
      throw cache.getCacheClosedException("Cache is shutting down");
    }

    Object[] keys = getKeysToBeLocked(event);
    waitUntilLocked(keys); // it might wait for long time

    if (wasPrimaryLockedPreviously(event)) {
      return true;
    }
    boolean lockedForPrimary = false;

    try {
      lockedForPrimary = doLockForPrimary(false);
      // tryLock is false means doLockForPrimary won't return false.
      // either the method returns true or fails with an exception
      assert lockedForPrimary : "expected doLockForPrimary returns true";
      return lockedForPrimary;
    } finally {
      if (!lockedForPrimary) {
        removeAndNotifyKeys(keys);
      }
    }
  }
Checks to make sure that this node is primary, and locks the bucket to make sure the bucket
stays the primary bucket while the write is in progress. This method must be followed with
a call to releaseLockForKeysAndPrimary() if keys and primary are locked.
geode-core/src/main/java/org/apache/geode/internal/cache/BucketRegion.java