{"record":{"id":"63e59502a039ec1c","repo":"apache/pulsar","slug":"incrementusage-on-tenant-s-ns-s-bytes-s-or","errorCode":null,"errorMessage":"incrementUsage on tenant=%s, NS=%s: bytes (%s) or mesgs (%s) is negative","messagePattern":"incrementUsage on tenant=(.+?), NS=(.+?): bytes \\((.+?)\\) or mesgs \\((.+?)\\) is negative","errorType":"exception","errorClass":"PulsarAdminException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java","lineNumber":370,"sourceCode":"     * @param nsName\n     * @param monClass\n     * @param incStats\n     * @returns true if the stats were updated; false if nothing was updated.\n     */\n    protected boolean incrementUsage(String tenantName, String nsName,\n                                  ResourceGroupMonitoringClass monClass,\n                                  BytesAndMessagesCount incStats) throws PulsarAdminException {\n        final ResourceGroup nsRG = this.namespaceToRGsMap.get(NamespaceName.get(tenantName, nsName));\n        final ResourceGroup tenantRG = this.tenantToRGsMap.get(tenantName);\n        if (tenantRG == null && nsRG == null) {\n            return false;\n        }\n\n        // Expect stats to increase monotonically.\n        if (incStats.bytes < 0 || incStats.messages < 0) {\n            String errMesg = String.format(\"incrementUsage on tenant=%s, NS=%s: bytes (%s) or mesgs (%s) is negative\",\n                    tenantName, nsName, incStats.bytes, incStats.messages);\n            throw new PulsarAdminException(errMesg);\n        }\n\n        if (nsRG == tenantRG) {\n            // Update only once in this case.\n            // Note that we will update both tenant and namespace RGs in other cases.\n            nsRG.incrementLocalUsageStats(monClass, incStats);\n            rgLocalUsageMessages.labels(nsRG.resourceGroupName, monClass.name()).inc(incStats.messages);\n            rgLocalUsageBytes.labels(nsRG.resourceGroupName, monClass.name()).inc(incStats.bytes);\n            return true;\n        }\n\n        if (tenantRG != null) {\n            tenantRG.incrementLocalUsageStats(monClass, incStats);\n            rgLocalUsageMessages.labels(tenantRG.resourceGroupName, monClass.name()).inc(incStats.messages);\n            rgLocalUsageBytes.labels(tenantRG.resourceGroupName, monClass.name()).inc(incStats.bytes);\n        }\n        if (nsRG != null) {\n            nsRG.incrementLocalUsageStats(monClass, incStats);","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java#L352-L388","documentation":"incrementUsage validates the usage delta before applying it: either the byte count or message count was negative, which is impossible for a usage increment and would corrupt the resource-group accounting, so the update is refused.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java:370 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the caller to report non-negative byte/message deltas","Check for integer overflow or double-counted decrements in the stats pipeline"],"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"}