Search in sources :

Example 1 with BufferAllocationException

use of org.apache.kafka.raft.errors.BufferAllocationException in project kafka by apache.

the class BatchAccumulator method append.

private long append(int epoch, List<T> records, boolean isAtomic) {
    if (epoch < this.epoch) {
        throw new NotLeaderException("Append failed because the epoch doesn't match");
    } else if (epoch > this.epoch) {
        throw new IllegalArgumentException("Attempt to append from epoch " + epoch + " which is larger than the current epoch " + this.epoch);
    }
    ObjectSerializationCache serializationCache = new ObjectSerializationCache();
    appendLock.lock();
    try {
        maybeCompleteDrain();
        BatchBuilder<T> batch = null;
        if (isAtomic) {
            batch = maybeAllocateBatch(records, serializationCache);
        }
        for (T record : records) {
            if (!isAtomic) {
                batch = maybeAllocateBatch(Collections.singleton(record), serializationCache);
            }
            if (batch == null) {
                throw new BufferAllocationException("Append failed because we failed to allocate memory to write the batch");
            }
            batch.appendRecord(record, serializationCache);
            nextOffset += 1;
        }
        maybeResetLinger();
        return nextOffset - 1;
    } finally {
        appendLock.unlock();
    }
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache) NotLeaderException(org.apache.kafka.raft.errors.NotLeaderException) BufferAllocationException(org.apache.kafka.raft.errors.BufferAllocationException)

Aggregations

ObjectSerializationCache (org.apache.kafka.common.protocol.ObjectSerializationCache)1 BufferAllocationException (org.apache.kafka.raft.errors.BufferAllocationException)1 NotLeaderException (org.apache.kafka.raft.errors.NotLeaderException)1