chproxy
chproxy copied to clipboard
[BUG] Always select node from a small subset of all nodes for any random session_id
Describe the bug
For any random session_id, chproxy always selects node from a small subset of all nodes.
To Reproduce
Run chproxy on 127.0.0.1:8090 with the following config.xml:
clusters:
- name: test_cluster
replicas:
- name: "replica1"
nodes:
- 127.0.1.1:8123
- 127.0.1.2:8123
- name: "replica2"
nodes:
- 127.0.2.1:8123
- 127.0.2.2:8123
#! /bin/bash
for session_id in $(seq 0 1000); do
echo "select hostname();" | curl "http://default:[email protected]:8090?session_id=$session_id" -d @-
done
the above script will always select node from 127.0.1.1 and 127.0.2.2, and the other nodes will never be selected.
Expected behavior
chproxy should select node from all nodes for any random session_id.
Screenshots
No.
Environment information
- chproxy version: 1.30.0.
Additional context
- The
getReplicaStickyandgetHostStickyfunctions exhibit performance bottlenecks and logical inconsistencies. - By design, sticky sessions should consistently route all requests with the same
session_idto the exact same node, regardless of whether the node is active or not. However, the current implementation fails to maintain this consistency when the selected node's active status changes during this period. Resolving this issue presents challenges, especially in chproxy topologies with 2 or more replicas, which may require introducing distributed storage solutions like Redis. I have addedTODOin the code and will open another issue about this.- Example 1: A sticky session initially routes requests to node
127.0.1.1based on itssession_id. If127.0.1.1later becomes inactive, subsequent requests with the samesession_idare incorrectly rerouted to another active node (e.g.,127.0.2.2) instead of remaining directed to127.0.1.1. - Example 2: A sticky session should route to node
127.0.1.1but initially selects127.0.2.2because127.0.1.1is inactive. When127.0.1.1later becomes active, subsequent requests with the samesession_idare incorrectly switched to127.0.1.1, breaking session stickiness.
- Example 1: A sticky session initially routes requests to node