{"record":{"id":"80442c7ef522658a","repo":"MyCATApache/Mycat-Server","slug":"initial-capacity-initialcapacity-exceeds-maximu","errorCode":null,"errorMessage":"Initial capacity ${initialCapacity} exceeds maximum capacity of ${maxCapacity}","messagePattern":"Initial capacity (.+?) exceeds maximum capacity of (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/map/BytesToBytesMap.java","lineNumber":196,"sourceCode":"      DataNodeDiskManager blockManager,\n      SerializerManager serializerManager,\n      int initialCapacity,\n      double loadFactor,\n      long pageSizeBytes,\n      boolean enablePerfMetrics) {\n    super(dataNodeMemoryManager, pageSizeBytes);\n    this.dataNodeMemoryManager = dataNodeMemoryManager;\n    this.blockManager = blockManager;\n    this.serializerManager = serializerManager;\n    this.loadFactor = loadFactor;\n    this.loc = new Location();\n    this.pageSizeBytes = pageSizeBytes;\n    this.enablePerfMetrics = enablePerfMetrics;\n    if (initialCapacity <= 0) {\n      throw new IllegalArgumentException(\"Initial capacity must be greater than 0\");\n    }\n    if (initialCapacity > MAX_CAPACITY) {\n      throw new IllegalArgumentException(\n        \"Initial capacity \" + initialCapacity + \" exceeds maximum capacity of \" + MAX_CAPACITY);\n    }\n    if (pageSizeBytes > DataNodeMemoryManager.MAXIMUM_PAGE_SIZE_BYTES) {\n      throw new IllegalArgumentException(\"Page size \" + pageSizeBytes + \" cannot exceed \" +\n        DataNodeMemoryManager.MAXIMUM_PAGE_SIZE_BYTES);\n    }\n    allocate(initialCapacity);\n  }\n\n  public BytesToBytesMap(\n      DataNodeMemoryManager dataNodeMemoryManager,\n      int initialCapacity,\n      long pageSizeBytes) {\n    this(dataNodeMemoryManager, initialCapacity, pageSizeBytes, false);\n  }\n\n  public BytesToBytesMap(\n      DataNodeMemoryManager dataNodeMemoryManager,","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/map/BytesToBytesMap.java#L178-L214","documentation":"BytesToBytesMap's constructor validates that the requested initial capacity is positive and does not exceed MAX_CAPACITY. This IllegalArgumentException is thrown when initialCapacity is greater than the map's hard maximum supported capacity, because internal sizing (to a power-of-2 long array) cannot accommodate it.","triggerScenarios":"Calling `new BytesToBytesMap(memoryManager, allocator, initialCapacity, pageSizeBytes, enablePerfMetrics)` (or the other constructor overloads) with initialCapacity > BytesToBytesMap.MAX_CAPACITY.","commonSituations":"Configuring a Mycat memory cache/join map with a capacity copied from a large production dataset or computed from `2 * expectedRows` where expectedRows is huge; copy-pasted Spark-style tuning configs specifying multi-billion entry capacities.","solutions":["Reduce the initialCapacity argument to a value <= BytesToBytesMap.MAX_CAPACITY (map grows internally as needed, so a modest initial capacity like 1024 or 65536 is fine).","Check the config source feeding initialCapacity (e.g. a capacity property) for unit mistakes — e.g. passing bytes or row counts of the whole dataset instead of an initial table size.","Clamp the value programmatically before constructing: `initialCapacity = Math.min(initialCapacity, BytesToBytesMap.MAX_CAPACITY)`.","If the workload genuinely needs more entries than MAX_CAPACITY, shard the data across multiple BytesToBytesMap instances."],"exampleFix":"// before\nBytesToBytesMap map = new BytesToBytesMap(\n    memoryManager, allocator, 4_000_000_000L, 64 * 1024 * 1024, false);\n// after\nlong initialCapacity = Math.min(4_000_000_000L, BytesToBytesMap.MAX_CAPACITY);\nBytesToBytesMap map = new BytesToBytesMap(\n    memoryManager, allocator, initialCapacity, 64 * 1024 * 1024, false);","handlingStrategy":"validation","validationCode":"if (initialCapacity <= 0 || initialCapacity > BytesToBytesMap.MAX_CAPACITY) {\n  initialCapacity = Math.min(Math.max(initialCapacity, 1), BytesToBytesMap.MAX_CAPACITY);\n}\nBytesToBytesMap map = new BytesToBytesMap(mm, allocator, initialCapacity, pageSize, metrics);","typeGuard":null,"tryCatchPattern":"try {\n  map = new BytesToBytesMap(mm, allocator, initialCapacity, pageSize, metrics);\n} catch (IllegalArgumentException e) {\n  map = new BytesToBytesMap(mm, allocator, BytesToBytesMap.MAX_CAPACITY, pageSize, metrics);\n}","preventionTips":["Clamp initialCapacity against BytesToBytesMap.MAX_CAPACITY before construction.","Never wire raw dataset row counts directly as initial capacity.","Use a modest default (e.g. 1024) — the map grows internally.","Unit-test config parsing that feeds capacity values."],"tags":["java","memory","illegal-argument","configuration"],"backgroundTag":"value-out-of-range","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"}