{"record":{"id":"1e9eb5745ef18416","repo":"apache/cassandra","slug":"trying-to-stream-locally-range-in-keyspace","errorCode":null,"errorMessage":"Trying to stream locally. Range:  in keyspace ","messagePattern":"Trying to stream locally\\. Range:  in keyspace ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/dht/RangeStreamer.java","lineNumber":669,"sourceCode":"            //Committing the cardinal sin of synthesizing a Replica, but it's ok because we assert earlier all of them\n            //are full and optimized range fetch map doesn't support transient replication yet.\n            wrapped.put(entry.getKey(), new FetchReplica(toFetch, fullReplica(entry.getKey(), entry.getValue())));\n        }\n\n        return wrapped;\n    }\n\n    /**\n     * Verify that source returned for each range is correct\n     */\n    @VisibleForTesting\n    static void validateRangeFetchMap(EndpointsByRange rangesWithSources, Multimap<InetAddressAndPort, Range<Token>> rangeFetchMapMap, String keyspace)\n    {\n        for (Map.Entry<InetAddressAndPort, Range<Token>> entry : rangeFetchMapMap.entries())\n        {\n            if(entry.getKey().equals(FBUtilities.getBroadcastAddressAndPort()))\n            {\n                throw new IllegalStateException(\"Trying to stream locally. Range: \" + entry.getValue()\n                                                + \" in keyspace \" + keyspace);\n            }\n\n            if (!rangesWithSources.get(entry.getValue()).endpoints().contains(entry.getKey()))\n            {\n                throw new IllegalStateException(\"Trying to stream from wrong endpoint. Range: \" + entry.getValue()\n                                                + \" in keyspace \" + keyspace + \" from endpoint: \" + entry.getKey());\n            }\n\n            logger.info(\"Streaming range {} from endpoint {} for keyspace {}\", entry.getValue(), entry.getKey(), keyspace);\n        }\n    }\n\n    // For testing purposes\n    @VisibleForTesting\n    Map<String, Multimap<InetAddressAndPort, FetchReplica>> toFetch()\n    {\n        return toFetch;","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/dht/RangeStreamer.java#L651-L687","documentation":"validateRangeFetchMap throws this IllegalStateException if the computed streaming fetch plan assigns a range to be streamed from the local node itself. Streaming data from yourself would be a no-op and indicates a bug in the fetch-map computation or invalid metadata.","triggerScenarios":"Calling getOptimizedWorkMap when the range-fetch map produced by the allocator contains an entry whose key equals FBUtilities.getBroadcastAddressAndPort() for the given keyspace.","commonSituations":"Topology changes (bootstrap/replace/move) racing with metadata updates so the local node still appears as a replica/source; bugs or stale token metadata in the range computation.","solutions":["Retry the operation after confirming token metadata is up to date (nodetool ring/status)","Report this as a bug — it is an internal invariant violation, not an expected user error","Ensure the node being bootstrapped/replaced does not already own the ranges (check system.local, system.peers, nodetool info ownership)","Restart the node to refresh its view of cluster metadata and retry"],"exampleFix":"// before: local endpoint appears in fetch map\nMap<InetAddressAndPort, Multimap<Range<Token>, InetAddressAndPort>> workMap = streamer.workMap;\n// after: filter/verify sources are remote before streaming\nif (source.equals(FBUtilities.getBroadcastAddressAndPort()))\n    throw new IllegalStateException(\"... \"); // surfaced error -> fix metadata via nodetool resetlocal? no: refresh gossip\nnodetool refreshpeers && nodetool status","handlingStrategy":"validation","validationCode":"// ensure token metadata is current before operations\n// nodetool ring; confirm the local node does not already own the target ranges","typeGuard":null,"tryCatchPattern":"try {\n    result = streamer.workMap;\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Trying to stream locally\")) {\n        // refresh gossip/token metadata and retry; report bug if persistent\n    }\n}","preventionTips":["Never start a topology operation while gossip shows stale or inconsistent ring state","Restart the node to refresh metadata before retrying bootstrap","Report persistent occurrences to the Cassandra project as a bug","Check system.local/system.peers consistency"],"tags":["streaming","internal-bug","metadata"],"backgroundTag":"internal-invariant-violation","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"}