MyCATApache/Mycat-Server · error · IllegalStateException
There is no space for new record
Error message
There is no space for new record
What it means
UnsafeInMemorySorter.insertRecord throws IllegalStateException("There is no space for new record") when hasSpaceForAnotherRecord() is false — i.e. pos+1 has reached the array's usable capacity (size / memoryAllocationFactor). The sorter requires the caller to expand the pointer array or spill before inserting more records.
Solutions
- Check hasSpaceForAnotherRecord() before insertRecord and spill or expand when false.
- Wire the sorter into a spill mechanism (UnsafeSorterSpillWriter / UnsafeExternalSorter pattern) that creates a new sorter page batch when full.
- Increase execution memory or page allocation so capacity covers the record count.
- Call expandPointerArray with a larger LongArray before continuing inserts.
Example fix
// before
for (Record r : records) sorter.insertRecord(r.pointer(), r.prefix());
// after
for (Record r : records) {
if (!sorter.hasSpaceForAnotherRecord()) { spill(sorter); sorter = newSorter(); }
sorter.insertRecord(r.pointer(), r.prefix());
} Defensive patterns
Strategy: validation
Validate before calling
if (!sorter.hasSpaceForAnotherRecord()) {
spill(sorter);
sorter = expandOrNewSorter();
}
sorter.insertRecord(recordPointer, keyPrefix); Try / catch
try { sorter.insertRecord(ptr, prefix); } catch (IllegalStateException e) { if (e.getMessage().contains("no space")) { spill(sorter); sorter.insertRecord(ptr, prefix); } else throw e; } Prevention
- Always check hasSpaceForAnotherRecord() before insertRecord
- Wire the sorter into an external-spill pipeline for unbounded input
- Size memory allocation to expected record counts
When it happens
Trigger: Calling insertRecord(recordPointer, keyPrefix) more times than the sorter's allocated capacity without an intervening expandPointerArray call — e.g. pushing more records into an in-memory sorter than memory was reserved for.
Common situations: Large sorts exceeding the execution memory budget with no spill path wired in; callers that bypass the spill check; memory allocation factor configured such that usable capacity is far below array size.
Related errors
- Not enough memory to grow pointer array
- the max activeConnnections size can not be max than…
- The ring buffer cannot accommodate
- Comparison method violates its general contract!
- Number of records written exceeded numRecordsToWrite =
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/188fadd7e9d8a7bd.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/utils/sort/UnsafeInMemorySorter.java:216
array.getBaseObject(),
array.getBaseOffset(),
newArray.getBaseObject(),
newArray.getBaseOffset(),
array.size() * (8 / memoryAllocationFactor));
consumer.freeLongArray(array);
array = newArray;
}
/**
* Inserts a record to be sorted. Assumes that the record pointer points to a record length
* stored as a 4-byte integer, followed by the record's bytes.
*
* @param recordPointer pointer to a record in a data page, encoded by {@link DataNodeMemoryManager}.
* @param keyPrefix a user-defined key prefix
*/
public void insertRecord(long recordPointer, long keyPrefix) {
if (!hasSpaceForAnotherRecord()) {
throw new IllegalStateException("There is no space for new record");
}
/**
* 先插入recordPointer,然后插入keyPrefix值
* */
array.set(pos, recordPointer);
pos++;
array.set(pos, keyPrefix);
pos++;
}
public final class SortedIterator extends UnsafeSorterIterator implements Cloneable {
private final int numRecords;
private int position;
private int offset;
private Object baseObject;
private long baseOffset;
private long keyPrefix;View on GitHub (pinned to 65f8d8beb7)