{"record":{"id":"3d7205c142d5accf","repo":"apache/cassandra","slug":"ttl-is-too-large-requested-d-maximum-d","errorCode":null,"errorMessage":"ttl is too large. requested (%d) maximum (%d)","messagePattern":"ttl is too large\\. requested \\((.+?)\\) maximum \\((.+?)\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Attributes.java","lineNumber":143,"sourceCode":"        // identity, so need to check this after checking that\n        if (ByteBufferUtil.EMPTY_BYTE_BUFFER.equals(tval))\n            return 0;\n\n        try\n        {\n            Int32Type.instance.validate(tval);\n        }\n        catch (MarshalException e)\n        {\n            throw new InvalidRequestException(\"Invalid TTL value: \" + tval);\n        }\n\n        int ttl = Int32Type.instance.compose(tval);\n        if (ttl < 0)\n            throw new InvalidRequestException(\"A TTL must be greater or equal to 0, but was \" + ttl);\n\n        if (ttl > MAX_TTL)\n            throw new InvalidRequestException(String.format(\"ttl is too large. requested (%d) maximum (%d)\", ttl, MAX_TTL));\n\n        if (metadata.params.defaultTimeToLive != LivenessInfo.NO_TTL && ttl == LivenessInfo.NO_TTL)\n            return LivenessInfo.NO_TTL;\n\n        ExpirationDateOverflowHandling.maybeApplyExpirationDateOverflowPolicy(metadata, ttl, false);\n\n        return ttl;\n    }\n\n    public void collectMarkerSpecification(VariableSpecifications boundNames)\n    {\n        if (timestamp != null)\n            timestamp.collectMarkerSpecification(boundNames, this);\n        if (timeToLive != null)\n            timeToLive.collectMarkerSpecification(boundNames, this);\n    }\n\n    public static class Raw","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Attributes.java#L125-L161","documentation":"Cassandra caps USING TTL at MAX_TTL (20 years, 630720000 seconds) because stored expiration timestamps are 32-bit; larger TTLs would overflow. getTimeToLive throws InvalidRequestException 'ttl is too large. requested (%d) maximum (%d)'. (Expiration-date overflow beyond 2038 is further handled by ExpirationDateOverflowHandling.)","triggerScenarios":"'USING TTL ?' bound with an int > 630720000 (20 years); e.g. computing a TTL in seconds from a multi-decade retention period or accidentally using milliseconds (e.g. 31536000000 = 1000 years in ms).","commonSituations":"Retention policies expressed in ms bound directly as TTL seconds; 'infinite' retention encoded as Integer.MAX_VALUE; business rules like 'never expire' mapped to huge numbers.","solutions":["Cap the TTL client-side to 630720000 (20 years) or use TTL 0 for no expiry","Convert milliseconds to seconds before binding (ms / 1000)","Express 'never expire' as TTL 0 rather than a very large number","Review retention logic so computed TTLs stay within 32-bit-second limits"],"exampleFix":"// before\nint ttl = (int) (retentionMs / 1); // wrong unit, huge value\n// after\nint ttl = (int) Math.min(retentionMs / 1000, 630720000L); // seconds, <= MAX_TTL","handlingStrategy":"validation","validationCode":"static final int MAX_TTL = 630720000; // 20 years\nint clampTtl(long ttlSeconds) {\n    return (int) Math.min(Math.max(ttlSeconds, 0), MAX_TTL);\n}","typeGuard":"boolean isTtlWithinLimit(long ttl) { return ttl >= 0 && ttl <= 630720000L; }","tryCatchPattern":"try {\n    session.execute(bs);\n} catch (InvalidQueryException e) {\n    if (e.getMessage().startsWith(\"ttl is too large\"))\n        log.error(\"TTL exceeds 20 years; convert ms->s or use TTL 0 for no expiry\");\n    throw e;\n}","preventionTips":["Convert milliseconds to seconds before binding TTL","Cap retention TTLs at 630720000 seconds or use 0 for never-expire","Never map Integer.MAX_VALUE or Long values into USING TTL","Document the 20-year TTL limit in client SDKs"],"tags":["cql","ttl","invalid-request"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}