@amritk/nish-aarch64-linux 0.36.0 → 0.38.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/INSTALL.md +92 -71
- package/bin/nish +0 -0
- package/docs/AI.md +75 -14
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/core/arrays.d.ts +4 -0
- package/runtime/core/arrays.mjs +33 -0
- package/runtime/nish.d.ts +1045 -512
- package/runtime/nish.h +53 -6
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +740 -0
- package/runtime/runtime-cross.c +2 -1
- package/runtime/runtime-region.c +85 -7
- package/runtime/runtime-text.c +1068 -0
- package/runtime/runtime-wasm.c +65 -9
- package/runtime/runtime.c +50 -961
- package/runtime/vite.mjs +48 -11
- package/scripts/build.sh +231 -31
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +109 -82
- package/std/array.ts +266 -0
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/host/text.ts +86 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/math.ts +743 -41
- package/std/net/dns-resolver.ts +46 -6
- package/std/net/dns.ts +50 -13
- package/std/net/fetch.ts +1744 -295
- package/std/net/handler.ts +30 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +42 -28
- package/std/net/http-fields.ts +19 -4
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +62 -91
- package/std/net/http1-server.ts +79 -57
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres-async.ts +1005 -0
- package/std/net/postgres.ts +185 -164
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/serve.ts +763 -0
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +242 -15
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/std/net/postgres.ts
CHANGED
|
@@ -30,18 +30,22 @@
|
|
|
30
30
|
* event = conn.next();
|
|
31
31
|
* }
|
|
32
32
|
*
|
|
33
|
-
* **Events.**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* (`
|
|
40
|
-
*
|
|
41
|
-
* `
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
33
|
+
* **Events.**
|
|
34
|
+
*
|
|
35
|
+
* `next()` answers `PG_READY` once, when the server has authenticated the
|
|
36
|
+
* connection and is ready for queries; `PG_DESCRIBED` when a prepared statement
|
|
37
|
+
* has been described (`columns` and `columnType(c)` say what its rows hold,
|
|
38
|
+
* `columns` is 0 when it returns none); `PG_ROW` for each row, its columns as
|
|
39
|
+
* windows into the input buffer (`colStart(c)`, `colLength(c)`, -1 for NULL);
|
|
40
|
+
* `PG_COMPLETE` when an execution has finished (`tagIs("UPDATE")`,
|
|
41
|
+
* `tagRows()`); `PG_ERROR` when a statement in the current group failed
|
|
42
|
+
* (`lastError`); `PG_NOTICE` for a notice (`lastNotice`); `PG_GROUP_DONE` when
|
|
43
|
+
* a group has been answered to its end (`groupFailed`, `txStatus`); and
|
|
44
|
+
* `PG_FAILED`, final: the connection broke a rule or the server ended it,
|
|
45
|
+
* `failure` says which and `lastError` holds the server's reason when it gave
|
|
46
|
+
* one.
|
|
47
|
+
*
|
|
48
|
+
* `PG_NEED_MORE` asks for more input.
|
|
45
49
|
*
|
|
46
50
|
* **Windows and buffers.** A column's window, the tag `tagIs` and `tagRows`
|
|
47
51
|
* read are valid until the next `next()`,
|
|
@@ -58,93 +62,101 @@
|
|
|
58
62
|
* In a failed group, `PG_DESCRIBED` comes once for each `prepare` the server
|
|
59
63
|
* parsed before the error: a program that counts them knows which statements
|
|
60
64
|
* exist (named ones last past the group) and which must be prepared again.
|
|
61
|
-
* Up to `maxInFlight` groups may wait for their answers at once; `canSend()`
|
|
62
|
-
* says whether another may start, and the builder calls refuse (and write
|
|
63
|
-
* nothing) when it may not. Nothing waits for a round trip that the protocol
|
|
64
|
-
* does not need: a program prepares a statement and executes it in the same
|
|
65
|
-
* flight.
|
|
66
65
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
66
|
+
* Up to `maxInFlight` groups may wait for their answers at once; `canSend()`
|
|
67
|
+
* says whether another may start, and the builder calls refuse (and write
|
|
68
|
+
* nothing) when it may not. Nothing waits for a round trip that the protocol
|
|
69
|
+
* does not need: a program prepares a statement and executes it in the same
|
|
70
|
+
* flight.
|
|
71
|
+
*
|
|
72
|
+
* **Text results, no copies.** Every parameter is in text format unless it is
|
|
73
|
+
* one of the binary integer arrays below, and every result column is text
|
|
74
|
+
* unless the bind asks otherwise. A row is read where it lies in the input
|
|
75
|
+
* buffer: `next()` frames each message once, validates its layout, and records
|
|
76
|
+
* each column's start and length in two reused arrays, so a row costs no
|
|
77
|
+
* allocation. `int`, `bool`, `isNull` and `PgText.timestamp` decode a column in
|
|
78
|
+
* place; `PgArrayWalker` walks a one-dimensional `text[]` in place.
|
|
79
|
+
* `columnText(c)` is the one that allocates, a string.
|
|
80
|
+
*
|
|
81
|
+
* An array parameter is a text array literal too: `paramIntArray` writes an
|
|
82
|
+
* `int8[]` from an `i64[]` window, and `arrayStart`, `arrayElement`,
|
|
83
|
+
* `arrayInt`, `arrayNull` and `arrayEnd` build an array one element at a time
|
|
84
|
+
* into the Bind, so a list needs no string built first. A program whose element
|
|
85
|
+
* was refused for room can drop the whole bind, unsent, with `bindCancel`.
|
|
80
86
|
*
|
|
81
87
|
* **Binary integer arrays.** `paramInt4Array` and `paramInt8Array` send an
|
|
82
|
-
* `i64[]` window as an `int4[]` or `int8[]` in PostgreSQL's binary layout:
|
|
83
|
-
*
|
|
84
|
-
* benchmark (`bench/postgres/arrays.mjs`) measured at about a tenth of the
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* `
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
88
|
+
* `i64[]` window as an `int4[]` or `int8[]` in PostgreSQL's binary layout: four
|
|
89
|
+
* or eight bytes an element and no digits to write or parse, which the
|
|
90
|
+
* benchmark (`bench/postgres/arrays.mjs`) measured at about a tenth of the text
|
|
91
|
+
* encoder's client CPU, and at 1,000 elements a 51% cut in the server's on
|
|
92
|
+
* `unnest` for `int8[]`, 30% for `int4[]`. `binaryArrayStart(oid)`,
|
|
93
|
+
* `binaryArrayInt` and `binaryArrayNull` build one element at a time, NULLs
|
|
94
|
+
* included, and `arrayEnd` closes it.
|
|
95
|
+
*
|
|
96
|
+
* The Bind's format codes stay a single zero word while every parameter is
|
|
97
|
+
* text; the first binary one makes `bindEnd` write a code for each, so an
|
|
98
|
+
* all-text bind costs nothing more. An `int4` element outside `int4` panics
|
|
99
|
+
* rather than wrapping. The element type must match the statement's parameter:
|
|
100
|
+
* the server answers a mismatch with `ErrorResponse` (42804) for that
|
|
101
|
+
* execution, and the connection goes on.
|
|
95
102
|
*
|
|
96
103
|
* **Binary results.** A bind opened with `bindStartBinary` instead of
|
|
97
|
-
* `bindStart` asks for every result column in binary format: an `int8` is
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* `
|
|
101
|
-
* `
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* asked for which, and reads each execution's rows with the matching
|
|
105
|
-
* decoders. A `PgBatcher` with `binary` set opens each batch this way and
|
|
106
|
-
* reads its routing ordinal with `binaryInt`, so its rows are binary too.
|
|
107
|
-
* `PgBinaryArray` walks a one-dimensional `int2[]`, `int4[]` or `int8[]`
|
|
108
|
-
* column in its binary layout, and refuses any other array (a `text[]` or a
|
|
109
|
-
* multi-dimensional one among them).
|
|
104
|
+
* `bindStart` asks for every result column in binary format: an `int8` is eight
|
|
105
|
+
* bytes, a `timestamptz` eight bytes of microseconds since 2000, a `bool` one
|
|
106
|
+
* byte, so there is nothing to parse and less on the wire. `binaryInt`,
|
|
107
|
+
* `binaryBool` and `binaryFloat` read them in place, and `PgBinary`'s
|
|
108
|
+
* `timestamp` and `iso` write a time as `PgText.timestamp` does. A `text`
|
|
109
|
+
* column is the same bytes in either format, so `columnText` and the column
|
|
110
|
+
* windows read it unchanged.
|
|
110
111
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* `
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* as
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
112
|
+
* The program knows which of its binds asked for which, and reads each
|
|
113
|
+
* execution's rows with the matching decoders. A `PgBatcher` with `binary` set
|
|
114
|
+
* opens each batch this way and reads its routing ordinal with `binaryInt`, so
|
|
115
|
+
* its rows are binary too. `PgBinaryArray` walks a one-dimensional `int2[]`,
|
|
116
|
+
* `int4[]` or `int8[]` column in its binary layout, and refuses any other array
|
|
117
|
+
* (a `text[]` or a multi-dimensional one among them).
|
|
118
|
+
*
|
|
119
|
+
* **Authentication.** SCRAM-SHA-256 (RFC 5802, RFC 7677) or none (`trust`). The
|
|
120
|
+
* password arrives as a `Secret<u8[]>`; the connection keeps a copy in a holder
|
|
121
|
+
* that is wiped as soon as the proof is computed, or when the connection fails
|
|
122
|
+
* or is disposed. The server's signature is checked in constant time before
|
|
123
|
+
* `AuthenticationOk` is believed, and an `AuthenticationOk` that skips the end
|
|
124
|
+
* of an exchange SCRAM began is refused.
|
|
125
|
+
*
|
|
126
|
+
* Cleartext and MD5 passwords, and SASL mechanisms other than SCRAM-SHA-256,
|
|
127
|
+
* are refused: with no TLS here the first sends the password as it is, and the
|
|
128
|
+
* second is a hash any eavesdropper can replay. The password's bytes are used
|
|
129
|
+
* as they are, without SASLprep (RFC 4013): an ASCII password works, and a
|
|
130
|
+
* non-ASCII one works only when it is already in the form SASLprep would give
|
|
131
|
+
* (PostgreSQL itself falls back to the raw bytes when it cannot prepare one).
|
|
132
|
+
* `docs/security/postgres.md` is the record.
|
|
124
133
|
*
|
|
125
134
|
* **Caps.** `PgConfig` bounds what a server can make the client hold: the
|
|
126
135
|
* longest message (`maxMessage`), the widest row (`maxColumns`) and the SCRAM
|
|
127
136
|
* iteration count (`minIterations`, `maxIterations`); and what a program can
|
|
128
|
-
* queue unsent (`maxOutput`), past which a builder call answers false.
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* `
|
|
133
|
-
*
|
|
134
|
-
*
|
|
137
|
+
* queue unsent (`maxOutput`), past which a builder call answers false.
|
|
138
|
+
*
|
|
139
|
+
* A message longer than the cap, a length below 4, a layout that does not add
|
|
140
|
+
* up, a message the protocol does not allow at that point (COPY among them), an
|
|
141
|
+
* encoding other than UTF-8, and a `DateStyle` other than ISO or a `TimeZone`
|
|
142
|
+
* other than UTC (at startup or after a `SET`), each fail the connection with
|
|
143
|
+
* their own `failure` code. The constructor panics on a cap out of range, as on
|
|
144
|
+
* a missing user or a short nonce.
|
|
135
145
|
*
|
|
136
146
|
* **Pools.** `PgPool` holds up to `size` connections to one server and a FIFO
|
|
137
147
|
* queue of up to `queueSize` requests, still sans-IO: `wanted()` names a slot
|
|
138
148
|
* that needs a socket, `connect(slot, nonce)` starts its connection, and the
|
|
139
|
-
* program moves its bytes as above through `connection(slot)`.
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* `
|
|
147
|
-
*
|
|
149
|
+
* program moves its bytes as above through `connection(slot)`.
|
|
150
|
+
*
|
|
151
|
+
* A request is a ticket from `request()`; `dispatch()` gives the oldest to the
|
|
152
|
+
* ready connection with the fewest groups in flight (or, with `PgConfig.pack`,
|
|
153
|
+
* to the first ready one with room, so a burst fills few connections in fuller
|
|
154
|
+
* writes), the program builds its group and ends it with `send()`, and
|
|
155
|
+
* `next(slot)` reads that connection's events with `ticket` naming the request.
|
|
156
|
+
* Statements given to `register` are prepared on each connection ahead of its
|
|
157
|
+
* first request. A connection that fails reports `PG_LOST` for each request it
|
|
158
|
+
* took, then `PG_FAILED`; the program closes the socket and the slot is built
|
|
159
|
+
* again on its next use.
|
|
148
160
|
*
|
|
149
161
|
* **Carrier.** `PgCarrier`, in `nish/net/postgres-carrier`, moves a pool's
|
|
150
162
|
* bytes on an `HttpHandler`'s loop, so a route handler queries without
|
|
@@ -153,23 +165,25 @@
|
|
|
153
165
|
*
|
|
154
166
|
* **Batching.** `PgBatcher` turns many reads of one row shape by key — a user
|
|
155
167
|
* by id, an article by slug — into one execution of a statement over
|
|
156
|
-
* `unnest($1) with ordinality`.
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* `
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* the
|
|
168
|
+
* `unnest($1) with ordinality`.
|
|
169
|
+
*
|
|
170
|
+
* `addInt` or `addText` queues a request's key and tag; `take(conn)` binds the
|
|
171
|
+
* oldest waiting, each distinct key once (past `PG_BATCH_PROBES` slots of its
|
|
172
|
+
* table probe, a key is bound again), up to `maxRequests` and `maxBytes`, and
|
|
173
|
+
* answers a run's handle; `row`, `end` and `fail` take that execution's events
|
|
174
|
+
* (a handle already answered makes them a no-op counted in `stray`, so a
|
|
175
|
+
* server's late event cannot panic), routing each row by its ordinal (checked
|
|
176
|
+
* first: a server's ordinal is refused before it routes anything), and
|
|
177
|
+
* `next(run)` answers `PG_BATCH_ROW`, then `PG_BATCH_DONE`, `PG_BATCH_MISSING`
|
|
178
|
+
* or `PG_BATCH_FAILED`, for each request.
|
|
179
|
+
*
|
|
180
|
+
* The statement orders its rows by ordinal, so a key's last events come as soon
|
|
181
|
+
* as a later key's row does; with `sorted` false it does not (no Sort node,
|
|
182
|
+
* when `orderBy` is ""), rows are answered in whatever order they come, and
|
|
183
|
+
* every last event waits for the execution's end. It reads no clock, and the
|
|
184
|
+
* batcher itself allocates only in its constructor (the connection's output
|
|
185
|
+
* buffer a take writes into may still grow, up to its `maxOutput`); when to
|
|
186
|
+
* take is the program's.
|
|
173
187
|
*
|
|
174
188
|
* **Batch timing.** `PgBatchClock` is one answer to when: given the time in
|
|
175
189
|
* microseconds, `check(now, inFlight)` says a batch is due once
|
|
@@ -1041,16 +1055,17 @@ export class PgBinary {
|
|
|
1041
1055
|
|
|
1042
1056
|
/**
|
|
1043
1057
|
* A walk over a one-dimensional `int2[]`, `int4[]` or `int8[]` column in
|
|
1044
|
-
* PostgreSQL's binary array layout, in place: `begin` the column, then
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1058
|
+
* PostgreSQL's binary array layout, in place: `begin` the column, then `next()`
|
|
1059
|
+
* until `PG_ARRAY_END` or `PG_ARRAY_BAD`, and `int()` decodes the current
|
|
1060
|
+
* element through `binary`. The header is `ndim`, `hasnull` and the element
|
|
1061
|
+
* OID, then for `ndim` 1 the dimension's length and lower bound (the bound is
|
|
1062
|
+
* read and not used); each element is a length word and its bytes, and a NULL
|
|
1063
|
+
* is a length of -1 with no bytes. `ndim` 0 is the empty array.
|
|
1064
|
+
*
|
|
1065
|
+
* Every refusal sets `binary.failed`: an `ndim` above 1, another element type,
|
|
1066
|
+
* an element whose length is not its type's size, a NULL when `hasnull` is 0, a
|
|
1067
|
+
* column cut short, or bytes after the last element. The walk allocates
|
|
1068
|
+
* nothing, and it reads nothing outside the column.
|
|
1054
1069
|
*/
|
|
1055
1070
|
export class PgBinaryArray {
|
|
1056
1071
|
/** The number of elements the header gives: 0 for an empty array. */
|
|
@@ -2612,9 +2627,9 @@ export class PgConnection {
|
|
|
2612
2627
|
}
|
|
2613
2628
|
|
|
2614
2629
|
/**
|
|
2615
|
-
* A `text[]` parameter: every element quoted,
|
|
2616
|
-
* element reads as NULL (build one
|
|
2617
|
-
* an array parameter is open.
|
|
2630
|
+
* A `text[]` parameter: every element quoted, with each double quote and
|
|
2631
|
+
* backslash escaped by a backslash, so no element reads as NULL (build one
|
|
2632
|
+
* with `arrayNull` for that). Panics while an array parameter is open.
|
|
2618
2633
|
* @param items The elements, in order; read now, not kept. Empty sends `{}`.
|
|
2619
2634
|
* @returns True when it was written; false, and nothing written, as every
|
|
2620
2635
|
* `param...` call is.
|
|
@@ -3755,10 +3770,13 @@ const PG_LOW32: i64 = 4294967295
|
|
|
3755
3770
|
* The batcher's table hash of an int8 key, 31 bits: the high half times an
|
|
3756
3771
|
* odd constant xored into the low half, then MurmurHash3's 32-bit finalizer,
|
|
3757
3772
|
* whose unsigned multiplies wrap by definition. Every step is a bijection on
|
|
3758
|
-
* 32 bits, so keys of one high half
|
|
3759
|
-
*
|
|
3760
|
-
*
|
|
3761
|
-
*
|
|
3773
|
+
* 32 bits, so keys of one high half get distinct 32-bit hashes; the last
|
|
3774
|
+
* `>> 1` drops their lowest bit, so at most two such keys share a 31-bit hash.
|
|
3775
|
+
* The finalizer spreads a dense run of ids over the whole table: runs that
|
|
3776
|
+
* would land on one another's slots under a near-identity hash do not merge
|
|
3777
|
+
* into one cluster longer than `PG_BATCH_PROBES`. Keys of different high
|
|
3778
|
+
* halves can be built to share one hash; each costs up to
|
|
3779
|
+
* `PG_BATCH_PROBES` probes.
|
|
3762
3780
|
*/
|
|
3763
3781
|
const pgIntHash = (key: i64): i32 => {
|
|
3764
3782
|
const lo: u32 = toU32(key & PG_LOW32)
|
|
@@ -3872,39 +3890,41 @@ class PgBatchRun {
|
|
|
3872
3890
|
}
|
|
3873
3891
|
|
|
3874
3892
|
/**
|
|
3875
|
-
* Batches keyed reads of one statement shape, sans-IO like `PgConnection`:
|
|
3876
|
-
*
|
|
3877
|
-
*
|
|
3878
|
-
* `take(conn)` binds up to `maxRequests` of them, and up to `maxBytes` of
|
|
3879
|
-
*
|
|
3880
|
-
*
|
|
3881
|
-
*
|
|
3882
|
-
* execution's run handle. Each `PG_ROW` of that execution goes to
|
|
3883
|
-
* `row(run, conn)`, its `PG_COMPLETE` to `end(run)`, and an error or a lost
|
|
3884
|
-
* connection to `fail(run)`; after each, `next(run)` answers events until
|
|
3885
|
-
* `PG_BATCH_NONE`, `tag` naming the request each is about. Every row goes to
|
|
3886
|
-
* every request for its key, and every request gets one last event:
|
|
3887
|
-
* `PG_BATCH_DONE`, `PG_BATCH_MISSING` or `PG_BATCH_FAILED`. Sorted (the
|
|
3888
|
-
* default), rows come in key order and a key's last events come as soon as
|
|
3889
|
-
* a later key's row does; with `sorted` false, rows come in any order, each
|
|
3890
|
-
* answered at once, and every last event waits for `end` or `fail`, then
|
|
3891
|
-
* comes in key order. A batch with
|
|
3892
|
-
* `binary` set comes in binary format: its rows are read with the binary
|
|
3893
|
-
* decoders, `binaryInt` for each ordinal, and the caller's `binary.failed`
|
|
3894
|
-
* is left as it was.
|
|
3893
|
+
* Batches keyed reads of one statement shape, sans-IO like `PgConnection`: it
|
|
3894
|
+
* reads no clock and makes no socket. Each request is a key and the caller's
|
|
3895
|
+
* `tag`, queued by `addInt` or `addText`. When a connection is free,
|
|
3896
|
+
* `take(conn)` binds up to `maxRequests` of them, and up to `maxBytes` of keys,
|
|
3897
|
+
* as one execution of `sql`, each distinct key once (a key whose probe of the
|
|
3898
|
+
* batcher's table passes 1024 slots, which takes keys chosen to collide, is
|
|
3899
|
+
* bound again and answered the same), and answers the execution's run handle.
|
|
3895
3900
|
*
|
|
3896
|
-
*
|
|
3897
|
-
* `end
|
|
3898
|
-
*
|
|
3899
|
-
*
|
|
3900
|
-
*
|
|
3901
|
-
* `
|
|
3902
|
-
*
|
|
3903
|
-
*
|
|
3904
|
-
*
|
|
3905
|
-
*
|
|
3906
|
-
*
|
|
3907
|
-
*
|
|
3901
|
+
* Each `PG_ROW` of that execution goes to `row(run, conn)`, its `PG_COMPLETE`
|
|
3902
|
+
* to `end(run)`, and an error or a lost connection to `fail(run)`; after each,
|
|
3903
|
+
* `next(run)` answers events until `PG_BATCH_NONE`, `tag` naming the request
|
|
3904
|
+
* each is about. Every row goes to every request for its key, and every request
|
|
3905
|
+
* gets one last event: `PG_BATCH_DONE`, `PG_BATCH_MISSING` or
|
|
3906
|
+
* `PG_BATCH_FAILED`.
|
|
3907
|
+
*
|
|
3908
|
+
* Sorted (the default), rows come in key order and a key's last events come as
|
|
3909
|
+
* soon as a later key's row does; with `sorted` false, rows come in any order,
|
|
3910
|
+
* each answered at once, and every last event waits for `end` or `fail`, then
|
|
3911
|
+
* comes in key order. A batch with `binary` set comes in binary format: its
|
|
3912
|
+
* rows are read with the binary decoders, `binaryInt` for each ordinal, and the
|
|
3913
|
+
* caller's `binary.failed` is left as it was.
|
|
3914
|
+
*
|
|
3915
|
+
* Nothing outlives its execution: a run is free again once the events `end` or
|
|
3916
|
+
* `fail` owe are answered, and its handle is then spent. What the server or the
|
|
3917
|
+
* network can send after that — a second `PG_COMPLETE`, a row or an error after
|
|
3918
|
+
* one, a lost connection — goes to a spent handle, and `row`, `end` and `fail`
|
|
3919
|
+
* count it in `stray` and do nothing, even once `take` has given the run out
|
|
3920
|
+
* again under a new handle. The ordinal each row carries comes from the server
|
|
3921
|
+
* and is checked before it routes anything.
|
|
3922
|
+
*
|
|
3923
|
+
* What panics is only the program's own misuse: a handle out of the range
|
|
3924
|
+
* `take` can give (-1 or any negative, or `runs` * 2^20 or more), or `row`,
|
|
3925
|
+
* `end` or `fail` before `next(run)` has answered `PG_BATCH_NONE` for the event
|
|
3926
|
+
* before. A handle in that range that `take` never gave is spent like any
|
|
3927
|
+
* other: counted in `stray`, not a panic.
|
|
3908
3928
|
*/
|
|
3909
3929
|
export class PgBatcher {
|
|
3910
3930
|
/** The prepared statement's name. */
|
|
@@ -5136,20 +5156,21 @@ const pgPortValue = (text: string): i32 => {
|
|
|
5136
5156
|
}
|
|
5137
5157
|
|
|
5138
5158
|
/**
|
|
5139
|
-
* The target a `postgres://` or `postgresql://` URL names, as libpq reads
|
|
5140
|
-
*
|
|
5141
|
-
*
|
|
5142
|
-
*
|
|
5143
|
-
*
|
|
5144
|
-
*
|
|
5145
|
-
*
|
|
5146
|
-
*
|
|
5159
|
+
* The target a `postgres://` or `postgresql://` URL names, as libpq reads one:
|
|
5160
|
+
* `postgres://[user[:password]@][host][:port][/dbname][?key=value&...]`. The
|
|
5161
|
+
* host, the port and every query key and value are percent-decoded, so a socket
|
|
5162
|
+
* directory is written `%2Ftmp` or passed as `?host=/tmp`; a `host` or `port`
|
|
5163
|
+
* in the query overrides the authority's, and other keys are ignored. The user,
|
|
5164
|
+
* password and database are not read here, but a bad escape in them still
|
|
5165
|
+
* refuses the URL. A `%` without two hex digits after it, `%00`, or a part that
|
|
5166
|
+
* decodes to bytes that are not UTF-8 is `PG_TARGET_BAD_ESCAPE`.
|
|
5167
|
+
*
|
|
5147
5168
|
* The user information ends at the first `@`, as in libpq; a raw `@` after a
|
|
5148
|
-
* `?` or after that first `@` in the authority, or a raw NUL byte anywhere,
|
|
5149
|
-
*
|
|
5150
|
-
*
|
|
5151
|
-
*
|
|
5152
|
-
*
|
|
5169
|
+
* `?` or after that first `@` in the authority, or a raw NUL byte anywhere, is
|
|
5170
|
+
* `PG_TARGET_BAD_HOST`, as is a URL with no host anywhere, where libpq would
|
|
5171
|
+
* use its default socket directory. An empty port or query value is refused,
|
|
5172
|
+
* where libpq would take it as unset. The decoded host is then resolved as
|
|
5173
|
+
* `pgTarget` resolves one.
|
|
5153
5174
|
*
|
|
5154
5175
|
* @param url The URL; any user or password it holds is not kept in the target.
|
|
5155
5176
|
* @returns The target; read `failure` before anything else.
|
package/std/net/prefork.ts
CHANGED
|
@@ -41,36 +41,39 @@
|
|
|
41
41
|
* a callback. With `serviceWorker` set, every other worker gets a pair to that
|
|
42
42
|
* worker. The ends go through `spawnWithFds`, from descriptor 3 in a fixed
|
|
43
43
|
* order: the supervisor channel, then a worker's service channel, or in the
|
|
44
|
-
* service worker its end to each other worker by index, skipping its own.
|
|
45
|
-
* they landed rides in `--nish-prefork-channels=` just before the worker flag,
|
|
46
|
-
* and `preforkSupervisorChannel`, `preforkServiceChannel` and
|
|
47
|
-
* `preforkServiceChannelOf` read it back. A pair cannot be handed to a worker
|
|
48
|
-
* already running, so service channels make the workers one group: when any of
|
|
49
|
-
* them exits, the supervisor sends the rest SIGTERM (SIGKILL after `graceMs`),
|
|
50
|
-
* and once none is left, starts them all again on fresh pairs, after the
|
|
51
|
-
* backoff of the one that exited first. No worker keeps an end whose peer is
|
|
52
|
-
* gone longer than that. With `restart` off nothing is signalled; a worker sees
|
|
53
|
-
* its peer's exit as a hang-up.
|
|
44
|
+
* service worker its end to each other worker by index, skipping its own.
|
|
54
45
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* by
|
|
46
|
+
* Where they landed rides in `--nish-prefork-channels=` just before the worker
|
|
47
|
+
* flag, and `preforkSupervisorChannel`, `preforkServiceChannel` and
|
|
48
|
+
* `preforkServiceChannelOf` read it back. A pair cannot be handed to a worker
|
|
49
|
+
* already running, so service channels make the workers one group: when any of
|
|
50
|
+
* them exits, the supervisor sends the rest SIGTERM (SIGKILL after `graceMs`),
|
|
51
|
+
* and once none is left, starts them all again on fresh pairs, after the
|
|
52
|
+
* backoff of the one that exited first. No worker keeps an end whose peer is
|
|
53
|
+
* gone longer than that. With `restart` off nothing is signalled; a worker sees
|
|
54
|
+
* its peer's exit as a hang-up.
|
|
55
|
+
*
|
|
56
|
+
* **Listeners and pinning.** With `listenPort` set (0 or above), the supervisor
|
|
57
|
+
* binds one `SO_REUSEPORT` listener per worker itself, in index order, keeps
|
|
58
|
+
* them for its whole run and hands listener `k` to every start of worker `k`
|
|
59
|
+
* after the channel ends; `preforkListener(args)` answers it in the worker
|
|
60
|
+
* (`--nish-prefork-listener=`, before the channels flag), so a worker serves
|
|
61
|
+
* that descriptor instead of binding its own. Port 0 binds the first listener
|
|
62
|
+
* anywhere and the rest to its port.
|
|
63
|
+
*
|
|
64
|
+
* With `pin` on as well, each listener steers by CPU (`tcpListenFlags`' flag
|
|
65
|
+
* 4): the kernel hands a connection that arrived on CPU `k` to listener `k`,
|
|
66
|
+
* and a worker that is restarted takes the same listener, so the order holds
|
|
67
|
+
* across restarts, which it would not if each worker bound its own. `pin` alone
|
|
68
|
+
* makes each worker call `setCpuAffinity(k)` before `preforkWith` answers it,
|
|
69
|
+
* so worker `k` runs on CPU `k` only; a worker the kernel refuses (CPU `k`
|
|
70
|
+
* outside the process's mask) says so on stderr and runs unpinned.
|
|
71
|
+
*
|
|
72
|
+
* More workers than `availableParallelism()` is refused with a panic, since a
|
|
73
|
+
* worker past the last CPU would be pinned nowhere and, steered, handed
|
|
74
|
+
* nothing. Pinning and steering are Linux's: elsewhere the supervisor says once
|
|
75
|
+
* that the workers run unpinned, and the listeners are plain `SO_REUSEPORT`
|
|
76
|
+
* ones. Both are off by default.
|
|
74
77
|
*
|
|
75
78
|
* **How many.** `NISH_WORKERS` when it is a positive whole number, else
|
|
76
79
|
* `PreforkConfig.workers` when that is positive, else
|
|
@@ -908,11 +911,12 @@ export const preforkWith = (args: string[], config: PreforkConfig): i32 => {
|
|
|
908
911
|
* error. The callback reads what is waiting, since an end left readable wakes
|
|
909
912
|
* the loop again at once, and may write back, but never closes `fd`: the
|
|
910
913
|
* supervisor closes it after a hang-up, when the worker is reaped and when it
|
|
911
|
-
* stops, and a restarted worker comes with a new one.
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
* `
|
|
914
|
+
* stops, and a restarted worker comes with a new one.
|
|
915
|
+
*
|
|
916
|
+
* Panics, besides, when `serviceWorker` is not below the worker count or the
|
|
917
|
+
* count is above 64 with a service worker (63 with `listenPort`), the most
|
|
918
|
+
* `spawnWithFds` hands one child; when `pin`, on Linux, asks for more workers
|
|
919
|
+
* than `availableParallelism()`; and, through `preforkInvalid`, on seqpacket
|
|
916
920
|
* channels off Linux. A listener that cannot bind answers
|
|
917
921
|
* `PREFORK_SPAWN_FAILED` before any worker starts.
|
|
918
922
|
*
|
package/std/net/qpack.ts
CHANGED
|
@@ -31,20 +31,21 @@
|
|
|
31
31
|
* block on (§2.1.2) and nothing to acknowledge (§4.4.1).
|
|
32
32
|
*
|
|
33
33
|
* **What is refused.** `QpackDecoder.decode` answers QPACK_DECOMPRESSION_FAILED
|
|
34
|
-
* for a section that ends inside a representation, an integer past 2^62 - 1
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* QPACK_DECODER_STREAM_ERROR for a
|
|
44
|
-
* it sent needs one), any Insert
|
|
45
|
-
* nothing) and a stream ID past
|
|
46
|
-
* so each is sticky: the same answer
|
|
47
|
-
* reading anything, and `reason` says
|
|
34
|
+
* for a section that ends inside a representation, an integer past 2^62 - 1 (or
|
|
35
|
+
* padded past the nine continuation bytes such an integer needs), a non-zero
|
|
36
|
+
* Required Insert Count (§4.5.1.1), a negative Base (§4.5.1.2), any reference
|
|
37
|
+
* to the dynamic table, relative or post-Base (§2.2.3), a static index past 98,
|
|
38
|
+
* and Huffman padding that is not EOS's prefix or an EOS inside a string.
|
|
39
|
+
*
|
|
40
|
+
* `receiveEncoderStream` answers QPACK_ENCODER_STREAM_ERROR for a Set Dynamic
|
|
41
|
+
* Table Capacity above 0 (§4.3.1), any Insert (§3.2.2: every entry is larger
|
|
42
|
+
* than the table) and any Duplicate (§2.2.3: there is nothing to duplicate).
|
|
43
|
+
* The encoder's `receiveDecoderStream` answers QPACK_DECODER_STREAM_ERROR for a
|
|
44
|
+
* Section Acknowledgment (§4.4.1: no section it sent needs one), any Insert
|
|
45
|
+
* Count Increment (§4.4.3: it has inserted nothing) and a stream ID past
|
|
46
|
+
* 2^62 - 1. Each of those is a connection error, so each is sticky: the same answer
|
|
47
|
+
* comes back from every later call without reading anything, and `reason` says
|
|
48
|
+
* which rule it was (`QPACK_REASON_*`).
|
|
48
49
|
*
|
|
49
50
|
* **What is accepted.** A Set Dynamic Table Capacity of 0 on the encoder
|
|
50
51
|
* stream, and a Stream Cancellation on the decoder stream, read a byte at a
|
package/std/net/quic-conn-ack.ts
CHANGED
|
@@ -47,6 +47,7 @@ export class QuicAckRanges {
|
|
|
47
47
|
/** Every packet number at or below this is answered as already received; -1 until a range is dropped. */
|
|
48
48
|
floor: i64 = -1
|
|
49
49
|
private ranges: i64[]
|
|
50
|
+
/** How many disjoint ranges are held, at most `QUIC_ACK_MAX_RANGES`. */
|
|
50
51
|
count: i32 = 0
|
|
51
52
|
/** Whether an ack-eliciting packet arrived since the last `pushAck`. */
|
|
52
53
|
ackPending: boolean = false
|