{"record":{"id":"adffeb7be7d038df","repo":"apache/cassandra","slug":"replica-filtering-protection-has-cached-over-d-ro-adffeb","errorCode":null,"errorMessage":"Replica filtering protection has cached over %d rows during query %s. (See 'cached_replica_rows_warn_threshold' in cassandra.yaml.)","messagePattern":"Replica filtering protection has cached over (.+?) rows during query (.+?)\\. \\(See 'cached_replica_rows_warn_threshold' in cassandra\\.yaml\\.\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/service/reads/ReplicaFilteringProtection.java","lineNumber":345,"sourceCode":"        if (currentRowsCached == cachedRowsFailThreshold + 1)\n        {\n            String message = String.format(\"Replica filtering protection has cached over %d rows during query %s. \" +\n                                           \"(See 'cached_replica_rows_fail_threshold' in cassandra.yaml.)\",\n                                           cachedRowsFailThreshold, command.toCQLString());\n\n            logger.error(message);\n            Tracing.trace(message);\n            throw new OverloadedException(message);\n        }\n        else if (currentRowsCached == cachedRowsWarnThreshold + 1 && !hitWarningThreshold)\n        {\n            hitWarningThreshold = true;\n\n            String message = String.format(\"Replica filtering protection has cached over %d rows during query %s. \" +\n                                           \"(See 'cached_replica_rows_warn_threshold' in cassandra.yaml.)\",\n                                           cachedRowsWarnThreshold, command.toCQLString());\n\n            ClientWarn.instance.warn(message);\n            oneMinuteLogger.warn(message);\n            Tracing.trace(message);\n        }\n    }\n\n    private void releaseCachedRows(int count)\n    {\n        maxRowsCached = Math.max(maxRowsCached, currentRowsCached);\n        currentRowsCached -= count;\n    }\n\n    /**\n     * Returns the protected results for the specified replica. These are generated fetching the extra rows and merging\n     * them with the cached original filtered results for that replica.\n     *\n     * @param merged the first iteration partitions, that should have been read used with the {@link #mergeController()}\n     * @param source the source\n     * @return the protected results for the specified replica","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/reads/ReplicaFilteringProtection.java#L327-L363","documentation":"ReplicaFilteringProtection caches rows on the coordinator when replica-side filtering cannot fully resolve the query (e.g. filtering with page-size limits). When the number of cached rows exceeds `cached_replica_rows_warn_threshold`, this warning is emitted to the client (ClientWarn), the server log, and the trace — indicating the coordinator is buffering many rows and memory pressure is possible.","triggerScenarios":"Executing a SELECT with ALLOW FILTERING (or secondary-index queries) across multiple paging cycles where per-page filtering protection caches more rows than cached_replica_rows_warn_threshold in a single query.","commonSituations":"Large ALLOW FILTERING queries over wide partitions; too-small page size with big result sets; threshold left at default while running analytics-style filtering scans.","solutions":["Rewrite the query/data model to avoid ALLOW FILTERING (denormalize or use a table designed for the access pattern)","Increase page size (LIMIT / paging state) so fewer paging rounds trigger protection caching, or reduce result set size","Raise cached_replica_rows_warn_threshold in cassandra.yaml if the buffering is acceptable and only the warning is unwanted","Monitor coordinator heap; if near limits, restrict the query with partition key constraints"],"exampleFix":"// before\nSELECT * FROM users WHERE country = 'US' ALLOW FILTERING;\n// after\nSELECT * FROM users_by_country WHERE country = 'US';","handlingStrategy":"validation","validationCode":"// client-side pre-check before issuing a filtering query\nif (query.hasAllowFiltering() && !query.hasPartitionKeyConstraint())\n    logger.warn(\"Query '{}' will trigger replica filtering protection; consider a denormalized table\", cql);","typeGuard":null,"tryCatchPattern":"try {\n    rs = session.execute(query);\n} catch (DriverException e) {\n    // warnings are non-fatal; inspect Warnings on the ResultSet\n    for (String w : rs.getExecutionInfo().getWarnings())\n        if (w.contains(\"cached over\")) planQueryRewrite(w);\n}","preventionTips":["Avoid ALLOW FILTERING on wide tables; model tables for the query","Enable and monitor cached_replica_rows metrics","Set realistic page sizes and cached_replica_rows_warn_threshold"],"tags":["query","filtering","memory","coordinator"],"backgroundTag":"payload-too-large","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}