@ultipa-graph/ultipa-driver
Version:
NodeJS SDK for Ultipa GQL
64 lines (63 loc) • 2.63 kB
TypeScript
/**
* Connection management for GQLDB Node.js driver.
*/
import * as grpc from '@grpc/grpc-js';
import { GqldbConfig } from './config';
/** Manages a pool of connections to GQLDB servers */
export declare class ConnectionPool {
private config;
private connections;
private closed;
private healthCheckTimer?;
constructor(config: GqldbConfig);
private initConnections;
private createConnection;
/** Get a healthy connection from the pool */
getConnection(): grpc.Client;
/** Get a connection for a specific host */
getConnectionForHost(host: string): grpc.Client;
private startHealthCheck;
/**
* Health-check tick. Connectivity-state semantics:
* - READY / IDLE → healthy; reset the unhealthy counter.
* - CONNECTING → transient; let the channel heal itself,
* don't count toward unhealthy.
* - SHUTDOWN → terminal; reconnect immediately.
* - TRANSIENT_FAILURE → count toward unhealthy; reconnect only
* after UNHEALTHY_RECONNECT_THRESHOLD
* consecutive ticks.
*
* Reconnect replaces the pool's channel reference; it does NOT close
* the old channel, so in-flight RPCs continue to completion on it.
*/
private checkHealth;
/**
* Replace the pool's channel for `host` with a fresh one.
*
* Critically, does NOT close the old channel. In-flight RPCs hold
* their own reference to it via the client they were issued on and
* continue to completion on that channel; the Node.js runtime's
* garbage collector releases the old channel only after every
* in-flight RPC has resolved.
*
* Earlier versions closed the old channel synchronously here, which
* cancelled every pending RPC with a "Channel closed!"-style error.
*/
/**
* Rebuild every host's gRPC client in the pool. Called by the client
* on transport-level errors (UNAVAILABLE / connection reset) so the
* next RPC gets a fresh channel. Like reconnect, this does NOT close
* old clients synchronously — in-flight RPCs hold them alive and gRPC
* closes them naturally once those calls complete.
*/
forceReconnectAll(): Promise<void>;
private reconnect;
/** Close all connections in the pool */
close(): void;
/** Get the number of healthy hosts */
healthyHostCount(): number;
/** Get the list of configured hosts */
hosts(): string[];
/** Check if the pool is closed */
isClosed(): boolean;
}