diff --git a/USING-HYDRADB.md b/USING-HYDRADB.md index c60f7d06..efb445f4 100644 --- a/USING-HYDRADB.md +++ b/USING-HYDRADB.md @@ -919,10 +919,18 @@ no meaning across scans. empty page to fetch. **A drained or dead cursor fails with yet another message**: -`result cursor is unknown or expired`. You will see it if you keep a cursor +`result cursor is unknown or expired on this node`. You will see it if you keep a cursor after its scan completed — including when a dropped `page_size` silently drained the scan in one response (see below). +**A cursor lives on one node.** The remaining rows are held in the memory of +the node that served page one, so every later page must reach that node. With +more than one node, a load balancer that spreads requests sends some pages +elsewhere, and they fail with the same `unknown or expired on this node` error. +In the Helm chart, set `service.https.sessionAffinity: ClientIP` when the proxy +is off, or `proxy.readRouting: owner` when it is on. Running queries work the +same way: a cancel must reach the node that runs the query. + Paged reads stay pinned to one storage snapshot, so rows do not shift underneath a long pagination. @@ -950,7 +958,9 @@ may mean a budget was hit, not that the data is missing.** `POST /v1/graphs/{graph_id}/queries/{query_id}/cancel`, using the `query_id` from the response. It only affects a query that is still running; against a finished or unknown id it returns **400** with - `no active query with id … was cancelled`. + `no active query with id … was cancelled on this node`. The cancel must reach + the node that runs the query; see [Pagination](#pagination) for the chart + settings that keep a client on one node. ## Transactions diff --git a/charts/hydradb/README.md b/charts/hydradb/README.md index d41d6dfe..1b635bb7 100644 --- a/charts/hydradb/README.md +++ b/charts/hydradb/README.md @@ -39,6 +39,17 @@ storage. Query nodes discover generations asynchronously and never perform a full topology build on a request thread. Scale `node.replicaCount` for query capacity and `indexer.replicaCount` for background indexing capacity. +HTTP result cursors and running queries are held in the memory of the node that +served the first request, so the next page of a paged result and a cancel must +reach that same node. With `node.replicaCount` above 1: + +- Proxy off: set `service.https.sessionAffinity: ClientIP` so the `-https` + Service keeps each client on one node. Clients behind one NAT or ingress + share a node. +- Proxy on: the default `proxy.readRouting: fleet` routes every page request + again. Set `proxy.readRouting: owner` if clients page HTTP results or cancel + reads. + ## Image Publication `.github/workflows/container.yml` builds the production Dockerfile on pull diff --git a/charts/hydradb/templates/services.yaml b/charts/hydradb/templates/services.yaml index b67596aa..1470ded5 100644 --- a/charts/hydradb/templates/services.yaml +++ b/charts/hydradb/templates/services.yaml @@ -64,6 +64,12 @@ spec: - name: https port: {{ .Values.service.https.port }} targetPort: https + {{- if eq (.Values.service.https.sessionAffinity | default "None") "ClientIP" }} + sessionAffinity: ClientIP + sessionAffinityConfig: + clientIP: + timeoutSeconds: {{ .Values.service.https.sessionAffinityTimeoutSeconds | default 10800 }} + {{- end }} {{- with .Values.service.https.loadBalancerSourceRanges }} loadBalancerSourceRanges: {{- toYaml . | nindent 4 }} diff --git a/charts/hydradb/values.schema.json b/charts/hydradb/values.schema.json index b80eb75a..77a7eeda 100644 --- a/charts/hydradb/values.schema.json +++ b/charts/hydradb/values.schema.json @@ -201,7 +201,17 @@ "properties": { "advertisedBoltAddress": { "type": "string" }, "bolt": { "$ref": "#/definitions/service" }, - "https": { "$ref": "#/definitions/service" }, + "https": { + "allOf": [ + { "$ref": "#/definitions/service" }, + { + "properties": { + "sessionAffinity": { "enum": ["None", "ClientIP"] }, + "sessionAffinityTimeoutSeconds": { "type": "integer", "minimum": 1, "maximum": 86400 } + } + } + ] + }, "adminPort": { "type": "integer", "minimum": 1, "maximum": 65535 } } }, diff --git a/charts/hydradb/values.yaml b/charts/hydradb/values.yaml index 522c1e1e..c5695404 100644 --- a/charts/hydradb/values.yaml +++ b/charts/hydradb/values.yaml @@ -203,6 +203,15 @@ service: port: 443 annotations: {} loadBalancerSourceRanges: [] + # HTTP result cursors and running queries are held in the memory of the + # node that served the first request. With node.replicaCount > 1 and the + # proxy off, set ClientIP so a client's next page and its cancel reach that + # node. ClientIP keys on the source address this Service sees, so clients + # behind one NAT or ingress share a node. Behind the proxy this Service is + # not on the client path; see proxy.readRouting. + sessionAffinity: None + # Used only with ClientIP. 10800 (3 hours) is the Kubernetes default. + sessionAffinityTimeoutSeconds: 10800 adminPort: 9090 runtime: @@ -279,6 +288,9 @@ proxy: pullPolicy: IfNotPresent # The env's read policy, the same knob graph-node reads. Behind the proxy the # nodes' own setting does nothing, since the proxy answers ROUTE. + # Under fleet, each HTTP page request is routed again, so the next page or a + # cancel can reach a node that does not hold the cursor or the query. Use + # owner if clients page HTTP results or cancel reads. readRouting: fleet # Concurrent units per graph-node across all proxy replicas; each replica # holds nodeBudget / replicas. diff --git a/src/client/service.rs b/src/client/service.rs index 7481e43e..be553315 100644 --- a/src/client/service.rs +++ b/src/client/service.rs @@ -2493,7 +2493,9 @@ impl ClientQueryService { return Err(GraphError::UnsupportedQuery { reason: QueryFailureReason::InvalidRequest, dialect: "ClientProtocol", - feature: "result cursor is unknown or expired".to_string(), + feature: "result cursor is unknown or expired on this node; a cursor lives only on the node that \ + served the first page, so send every page of a scan to that node" + .to_string(), }); }; if cursor.owner != expected_owner @@ -2591,7 +2593,10 @@ impl ClientQueryService { return Err(GraphError::UnsupportedQuery { reason: QueryFailureReason::InvalidRequest, dialect: "ClientProtocol", - feature: format!("no active query with id {query_id} was cancelled"), + feature: format!( + "no active query with id {query_id} was cancelled on this node; a query can only be \ + cancelled on the node that runs it" + ), }); }; active.cancellation_token.cancel();