MyCATApache/Mycat-Server · error · IllegalArgumentException

bufferSize must not be less than 1

Error message

bufferSize must not be less than 1

What it means

AbstractSequencer's constructor validates the ring buffer size before initializing the sequencer. It throws IllegalArgumentException when bufferSize is less than 1, because a ring buffer must hold at least one entry. This is an eager fail-fast guard so misconfiguration is caught at construction time rather than at first publish.

Solutions

  1. Pass a bufferSize >= 1 when constructing the sequencer or RingBuffer.create* factory
  2. If the size comes from config, default it to a sane positive value (e.g. 1024) before constructing
  3. Clamp/validate user-supplied size with Math.max(1, size) before constructing

Example fix

// before
int size = config.getBufferSize(); // 0 when unset
RingBuffer<ByteBuffer> rb = RingBuffer.createMultiProducer(()->ByteBuffer.allocate(64), size);
// after
int size = Math.max(1, config.getBufferSize("ring.buffer.size", 1024));
RingBuffer<ByteBuffer> rb = RingBuffer.createMultiProducer(()->ByteBuffer.allocate(64), size);
Defensive patterns

Strategy: validation

Validate before calling

if (bufferSize < 1) throw new IllegalArgumentException("bufferSize must be >= 1, got " + bufferSize);
RingBuffer<T> rb = RingBuffer.createMultiProducer(factory, bufferSize);

Type guard

boolean isValidBufferSize(int n) { return n >= 1; }

Prevention

When it happens

Trigger: Calling new RingBufferFields / MultiProducerSequencer / SingleProducerSequencer (or any subclass constructor) with bufferSize < 1, typically via a RingBuffer.create(...) factory with a size computed to 0 or a negative value.

Common situations: Sizing the buffer from a config value that is unset (0) or computed as records-per-batch minus one; typos passing an index instead of a size; reading buffer size from properties where the key is missing and the default is 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/fc432a80a83fbb19. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/memory/unsafe/ringbuffer/producer/AbstractSequencer.java:31

 * @author lmax.Disruptor
 * @version 3.3.5
 * @date 2016/7/24
 */
public abstract class AbstractSequencer implements Sequencer {

    private static final AtomicReferenceFieldUpdater<AbstractSequencer, Sequence[]> SEQUENCE_UPDATER =
            AtomicReferenceFieldUpdater.newUpdater(AbstractSequencer.class, Sequence[].class, "gatingSequences");

    protected final int bufferSize;
    protected final WaitStrategy waitStrategy;
    protected final Sequence cursor = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
    protected volatile Sequence[] gatingSequences = new Sequence[0];

    public AbstractSequencer(int bufferSize, WaitStrategy waitStrategy)
    {
        if (bufferSize < 1)
        {
            throw new IllegalArgumentException("bufferSize must not be less than 1");
        }
        if (Integer.bitCount(bufferSize) != 1)
        {
            throw new IllegalArgumentException("bufferSize must be a power of 2");
        }

        this.bufferSize = bufferSize;
        this.waitStrategy = waitStrategy;
    }

    @Override
    public final long getCursor()
    {
        return cursor.get();
    }


    @Override

View on GitHub (pinned to 65f8d8beb7)