public int invalidateAndRelease() {
    boolean result;
    long oldValue, newValue;
    do {
      result = false;
      oldValue = state.get();
      if (State.getRefCount(oldValue) != 0) {
        throw new AssertionError("Refcount is " + State.getRefCount(oldValue));
      }
      if (State.hasFlags(oldValue, State.FLAG_EVICTED)) {
        return -1; // Concurrent force-eviction - ignore.
      }
      newValue = State.setFlag(oldValue, State.FLAG_EVICTED);
      if (!State.hasFlags(oldValue, State.FLAG_MOVING)) {
        // No move pending, the allocator can release.
        newValue = State.setFlag(newValue, State.FLAG_REMOVED | State.FLAG_MEM_RELEASED);
        result = true;
      }
    } while (!state.compareAndSet(oldValue, newValue));
    if (LlapIoImpl.LOCKING_LOGGER.isTraceEnabled()) {
      LlapIoImpl.LOCKING_LOGGER.trace("Invalidated {} due to direct deallocation", this);
    }
    // Arena cannot change after we have marked it as released.
    return result ? State.getArena(oldValue) : -1;
  }
Invalidates the uncached buffer. The memory allocation in memory manager is managed by the
allocator; we will only mark it as released if there are no concurrent moves. In that case,
the caller of this will release the memory; otherwise, the end of move will release.
@return Arena index, if the buffer memory can be released; -1 otherwise.
llap-server/src/java/org/apache/hadoop/hive/llap/cache/LlapAllocatorBuffer.java