@mark1russell7/service 0.8.19 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/build/backoff.d.ts +44 -2
- package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
- package/build/builder.js +499 -0
- package/build/builder.js.map +1 -0
- package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
- package/build/channel.d.ts +1 -1
- package/build/channel.js.map +1 -1
- package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
- package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
- package/build/client/core.js.map +1 -0
- package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
- package/build/client/dial.js +52 -0
- package/build/client/dial.js.map +1 -0
- package/build/client/machine.js +29 -0
- package/build/client/machine.js.map +1 -0
- package/build/client/meets.d.ts +35 -0
- package/build/client/meets.js +78 -0
- package/build/client/meets.js.map +1 -0
- package/build/clock.d.ts +2 -2
- package/build/clock.js +1 -1
- package/build/conformance.d.ts +122 -0
- package/build/conformance.js +469 -0
- package/build/conformance.js.map +1 -0
- package/build/contract.d.ts +28 -0
- package/build/contract.js +184 -0
- package/build/contract.js.map +1 -0
- package/build/description.d.ts +161 -0
- package/build/description.js +11 -0
- package/build/description.js.map +1 -0
- package/build/drains.js +35 -0
- package/build/drains.js.map +1 -0
- package/build/events.d.ts +25 -0
- package/build/fakes.d.ts +43 -0
- package/build/fakes.js +93 -0
- package/build/fakes.js.map +1 -0
- package/build/grpc/client.d.ts +153 -0
- package/build/grpc/client.js +474 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/connection.d.ts +97 -0
- package/build/grpc/connection.js +59 -0
- package/build/grpc/connection.js.map +1 -0
- package/build/grpc/machine.d.ts +12 -0
- package/build/grpc/machine.js +149 -0
- package/build/grpc/machine.js.map +1 -0
- package/build/grpc/meets.d.ts +14 -0
- package/build/grpc/meets.js +105 -0
- package/build/grpc/meets.js.map +1 -0
- package/build/grpc/starting.d.ts +33 -0
- package/build/grpc/starting.js +89 -0
- package/build/grpc/starting.js.map +1 -0
- package/build/grpc.d.ts +9 -303
- package/build/grpc.js +7 -854
- package/build/health.d.ts +93 -0
- package/build/health.js +225 -0
- package/build/health.js.map +1 -0
- package/build/heartbeat.d.ts +6 -2
- package/build/heartbeat.js.map +1 -1
- package/build/host/discovery.d.ts +61 -0
- package/build/host/discovery.js +113 -0
- package/build/host/discovery.js.map +1 -0
- package/build/host/env.d.ts +14 -0
- package/build/host/env.js +57 -0
- package/build/host/env.js.map +1 -0
- package/build/host/fakes.d.ts +82 -0
- package/build/host/fakes.js +239 -0
- package/build/host/fakes.js.map +1 -0
- package/build/host/group.d.ts +142 -0
- package/build/host/group.js +524 -0
- package/build/host/group.js.map +1 -0
- package/build/host/install.d.ts +96 -0
- package/build/host/install.js +330 -0
- package/build/host/install.js.map +1 -0
- package/build/host/lock.d.ts +78 -0
- package/build/host/lock.js +190 -0
- package/build/host/lock.js.map +1 -0
- package/build/host/logs.d.ts +26 -0
- package/build/host/logs.js +48 -0
- package/build/host/logs.js.map +1 -0
- package/build/host/node.d.ts +14 -0
- package/build/host/node.js +309 -0
- package/build/host/node.js.map +1 -0
- package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
- package/build/host/ports.js +17 -0
- package/build/host/ports.js.map +1 -0
- package/build/host/probes.d.ts +51 -0
- package/build/host/probes.js +139 -0
- package/build/host/probes.js.map +1 -0
- package/build/host/processes.d.ts +32 -0
- package/build/host/processes.js +63 -0
- package/build/host/processes.js.map +1 -0
- package/build/host/render.d.ts +84 -0
- package/build/host/render.js +235 -0
- package/build/host/render.js.map +1 -0
- package/build/host/watch.d.ts +90 -0
- package/build/host/watch.js +165 -0
- package/build/host/watch.js.map +1 -0
- package/build/host.d.ts +13 -671
- package/build/host.js +12 -2126
- package/build/http/answers.js +29 -0
- package/build/http/answers.js.map +1 -0
- package/build/http/fake-server.js +61 -0
- package/build/http/fake-server.js.map +1 -0
- package/build/http/outcome.d.ts +115 -0
- package/build/http/outcome.js +325 -0
- package/build/http/outcome.js.map +1 -0
- package/build/http/probes.d.ts +83 -0
- package/build/http/probes.js +232 -0
- package/build/http/probes.js.map +1 -0
- package/build/http/transport.d.ts +165 -0
- package/build/http/transport.js +518 -0
- package/build/http/transport.js.map +1 -0
- package/build/http-client/client.d.ts +121 -0
- package/build/http-client/client.js +330 -0
- package/build/http-client/client.js.map +1 -0
- package/build/http-client/connection.d.ts +78 -0
- package/build/http-client/connection.js +54 -0
- package/build/http-client/connection.js.map +1 -0
- package/build/http-client/machine.d.ts +14 -0
- package/build/http-client/machine.js +109 -0
- package/build/http-client/machine.js.map +1 -0
- package/build/http-client/meets.d.ts +11 -0
- package/build/http-client/meets.js +74 -0
- package/build/http-client/meets.js.map +1 -0
- package/build/http-client/session.d.ts +87 -0
- package/build/http-client/session.js +99 -0
- package/build/http-client/session.js.map +1 -0
- package/build/http-client/starting.d.ts +25 -0
- package/build/http-client/starting.js +65 -0
- package/build/http-client/starting.js.map +1 -0
- package/build/http-client.d.ts +9 -330
- package/build/http-client.js +8 -707
- package/build/http.d.ts +5 -353
- package/build/http.js +3 -1086
- package/build/identity.d.ts +16 -0
- package/build/identity.js +44 -0
- package/build/identity.js.map +1 -0
- package/build/index.d.ts +35 -412
- package/build/index.js +25 -3278
- package/build/knobs.d.ts +1 -0
- package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
- package/build/knobs.js.map +1 -0
- package/build/latch.d.ts +29 -0
- package/build/latch.js +122 -0
- package/build/latch.js.map +1 -0
- package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
- package/build/law.js +149 -0
- package/build/law.js.map +1 -0
- package/build/lifecycle.d.ts +144 -0
- package/build/lifecycle.js +411 -0
- package/build/lifecycle.js.map +1 -0
- package/build/limiter/machine.d.ts +40 -0
- package/build/limiter/machine.js +279 -0
- package/build/limiter/machine.js.map +1 -0
- package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
- package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
- package/build/limiter/policy.js.map +1 -0
- package/build/{limiter-BNKnwzeY.d.ts → limiter/quota.d.ts} +32 -74
- package/build/{limiter-DrM0PQV9.js → limiter/quota.js} +3 -418
- package/build/limiter/quota.js.map +1 -0
- package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
- package/build/limiter/store.js +145 -0
- package/build/limiter/store.js.map +1 -0
- package/build/limiter.d.ts +4 -3
- package/build/limiter.js +4 -2
- package/build/lint.d.ts +152 -0
- package/build/lint.js +576 -0
- package/build/lint.js.map +1 -0
- package/build/logger.d.ts +71 -0
- package/build/logger.js +183 -0
- package/build/logger.js.map +1 -0
- package/build/machines.d.ts +41 -0
- package/build/machines.js +451 -0
- package/build/machines.js.map +1 -0
- package/build/metrics.d.ts +53 -0
- package/build/metrics.js +111 -0
- package/build/metrics.js.map +1 -0
- package/build/mongodb/client.d.ts +131 -0
- package/build/mongodb/client.js +388 -0
- package/build/mongodb/client.js.map +1 -0
- package/build/mongodb/connection.d.ts +112 -0
- package/build/mongodb/connection.js +12 -0
- package/build/mongodb/connection.js.map +1 -0
- package/build/mongodb/machine.d.ts +14 -0
- package/build/mongodb/machine.js +122 -0
- package/build/mongodb/machine.js.map +1 -0
- package/build/mongodb/meets.d.ts +15 -0
- package/build/mongodb/meets.js +103 -0
- package/build/mongodb/meets.js.map +1 -0
- package/build/mongodb/starting.d.ts +29 -0
- package/build/mongodb/starting.js +77 -0
- package/build/mongodb/starting.js.map +1 -0
- package/build/mongodb.d.ts +8 -296
- package/build/mongodb.js +7 -682
- package/build/operation.d.ts +27 -0
- package/build/{operation-DF73RZOI.js → operation.js} +2 -2
- package/build/operation.js.map +1 -0
- package/build/otel.d.ts +2 -2
- package/build/pg/client.d.ts +96 -0
- package/build/pg/client.js +277 -0
- package/build/pg/client.js.map +1 -0
- package/build/pg/connection.d.ts +75 -0
- package/build/pg/connection.js +11 -0
- package/build/pg/connection.js.map +1 -0
- package/build/pg/machine.d.ts +13 -0
- package/build/pg/machine.js +111 -0
- package/build/pg/machine.js.map +1 -0
- package/build/pg/meets.d.ts +14 -0
- package/build/pg/meets.js +83 -0
- package/build/pg/meets.js.map +1 -0
- package/build/pg/starting.d.ts +26 -0
- package/build/pg/starting.js +62 -0
- package/build/pg/starting.js.map +1 -0
- package/build/pg.d.ts +8 -219
- package/build/pg.js +7 -525
- package/build/poller.d.ts +9 -0
- package/build/poller.js +154 -0
- package/build/poller.js.map +1 -0
- package/build/process.d.ts +114 -0
- package/build/process.js +170 -0
- package/build/process.js.map +1 -0
- package/build/profiles.d.ts +68 -0
- package/build/profiles.js +120 -0
- package/build/profiles.js.map +1 -0
- package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
- package/build/queue.js +279 -0
- package/build/queue.js.map +1 -0
- package/build/rabbitmq/client.d.ts +144 -0
- package/build/rabbitmq/client.js +426 -0
- package/build/rabbitmq/client.js.map +1 -0
- package/build/rabbitmq/connection.d.ts +91 -0
- package/build/rabbitmq/connection.js +15 -0
- package/build/rabbitmq/connection.js.map +1 -0
- package/build/rabbitmq/machine.d.ts +13 -0
- package/build/rabbitmq/machine.js +159 -0
- package/build/rabbitmq/machine.js.map +1 -0
- package/build/rabbitmq/meets.d.ts +12 -0
- package/build/rabbitmq/meets.js +96 -0
- package/build/rabbitmq/meets.js.map +1 -0
- package/build/rabbitmq/starting.d.ts +27 -0
- package/build/rabbitmq/starting.js +67 -0
- package/build/rabbitmq/starting.js.map +1 -0
- package/build/rabbitmq.d.ts +8 -283
- package/build/rabbitmq.js +7 -742
- package/build/redis/client.d.ts +86 -0
- package/build/redis/client.js +285 -0
- package/build/redis/client.js.map +1 -0
- package/build/redis/connection.d.ts +57 -0
- package/build/redis/connection.js +11 -0
- package/build/redis/connection.js.map +1 -0
- package/build/redis/limiter.d.ts +43 -0
- package/build/redis/limiter.js +164 -0
- package/build/redis/limiter.js.map +1 -0
- package/build/redis/machine.d.ts +12 -0
- package/build/redis/machine.js +144 -0
- package/build/redis/machine.js.map +1 -0
- package/build/redis/meets.d.ts +11 -0
- package/build/redis/meets.js +75 -0
- package/build/redis/meets.js.map +1 -0
- package/build/redis/operations.d.ts +5 -0
- package/build/redis/operations.js +114 -0
- package/build/redis/operations.js.map +1 -0
- package/build/redis.d.ts +10 -207
- package/build/redis.js +9 -771
- package/build/requests.d.ts +66 -0
- package/build/requests.js +279 -0
- package/build/requests.js.map +1 -0
- package/build/retrier.d.ts +62 -0
- package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
- package/build/retrier.js.map +1 -0
- package/build/routes.d.ts +35 -0
- package/build/routes.js +77 -0
- package/build/routes.js.map +1 -0
- package/build/rules.d.ts +19 -2
- package/build/stops.d.ts +51 -0
- package/build/stops.js +86 -0
- package/build/stops.js.map +1 -0
- package/build/testing.d.ts +8 -270
- package/build/testing.js +4 -1027
- package/build/testing.js.map +1 -1
- package/build/timing.d.ts +63 -0
- package/build/{timing-DZl36uXs.js → timing.js} +2 -2
- package/build/timing.js.map +1 -0
- package/build/units.d.ts +17 -0
- package/build/units.js +236 -0
- package/build/units.js.map +1 -0
- package/build/watchdog.d.ts +38 -0
- package/build/watchdog.js +57 -0
- package/build/watchdog.js.map +1 -0
- package/build/websocket/client.d.ts +136 -0
- package/build/websocket/client.js +422 -0
- package/build/websocket/client.js.map +1 -0
- package/build/websocket/connection.d.ts +83 -0
- package/build/websocket/connection.js +57 -0
- package/build/websocket/connection.js.map +1 -0
- package/build/websocket/machine.d.ts +12 -0
- package/build/websocket/machine.js +155 -0
- package/build/websocket/machine.js.map +1 -0
- package/build/websocket/meets.d.ts +14 -0
- package/build/websocket/meets.js +92 -0
- package/build/websocket/meets.js.map +1 -0
- package/build/websocket/starting.d.ts +25 -0
- package/build/websocket/starting.js +69 -0
- package/build/websocket/starting.js.map +1 -0
- package/build/websocket.d.ts +9 -264
- package/build/websocket.js +8 -774
- package/build/worker.d.ts +92 -0
- package/build/worker.js +153 -0
- package/build/worker.js.map +1 -0
- package/package.json +5 -4
- package/build/backoff-QTRGfkEK.d.ts +0 -45
- package/build/clock-DpVgpY4h.d.ts +0 -2
- package/build/grpc.js.map +0 -1
- package/build/host.js.map +0 -1
- package/build/http-client.js.map +0 -1
- package/build/http.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/knobs-BJcz6m01.js.map +0 -1
- package/build/lifecycle-D0J-zwZF.d.ts +0 -374
- package/build/limiter-DrM0PQV9.js.map +0 -1
- package/build/logger-B6drv9w0.d.ts +0 -488
- package/build/machine-BhVeHr_m.js.map +0 -1
- package/build/mongodb.js.map +0 -1
- package/build/operation-DF73RZOI.js.map +0 -1
- package/build/pg.js.map +0 -1
- package/build/policy-UYALkqVq.js.map +0 -1
- package/build/process-7R9M29wN.js +0 -437
- package/build/process-7R9M29wN.js.map +0 -1
- package/build/rabbitmq.js.map +0 -1
- package/build/redis.js.map +0 -1
- package/build/requests-DD2ALv0_.js +0 -583
- package/build/requests-DD2ALv0_.js.map +0 -1
- package/build/retrier-Dnjhvxol.js.map +0 -1
- package/build/timing-DZl36uXs.js.map +0 -1
- package/build/websocket.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","names":[],"sources":["../src/metrics.ts"],"sourcesContent":["import { valueIn } from \"@mark1russell7/quantity\";\nimport type { Check } from \"./description.ts\";\nimport type { LifecycleEvent } from \"./events.ts\";\nimport type { Result } from \"./latch.ts\";\n\n/**\n * A histogram of durations counts the polls of a check by how long each one took (B18). Each bound\n * is a fraction of the timeout of the poll, thus the last bound is the timeout. A poll that failed\n * at its timeout goes into `timedOut`, not into a bucket. Thus the histogram marks the timeouts.\n */\nexport interface DurationHistogram {\n /** These bounds are in milliseconds, from the smallest. A bucket counts each poll that took more than the bound before it, up to its own bound. */\n readonly le: readonly number[];\n /** These counts are not cumulative: one count for each bound. */\n readonly counts: readonly number[];\n readonly timedOut: number;\n}\n\n/** An episode of failure starts at the first error of a sequence, and ends at the next pass (B18). */\nexport interface Episode {\n /** This time is the first error, in milliseconds on the monotonic clock. */\n readonly start: number;\n /** This time is the pass that ended the episode, or null while the episode continues. */\n readonly end: number | null;\n /** This count is the polls that failed in the episode. */\n readonly failures: number;\n /** This cause is the cause of the first error, with each secret removed. */\n readonly cause: string | null;\n}\n\n/** The metrics of one check: the count of each outcome, its durations and its last episodes. */\nexport interface CheckMetrics {\n readonly outcomes: { readonly ok: number; readonly error: number; readonly indeterminate: number };\n readonly thrown: number;\n readonly forced: number;\n readonly durations: DurationHistogram;\n /** These are the last episodes, from the oldest. The runtime keeps `EPISODES_KEPT` of them. */\n readonly episodes: readonly Episode[];\n}\n\n/** The metrics of a health runtime. Nothing in them starts a check. */\nexport interface HealthMetrics {\n readonly checks: Readonly<Record<string, CheckMetrics>>;\n /** Each count is the transitions of one machine of the runtime, by the key `machine instance from -> to`. */\n readonly transitions: Readonly<Record<string, number>>;\n}\n\n/** These fractions of the timeout of a poll are the bounds of its histogram. */\nexport const DURATION_FRACTIONS: readonly number[] = [0.05, 0.1, 0.25, 0.5, 0.75, 1];\n\n/** The runtime keeps this many episodes of each check. */\nexport const EPISODES_KEPT = 8;\n\n/**\n * This function removes the secrets that a cause can hold. These are the user and the password of a\n * URL, and the value of a key, for example `password=`. A driver error can hold a connection string.\n */\nexport const redact = (cause: string): string =>\n cause\n .replace(/(\\b[a-z][a-z0-9+.-]*:\\/\\/)[^\\s/@]*@/gi, \"$1***@\")\n .replace(/\\b(password|passwd|pwd|secret|token|api[_-]?key|auth)(\\s*[=:]\\s*)(\"[^\"]*\"|'[^']*'|[^\\s,;&]+)/gi, \"$1$2***\");\n\ninterface Counted {\n ok: number;\n error: number;\n indeterminate: number;\n thrown: number;\n forced: number;\n readonly le: readonly number[];\n readonly counts: number[];\n timedOut: number;\n readonly episodes: Episode[];\n open: { start: number; failures: number; cause: string | null } | null;\n}\n\n/** A meter counts the results of the checks and the transitions of the machines of a runtime. */\nexport interface Meter {\n add(check: Check): void;\n poll(check: Check, result: Result): void;\n event(event: LifecycleEvent): void;\n metrics(): HealthMetrics;\n}\n\n/** This function makes a meter. */\nexport const meter = (): Meter => {\n const checks = new Map<string, Counted>();\n const transitions = new Map<string, number>();\n\n const add = (check: Check): void => {\n if (checks.has(check.name)) return;\n const timeout = valueIn(check.poll.timeout, \"ms\");\n checks.set(check.name, {\n ok: 0,\n error: 0,\n indeterminate: 0,\n thrown: 0,\n forced: 0,\n le: DURATION_FRACTIONS.map((fraction) => fraction * timeout),\n counts: DURATION_FRACTIONS.map(() => 0),\n timedOut: 0,\n episodes: [],\n open: null,\n });\n };\n\n const close = (counted: Counted, end: number | null): Episode | null => {\n if (counted.open === null) return null;\n return { start: counted.open.start, end, failures: counted.open.failures, cause: counted.open.cause };\n };\n\n const poll = (check: Check, result: Result): void => {\n add(check);\n const counted = checks.get(check.name) as Counted;\n counted[result.outcome] += 1;\n if (result.thrown) counted.thrown += 1;\n if (result.forced) counted.forced += 1;\n if (result.timedOut) counted.timedOut += 1;\n else {\n const at = counted.le.findIndex((bound) => result.took <= bound);\n // a poll that took longer than its timeout and did not time out goes into the last bucket\n const bucket = at === -1 ? counted.counts.length - 1 : at;\n counted.counts[bucket] = (counted.counts[bucket] ?? 0) + 1;\n }\n // an indeterminate poll measured nothing, thus it moves no episode\n if (result.outcome === \"error\") {\n if (counted.open === null) counted.open = { start: result.at, failures: 0, cause: result.cause === null ? null : redact(result.cause) };\n counted.open.failures += 1;\n } else if (result.outcome === \"ok\" && counted.open !== null) {\n counted.episodes.push(close(counted, result.at) as Episode);\n counted.open = null;\n if (counted.episodes.length > EPISODES_KEPT) counted.episodes.shift();\n }\n };\n\n const event = (event: LifecycleEvent): void => {\n const key = `${event.machine} ${event.instance} ${event.from} -> ${event.to}`;\n transitions.set(key, (transitions.get(key) ?? 0) + 1);\n };\n\n const metrics = (): HealthMetrics => {\n const out: Record<string, CheckMetrics> = {};\n for (const [name, counted] of checks) {\n const open = close(counted, null);\n out[name] = {\n outcomes: { ok: counted.ok, error: counted.error, indeterminate: counted.indeterminate },\n thrown: counted.thrown,\n forced: counted.forced,\n durations: { le: [...counted.le], counts: [...counted.counts], timedOut: counted.timedOut },\n episodes: open === null ? [...counted.episodes] : [...counted.episodes, open].slice(-EPISODES_KEPT),\n };\n }\n return { checks: out, transitions: Object.fromEntries(transitions) };\n };\n\n return { add, poll, event, metrics };\n};\n"],"mappings":";;;AAgDA,MAAa,qBAAwC;CAAC;CAAM;CAAK;CAAM;CAAK;CAAM;AAAC;;AAGnF,MAAa,gBAAgB;;;;;AAM7B,MAAa,UAAU,UACrB,MACG,QAAQ,yCAAyC,QAAQ,CAAC,CAC1D,QAAQ,kGAAkG,SAAS;;AAwBxH,MAAa,cAAqB;CAChC,MAAM,yBAAS,IAAI,IAAqB;CACxC,MAAM,8BAAc,IAAI,IAAoB;CAE5C,MAAM,OAAO,UAAuB;EAClC,IAAI,OAAO,IAAI,MAAM,IAAI,GAAG;EAC5B,MAAM,UAAU,QAAQ,MAAM,KAAK,SAAS,IAAI;EAChD,OAAO,IAAI,MAAM,MAAM;GACrB,IAAI;GACJ,OAAO;GACP,eAAe;GACf,QAAQ;GACR,QAAQ;GACR,IAAI,mBAAmB,KAAK,aAAa,WAAW,OAAO;GAC3D,QAAQ,mBAAmB,UAAU,CAAC;GACtC,UAAU;GACV,UAAU,CAAC;GACX,MAAM;EACR,CAAC;CACH;CAEA,MAAM,SAAS,SAAkB,QAAuC;EACtE,IAAI,QAAQ,SAAS,MAAM,OAAO;EAClC,OAAO;GAAE,OAAO,QAAQ,KAAK;GAAO;GAAK,UAAU,QAAQ,KAAK;GAAU,OAAO,QAAQ,KAAK;EAAM;CACtG;CAEA,MAAM,QAAQ,OAAc,WAAyB;EACnD,IAAI,KAAK;EACT,MAAM,UAAU,OAAO,IAAI,MAAM,IAAI;EACrC,QAAQ,OAAO,YAAY;EAC3B,IAAI,OAAO,QAAQ,QAAQ,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O,CAAC,GAAG,QAAQ,QAAQ,IAAI,CAAC,GAAG,QAAQ,UAAU,IAAI,CAAC,CAAC,MAAM,EAAc;GACpG;EACF;EACA,OAAO;GAAE,QAAQ;GAAK,aAAa,OAAO,YAAY,WAAW;EAAE;CACrE;CAEA,OAAO;EAAE;EAAK;EAAM;EAAO;CAAQ;AACrC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Attempt, Client, ClientJoin, ClientKnobs, ClientOptions, ClientSpec, ClientStep, DialFn, SendOptions, Sent } from "../client/core.js";
|
|
2
|
+
import { Judge } from "../client/dial.js";
|
|
3
|
+
import { Operation } from "../operation.js";
|
|
4
|
+
import { MongoConnectOptions, MongoDocument, MongoFactory } from "./connection.js";
|
|
5
|
+
import { Extent, Quantity } from "@mark1russell7/quantity";
|
|
6
|
+
/**
|
|
7
|
+
* These are the knobs of the client, each a time, by the names of the ordering law where the law
|
|
8
|
+
* has them. The runtime has no defaults, thus each knob is necessary. A bound that nobody gives is
|
|
9
|
+
* "infinite", not zero. `MONGO_STARTING_KNOBS` gives a declaration from the cells of S1. The knobs
|
|
10
|
+
* that each client has come from the core.
|
|
11
|
+
*/
|
|
12
|
+
export interface MongoKnobs extends ClientKnobs {
|
|
13
|
+
/** This time bounds the TCP connect and the handshake of each connection (`connectTimeoutMS`). It also bounds the wait of the startup. */
|
|
14
|
+
readonly connect_bound: Quantity;
|
|
15
|
+
/** This time bounds a read of a command in flight (`socketTimeoutMS`). At its end, the driver closes the connection. */
|
|
16
|
+
readonly request_timeout: Quantity;
|
|
17
|
+
/**
|
|
18
|
+
* This time is the deadline of each command on the server (`maxTimeMS`). The wrapper writes it in
|
|
19
|
+
* each command. The server then ends the command with error 50, a certain outcome. "infinite" sends no deadline.
|
|
20
|
+
*/
|
|
21
|
+
readonly statement_timeout: Extent;
|
|
22
|
+
/** This time is the period of the monitor (`heartbeatFrequencyMS`). The driver takes 500 ms at least. */
|
|
23
|
+
readonly heartbeat_interval: Quantity;
|
|
24
|
+
/**
|
|
25
|
+
* This time bounds the wait for a writable server (`serverSelectionTimeoutMS`). A command waits
|
|
26
|
+
* through a failover in this time, thus it is the retry window of the client (O29).
|
|
27
|
+
*/
|
|
28
|
+
readonly client_retry_window: Quantity;
|
|
29
|
+
/** This time bounds a checkout from a full pool (`waitQueueTimeoutMS`). */
|
|
30
|
+
readonly checkout_timeout: Extent;
|
|
31
|
+
/** A checkout ends an idle connection older than this time (`maxIdleTimeMS`). The driver checks it only at a checkout. */
|
|
32
|
+
readonly pool_idle_expiry: Extent;
|
|
33
|
+
/** This time is the idle time of TCP keepalive (`keepAliveInitialDelay`), in whole seconds. The driver always turns keepalive on. */
|
|
34
|
+
readonly keepalive_idle: Extent;
|
|
35
|
+
/** The driver has no age for a connection, thus this knob must be "infinite". */
|
|
36
|
+
readonly max_connection_age: Extent;
|
|
37
|
+
/** This time bounds the close of the client at the shutdown. */
|
|
38
|
+
readonly close_bound: Quantity;
|
|
39
|
+
}
|
|
40
|
+
/** A seed is one more host that the driver connects to first, for example a member of a replica set. */
|
|
41
|
+
export interface MongoSeed {
|
|
42
|
+
readonly host: string;
|
|
43
|
+
readonly port: number;
|
|
44
|
+
}
|
|
45
|
+
/** A MongoDB client spec is the declaration of one MongoDB client: where it connects, its pool, and its knobs. */
|
|
46
|
+
export interface MongoClientSpec extends ClientSpec<MongoKnobs> {
|
|
47
|
+
/** This name is the database of the commands of the client. */
|
|
48
|
+
readonly database: string;
|
|
49
|
+
readonly username?: string | undefined;
|
|
50
|
+
/** This name is the database of the user. The default of the driver is `database`, or `admin`. */
|
|
51
|
+
readonly authSource?: string | undefined;
|
|
52
|
+
readonly replicaSet?: string | undefined;
|
|
53
|
+
/** These hosts are more seeds of the topology, after `host` and `port`. */
|
|
54
|
+
readonly seeds?: readonly MongoSeed[] | undefined;
|
|
55
|
+
/** These counts are the sizes of the pool of each server: at most `max` connections, and `min` that the driver keeps open. */
|
|
56
|
+
readonly pool: {
|
|
57
|
+
readonly max: number;
|
|
58
|
+
readonly min: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* These operations are the commands of the service, by name, with their idempotency. A command
|
|
62
|
+
* name does not tell if a command changes a state, for example an `aggregate` with `$merge`. Thus
|
|
63
|
+
* the client sends again only a command that this table names.
|
|
64
|
+
*/
|
|
65
|
+
readonly operations?: Readonly<Record<string, Operation>> | undefined;
|
|
66
|
+
}
|
|
67
|
+
/** These options make a client. Without them, it uses the driver, the real clock, and a dial with a hello. */
|
|
68
|
+
export type MongoClientOptions = ClientOptions<MongoFactory>;
|
|
69
|
+
/**
|
|
70
|
+
* A join is one connection of the pool, when its handshake is done (D1, D2). The prober joins its
|
|
71
|
+
* kernel records to the server's view of the connection through it. The driver gives no socket,
|
|
72
|
+
* thus the local address and port are null. The server's view is the connection id of its hello.
|
|
73
|
+
*/
|
|
74
|
+
export interface MongoJoin extends ClientJoin {
|
|
75
|
+
/** This text is the address of the server, as `host:port`. */
|
|
76
|
+
readonly address: string;
|
|
77
|
+
/** This number is the connection id that the server gave, from the first command on the connection. Null until that command. */
|
|
78
|
+
readonly serverConnectionId: number | null;
|
|
79
|
+
}
|
|
80
|
+
/** The steps that the MongoDB client gives a check for. A pool of the driver has no checkout that the wrapper can use. */
|
|
81
|
+
export type MongoStep = ClientStep;
|
|
82
|
+
/** A MongoDB client is a dependency of a service: its declaration, its handle, its checks and its commands. */
|
|
83
|
+
export interface MongoClient extends Client<MongoStep, MongoJoin> {
|
|
84
|
+
/** This text is the state of the client, as `MONGO_CLIENT_MACHINE` names it. */
|
|
85
|
+
readonly status: string;
|
|
86
|
+
/**
|
|
87
|
+
* This method sends a command to the database of the spec, and gives its outcome in three values.
|
|
88
|
+
* `operation` names the command in the table of operations. The client sends again only an
|
|
89
|
+
* idempotent operation, one time at most, after an outcome that is not certain.
|
|
90
|
+
*/
|
|
91
|
+
command(operation: string, document: MongoDocument, options?: SendOptions): Promise<Sent<MongoDocument>>;
|
|
92
|
+
}
|
|
93
|
+
/** This function gives the problems of a spec: the knobs that the driver cannot use. */
|
|
94
|
+
export declare const specProblems: (name: string, spec: MongoClientSpec) => string[];
|
|
95
|
+
/** This function gives the arguments of `new MongoClient` from a spec. Each timer of the driver comes from the declaration. */
|
|
96
|
+
export declare const mongoOptions: (name: string, spec: MongoClientSpec) => MongoConnectOptions;
|
|
97
|
+
/**
|
|
98
|
+
* The bytes of an OP_MSG with the command `{ hello: 1, $db: "admin" }`. They are a header of 16
|
|
99
|
+
* bytes with the op code 2013, the flags, a section of kind 0, and the BSON document. The server answers a
|
|
100
|
+
* hello before the authentication, thus the dial needs no password.
|
|
101
|
+
*/
|
|
102
|
+
export declare const HELLO: Uint8Array;
|
|
103
|
+
/**
|
|
104
|
+
* This judge reads the answer to the hello. It waits for the whole message. The message must be an
|
|
105
|
+
* OP_MSG with a section of kind 0, and its document must have `ok` 1.
|
|
106
|
+
*/
|
|
107
|
+
export declare const helloJudge: Judge;
|
|
108
|
+
/** This dial function opens a TCP connection, sends a hello, and waits for its reply. The server opens no session for it. */
|
|
109
|
+
export declare const helloCommandDial: DialFn;
|
|
110
|
+
/**
|
|
111
|
+
* This function gives the outcome of a failure of the driver. The driver names each error class,
|
|
112
|
+
* thus the wrapper reads the name, and depends on no class of the driver:
|
|
113
|
+
* - A failure before the command left the client is certain: it did not apply.
|
|
114
|
+
* - An error of the server is certain, except an interruption, which can leave a part applied.
|
|
115
|
+
* - A write concern error, a network error after the handshake, and a timeout of the socket are not certain.
|
|
116
|
+
*/
|
|
117
|
+
export declare const failureOutcome: (error: unknown) => Attempt<never>;
|
|
118
|
+
/**
|
|
119
|
+
* This function makes a MongoDB client, a dependency of a service over a `MongoClient`.
|
|
120
|
+
* - It sets each timer of the driver from the declaration, and it turns off the retries of the driver.
|
|
121
|
+
* The client sends again only an idempotent operation of its table.
|
|
122
|
+
* - It tells the outcome of a command in three values, from the name of each error of the driver.
|
|
123
|
+
* - It writes the deadline of the server in each command (`maxTimeMS`), thus the server ends a slow command first (O07).
|
|
124
|
+
* - It gives the state from the view of the topology: ready while a server is writable.
|
|
125
|
+
* - It listens to each error of the driver. In Node, an error with no listener throws, and library code does not end the process (A5).
|
|
126
|
+
* - It records the connection id of the server for each connection of the pool (D1).
|
|
127
|
+
*
|
|
128
|
+
* The outcomes, the second try, the commands in flight, the bounded close and the checks come from
|
|
129
|
+
* the core of the clients. This entry gives what the driver does in its own way.
|
|
130
|
+
*/
|
|
131
|
+
export declare const mongoClient: (name: string, spec: MongoClientSpec, options?: MongoClientOptions) => MongoClient;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { realClock } from "../clock.js";
|
|
2
|
+
import { ageProblems, attachClient, clientBounds, clientProblems, clientRecorder, deadlineProblem, dialCheck, finiteMs, inFlight, keepaliveOnProblems, localStateCheck, message, ms, notSent, operationTable, orZero, poolProblems, roundTripCheck, sendWithReissue, stepChecks, timeProblems, wholeProblems, withinBound, zeroProblems } from "../client/core.js";
|
|
3
|
+
import { helloDial } from "../client/dial.js";
|
|
4
|
+
import { nodeMongo } from "./connection.js";
|
|
5
|
+
import { mongoMeetings } from "./meets.js";
|
|
6
|
+
// src/mongodb/client.ts
|
|
7
|
+
/** The driver takes a period of the monitor of 500 ms at least. */
|
|
8
|
+
const LEAST_HEARTBEAT_MS = 500;
|
|
9
|
+
/** This function gives the problems of a spec: the knobs that the driver cannot use. */
|
|
10
|
+
const specProblems = (name, spec) => {
|
|
11
|
+
const { knobs } = spec;
|
|
12
|
+
const problems = [
|
|
13
|
+
...timeProblems(name, knobs),
|
|
14
|
+
...zeroProblems(name, "the driver", knobs, {
|
|
15
|
+
bounded: [
|
|
16
|
+
"connect_bound",
|
|
17
|
+
"request_timeout",
|
|
18
|
+
"heartbeat_interval",
|
|
19
|
+
"client_retry_window",
|
|
20
|
+
"close_bound"
|
|
21
|
+
],
|
|
22
|
+
open: [
|
|
23
|
+
"statement_timeout",
|
|
24
|
+
"checkout_timeout",
|
|
25
|
+
"pool_idle_expiry"
|
|
26
|
+
]
|
|
27
|
+
}),
|
|
28
|
+
...wholeProblems(name, knobs, {
|
|
29
|
+
millis: [
|
|
30
|
+
"connect_bound",
|
|
31
|
+
"request_timeout",
|
|
32
|
+
"statement_timeout",
|
|
33
|
+
"heartbeat_interval",
|
|
34
|
+
"client_retry_window",
|
|
35
|
+
"checkout_timeout",
|
|
36
|
+
"pool_idle_expiry"
|
|
37
|
+
],
|
|
38
|
+
seconds: ["keepalive_idle"]
|
|
39
|
+
}),
|
|
40
|
+
...poolProblems(name, spec.pool)
|
|
41
|
+
];
|
|
42
|
+
if (ms(knobs.heartbeat_interval) < LEAST_HEARTBEAT_MS) problems.push(`${name}'s heartbeat_interval is below 500 ms, the least that the driver takes`);
|
|
43
|
+
problems.push(...keepaliveOnProblems(name, knobs, "the driver"), ...ageProblems(name, knobs, "the driver has no age for a connection"));
|
|
44
|
+
return problems;
|
|
45
|
+
};
|
|
46
|
+
/** This function gives the arguments of `new MongoClient` from a spec. Each timer of the driver comes from the declaration. */
|
|
47
|
+
const mongoOptions = (name, spec) => {
|
|
48
|
+
const { knobs } = spec;
|
|
49
|
+
return {
|
|
50
|
+
url: `mongodb://${[{
|
|
51
|
+
host: spec.host,
|
|
52
|
+
port: spec.port
|
|
53
|
+
}, ...spec.seeds ?? []].map((seed) => `${seed.host}:${seed.port}`).join(",")}/`,
|
|
54
|
+
options: {
|
|
55
|
+
appName: name,
|
|
56
|
+
...spec.replicaSet === void 0 ? {} : { replicaSet: spec.replicaSet },
|
|
57
|
+
...spec.username === void 0 ? {} : { auth: {
|
|
58
|
+
username: spec.username,
|
|
59
|
+
password: spec.password ?? ""
|
|
60
|
+
} },
|
|
61
|
+
...spec.authSource === void 0 ? {} : { authSource: spec.authSource },
|
|
62
|
+
maxPoolSize: spec.pool.max,
|
|
63
|
+
minPoolSize: spec.pool.min,
|
|
64
|
+
connectTimeoutMS: ms(knobs.connect_bound),
|
|
65
|
+
socketTimeoutMS: ms(knobs.request_timeout),
|
|
66
|
+
serverSelectionTimeoutMS: ms(knobs.client_retry_window),
|
|
67
|
+
heartbeatFrequencyMS: ms(knobs.heartbeat_interval),
|
|
68
|
+
waitQueueTimeoutMS: orZero(knobs.checkout_timeout),
|
|
69
|
+
maxIdleTimeMS: orZero(knobs.pool_idle_expiry),
|
|
70
|
+
keepAliveInitialDelay: ms(knobs.keepalive_idle),
|
|
71
|
+
serverMonitoringMode: "stream",
|
|
72
|
+
retryReads: false,
|
|
73
|
+
retryWrites: false,
|
|
74
|
+
monitorCommands: true
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The bytes of an OP_MSG with the command `{ hello: 1, $db: "admin" }`. They are a header of 16
|
|
80
|
+
* bytes with the op code 2013, the flags, a section of kind 0, and the BSON document. The server answers a
|
|
81
|
+
* hello before the authentication, thus the dial needs no password.
|
|
82
|
+
*/
|
|
83
|
+
const HELLO = Uint8Array.of(52, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 221, 7, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 16, 104, 101, 108, 108, 111, 0, 1, 0, 0, 0, 2, 36, 100, 98, 0, 6, 0, 0, 0, 97, 100, 109, 105, 110, 0, 0);
|
|
84
|
+
/** The sizes of the values of the BSON types that a hello reply holds, by type. A null size has a length prefix. */
|
|
85
|
+
const FIXED = {
|
|
86
|
+
1: 8,
|
|
87
|
+
7: 12,
|
|
88
|
+
8: 1,
|
|
89
|
+
9: 8,
|
|
90
|
+
10: 0,
|
|
91
|
+
16: 4,
|
|
92
|
+
17: 8,
|
|
93
|
+
18: 8,
|
|
94
|
+
19: 16
|
|
95
|
+
};
|
|
96
|
+
/** This function gives the value of `ok` at the top of a BSON document, or an error. */
|
|
97
|
+
const okOf = (doc) => {
|
|
98
|
+
let at = 4;
|
|
99
|
+
while (at < doc.length - 1) {
|
|
100
|
+
const type = doc[at];
|
|
101
|
+
const end = doc.indexOf(0, at + 1);
|
|
102
|
+
if (end < 0) return /* @__PURE__ */ new Error("the hello reply has a field with no end");
|
|
103
|
+
const key = doc.toString("latin1", at + 1, end);
|
|
104
|
+
at = end + 1;
|
|
105
|
+
if (key === "ok") {
|
|
106
|
+
if (type === 1) return doc.readDoubleLE(at);
|
|
107
|
+
if (type === 16) return doc.readInt32LE(at);
|
|
108
|
+
return /* @__PURE__ */ new Error(`the ok of the hello reply has the BSON type ${type}`);
|
|
109
|
+
}
|
|
110
|
+
const fixed = FIXED[type];
|
|
111
|
+
if (fixed !== void 0) at += fixed;
|
|
112
|
+
else if (type === 2) at += 4 + doc.readInt32LE(at);
|
|
113
|
+
else if (type === 3 || type === 4) at += doc.readInt32LE(at);
|
|
114
|
+
else if (type === 5) at += 5 + doc.readInt32LE(at);
|
|
115
|
+
else return /* @__PURE__ */ new Error(`the hello reply has the BSON type ${type}, which the dial does not read`);
|
|
116
|
+
}
|
|
117
|
+
return /* @__PURE__ */ new Error("the hello reply has no ok");
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* This judge reads the answer to the hello. It waits for the whole message. The message must be an
|
|
121
|
+
* OP_MSG with a section of kind 0, and its document must have `ok` 1.
|
|
122
|
+
*/
|
|
123
|
+
const helloJudge = (received) => {
|
|
124
|
+
if (received.length < 4) return "more";
|
|
125
|
+
const length = received.readInt32LE(0);
|
|
126
|
+
if (length < 26 || length > 50331648) return /* @__PURE__ */ new Error(`the answer to the hello has a length of ${length}`);
|
|
127
|
+
if (received.length < length) return "more";
|
|
128
|
+
const opCode = received.readInt32LE(12);
|
|
129
|
+
if (opCode !== 2013) return /* @__PURE__ */ new Error(`the answer to the hello has the op code ${opCode}, not 2013`);
|
|
130
|
+
if (received[20] !== 0) return /* @__PURE__ */ new Error("the answer to the hello has no section of kind 0");
|
|
131
|
+
const ok = okOf(received.subarray(21, length));
|
|
132
|
+
if (ok instanceof Error) return ok;
|
|
133
|
+
return ok === 1 ? null : /* @__PURE__ */ new Error(`the hello reply has ok ${ok}`);
|
|
134
|
+
};
|
|
135
|
+
/** This dial function opens a TCP connection, sends a hello, and waits for its reply. The server opens no session for it. */
|
|
136
|
+
const helloCommandDial = helloDial(HELLO, helloJudge);
|
|
137
|
+
/** These errors tell that the command did not leave the client: no server, a full pool, a cleared pool, or a closed client. */
|
|
138
|
+
const NOT_SENT = /* @__PURE__ */ new Set([
|
|
139
|
+
"MongoServerSelectionError",
|
|
140
|
+
"MongoWaitQueueTimeoutError",
|
|
141
|
+
"MongoPoolClearedError",
|
|
142
|
+
"MongoPoolClosedError",
|
|
143
|
+
"MongoServerClosedError",
|
|
144
|
+
"MongoTopologyClosedError",
|
|
145
|
+
"MongoNotConnectedError",
|
|
146
|
+
"MongoClientClosedError"
|
|
147
|
+
]);
|
|
148
|
+
/**
|
|
149
|
+
* These codes of the server tell that the server interrupted the command. The causes are its
|
|
150
|
+
* shutdown, a step down, or a change of the state of the replica set. A part of the command can have applied.
|
|
151
|
+
*/
|
|
152
|
+
const INTERRUPTED = /* @__PURE__ */ new Set([
|
|
153
|
+
91,
|
|
154
|
+
189,
|
|
155
|
+
11600,
|
|
156
|
+
11602
|
|
157
|
+
]);
|
|
158
|
+
/** The writable servers: a primary, a standalone, a mongos, and a load balancer. */
|
|
159
|
+
const WRITABLE = /* @__PURE__ */ new Set([
|
|
160
|
+
"RSPrimary",
|
|
161
|
+
"Standalone",
|
|
162
|
+
"Mongos",
|
|
163
|
+
"LoadBalancer"
|
|
164
|
+
]);
|
|
165
|
+
/** This function gives the outcome of a reply. A write concern error tells that the write can roll back, thus it is not certain. */
|
|
166
|
+
const replyOutcome = (reply) => {
|
|
167
|
+
const concern = reply["writeConcernError"];
|
|
168
|
+
if (concern === void 0 || concern === null) return {
|
|
169
|
+
outcome: "ok",
|
|
170
|
+
value: reply
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
outcome: "indeterminate",
|
|
174
|
+
error: `write concern ${String(concern.code)} ${String(concern.errmsg)}`
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* This function gives the outcome of a failure of the driver. The driver names each error class,
|
|
179
|
+
* thus the wrapper reads the name, and depends on no class of the driver:
|
|
180
|
+
* - A failure before the command left the client is certain: it did not apply.
|
|
181
|
+
* - An error of the server is certain, except an interruption, which can leave a part applied.
|
|
182
|
+
* - A write concern error, a network error after the handshake, and a timeout of the socket are not certain.
|
|
183
|
+
*/
|
|
184
|
+
const failureOutcome = (error) => {
|
|
185
|
+
const text = message(error);
|
|
186
|
+
const { name, code, beforeHandshake } = typeof error === "object" && error !== null ? error : {};
|
|
187
|
+
if (typeof name === "string" && NOT_SENT.has(name)) return notSent(text);
|
|
188
|
+
if (name === "MongoNetworkError" && beforeHandshake === true) return notSent(text);
|
|
189
|
+
if (name === "MongoServerError" && typeof code === "number") {
|
|
190
|
+
const said = `${code} ${text}`;
|
|
191
|
+
return INTERRUPTED.has(code) ? {
|
|
192
|
+
outcome: "indeterminate",
|
|
193
|
+
error: said
|
|
194
|
+
} : {
|
|
195
|
+
outcome: "error",
|
|
196
|
+
error: said,
|
|
197
|
+
reply: true
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
outcome: "indeterminate",
|
|
202
|
+
error: text
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
/** This function gives the host and the port of an address `host:port`. */
|
|
206
|
+
const endsOf = (address) => {
|
|
207
|
+
const at = address.lastIndexOf(":");
|
|
208
|
+
const port = Number(address.slice(at + 1));
|
|
209
|
+
return at < 0 || !Number.isInteger(port) ? {
|
|
210
|
+
host: address,
|
|
211
|
+
port: null
|
|
212
|
+
} : {
|
|
213
|
+
host: address.slice(0, at),
|
|
214
|
+
port
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* This function makes a MongoDB client, a dependency of a service over a `MongoClient`.
|
|
219
|
+
* - It sets each timer of the driver from the declaration, and it turns off the retries of the driver.
|
|
220
|
+
* The client sends again only an idempotent operation of its table.
|
|
221
|
+
* - It tells the outcome of a command in three values, from the name of each error of the driver.
|
|
222
|
+
* - It writes the deadline of the server in each command (`maxTimeMS`), thus the server ends a slow command first (O07).
|
|
223
|
+
* - It gives the state from the view of the topology: ready while a server is writable.
|
|
224
|
+
* - It listens to each error of the driver. In Node, an error with no listener throws, and library code does not end the process (A5).
|
|
225
|
+
* - It records the connection id of the server for each connection of the pool (D1).
|
|
226
|
+
*
|
|
227
|
+
* The outcomes, the second try, the commands in flight, the bounded close and the checks come from
|
|
228
|
+
* the core of the clients. This entry gives what the driver does in its own way.
|
|
229
|
+
*/
|
|
230
|
+
const mongoClient = (name, spec, options = {}) => {
|
|
231
|
+
const problems = specProblems(name, spec);
|
|
232
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
233
|
+
const { knobs } = spec;
|
|
234
|
+
const clock = options.clock ?? realClock;
|
|
235
|
+
const create = options.create ?? nodeMongo;
|
|
236
|
+
const dial = options.dial ?? helloCommandDial;
|
|
237
|
+
const operations = operationTable({}, spec.operations);
|
|
238
|
+
const deadline = finiteMs(knobs.statement_timeout);
|
|
239
|
+
const callBound = ms(knobs.client_retry_window) + ms(knobs.request_timeout);
|
|
240
|
+
let driver = null;
|
|
241
|
+
let status = "none";
|
|
242
|
+
const joins = [];
|
|
243
|
+
const joined = /* @__PURE__ */ new Map();
|
|
244
|
+
const flight = inFlight();
|
|
245
|
+
const emit = clientRecorder(options.record, clock, name);
|
|
246
|
+
const record = (on, to = status, detail) => {
|
|
247
|
+
const from = status;
|
|
248
|
+
status = to;
|
|
249
|
+
emit(from, to, on, detail);
|
|
250
|
+
};
|
|
251
|
+
const closing = () => status === "closing" || status === "end";
|
|
252
|
+
const onTopology = (event) => {
|
|
253
|
+
const writable = [...event.newDescription.servers.values()].some((server) => WRITABLE.has(server.type));
|
|
254
|
+
if (writable && (status === "connecting" || status === "failing")) record("topology.writable", "ready");
|
|
255
|
+
else if (!writable && status === "ready") record("topology.unwritable", "failing");
|
|
256
|
+
};
|
|
257
|
+
const onReady = (event) => {
|
|
258
|
+
const generation = joins.length + 1;
|
|
259
|
+
const { host, port } = endsOf(event.address);
|
|
260
|
+
joined.set(`${event.address}#${String(event.connectionId)}`, joins.length);
|
|
261
|
+
joins.push({
|
|
262
|
+
generation,
|
|
263
|
+
at: clock.now(),
|
|
264
|
+
address: event.address,
|
|
265
|
+
serverConnectionId: null,
|
|
266
|
+
localAddress: null,
|
|
267
|
+
localPort: null,
|
|
268
|
+
remoteAddress: host,
|
|
269
|
+
remotePort: port
|
|
270
|
+
});
|
|
271
|
+
record("join", status, `generation ${generation}, ${event.address}`);
|
|
272
|
+
};
|
|
273
|
+
const onStarted = (event) => {
|
|
274
|
+
const index = joined.get(`${event.address}#${String(event.connectionId)}`);
|
|
275
|
+
const id = event.serverConnectionId;
|
|
276
|
+
if (index === void 0 || id === null || id === void 0) return;
|
|
277
|
+
joined.delete(`${event.address}#${String(event.connectionId)}`);
|
|
278
|
+
joins[index] = {
|
|
279
|
+
...joins[index],
|
|
280
|
+
serverConnectionId: Number(id)
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
const onCleared = (event) => record("pool.cleared", status, `${event.address}${event.interruptInUseConnections === true ? ", with the commands in flight" : ""}`);
|
|
284
|
+
const onHeartbeat = (event) => record("heartbeat.failed", status, `${event.connectionId}: ${message(event.failure)}`);
|
|
285
|
+
const onError = (error) => {
|
|
286
|
+
if (status !== "end") record("client.error", status, message(error));
|
|
287
|
+
};
|
|
288
|
+
const listeners = [
|
|
289
|
+
["topologyDescriptionChanged", onTopology],
|
|
290
|
+
["connectionReady", onReady],
|
|
291
|
+
["commandStarted", onStarted],
|
|
292
|
+
["connectionPoolCleared", onCleared],
|
|
293
|
+
["serverHeartbeatFailed", onHeartbeat]
|
|
294
|
+
];
|
|
295
|
+
/** This function makes one try of a command. The driver selects a server, checks out a connection, and sends the command. */
|
|
296
|
+
const attempt = (document, signal) => {
|
|
297
|
+
const c = driver;
|
|
298
|
+
if (c === null) return Promise.resolve(notSent(`${name} has not connected`));
|
|
299
|
+
if (closing()) return Promise.resolve(notSent(`${name} is ${status}: the command did not leave the client`));
|
|
300
|
+
if (signal?.aborted) return Promise.resolve(notSent("the caller aborted the command before it left the client"));
|
|
301
|
+
const sent = deadline === void 0 || "maxTimeMS" in document ? document : {
|
|
302
|
+
...document,
|
|
303
|
+
maxTimeMS: deadline
|
|
304
|
+
};
|
|
305
|
+
return flight.track(signal, "the caller abandoned the command after it went to the driver", (settle) => {
|
|
306
|
+
c.db(spec.database).command(sent, signal === void 0 ? {} : { signal }).then((reply) => settle(replyOutcome(reply)), (error) => settle(failureOutcome(error)));
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
const command = (operation, document, sendOptions = {}) => sendWithReissue({
|
|
310
|
+
clock,
|
|
311
|
+
bound: callBound,
|
|
312
|
+
operation: operations[operation],
|
|
313
|
+
options: sendOptions,
|
|
314
|
+
attempt: (signal) => attempt(document, signal),
|
|
315
|
+
onReissue: () => record("command.reissue", status, operation)
|
|
316
|
+
});
|
|
317
|
+
const handle = {
|
|
318
|
+
async connect(signal) {
|
|
319
|
+
record("status.connecting", "connecting");
|
|
320
|
+
const c = await create(mongoOptions(name, spec));
|
|
321
|
+
driver = c;
|
|
322
|
+
for (const [event, listener] of listeners) c.on(event, listener);
|
|
323
|
+
c.on("error", onError);
|
|
324
|
+
if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);
|
|
325
|
+
const connecting = c.connect().then(() => void 0, (error) => {
|
|
326
|
+
if (!closing() && status !== "ready") record("connect.failed", "failing", message(error));
|
|
327
|
+
});
|
|
328
|
+
await withinBound(clock, ms(knobs.connect_bound), connecting);
|
|
329
|
+
if (status === "connecting") record("connect.failed", "failing", "no writable server in connect_bound");
|
|
330
|
+
},
|
|
331
|
+
async close() {
|
|
332
|
+
const c = driver;
|
|
333
|
+
if (c === null || closing()) return;
|
|
334
|
+
record("close.request", "closing");
|
|
335
|
+
if (!await withinBound(clock, ms(knobs.close_bound), c.close())) record("close.bound", status, "the close of the driver goes on");
|
|
336
|
+
flight.settleAll("the client closed with the command in flight");
|
|
337
|
+
for (const [event, listener] of listeners) c.off(event, listener);
|
|
338
|
+
record("status.end", "end");
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const declaration = {
|
|
342
|
+
system: spec.system,
|
|
343
|
+
knobs: {
|
|
344
|
+
connect_bound: knobs.connect_bound,
|
|
345
|
+
request_timeout: knobs.request_timeout,
|
|
346
|
+
statement_timeout: knobs.statement_timeout,
|
|
347
|
+
heartbeat_interval: knobs.heartbeat_interval,
|
|
348
|
+
client_retry_window: knobs.client_retry_window,
|
|
349
|
+
driver_writeoff_time: {
|
|
350
|
+
value: (ms(knobs.connect_bound) + ms(knobs.heartbeat_interval)) / 1e3,
|
|
351
|
+
unit: "s"
|
|
352
|
+
},
|
|
353
|
+
checkout_timeout: knobs.checkout_timeout,
|
|
354
|
+
pool_idle_expiry: knobs.pool_idle_expiry,
|
|
355
|
+
keepalive_idle: knobs.keepalive_idle,
|
|
356
|
+
idle_refresh_interval: knobs.keepalive_idle,
|
|
357
|
+
max_connection_age: knobs.max_connection_age,
|
|
358
|
+
close_bound: knobs.close_bound,
|
|
359
|
+
retrans_giveup_time: knobs.retrans_giveup_time
|
|
360
|
+
},
|
|
361
|
+
operations
|
|
362
|
+
};
|
|
363
|
+
const checks = (checkOptions) => stepChecks(name, checkOptions, {
|
|
364
|
+
"local-state": localStateCheck(() => status === "ready"),
|
|
365
|
+
"round-trip": roundTripCheck((sendOptions) => command("check", { ping: 1 }, sendOptions)),
|
|
366
|
+
dial: dialCheck(dial, spec.host, spec.port)
|
|
367
|
+
});
|
|
368
|
+
return {
|
|
369
|
+
name,
|
|
370
|
+
declaration,
|
|
371
|
+
handle,
|
|
372
|
+
meets: mongoMeetings(name, knobs),
|
|
373
|
+
get status() {
|
|
374
|
+
return status;
|
|
375
|
+
},
|
|
376
|
+
joins,
|
|
377
|
+
command,
|
|
378
|
+
checks,
|
|
379
|
+
attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),
|
|
380
|
+
problems(description) {
|
|
381
|
+
const late = deadlineProblem(name, knobs.request_timeout, knobs.statement_timeout, "command");
|
|
382
|
+
return [...clientProblems(name, description, clientBounds(knobs)), ...late === null ? [] : [late]];
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
export { HELLO, failureOutcome, helloCommandDial, helloJudge, mongoClient, mongoOptions, specProblems };
|
|
387
|
+
|
|
388
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/mongodb/client.ts"],"sourcesContent":["import type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport { realClock } from \"../clock.ts\";\nimport type { Attempt, CheckOptions, Client, ClientJoin, ClientKnobs, ClientOptions, ClientSpec, ClientStep, DialFn, SendOptions, Sent } from \"../client/core.ts\";\nimport {\n ageProblems,\n attachClient,\n clientBounds,\n clientProblems,\n clientRecorder,\n deadlineProblem,\n dialCheck,\n finiteMs,\n inFlight,\n keepaliveOnProblems,\n localStateCheck,\n message,\n ms,\n notSent,\n operationTable,\n orZero,\n poolProblems,\n roundTripCheck,\n sendWithReissue,\n stepChecks,\n timeProblems,\n wholeProblems,\n withinBound,\n zeroProblems,\n} from \"../client/core.ts\";\nimport type { Judge } from \"../client/dial.ts\";\nimport { helloDial } from \"../client/dial.ts\";\nimport type { Dependency } from \"../description.ts\";\nimport type { DependencyHandle } from \"../lifecycle.ts\";\nimport type { Operation } from \"../operation.ts\";\nimport type { MongoConnectOptions, MongoDocument, MongoDriverClient, MongoEventName, MongoEvents, MongoFactory } from \"./connection.ts\";\nimport { nodeMongo } from \"./connection.ts\";\nimport { mongoMeetings } from \"./meets.ts\";\n\n/**\n * These are the knobs of the client, each a time, by the names of the ordering law where the law\n * has them. The runtime has no defaults, thus each knob is necessary. A bound that nobody gives is\n * \"infinite\", not zero. `MONGO_STARTING_KNOBS` gives a declaration from the cells of S1. The knobs\n * that each client has come from the core.\n */\nexport interface MongoKnobs extends ClientKnobs {\n /** This time bounds the TCP connect and the handshake of each connection (`connectTimeoutMS`). It also bounds the wait of the startup. */\n readonly connect_bound: Quantity;\n /** This time bounds a read of a command in flight (`socketTimeoutMS`). At its end, the driver closes the connection. */\n readonly request_timeout: Quantity;\n /**\n * This time is the deadline of each command on the server (`maxTimeMS`). The wrapper writes it in\n * each command. The server then ends the command with error 50, a certain outcome. \"infinite\" sends no deadline.\n */\n readonly statement_timeout: Extent;\n /** This time is the period of the monitor (`heartbeatFrequencyMS`). The driver takes 500 ms at least. */\n readonly heartbeat_interval: Quantity;\n /**\n * This time bounds the wait for a writable server (`serverSelectionTimeoutMS`). A command waits\n * through a failover in this time, thus it is the retry window of the client (O29).\n */\n readonly client_retry_window: Quantity;\n /** This time bounds a checkout from a full pool (`waitQueueTimeoutMS`). */\n readonly checkout_timeout: Extent;\n /** A checkout ends an idle connection older than this time (`maxIdleTimeMS`). The driver checks it only at a checkout. */\n readonly pool_idle_expiry: Extent;\n /** This time is the idle time of TCP keepalive (`keepAliveInitialDelay`), in whole seconds. The driver always turns keepalive on. */\n readonly keepalive_idle: Extent;\n /** The driver has no age for a connection, thus this knob must be \"infinite\". */\n readonly max_connection_age: Extent;\n /** This time bounds the close of the client at the shutdown. */\n readonly close_bound: Quantity;\n}\n\n/** A seed is one more host that the driver connects to first, for example a member of a replica set. */\nexport interface MongoSeed {\n readonly host: string;\n readonly port: number;\n}\n\n/** A MongoDB client spec is the declaration of one MongoDB client: where it connects, its pool, and its knobs. */\nexport interface MongoClientSpec extends ClientSpec<MongoKnobs> {\n /** This name is the database of the commands of the client. */\n readonly database: string;\n readonly username?: string | undefined;\n /** This name is the database of the user. The default of the driver is `database`, or `admin`. */\n readonly authSource?: string | undefined;\n readonly replicaSet?: string | undefined;\n /** These hosts are more seeds of the topology, after `host` and `port`. */\n readonly seeds?: readonly MongoSeed[] | undefined;\n /** These counts are the sizes of the pool of each server: at most `max` connections, and `min` that the driver keeps open. */\n readonly pool: { readonly max: number; readonly min: number };\n /**\n * These operations are the commands of the service, by name, with their idempotency. A command\n * name does not tell if a command changes a state, for example an `aggregate` with `$merge`. Thus\n * the client sends again only a command that this table names.\n */\n readonly operations?: Readonly<Record<string, Operation>> | undefined;\n}\n\n/** These options make a client. Without them, it uses the driver, the real clock, and a dial with a hello. */\nexport type MongoClientOptions = ClientOptions<MongoFactory>;\n\n/**\n * A join is one connection of the pool, when its handshake is done (D1, D2). The prober joins its\n * kernel records to the server's view of the connection through it. The driver gives no socket,\n * thus the local address and port are null. The server's view is the connection id of its hello.\n */\nexport interface MongoJoin extends ClientJoin {\n /** This text is the address of the server, as `host:port`. */\n readonly address: string;\n /** This number is the connection id that the server gave, from the first command on the connection. Null until that command. */\n readonly serverConnectionId: number | null;\n}\n\n/** The steps that the MongoDB client gives a check for. A pool of the driver has no checkout that the wrapper can use. */\nexport type MongoStep = ClientStep;\n\n/** A MongoDB client is a dependency of a service: its declaration, its handle, its checks and its commands. */\nexport interface MongoClient extends Client<MongoStep, MongoJoin> {\n /** This text is the state of the client, as `MONGO_CLIENT_MACHINE` names it. */\n readonly status: string;\n /**\n * This method sends a command to the database of the spec, and gives its outcome in three values.\n * `operation` names the command in the table of operations. The client sends again only an\n * idempotent operation, one time at most, after an outcome that is not certain.\n */\n command(operation: string, document: MongoDocument, options?: SendOptions): Promise<Sent<MongoDocument>>;\n}\n\n/** The driver takes a period of the monitor of 500 ms at least. */\nconst LEAST_HEARTBEAT_MS = 500;\n\n/** This function gives the problems of a spec: the knobs that the driver cannot use. */\nexport const specProblems = (name: string, spec: MongoClientSpec): string[] => {\n const { knobs } = spec;\n const problems = [\n ...timeProblems(name, knobs),\n // the driver reads 0 as no timer, thus a bound of 0 is not a bound\n ...zeroProblems(name, \"the driver\", knobs, {\n bounded: [\"connect_bound\", \"request_timeout\", \"heartbeat_interval\", \"client_retry_window\", \"close_bound\"],\n open: [\"statement_timeout\", \"checkout_timeout\", \"pool_idle_expiry\"],\n }),\n // the options are whole milliseconds, and Node truncates the keepalive delay to whole seconds\n ...wholeProblems(name, knobs, {\n millis: [\"connect_bound\", \"request_timeout\", \"statement_timeout\", \"heartbeat_interval\", \"client_retry_window\", \"checkout_timeout\", \"pool_idle_expiry\"],\n seconds: [\"keepalive_idle\"],\n }),\n ...poolProblems(name, spec.pool),\n ];\n if (ms(knobs.heartbeat_interval) < LEAST_HEARTBEAT_MS)\n problems.push(`${name}'s heartbeat_interval is below 500 ms, the least that the driver takes`);\n problems.push(...keepaliveOnProblems(name, knobs, \"the driver\"), ...ageProblems(name, knobs, \"the driver has no age for a connection\"));\n return problems;\n};\n\n/** This function gives the arguments of `new MongoClient` from a spec. Each timer of the driver comes from the declaration. */\nexport const mongoOptions = (name: string, spec: MongoClientSpec): MongoConnectOptions => {\n const { knobs } = spec;\n const hosts = [{ host: spec.host, port: spec.port }, ...(spec.seeds ?? [])].map((seed) => `${seed.host}:${seed.port}`);\n return {\n url: `mongodb://${hosts.join(\",\")}/`,\n options: {\n appName: name,\n ...(spec.replicaSet === undefined ? {} : { replicaSet: spec.replicaSet }),\n ...(spec.username === undefined ? {} : { auth: { username: spec.username, password: spec.password ?? \"\" } }),\n ...(spec.authSource === undefined ? {} : { authSource: spec.authSource }),\n maxPoolSize: spec.pool.max,\n minPoolSize: spec.pool.min,\n connectTimeoutMS: ms(knobs.connect_bound),\n socketTimeoutMS: ms(knobs.request_timeout),\n serverSelectionTimeoutMS: ms(knobs.client_retry_window),\n heartbeatFrequencyMS: ms(knobs.heartbeat_interval),\n waitQueueTimeoutMS: orZero(knobs.checkout_timeout),\n maxIdleTimeMS: orZero(knobs.pool_idle_expiry),\n keepAliveInitialDelay: ms(knobs.keepalive_idle),\n serverMonitoringMode: \"stream\",\n retryReads: false,\n retryWrites: false,\n monitorCommands: true,\n },\n };\n};\n\n/**\n * The bytes of an OP_MSG with the command `{ hello: 1, $db: \"admin\" }`. They are a header of 16\n * bytes with the op code 2013, the flags, a section of kind 0, and the BSON document. The server answers a\n * hello before the authentication, thus the dial needs no password.\n */\nexport const HELLO: Uint8Array = Uint8Array.of(\n // the header: the length 52, the request id 1, the response to 0, the op code 2013\n 52, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0xdd, 0x07, 0, 0,\n // the flags, and the section of kind 0\n 0, 0, 0, 0, 0,\n // the document: its length 31, the int32 `hello` 1, the string `$db` \"admin\", and its end\n 31, 0, 0, 0,\n 0x10, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0, 1, 0, 0, 0,\n 0x02, 0x24, 0x64, 0x62, 0, 6, 0, 0, 0, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0,\n 0,\n);\n\n/** The sizes of the values of the BSON types that a hello reply holds, by type. A null size has a length prefix. */\nconst FIXED: Readonly<Record<number, number>> = { 0x01: 8, 0x07: 12, 0x08: 1, 0x09: 8, 0x0a: 0, 0x10: 4, 0x11: 8, 0x12: 8, 0x13: 16 };\n\n/** This function gives the value of `ok` at the top of a BSON document, or an error. */\nconst okOf = (doc: Buffer): number | Error => {\n let at = 4;\n while (at < doc.length - 1) {\n const type = doc[at]!;\n const end = doc.indexOf(0, at + 1);\n if (end < 0) return new Error(\"the hello reply has a field with no end\");\n const key = doc.toString(\"latin1\", at + 1, end);\n at = end + 1;\n if (key === \"ok\") {\n if (type === 0x01) return doc.readDoubleLE(at);\n if (type === 0x10) return doc.readInt32LE(at);\n return new Error(`the ok of the hello reply has the BSON type ${type}`);\n }\n const fixed = FIXED[type];\n if (fixed !== undefined) at += fixed;\n else if (type === 0x02) at += 4 + doc.readInt32LE(at);\n else if (type === 0x03 || type === 0x04) at += doc.readInt32LE(at);\n else if (type === 0x05) at += 5 + doc.readInt32LE(at);\n else return new Error(`the hello reply has the BSON type ${type}, which the dial does not read`);\n }\n return new Error(\"the hello reply has no ok\");\n};\n\n/**\n * This judge reads the answer to the hello. It waits for the whole message. The message must be an\n * OP_MSG with a section of kind 0, and its document must have `ok` 1.\n */\nexport const helloJudge: Judge = (received) => {\n if (received.length < 4) return \"more\";\n const length = received.readInt32LE(0);\n if (length < 26 || length > 48 * 1024 * 1024) return new Error(`the answer to the hello has a length of ${length}`);\n if (received.length < length) return \"more\";\n const opCode = received.readInt32LE(12);\n if (opCode !== 2013) return new Error(`the answer to the hello has the op code ${opCode}, not 2013`);\n if (received[20] !== 0) return new Error(\"the answer to the hello has no section of kind 0\");\n const ok = okOf(received.subarray(21, length));\n if (ok instanceof Error) return ok;\n return ok === 1 ? null : new Error(`the hello reply has ok ${ok}`);\n};\n\n/** This dial function opens a TCP connection, sends a hello, and waits for its reply. The server opens no session for it. */\nexport const helloCommandDial: DialFn = helloDial(HELLO, helloJudge);\n\n/** These errors tell that the command did not leave the client: no server, a full pool, a cleared pool, or a closed client. */\nconst NOT_SENT = new Set([\n \"MongoServerSelectionError\",\n \"MongoWaitQueueTimeoutError\",\n \"MongoPoolClearedError\",\n \"MongoPoolClosedError\",\n \"MongoServerClosedError\",\n \"MongoTopologyClosedError\",\n \"MongoNotConnectedError\",\n \"MongoClientClosedError\",\n]);\n\n/**\n * These codes of the server tell that the server interrupted the command. The causes are its\n * shutdown, a step down, or a change of the state of the replica set. A part of the command can have applied.\n */\nconst INTERRUPTED = new Set([91, 189, 11600, 11602]);\n\n/** The writable servers: a primary, a standalone, a mongos, and a load balancer. */\nconst WRITABLE = new Set([\"RSPrimary\", \"Standalone\", \"Mongos\", \"LoadBalancer\"]);\n\n/** This function gives the outcome of a reply. A write concern error tells that the write can roll back, thus it is not certain. */\nconst replyOutcome = (reply: MongoDocument): Attempt<MongoDocument> => {\n const concern = reply[\"writeConcernError\"] as { code?: unknown; errmsg?: unknown } | undefined;\n if (concern === undefined || concern === null) return { outcome: \"ok\", value: reply };\n return { outcome: \"indeterminate\", error: `write concern ${String(concern.code)} ${String(concern.errmsg)}` };\n};\n\n/**\n * This function gives the outcome of a failure of the driver. The driver names each error class,\n * thus the wrapper reads the name, and depends on no class of the driver:\n * - A failure before the command left the client is certain: it did not apply.\n * - An error of the server is certain, except an interruption, which can leave a part applied.\n * - A write concern error, a network error after the handshake, and a timeout of the socket are not certain.\n */\nexport const failureOutcome = (error: unknown): Attempt<never> => {\n const text = message(error);\n const { name, code, beforeHandshake } = (typeof error === \"object\" && error !== null ? error : {}) as {\n name?: unknown;\n code?: unknown;\n beforeHandshake?: unknown;\n };\n if (typeof name === \"string\" && NOT_SENT.has(name)) return notSent(text);\n // a network error of a new connection, before its handshake: the command did not go to it\n if (name === \"MongoNetworkError\" && beforeHandshake === true) return notSent(text);\n if (name === \"MongoServerError\" && typeof code === \"number\") {\n const said = `${code} ${text}`;\n return INTERRUPTED.has(code) ? { outcome: \"indeterminate\", error: said } : { outcome: \"error\", error: said, reply: true };\n }\n return { outcome: \"indeterminate\", error: text };\n};\n\n/** This function gives the host and the port of an address `host:port`. */\nconst endsOf = (address: string): { readonly host: string | null; readonly port: number | null } => {\n const at = address.lastIndexOf(\":\");\n const port = Number(address.slice(at + 1));\n return at < 0 || !Number.isInteger(port) ? { host: address, port: null } : { host: address.slice(0, at), port };\n};\n\n/**\n * This function makes a MongoDB client, a dependency of a service over a `MongoClient`.\n * - It sets each timer of the driver from the declaration, and it turns off the retries of the driver.\n * The client sends again only an idempotent operation of its table.\n * - It tells the outcome of a command in three values, from the name of each error of the driver.\n * - It writes the deadline of the server in each command (`maxTimeMS`), thus the server ends a slow command first (O07).\n * - It gives the state from the view of the topology: ready while a server is writable.\n * - It listens to each error of the driver. In Node, an error with no listener throws, and library code does not end the process (A5).\n * - It records the connection id of the server for each connection of the pool (D1).\n *\n * The outcomes, the second try, the commands in flight, the bounded close and the checks come from\n * the core of the clients. This entry gives what the driver does in its own way.\n */\nexport const mongoClient = (name: string, spec: MongoClientSpec, options: MongoClientOptions = {}): MongoClient => {\n const problems = specProblems(name, spec);\n if (problems.length > 0) throw new Error(problems.join(\"; \"));\n const { knobs } = spec;\n const clock = options.clock ?? realClock;\n const create = options.create ?? nodeMongo;\n const dial = options.dial ?? helloCommandDial;\n const operations = operationTable({}, spec.operations);\n const deadline = finiteMs(knobs.statement_timeout);\n // a command waits for a writable server in the retry window, then it reads in the request bound\n const callBound = ms(knobs.client_retry_window) + ms(knobs.request_timeout);\n\n let driver: MongoDriverClient | null = null;\n let status = \"none\";\n const joins: MongoJoin[] = [];\n // the index in `joins` of each connection, by its address and the id that the pool gives\n const joined = new Map<string, number>();\n const flight = inFlight();\n\n const emit = clientRecorder(options.record, clock, name);\n const record = (on: string, to: string = status, detail?: string): void => {\n const from = status;\n status = to;\n emit(from, to, on, detail);\n };\n const closing = (): boolean => status === \"closing\" || status === \"end\";\n\n // the state is the view of the topology: a writable server makes the client ready. The close ignores the topology\n const onTopology = (event: MongoEvents[\"topologyDescriptionChanged\"]): void => {\n const writable = [...event.newDescription.servers.values()].some((server) => WRITABLE.has(server.type));\n if (writable && (status === \"connecting\" || status === \"failing\")) record(\"topology.writable\", \"ready\");\n else if (!writable && status === \"ready\") record(\"topology.unwritable\", \"failing\");\n };\n const onReady = (event: MongoEvents[\"connectionReady\"]): void => {\n const generation = joins.length + 1;\n const { host, port } = endsOf(event.address);\n joined.set(`${event.address}#${String(event.connectionId)}`, joins.length);\n joins.push({\n generation,\n at: clock.now(),\n address: event.address,\n serverConnectionId: null,\n localAddress: null,\n localPort: null,\n remoteAddress: host,\n remotePort: port,\n });\n record(\"join\", status, `generation ${generation}, ${event.address}`);\n };\n // the hello of a connection gives the id of the server, and the driver gives it only in the events of a command\n const onStarted = (event: MongoEvents[\"commandStarted\"]): void => {\n const index = joined.get(`${event.address}#${String(event.connectionId)}`);\n const id = event.serverConnectionId;\n if (index === undefined || id === null || id === undefined) return;\n joined.delete(`${event.address}#${String(event.connectionId)}`);\n joins[index] = { ...joins[index]!, serverConnectionId: Number(id) };\n };\n const onCleared = (event: MongoEvents[\"connectionPoolCleared\"]): void =>\n record(\"pool.cleared\", status, `${event.address}${event.interruptInUseConnections === true ? \", with the commands in flight\" : \"\"}`);\n const onHeartbeat = (event: MongoEvents[\"serverHeartbeatFailed\"]): void =>\n record(\"heartbeat.failed\", status, `${event.connectionId}: ${message(event.failure)}`);\n // after the end, the listener only keeps the error from a throw\n const onError = (error: Error): void => {\n if (status !== \"end\") record(\"client.error\", status, message(error));\n };\n const listeners: ReadonlyArray<readonly [MongoEventName, (payload: never) => void]> = [\n [\"topologyDescriptionChanged\", onTopology],\n [\"connectionReady\", onReady],\n [\"commandStarted\", onStarted],\n [\"connectionPoolCleared\", onCleared],\n [\"serverHeartbeatFailed\", onHeartbeat],\n ];\n\n /** This function makes one try of a command. The driver selects a server, checks out a connection, and sends the command. */\n const attempt = (document: MongoDocument, signal: AbortSignal | undefined): Promise<Attempt<MongoDocument>> => {\n const c = driver;\n if (c === null) return Promise.resolve(notSent(`${name} has not connected`));\n if (closing()) return Promise.resolve(notSent(`${name} is ${status}: the command did not leave the client`));\n if (signal?.aborted) return Promise.resolve(notSent(\"the caller aborted the command before it left the client\"));\n // the deadline of the server goes in the command. The driver adds maxTimeMS only with timeoutMS, which the wrapper does not use\n const sent = deadline === undefined || \"maxTimeMS\" in document ? document : { ...document, maxTimeMS: deadline };\n return flight.track(signal, \"the caller abandoned the command after it went to the driver\", (settle) => {\n c.db(spec.database)\n .command(sent, signal === undefined ? {} : { signal })\n .then(\n (reply) => settle(replyOutcome(reply)),\n (error: unknown) => settle(failureOutcome(error)),\n );\n });\n };\n\n const command = (operation: string, document: MongoDocument, sendOptions: SendOptions = {}): Promise<Sent<MongoDocument>> =>\n sendWithReissue({\n clock,\n bound: callBound,\n operation: operations[operation],\n options: sendOptions,\n // the second try waits in the selection of a server, thus it needs no wait before it\n attempt: (signal) => attempt(document, signal),\n onReissue: () => record(\"command.reissue\", status, operation),\n });\n\n const handle: DependencyHandle = {\n async connect(signal) {\n record(\"status.connecting\", \"connecting\");\n const c = await create(mongoOptions(name, spec));\n driver = c;\n for (const [event, listener] of listeners) c.on(event, listener as never);\n c.on(\"error\", onError);\n if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);\n // the driver waits for a server in client_retry_window. The startup waits connect_bound at most, and the connect goes on.\n // A server that is down does not stop the startup: the checks keep readiness tripped until a server is writable\n const connecting = c.connect().then(\n () => undefined,\n (error: unknown) => {\n if (!closing() && status !== \"ready\") record(\"connect.failed\", \"failing\", message(error));\n },\n );\n await withinBound(clock, ms(knobs.connect_bound), connecting);\n if (status === \"connecting\") record(\"connect.failed\", \"failing\", \"no writable server in connect_bound\");\n },\n async close() {\n const c = driver;\n if (c === null || closing()) return;\n record(\"close.request\", \"closing\");\n // the close of the driver fails the commands in flight, then waits for endSessions. Behind a\n // black hole that wait has no bound. The driver gives no socket, thus the bound cannot destroy one\n if (!(await withinBound(clock, ms(knobs.close_bound), c.close()))) record(\"close.bound\", status, \"the close of the driver goes on\");\n flight.settleAll(\"the client closed with the command in flight\");\n for (const [event, listener] of listeners) c.off(event, listener as never);\n // the error listener stays: a socket that closes later can emit an error, and with no listener it throws\n record(\"status.end\", \"end\");\n },\n };\n\n const declaration: Omit<Dependency, \"name\"> = {\n system: spec.system,\n knobs: {\n connect_bound: knobs.connect_bound,\n request_timeout: knobs.request_timeout,\n statement_timeout: knobs.statement_timeout,\n heartbeat_interval: knobs.heartbeat_interval,\n client_retry_window: knobs.client_retry_window,\n // the stream of the monitor times out at connectTimeoutMS + heartbeatFrequencyMS: the driver then\n // marks the server unknown, clears its pool and fails the commands in flight. The cells measured 7 s for 5 s + 2 s\n driver_writeoff_time: { value: (ms(knobs.connect_bound) + ms(knobs.heartbeat_interval)) / 1000, unit: \"s\" },\n checkout_timeout: knobs.checkout_timeout,\n pool_idle_expiry: knobs.pool_idle_expiry,\n keepalive_idle: knobs.keepalive_idle,\n // the driver sends nothing on an idle connection of the pool, thus its keepalive is the only refresh of an idle flow (O03)\n idle_refresh_interval: knobs.keepalive_idle,\n max_connection_age: knobs.max_connection_age,\n close_bound: knobs.close_bound,\n retrans_giveup_time: knobs.retrans_giveup_time,\n },\n operations,\n };\n\n const checks = (checkOptions: CheckOptions<MongoStep>) =>\n stepChecks<MongoStep>(name, checkOptions, {\n // the view of the topology, without a round trip: the monitor keeps it current\n \"local-state\": localStateCheck(() => status === \"ready\"),\n // a ping through the pool of the application\n \"round-trip\": roundTripCheck((sendOptions) => command(\"check\", { ping: 1 }, sendOptions)),\n // a new connection each time, with a hello and no session\n dial: dialCheck(dial, spec.host, spec.port),\n });\n\n return {\n name,\n declaration,\n handle,\n meets: mongoMeetings(name, knobs),\n get status() {\n return status;\n },\n joins,\n command,\n checks,\n attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),\n problems(description) {\n // O07: the server must end a slow command first, with a certain error\n const late = deadlineProblem(name, knobs.request_timeout, knobs.statement_timeout, \"command\");\n return [...clientProblems(name, description, clientBounds(knobs)), ...(late === null ? [] : [late])];\n },\n };\n};\n"],"mappings":";;;;;;;AAkIA,MAAM,qBAAqB;;AAG3B,MAAa,gBAAgB,MAAc,SAAoC;CAC7E,MAAM,EAAE,UAAU;CAClB,MAAM,WAAW;EACf,GAAG,aAAa,MAAM,KAAK;EAE3B,GAAG,aAAa,MAAM,cAAc,OAAO;GACzC,SAAS;IAAC;IAAiB;IAAmB;IAAsB;IAAuB;GAAa;GACxG,MAAM;IAAC;IAAqB;IAAoB;GAAkB;EACpE,CAAC;EAED,GAAG,cAAc,MAAM,OAAO;GAC5B,QAAQ;IAAC;IAAiB;IAAmB;IAAqB;IAAsB;IAAuB;IAAoB;GAAkB;GACrJ,SAAS,CAAC,gBAAgB;EAC5B,CAAC;EACD,GAAG,aAAa,MAAM,KAAK,IAAI;CACjC;CACA,IAAI,GAAG,MAAM,kBAAkB,IAAI,oBACjC,SAAS,KAAK,GAAG,KAAK,uEAAuE;CAC/F,SAAS,KAAK,GAAG,oBAAoB,MAAM,OAAO,YAAY,GAAG,GAAG,YAAY,MAAM,OAAO,wCAAwC,CAAC;CACtI,OAAO;AACT;;AAGA,MAAa,gBAAgB,MAA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