{"record":{"id":"5669d9d57dcb9db9","repo":"MyCATApache/Mycat-Server","slug":"have-already-allocated-a-maximum-of-pagetablesiz","errorCode":null,"errorMessage":"Have already allocated a maximum of ${pageTableSize} pages","messagePattern":"Have already allocated a maximum of (.+?) pages","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/memory/mm/DataNodeMemoryManager.java","lineNumber":254,"sourceCode":"     */\n    long acquired = 0;\n    try {\n      acquired = acquireExecutionMemory(size,tungstenMemoryMode, consumer);\n    } catch (InterruptedException e) {\n      logger.error(e.getMessage());\n    }\n\n    if (acquired <= 0) {\n      return null;\n    }\n\n    final int pageNumber;\n\n    synchronized (this) {\n      pageNumber = allocatedPages.nextClearBit(0);\n      if (pageNumber >= PAGE_TABLE_SIZE) {\n        releaseExecutionMemory(acquired, tungstenMemoryMode, consumer);\n        throw new IllegalStateException(\n          \"Have already allocated a maximum of \" + PAGE_TABLE_SIZE + \" pages\");\n      }\n      allocatedPages.set(pageNumber);\n    }\n\n\n\n    MemoryBlock page = null;\n\n    try {\n      page = memoryManager.tungstenMemoryAllocator().allocate(acquired);\n    } catch (OutOfMemoryError e) {\n      logger.warn(\"Failed to allocate a page ({} bytes), try again.\", acquired);\n      // there is no enough memory actually, it means the actual free memory is smaller than\n      // MemoryManager thought, we should keep the acquired memory.\n      synchronized (this) {\n        acquiredButNotUsed += acquired;\n        allocatedPages.clear(pageNumber);","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/memory/mm/DataNodeMemoryManager.java#L236-L272","documentation":"DataNodeMemoryManager maintains a fixed-size page table (PAGE_TABLE_SIZE entries) mapping page numbers to allocated MemoryBlocks. When allocatePage cannot find a free page number below PAGE_TABLE_SIZE, it releases the just-acquired memory and throws IllegalStateException — the consumer has exhausted the page table.","triggerScenarios":"Calling allocatePage so many times (without freeing pages) that allocatedPages has every bit set; leaking pages across many allocatePage calls within one task/consumer.","commonSituations":"Long-running tasks allocating many small pages instead of reusing them; code paths that forget to freePage; consumers allocating a page per record on huge datasets.","solutions":["Free pages with `memoryManager.freePage(page, consumer)` when no longer needed; audit for leaked allocations.","Reuse/pool pages instead of allocating a new page per record or batch.","Increase PAGE_TABLE_SIZE if the workload legitimately needs more live pages (rebuild with a larger constant).","Use larger pages so fewer page allocations are needed for the same data volume."],"exampleFix":"// before\nMemoryBlock p = mm.allocatePage(size, consumer);\n// p never freed\n// after\nMemoryBlock p = mm.allocatePage(size, consumer);\ntry {\n  // use page\n} finally {\n  mm.freePage(p, consumer);\n}","handlingStrategy":"try-catch","validationCode":"if (memoryManager.getPageCountEstimate() >= PAGE_TABLE_SIZE_LIMIT) {\n  // consolidate into fewer, larger pages before allocating more\n  consolidatePages();\n}","typeGuard":null,"tryCatchPattern":"try {\n  page = memoryManager.allocatePage(size, consumer);\n} catch (IllegalStateException e) {\n  // page table exhausted — free stale pages or switch to a larger-page strategy\n  freeUnusedPages(consumer);\n  page = memoryManager.allocatePage(size, consumer);\n}","preventionTips":["Always freePage() allocations, ideally in try/finally.","Pool and reuse pages rather than allocating per record.","Prefer fewer larger pages for high-volume workloads.","Audit for leaked pages (leakedPageMemoryIsDetected-style checks)."],"tags":["java","memory","page-table","resource-leak","illegal-state"],"backgroundTag":"resource-exhaustion","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"}