@@ -192,10 +192,7 @@ export type SelectRunOpsTopologyConfig = {
192192 legacyReplicaUrl ?: string ;
193193 newUrl ?: string ;
194194 newReplicaUrl ?: string ;
195- // When the legacy DSN targets the same physical DB as the control plane (the pre-cutover reality),
196- // reuse the control-plane client by reference instead of opening a second, redundant pool against
197- // the same server. The env-bound singleton computes this via sameDatabaseTarget(). Defaults to false
198- // (build an independent legacy client — the post-cutover / distinct-DB behaviour).
195+ // When true, legacy reuses the control-plane client instead of opening its own pool. Defaults to false.
199196 legacySharesControlPlane ?: boolean ;
200197} ;
201198export type RunOpsClientBuilders = {
@@ -231,15 +228,12 @@ export function selectRunOpsTopology(
231228 return { newRunOps : cpFallback , legacyRunOps : controlPlane , controlPlane } ;
232229 }
233230
234- // When the legacy DSN targets the same physical DB as the control plane (true pre-cutover), reuse
235- // the control-plane client by reference — no second pool against the same server, so split-on can't
236- // double RDS connections. buildLegacy* runs only once the DSNs diverge (post control-plane cutover).
231+ // Same-DB legacy reuses the control-plane pool; only build a separate pool once the DSNs diverge.
237232 let legacyRunOps : RunOpsClients ;
238233 if ( config . legacySharesControlPlane ) {
239234 legacyRunOps = controlPlane ;
240235 } else {
241236 const legacyWriter = builders . buildLegacyWriter ( config . legacyUrl , "run-ops-legacy-writer" ) ;
242- // Brand a real replica (in the builder), otherwise fall back to the legacy WRITER — unbranded.
243237 const legacyReplica : PrismaReplicaClient = config . legacyReplicaUrl
244238 ? builders . buildLegacyReplica ( config . legacyReplicaUrl , "run-ops-legacy-reader" )
245239 : legacyWriter ;
@@ -270,8 +264,8 @@ const runOpsTopology: RunOpsTopology = singleton("runOpsTopology", () => {
270264 // Gate on the opt-in flag too: the distinct-DB sentinel only runs when the flag is on.
271265 const splitEnabled = env . RUN_OPS_SPLIT_ENABLED && ! ! newUrl && ! ! env . RUN_OPS_LEGACY_DATABASE_URL ;
272266
273- // Reuse the control-plane pool for legacy when both roles target the same physical DB (compare the
274- // effective URLs, applying the same writer fallback each replica uses when its own URL is unset ).
267+ // Alias legacy onto the control-plane pool when both roles resolve to the same DB (replica URLs
268+ // fall back to their writer, matching how the clients themselves fall back ).
275269 const cpWriterUrl = env . CONTROL_PLANE_DATABASE_URL ?? env . DATABASE_URL ;
276270 const cpReplicaUrl = env . CONTROL_PLANE_DATABASE_READ_REPLICA_URL ?? env . DATABASE_READ_REPLICA_URL ;
277271 const legacySharesControlPlane =
@@ -281,8 +275,7 @@ const runOpsTopology: RunOpsTopology = singleton("runOpsTopology", () => {
281275 cpReplicaUrl ?? cpWriterUrl
282276 ) ;
283277
284- // Only meaningful for an INDEPENDENT legacy pool: without its own replica URL, legacy reads fall
285- // back to the legacy primary. A shared pool routes through $replica instead, so the warning is moot.
278+ // Only meaningful for an independent legacy pool; a shared pool routes reads through $replica.
286279 if ( splitEnabled && ! legacySharesControlPlane && ! env . RUN_OPS_LEGACY_DATABASE_READ_REPLICA_URL ) {
287280 logger . warn (
288281 "RUN_OPS_LEGACY_DATABASE_READ_REPLICA_URL is unset while split is enabled; legacy reads will hit the legacy primary"
@@ -731,8 +724,7 @@ function buildRunOpsReplicaClient({
731724 clientType : string ;
732725} ) : RunOpsPrismaClient {
733726 const replicaUrl = extendQueryParams ( url , {
734- // The new run-ops replica is UNPOOLED (direct to the replica host), so it draws raw backend
735- // connections. Cap it independently when set; otherwise behave exactly as before.
727+ // The new run-ops replica connects unpooled, so allow capping it independently of the writer.
736728 connection_limit : (
737729 env . RUN_OPS_DATABASE_READ_REPLICA_CONNECTION_LIMIT ?? env . DATABASE_CONNECTION_LIMIT
738730 ) . toString ( ) ,
@@ -778,10 +770,8 @@ function buildRunOpsReplicaClient({
778770 return client ;
779771}
780772
781- // True when two DSNs point at the same physical database (host/port/dbname/user), ignoring query
782- // params (connection_limit etc. differ) and password. Parse failure -> false: don't alias, just build
783- // independently (no correctness risk, only a missed dedup). Used to decide whether the legacy run-ops
784- // client can share the control-plane pool instead of opening a redundant one against the same server.
773+ // True when two DSNs point at the same database (host/port/dbname/user), ignoring query params and
774+ // password. Parse failure or a missing URL returns false, so an unrecognized DSN just isn't aliased.
785775export function sameDatabaseTarget ( a : string | undefined , b : string | undefined ) : boolean {
786776 if ( ! a || ! b ) return false ;
787777 try {
0 commit comments