{"record":{"id":"00feedd3dfae66c4","repo":"apache/cassandra","slug":"node-local-consistency-level-is-highly-dangerous-a","errorCode":null,"errorMessage":"NODE_LOCAL consistency level is highly dangerous and should be used only for debugging purposes","messagePattern":"NODE_LOCAL consistency level is highly dangerous and should be used only for debugging purposes","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/QueryProcessor.java","lineNumber":320,"sourceCode":"    public ResultMessage processStatement(CQLStatement statement, QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)\n    throws RequestExecutionException, RequestValidationException\n    {\n        logger.trace(\"Process {} @CL.{}\", statement, options.getConsistency());\n        ClientState clientState = queryState.getClientState();\n        statement.authorize(clientState);\n        statement.validate(clientState);\n\n        ResultMessage result = options.getConsistency() == ConsistencyLevel.NODE_LOCAL\n                             ? processNodeLocalStatement(statement, queryState, options)\n                             : statement.execute(queryState, options, requestTime);\n\n        return result == null ? new ResultMessage.Void() : result;\n    }\n\n    private ResultMessage processNodeLocalStatement(CQLStatement statement, QueryState queryState, QueryOptions options)\n    {\n        if (!ENABLE_NODELOCAL_QUERIES.getBoolean())\n            throw new InvalidRequestException(\"NODE_LOCAL consistency level is highly dangerous and should be used only for debugging purposes\");\n\n        if (statement instanceof BatchStatement || statement instanceof ModificationStatement)\n            return processNodeLocalWrite(statement, queryState, options);\n        else if (statement instanceof SelectStatement)\n            return processNodeLocalSelect((SelectStatement) statement, queryState, options);\n        else if (statement instanceof TransactionStatement)\n            return statement.executeLocally(queryState, options);\n        else\n            throw new InvalidRequestException(\"NODE_LOCAL consistency level can only be used with BATCH, UPDATE, INSERT, DELETE, and SELECT statements\");\n    }\n\n    private ResultMessage processNodeLocalWrite(CQLStatement statement, QueryState queryState, QueryOptions options)\n    {\n        ClientRequestMetrics levelMetrics = ClientRequestsMetricsHolder.writeMetricsForLevel(ConsistencyLevel.NODE_LOCAL);\n        ClientRequestMetrics globalMetrics = ClientRequestsMetricsHolder.writeMetrics;\n\n        long startTime = nanoTime();\n        try","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/QueryProcessor.java#L302-L338","documentation":"processNodeLocalStatement() executes statements with NODE_LOCAL consistency, a debugging-only mechanism that reads/writes on the local node without normal distributed guarantees. It is gated by the enable_nodelocal_queries system property flag; when disabled, any NODE_LOCAL query is rejected outright.","triggerScenarios":"Sending a query with consistency level NODE_LOCAL while -Dcassandra.enable_nodelocal_queries=true (or the corresponding Config flag) is not set.","commonSituations":"Internal tooling or tests using NODE_LOCAL forgetting to set the flag; accidental NODE_LOCAL from a misconfigured driver on a debug feature.","solutions":["Start Cassandra with -Dcassandra.enable_nodelocal_queries=true (debug environments only).","Use a normal consistency level (e.g. LOCAL_QUORUM) instead of NODE_LOCAL in production code."],"exampleFix":"// before (jvm opts)\ncassandra.enable_nodelocal_queries unset\n// after\nJVM_OPTS=\"$JVM_OPTS -Dcassandra.enable_nodelocal_queries=true\"","handlingStrategy":"validation","validationCode":"if (cl == ConsistencyLevel.NODE_LOCAL && !Boolean.getBoolean(\"cassandra.enable_nodelocal_queries\")) throw new IllegalStateException(\"NODE_LOCAL requires -Dcassandra.enable_nodelocal_queries=true\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt.setConsistencyLevel(NODE_LOCAL)); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"NODE_LOCAL consistency level is highly dangerous\")) { /* enable flag or use standard CL */ } }","preventionTips":["Use NODE_LOCAL only in debug/test environments","Set the flag explicitly in test JVM options","Default code to standard consistency levels"],"tags":["consistency-level","nodelocal","debug-flag"],"backgroundTag":"feature-not-enabled","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}