{"record":{"id":"188fadd7e9d8a7bd","repo":"MyCATApache/Mycat-Server","slug":"there-is-no-space-for-new-record","errorCode":null,"errorMessage":"There is no space for new record","messagePattern":"There is no space for new record","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/utils/sort/UnsafeInMemorySorter.java","lineNumber":216,"sourceCode":"      array.getBaseObject(),\n      array.getBaseOffset(),\n      newArray.getBaseObject(),\n      newArray.getBaseOffset(),\n      array.size() * (8 / memoryAllocationFactor));\n    consumer.freeLongArray(array);\n    array = newArray;\n  }\n\n  /**\n   * Inserts a record to be sorted. Assumes that the record pointer points to a record length\n   * stored as a 4-byte integer, followed by the record's bytes.\n   *\n   * @param recordPointer pointer to a record in a data page, encoded by {@link DataNodeMemoryManager}.\n   * @param keyPrefix a user-defined key prefix\n   */\n  public void insertRecord(long recordPointer, long keyPrefix) {\n    if (!hasSpaceForAnotherRecord()) {\n      throw new IllegalStateException(\"There is no space for new record\");\n    }\n      /**\n       * 先插入recordPointer，然后插入keyPrefix值\n       * */\n    array.set(pos, recordPointer);\n    pos++;\n    array.set(pos, keyPrefix);\n    pos++;\n  }\n\n  public final class SortedIterator extends UnsafeSorterIterator implements Cloneable {\n\n    private final int numRecords;\n    private int position;\n    private int offset;\n    private Object baseObject;\n    private long baseOffset;\n    private long keyPrefix;","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/utils/sort/UnsafeInMemorySorter.java#L198-L234","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfor (Record r : records) sorter.insertRecord(r.pointer(), r.prefix());\n// after\nfor (Record r : records) {\n  if (!sorter.hasSpaceForAnotherRecord()) { spill(sorter); sorter = newSorter(); }\n  sorter.insertRecord(r.pointer(), r.prefix());\n}","handlingStrategy":"validation","validationCode":"if (!sorter.hasSpaceForAnotherRecord()) {\n  spill(sorter);\n  sorter = expandOrNewSorter();\n}\nsorter.insertRecord(recordPointer, keyPrefix);","typeGuard":null,"tryCatchPattern":"try { sorter.insertRecord(ptr, prefix); } catch (IllegalStateException e) { if (e.getMessage().contains(\"no space\")) { spill(sorter); sorter.insertRecord(ptr, prefix); } else throw e; }","preventionTips":["Always check hasSpaceForAnotherRecord() before insertRecord","Wire the sorter into an external-spill pipeline for unbounded input","Size memory allocation to expected record counts"],"tags":["sorting","memory-management","capacity"],"backgroundTag":"insufficient-memory","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}