{"record":{"id":"71d2b976e15ba635","repo":"apache/cassandra","slug":"node-local-consistency-level-can-only-be-used-with","errorCode":null,"errorMessage":"NODE_LOCAL consistency level can only be used with BATCH, UPDATE, INSERT, DELETE, and SELECT statements","messagePattern":"NODE_LOCAL consistency level can only be used with BATCH, UPDATE, INSERT, DELETE, and SELECT statements","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/QueryProcessor.java","lineNumber":329,"sourceCode":"                             ? 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\n        {\n            return statement.executeLocally(queryState, options);\n        }\n        finally\n        {\n            long latency = nanoTime() - startTime;\n             levelMetrics.addNano(latency);\n            globalMetrics.addNano(latency);\n        }","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/QueryProcessor.java#L311-L347","documentation":"Even when enabled, NODE_LOCAL consistency is only implemented for BatchStatement, ModificationStatement (INSERT/UPDATE/DELETE), SelectStatement, and TransactionStatement. Any other statement type executed with NODE_LOCAL falls through to this InvalidRequestException.","triggerScenarios":"Running e.g. CREATE TABLE, ALTER, or other DDL/utility statements with consistency level NODE_LOCAL while enable_nodelocal_queries=true.","commonSituations":"Test harnesses setting NODE_LOCAL globally for all statements and then running schema statements; scripts that set the CL per-session rather than per-query.","solutions":["Use a standard consistency level for non-DML statements.","Restrict NODE_LOCAL to BATCH/UPDATE/INSERT/DELETE/SELECT statements only."],"exampleFix":"// before\nsession.execute(\"CREATE TABLE t (...)\").setConsistencyLevel(NODE_LOCAL); // fails\n// after\nsession.execute(\"CREATE TABLE t (...)\").setConsistencyLevel(LOCAL_QUORUM);","handlingStrategy":"validation","validationCode":"boolean nodeLocalAllowed = stmt instanceof BatchStatement || stmt instanceof ModificationStatement || stmt instanceof SelectStatement || stmt instanceof TransactionStatement; if (usesNodeLocal && !nodeLocalAllowed) throw new IllegalStateException(\"NODE_LOCAL not supported for this statement type\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"can only be used with BATCH\")) { /* switch CL for DDL */ } }","preventionTips":["Apply NODE_LOCAL per-query to DML only, never session-wide","Exclude DDL/schema statements from NODE_LOCAL tooling","Whitelist statement types when automating with NODE_LOCAL"],"tags":["consistency-level","nodelocal","statement-type"],"backgroundTag":"unsupported-operation","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"}