{"record":{"id":"7b02032b340987c0","repo":"elastic/elasticsearch","slug":"resource-count-must-be-between-1-and-4","errorCode":null,"errorMessage":"Resource count must be between 1 and 4","messagePattern":"Resource count must be between 1 and 4","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/CuVSResourceManager.java","lineNumber":126,"sourceCode":"\n        static class Holder {\n            static final PoolingCuVSResourceManager INSTANCE = new PoolingCuVSResourceManager(\n                MAX_RESOURCES,\n                new RealGPUMemoryService(CuVSProvider.provider().gpuInfoProvider())\n            );\n        }\n\n        private final ManagedCuVSResources[] pool;\n        private final int capacity;\n        private final GPUMemoryService gpuMemoryService;\n        private int createdCount;\n\n        ReentrantLock lock = new ReentrantLock();\n        Condition enoughResourcesCondition = lock.newCondition();\n\n        PoolingCuVSResourceManager(int capacity, GPUMemoryService gpuMemoryService) {\n            if (capacity < 1 || capacity > MAX_RESOURCES) {\n                throw new IllegalArgumentException(\"Resource count must be between 1 and \" + MAX_RESOURCES);\n            }\n            this.capacity = capacity;\n            this.gpuMemoryService = gpuMemoryService;\n            this.pool = new ManagedCuVSResources[MAX_RESOURCES];\n        }\n\n        private ManagedCuVSResources getResourceFromPool() {\n            for (int i = 0; i < createdCount; ++i) {\n                var res = pool[i];\n                if (res.isLocked() == false) {\n                    return res;\n                }\n            }\n            if (createdCount < capacity) {\n                var delegate = createNew();\n                if (delegate == null) {\n                    logger.warn(\"Failed to create new GPU resource, will wait for an existing one\");\n                    return null;","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/CuVSResourceManager.java#L108-L144","documentation":"Thrown by the PoolingCuVSResourceManager constructor when the requested pool capacity is < 1 or > MAX_RESOURCES (4). The pool size is bounded because each ManagedCuVSResources holds a dedicated GPU resource and GPU memory; the hard cap of 4 prevents over-allocation.","triggerScenarios":"Constructing a PoolingCuVSResourceManager with a capacity value outside [1, 4]. This typically comes from configuration (e.g., a setting like index.gpu.codec.resources.count) being set to 0, negative, or greater than 4.","commonSituations":"A user setting the resource count setting to 0 (disable) or to a large number expecting more parallelism; a config parsing bug yielding 0; a test constructing the pool with an extreme value.","solutions":["Set the GPU resource count configuration to a value in [1, 4].","If you genuinely need > 4 concurrent GPU resources, that exceeds the supported design; reduce concurrency or shard across nodes instead.","Clamp the configured value to [1, 4] at the configuration layer with a clear validation message."],"exampleFix":"// before: invalid capacity from config\nint capacity = config.get(\"gpu.resources.count\"); // 0 or 8\nmanager = new PoolingCuVSResourceManager(capacity, memService);\n\n// after: validate and clamp\nint capacity = config.get(\"gpu.resources.count\");\nif (capacity < 1 || capacity > 4) {\n    throw new IllegalArgumentException(\"gpu.resources.count must be 1..4, got \" + capacity);\n}\nmanager = new PoolingCuVSResourceManager(capacity, memService);","handlingStrategy":"validation","validationCode":"static int validatePoolCapacity(int configured) {\n    if (configured < 1 || configured > 4) {\n        throw new IllegalArgumentException(\"gpu resource count must be 1..4, got \" + configured);\n    }\n    return configured;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the resource count setting is in [1, 4] at configuration load time.","Clamp out-of-range values with a clear error rather than letting them reach the constructor.","Document the hard cap of 4 in setting docs."],"tags":["gpu","validation","elasticsearch","codec","configuration","resource-pool"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}