{"record":{"id":"3f892a657459daf9","repo":"apache/pulsar","slug":"compactionthreshold-must-be-0-or-more","errorCode":null,"errorMessage":"compactionThreshold must be 0 or more","messagePattern":"compactionThreshold must be 0 or more","errorType":"validation","errorClass":"RestException","httpStatus":412,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java","lineNumber":2612,"sourceCode":"\n        } catch (RestException pfe) {\n            throw pfe;\n        } catch (Exception e) {\n            log.error()\n                    .attr(\"namespace\", namespaceName)\n                    .exception(e)\n                    .log(\"Failed to update maxUnackedMessagesPerSubscription configuration\");\n            throw new RestException(e);\n        }\n    }\n\n    protected void internalSetCompactionThreshold(Long newThreshold) {\n        validateNamespacePolicyOperation(namespaceName, PolicyName.COMPACTION, PolicyOperation.WRITE);\n        validatePoliciesReadOnlyAccess();\n\n        try {\n            if (newThreshold != null && newThreshold < 0) {\n                throw new RestException(Status.PRECONDITION_FAILED,\n                        \"compactionThreshold must be 0 or more\");\n            }\n            updatePolicies(namespaceName, policies -> {\n                policies.compaction_threshold = newThreshold;\n                return policies;\n            });\n            log.info()\n                    .attr(\"namespace\", namespaceName)\n                    .attr(\"compactionThreshold\", newThreshold)\n                    .log(\"Successfully updated compactionThreshold configuration\");\n\n        } catch (RestException pfe) {\n            throw pfe;\n        } catch (Exception e) {\n            log.error()\n                    .attr(\"namespace\", namespaceName)\n                    .exception(e)\n                    .log(\"Failed to update compactionThreshold configuration\");","sourceCodeStart":2594,"sourceCodeEnd":2630,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java#L2594-L2630","documentation":"internalSetCompactionThreshold validates the new compaction threshold before persisting namespace policies; a negative value is rejected with 412 Precondition Failed because the threshold (bytes before compaction triggers) must be zero or a positive size.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:2612 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a threshold of 0 or more bytes (0 disables size-threshold-based compaction)","Verify the units — the value is in bytes, not MB"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}