public boolean beginFlush(long timeout, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        if (flushInProgress.tryAcquire(Math.max(0, timeout), timeUnit)) {
            synchronized (this) {
                if (data.isEmpty()) {
                    flushInProgress.release();
                    return false;
                } else {
                    toFlush = data;
                    data = new HashMap<>();
                    return true;
                }
            }
        } else {
            throw new TimeoutException("Timed out waiting for previous flush to finish");
        }
    }
Performs the first step of a flush operation, snapshotting the current state. This does not
actually initiate the flush with the underlying storage. Ensures that any previous flush operations
have finished before beginning a new flush.
<p>If and only if this method returns true, the caller must call {@link #doFlush(Callback)}
or {@link #cancelFlush()} to finish the flush operation and allow later calls to complete.

@param timeout A maximum duration to wait for previous flushes to finish before giving up on waiting
@param timeUnit Units of the timeout argument
@return true if a flush was initiated, false if no data was available
@throws InterruptedException if this thread was interrupted while waiting for the previous flush to complete
@throws TimeoutException if the {@code timeout} elapses before previous flushes are complete.
connect/runtime/src/main/java/org/apache/kafka/connect/storage/OffsetStorageWriter.java