{"record":{"id":"4ee464eb351ec471","repo":"apache/cassandra","slug":"trying-to-stream-from-wrong-endpoint-range-in-k","errorCode":null,"errorMessage":"Trying to stream from wrong endpoint. Range:  in keyspace  from endpoint: ","messagePattern":"Trying to stream from wrong endpoint\\. Range:  in keyspace  from endpoint: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/dht/RangeStreamer.java","lineNumber":675,"sourceCode":"    }\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;\n    }\n\n    public StreamResultFuture fetchAsync()\n    {\n        toFetch.forEach((keyspace, sources) -> {\n            logger.debug(\"Keyspace {} Sources {}\", keyspace, sources);","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/dht/RangeStreamer.java#L657-L693","documentation":"validateRangeFetchMap throws this IllegalStateException when a range in the fetch plan is assigned to a source endpoint that was not among the validated sources (rangesWithSources) for that range in the given keyspace. It is an internal consistency check ensuring streaming only happens from legitimate replicas.","triggerScenarios":"Calling getOptimizedWorkMap when the rangeFetchMapMap pairs a range with an endpoint not present in rangesWithSources.get(range).endpoints(), i.e. a source selected outside the computed candidate set.","commonSituations":"Concurrent topology changes making the chosen endpoint stale between candidate computation and validation; custom/patched load-balancing or allocation logic returning non-replica endpoints; corrupt token metadata.","solutions":["Retry streaming after topology stabilizes (nodetool status shows all Up/Normal)","Report as a bug: the fetch-map builder selected an endpoint outside the validated source set","Refresh cluster metadata (restart the node or nodetool gossip file inspection) to clear stale token maps","Check for concurrent bootstrap/decommission/replace operations and serialize them"],"exampleFix":"// before: streaming attempt fails validation\nnodetool move <token>\n// after: ensure no concurrent topology ops, then retry\nnodetool status   # all nodes Up/Normal, no leavings\nnodetool move <token>","handlingStrategy":"validation","validationCode":"// verify chosen source endpoints are natural replicas before streaming\n// cross-check endpoints with token metadata: StorageService.instance.getNaturalEndpoints(...).contains(source)","typeGuard":null,"tryCatchPattern":"try {\n    result = streamer.getOptimizedWorkMap();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Trying to stream from wrong endpoint\")) {\n        // refresh metadata and retry; serialize topology operations\n    }\n}","preventionTips":["Serialize bootstrap/decommission/replace operations","Ensure token metadata converged (nodetool ring agrees cluster-wide) before moving data","Avoid custom patched allocation logic returning non-replica endpoints"],"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"}