Skip to content

feat(qwp): schema aware clients - #101

Open
jerrinot wants to merge 76 commits into
mainfrom
jh_schema_aware_clients
Open

jerrinot wants to merge 76 commits into
mainfrom
jh_schema_aware_clients

Conversation

@jerrinot

Copy link
Copy Markdown
Contributor

No description provided.

jerrinot and others added 30 commits September 14, 2026 09:54
The first setter of a row waited at most one second for the initial
WebSocket handshake and the schema DESCRIBE round trip, then threw
SCHEMA_UNAVAILABLE and dropped the row. One second is a per-row bound on
what is really a connection-setup cost, so a cold TLS handshake, a GC
pause, or an I/O thread busy draining a backlog could push an ordinary
lookup over the line. Every reconnect clears the schema cache, so a
flaky link turned into a stream of lost rows.

QwpWebSocketSender now reads the budget from a single field defaulting
to DEFAULT_SCHEMA_WAIT_MILLIS (30 s). Both the per-row deadline in
bindingForEffectiveWrite() and the refresh in
refreshAfterSchemaRejection() use it. A healthy lookup still completes
in milliseconds; the constant only bounds a dead or still-connecting
link.

setSchemaWaitMillisForTesting() lets the one test that asserts the
deadline fires against an unreachable port keep its short budget.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BDP5ZVN8xijRp9LhQoreMf
Parse textual decimals through the existing Decimal256 scratch and reuse
the established decimal and text conversion paths. Preserve row rollback,
schema refresh, duplicate ordering, and missing-column scale semantics
without adding retained converter state.

Cover exact wire values, every decimal width, text targets, nulls,
invalid rows, inference, and real-server ingestion. Record the design
decisions, validation evidence, and remaining branch-level blockers.
The client carried two double-to-text implementations that disagreed on
about 0.3% of values. Numbers.append() used the pre-Ryu algorithm and
served the legacy ILP path, while QwpSchemaDoubleFormatter wrapped a
private copy of the server's Ryu for schema-aware QWP writes. The same
double therefore reached the server as two different strings, depending
only on which transport carried it.

Numbers.append() now formats through Ryu, copied from the server so that
client and server produce identical text. RyuDouble moves to
io.questdb.client.std as the single copy, and QwpSchemaBinding calls
Numbers.append() directly. QwpSchemaRyuDouble and
QwpSchemaDoubleFormatter are gone.

RyuDouble calls Math.multiplyHigh, which Java 8 lacks, so Compat gains a
multiplyHigh shim: the intrinsic on Java 9+, and a hand-rolled equivalent
on Java 8. A differential over 20 million random pairs plus edge cases
shows the fallback matches the intrinsic exactly.

Retiring the old formatter also retires the FdBig bridge and the
jdk.internal.math export flags it needed. The multi-release jar stays,
because Compat still supplies currentPid() and onSpinWait() to five other
callers. JarPackagingIT now guards the Compat variants rather than the
FdBig ones, and still executes the formatter out of the packaged jar on
both JDKs.

This also fixes two Java 8 breaks that predate the change and that a
modern JDK hides. QwpSchemaRyuDouble called Math.multiplyHigh from a
shared source root, and QwpSchemaFeedbackResponseTest chained putShort()
off position(), which returns Buffer rather than ByteBuffer on Java 8.
Both would have failed the Java 8 CI job.

The legacy ILP path changes its wire text for roughly 0.3% of doubles.
Ryu emits the shortest form that still reads back to the same value, so
the output is never longer and never loses precision; over 3 million
random values both formatters round-trip to identical doubles. One
NumbersTest expectation encoded the old extra digit and is updated.

Verified on JDK 8 and JDK 25: 3721 unit tests and the packaging ITs pass
on both, and the shared floating-to-text corpus matches on all 40 rows.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BDP5ZVN8xijRp9LhQoreMf
Every row-building setter in QwpWebSocketSender repeated the same two
catch blocks: roll the partial row back, run the one-refresh rule for
a LineSenderSchemaException, and rethrow everything else. The policy
lived in 31 copies, and D045 already recorded one setter (CHAR) that
shipped without the schema branch.

onRowFailure() now owns that policy. It rolls the whole row back
first, so a failed refresh cannot leave a half-written row, then
hands a schema rejection to refreshAfterSchemaRejection() and lets
every other failure propagate unchanged. All 36 row guards call it
from a single catch. The two catches in installSchemaBinding() guard
buffer cleanup, not rows, and stay as they are.

Behaviour change: the four longArray() overloads had only the generic
catch, so their UNSUPPORTED_FEATURE rejection skipped the refresh.
They now follow the standard path: the first rejection costs one
DESCRIBE round trip and reports SCHEMA_CHANGED when the target
column changed. atNow() also routes through the helper, but its null
column name keeps it on the no-refresh path.

QwpSchemaSenderIntegrationTest covers both longArray() outcomes,
asserts whole-row rollback and exactly one refresh, and extends the
null no-op test with the four longArray() null forms.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The QWP longArray setters cannot become valid after a schema
change. Preserve their UNSUPPORTED_FEATURE rejection without
issuing DESCRIBE, while retaining the shared row rollback helper.

Cover all four overloads, rollback, changed schemas and unavailable
metadata. Keep double-array schema recovery and null no-ops unchanged.
A QWP frame has one wire family, so a flush that held both legacy and
schema table blocks needed its own delivery pipeline.
flushPendingRowsMixed() duplicated the split path's pre-flight sizing,
dictionary-chunk fallback, publish loop, baseline advance and commit
bookkeeping, and it encoded every block two to three times.

Row-boundary adoption was the only source of such batches. A batch now
has one wire contract, selected by its first committed row.
bindingForEffectiveWrite() keeps returning the legacy contract while a
legacy batch is pending, and the first row after the flush adopts
schema mode. The upgrade stays one-way and is delayed by at most one
batch. This deletes flushPendingRowsMixed(), mixedFramesFit(),
encodeSingleTableFrame() and isMixedSchemaBatch(); the encoder is
unchanged.

Trade-off: rows written after the supporting handshake but inside the
pending legacy batch keep legacy conversion, for example microsecond
Instant truncation. Which rows preceded the handshake was already a
timing race.

The change also fixes an existing defect. A legacy row, a flush, a
supporting reconnect and then a row on the same table threw
IllegalStateException from the column setter: installSchemaBinding()
bound in place whenever the buffer had no rows, but a flushed legacy
buffer keeps its column layout. It now binds in place only a buffer
with no columns and replaces the buffer otherwise.

The two upgrade integration tests now assert the batch-boundary rule
and cover the flushed-legacy-buffer path. The design document and the
journal record the superseded row-boundary rule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The ASYNC initial-connect javadoc in Sender still described the
superseded rule: once schema support is confirmed, all future rows use
strict schema lookup and only a row already in progress keeps its
contract. The sender now selects one wire contract per batch, so rows
added to a pending legacy batch stay legacy, and the first row after
that batch flushes adopts schema mode. The javadoc states that rule.

Two passages in the design document still named the row-boundary
transition; they now name the batch boundary.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
QwpSchemaProtocol.decodePayload() built a case-insensitive column-name
index to reject duplicate names and then discarded it. Every
QwpSchemaBinding rebuilt the same index in its constructor, and
hasSameRelevantTarget() resolved names in the refreshed schema with a
third mechanism, a linear equalsIgnoreCase scan.

The decoder now hands its index to QwpSchemaResponse, which exposes
getColumnIndex() and owns hasSameRelevantTarget(). The binding drops
its columns field and its constructor loop, and delegates the
comparison to the snapshot. The index is never mutated after the
decoder publishes it through a final field, so the I/O thread to user
thread handoff stays safe.

Each cached QwpSchemaResponse now retains its index for its lifetime.
Before, only live bindings held one.

QwpSchemaProtocolTest gains direct coverage for the case-insensitive
lookup and for the target comparison, which only sender-level tests
exercised before: absence on one or both sides, a retyped column, the
extension-parameter flag, a moved or removed designated timestamp, and
a schema-less RESULT_MISSING response.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The 21 QwpSchemaBinding*Test classes each carried a private wire
Reader plus their own copies of the schema-response builders: 21
readers in 17 textual variants and two naming dialects (u8/i32/i64
vs byteValue/intValue/longValue), 8 variants of known(), 6 of
column(), 4 of decode(). The copies were semantically identical, so
a change to the schema envelope or the table header meant hand-editing
up to 19 slightly different helpers.

QwpSchemaTestFixtures now owns the schema-response builders (known,
missing, schemaResult, column, parameterizedColumn, frame, decode),
binding(), assertReason(), and the encoded-table header checks
(tableHeader, skipTablePrefix, skipTableHeader). It writes the schema
envelope by hand, independently of any production encoder.
QwpTestWireReader is the single bounds-checked reader, with one
naming dialect and a bounded varint; it never calls production
decoders. The tests keep tableReader(), wireType(), targetType() and
every conversion expectation, because those encode per-test intent.

Two shared assertions are stricter than some of the copies they
replace. assertReason() always asserts that the rejection is not
retryable. tableHeader() always asserts the message magic, version,
flags, and table count; six classes only skipped the header before.
Four of the old readers read i32/i64 without a bounds check, and only
one bounded its varint loop.

The test count is unchanged at 139 across the binding classes. The
change removes about 2,000 lines of test code.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The schema-aware sender no longer swaps a table's schema binding
under pending rows. Once a table holds rows in the current batch,
every later row of that batch validates against the snapshot the
first row pinned; bindingForEffectiveWrite() consults the cache
only when the table buffer is row-less, which is the first row
after a flush or reset. installSchemaBinding() then clears the
buffer and rebinds it in place instead of retiring the old buffer
alongside a new one.

A failed setter reports its local INVALID_VALUE or
UNSUPPORTED_FEATURE directly. onRowFailure() rolls the row back
and rethrows; it never performs a network lookup, so a rejection
costs no round trip and cannot fail for a transport reason. The
cache stays current through the paths that already exist: the
server attaches the table's current schema to the ACK of a frame
that carries a stale identity, the send loop applies that feedback
before it advances the ack watermark, INVALIDATE_ALL empties the
cache so the next batch looks the table up again, and a reconnect
clears the cache. An explicit refresh API was considered and
dropped: a caller cannot tell a stale-snapshot rejection from
invalid input, so there is no sound rule for when to call it.

This removes retiredTableBuffers and its handling on flush
collection, post-flush reset, reset(), close() and byte
accounting; the schemaResolutionFresh out-parameter threaded
through resolveSchema() and QwpSchemaCoordinator.resolve();
refreshAfterSchemaRejection(); QwpSchemaResponse
.hasSameRelevantTarget() and its binding delegate; and the
SCHEMA_CHANGED reason, which nothing raises any more.

The integration test fixtures now acknowledge like the real
server: SchemaHandler and LongTextSchemaHandler attach the current
schema to the ACK when the snapshot they last delivered is stale,
or answer INVALIDATE_ALL when they cannot describe. The generation
rebind tests drive adoption through flushAndGetSequence() and
awaitAckedFsn() and read the two generations from two single-block
frames via a multi-frame FrameReader. New coverage: an
INVALIDATE_ALL ACK makes the next batch surface the typed lookup
failure from the setter, a version change does not split the
pending batch, and reset() keeps the cached snapshot because it
ships no frame.

The design doc's "Local errors and stale schemas" and "One schema
snapshot per table per batch" sections describe the new contract,
and the contract-simplification proposal records proposal 1 as
implemented without an explicit refresh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Server PR #7531 (browser negotiation) already claimed header flag
bit 0x02 for FLAG_DURABLE_ACK_POLL, a zero-table control frame.
Merging server master into the schema-aware branch produced a clean
textual merge, but the ingress dispatch then read a poll frame as a
schema-flagged frame on a connection that had not negotiated schema
and rejected it.

The poll bit is already on server master, while FLAG_SCHEMA is
unreleased, so FLAG_SCHEMA moves to the free bit 0x40. The server
constant changes in lockstep. The design doc and the journal record
the new value and the reason.

Store-and-forward frames persisted by an earlier build of this
branch carry 0x02 and no longer replay as schema frames.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Retain pending schema lookups when the transport disconnects, including
requests that have not reached the wire. Resend on the replacement
connection with a fresh request ID while preserving the original lookup
deadline, so a brief server outage does not abort row construction.

Keep explicit schema errors and malformed-response cancellation intact.
Add lifecycle coverage for repeated disconnects, stale replies, unsent
requests, timeout, interruption and close, and update the design contract.

Validate 296 client tests on Java 8 and Java 25, the original failing fuzz
seeds, and 18 server integration tests. All pass.
A store-and-forward slot recovered with only a deferred (uncommitted)
tail of schema-framed frames made requiresSchema() true. The foreground
sender set that requirement on its reconnect factory before any send
loop existed, so build() failed with QwpSchemaCapabilityMismatchException
against every server without schema support, even with schema_mode=off.
The tail belongs to an aborted transaction and never reaches the wire.

ensureConnected() now calls retireRecoveredOrphanTailIfReady() before it
sets the schema requirement, matching BackgroundDrainer. The sender
starts against a legacy server and sends new rows as legacy frames.
QwpSchemaReplayNetworkTest now asserts that outcome instead of the
startup failure.
QwpSchemaCoordinator.resolve() lower-cased the table name into a new
String before every cache lookup, hit or miss. In AUTO and STRICT modes
the sender resolves twice on the first row of each table in each batch,
so a schema-aware sender produced two garbage Strings per table per
batch on the producer thread, and one pair per row for callers that
flush every row.

QwpTableBuffer now computes the lower-cased schema key once, reusing the
name itself when it is already lower case. The sender passes that key to
resolveSchema(), peekSchema() and refreshSchema(), and normalize()
returns an already lower-case String unchanged, so a cache hit no longer
allocates. DESCRIBE requests now carry the lower-cased name; the server
resolves table names case-insensitively, so the answer is unchanged.
Move FLAG_SCHEMA into its alphabetical slot after FLAG_GORILLA in
QwpConstants. Reword the Unsafe comment on the override field offset:
it named the FdBig double-formatting bridge, which this branch deleted,
so it now names the makeAccessible() callers that the offset protects.
No behavior change.
Schema-validated rows now go out as ordinary QWP frames. The encoder no
longer writes FLAG_SCHEMA or the per-table (tableId, metadataVersion)
identity; the snapshot stays in client memory, where the binding
validates and converts rows against it. The server ingested both frame
families identically and used the identity only to decide schema
feedback, which it decides from the version it last reported on the
connection instead.

With one frame format every persisted frame is sendable to any peer, so
the store-and-forward replay path needs no capability gating. This
removes maxSchemaFsn, requiresSchema(), setSchemaRequired(),
QwpSchemaCapabilityMismatchException, the recovery scan for schema
frames and the drainer checks. The sender drops its one-wire-family-
per-batch rule: a legacy row joins a pending schema batch instead of
forcing a flush. The encoder keeps one path; a schema-bound table
differs only by always shipping the GEOHASH null bitmap.

The cost is that the first ACK per table on each connection carries
the table's schema. Senders above roughly 400 wide tables exceed the
1 MiB feedback limit after a reconnect, receive invalidate-all and
send one DESCRIBE per table in the next batch. The design doc records
the measurements and marks the head-frame gating proposal superseded:
a prototype of it livelocked at the format boundary and its transaction
gate failed against 9.4.x servers.
Replace per-digit division by variable powers of ten with a two-digit
lookup and constant division by 100. Reuse the existing thread-local
scratch array and decode only the digits that fixed-point scale emits.

Keep Ryu conversion, notation boundaries and scale behavior unchanged.
Add character and UTF-8 sink coverage for scale truncation, scratch reuse,
special values and randomized raw-bit round trips.

JDK 25 measurements show 28-30% faster full-precision and wide-range
formatting and about 17% faster eight-field text-row construction for
those workloads. Short decimals remain slower than the pre-Ryu formatter;
this change does not close that regression. Selected low-scale cases
cost about 0.6 ns/value more than the previous head.

Validate 138 focused tests on Java 8 and Java 25 and compare more than
11 million formatting cases with the unchanged head.
Clarify that AUTO avoids schema waits after a detected disconnect, but
an open unresponsive connection can consume a fresh timeout per lookup.
Document the intentional repeated-wait trade-off and keep the timeout
API description concise. This changes comments only.
Brings in upstream through 1.3.13-SNAPSHOT: the event-driven I/O loop,
batched WebSocket sends, symbol dictionary recycling, durable-ack tiers,
refreshing token providers and the azure module.

Conflict resolutions that go beyond picking both sides:

- CursorWebSocketSendLoop: upstream's loop now blocks in poll(2) when
  idle instead of parking 50 us, so a queued DESCRIBE would wait until
  the next PING. QwpSchemaCoordinator now rings the loop's idle
  doorbell (wakeIoIfParked) after it queues a request, and the loop
  does not park while hasUnsentRequest() is true. The doorbell only
  ends the idle poll, so lookups during an outage still cannot cut the
  reconnect backoff short.
- Symbol dictionary recycle: the rebuilt loop starts without a client,
  which made STRICT treat the sender as never having negotiated schema
  and let legacy rows through, and dropped the schema cache. The
  sender now carries hasNegotiatedSchema and the cache across the
  rebuild (seedSchemaState), the schema counterpart of
  markEverConnected(). The coordinator keeps its cache after close so
  retireStoppedLoop() can export it.
- connectWithCredentialSupplier: upstream's 27-argument master stays as
  an overload; a new master adds schemaMode and schemaWaitMillis. The
  obsolete boolean-durable-ack overload is gone, as upstream removed
  the boolean variants.
- awaitAckedFsn() and the close drain keep the branch's
  elapsed-versus-budget timeout, so Long.MAX_VALUE still waits without
  a limit under upstream's park-based waits.
- QwpColumnWriter uses upstream's pre-encoded table header; the
  schema-bound GEOHASH null bitmap stays.
- SymbolDictRecycleTest: a row's first setter now resolves the schema
  and so completes a pending REBUILD before the row takes a value. The
  test asserts that instead of atNow() refusing the row.

QwpSchemaSenderIntegrationTest#testSymbolDictRecycleKeepsSchemaContractAndCache
covers the recycle fix; with the seed removed, STRICT ships the UUID
text as VARCHAR. Without the doorbell, 18 schema coordinator and
lifecycle tests time out.
Remove the four design notes the branch added under design/: the
implementation journal, the 47-test failure plan, the superseded
head-frame gating proposal and the contract simplification proposals.
They recorded work in progress, including local paths and log files,
and parts of them contradicted the shipped code.

Fix documentation that still described the removed schema frame
family:

- Sender.SchemaMode: OFF never requests schema support, and a table,
  not a batch, keeps one contract while it holds pending rows.
- Sender.table(): only STRICT waits for the first connection, and the
  first setter after a flush resolves the schema again.
- WebSocketClient: the Sender does request schema support.
- README: drop the link to docs/schema-aware-ingestion.md, which never
  existed.

Document the four LineSenderSchemaException.Reason values, merge the
two summaries in the RyuDouble class comment, and record why
QwpSchemaBinding.longColumn() does not delegate to integerColumn():
delegating measured about 4% slower per row in
QwpSchemaBindingBenchmark.schemaRow (38.2 to 39.8 ns, three forks each).

Tests: drop the unchecked tableId and version parameters from the
QwpSchemaSenderIntegrationTest frame readers and from
QwpSchemaTestFixtures, and rename the STRICT recovery test after what
it checks now, the wait for the first connection.
A sender converts values against a cached table schema. After ALTER
COLUMN TYPE widened a column (FLOAT to DOUBLE, TIMESTAMP to
TIMESTAMP_NS, INT to LONG), it kept converting to the old type until
the server's reply to a frame for that table reported the change. An
idle sender never got such a reply, so its next batch lost precision
(0.1 stored as 0.10000000149011612, nanoseconds truncated) or rejected
values the column now takes, however long ago the ALTER ran. Reconnects
kept the stale cache too.

The sender now tracks when the server last confirmed each table's
cached schema. A DESCRIBE confirms it as of the moment before the
request. An OK reply to a frame that writes the table confirms it as of
that frame's flush: the I/O thread applies the reply's schema feedback
before it publishes the OK watermark. At the first row of a batch, a
schema unconfirmed for more than SCHEMA_MAX_AGE_MILLIS (1 s) is looked
up again while the wire is up. Busy senders keep getting confirmations
from their replies and never pay the lookup. A re-check that fails as
unavailable keeps the cached entry and defers the next re-check by the
same limit; a denial still fails the row. While the wire is down the
sender keeps using the cache, as before.

- QwpSchemaFreshness holds the per-table confirmation state.
- QwpSchemaCoordinator.revalidate() asks even on a cache hit and keeps
  the entry when the lookup fails.
- CursorWebSocketSendLoop publishes its OK-level watermark to the
  producer; in durable-ack mode the trim watermark lags it.

Rows converted between a change and the reply that reports it still
use the old type: frames in flight, rows written within the age limit,
and rows written while the wire is down. Sender.SchemaMode documents
this.

Tests: QwpSchemaFreshnessTest pins the confirmation rules and checks
random sequences against a log of confirmations. Coordinator tests pin
revalidation on a hit, on a timeout, on UNAVAILABLE and on DENIED.
Sender tests against a fake server pin expiry at the limit and that
only acknowledged frames confirm, including in durable-ack mode, split
flushes, frames written while the wire is down and across a
symbol-dictionary recycle, plus failed and denied re-checks. Test
helpers that count DESCRIBE requests across outages now freeze the
sender clock, so the age limit cannot fire under them.
The comments of the schema age limit explained the same mechanism in
five places. QwpSchemaFreshness and Sender.SchemaMode now carry it; the
constant, the sender's helpers and the send loop's accessors point
there and keep only what is specific to them.

Also corrects two docs: QwpTableBuffer.getSchemaFreshness() returns a
tracker, not a time, and a frame published while another waits for its
reply is never recorded, not recorded later. No code changes.
Ryu finds the shortest decimal by removing one digit per pass from a
17-digit interval, so it is slowest when the answer is short: 0.1 or
3.25 took about 36 ns against 21 ns with the pre-Ryu formatter of
1.3.12, which made legacy ILP text rows with such values up to 1.5x
more expensive to build.

Numbers.append() now tries an exact path first. For a value below 10^7
it computes m = round(abs * 10^8) and checks m / 10^8 == abs. The check
is exact, because both operands are exact doubles and IEEE division
rounds correctly with ties to even. Below 10^7 the rounding interval
holds at most one decimal with 8 fractional digits, so a passing check
gives the shortest decimal, the one Ryu returns, once the trailing
zeros of m are stripped. Every other value goes to Ryu as before, so
the output does not change.

JMH on JDK 25, ns, mean of two interleaved passes, 1.3.12 / before /
after:
- 0.1, 3.25, 42.5, 101.75: 21.3 / 36.1 / 12.7
- random two-decimal values: 27.8 / 38.2 / 15.1
- full-mantissa values: 92.6 / 31.1 / 32.6
- integers below 10^7 (one pass): 17.5 / 12.5 / 14.2
- ILP text row with five short values: 155 / 233 / 129
JDK 8 and JDK 11 show the same order. Nothing allocates.

The tests check the output against the shortest nearest decimal,
computed with BigDecimal from its definition, on every JDK, and against
Double.toString on JDK 19 and later.

Also remove the helpers and tables of the pre-Ryu formatter, which
nothing calls any more.
QwpSchemaSenderIntegrationTest called Thread.onSpinWait(), which exists
only from Java 9 on, so the test tree did not compile on JDK 8 and the
JDK 8 build-and-test CI jobs failed. Call Compat.onSpinWait(), as the
other tests do.
After ALTER COLUMN TYPE widened a column, a sender whose every row
needed the new type kept rejecting rows against its cached schema until
the application flushed or restarted. The batch pins its schema while it
holds pending rows, and a row that fails at a setter never reaches the
at() that runs auto-flush, so no reply could report the change. Client
1.3.12 stored those rows.

Now two consecutive rows the cached schema rejects for a column it
knows, as an invalid value or one its type cannot take, make the next
row of that table look the schema up again. The lookup waits at most one
second, runs at most once a second per table, and only while the wire is
up; a failed lookup keeps the cached schema. When the server reports a
change, the sender flushes its pending rows, whose old types the server
converts, and converts the row to the new types.

A single bad value in an otherwise accepted batch still costs no lookup,
and inputs no column type takes, such as LONG_ARRAY, never count.
testIpv4TargetsUsePinnedTargetWireAndRollback now expects the one lookup
its two consecutive rejected rows cause: the schema has not changed, so
the row keeps the pinned wire.
Self-review of the re-check after a run of rejected rows found:

- A re-check that got no answer timed the next one from its start. The
  wait lasts up to the interval, so a server that never answers lookups
  could hold the producer almost all the time on a table with bad data.
  A failed re-check now defers the next one from the end of its wait,
  through the same deferCheck() the age-based lookup uses, and either
  failure defers both.
- The re-check skipped the lookup on a wire without schema support and
  first peeked at the cache. A lookup on such a wire fails at once, and
  the peek saved a round trip only when an ACK raced the pending row, a
  case no test can force. Both branches are gone; the loop that
  ensureConnected() installs is now asserted rather than null-checked.

New tests cover a transactional sender, whose re-check flush keeps the
transaction open; a recreated table, which changes the table id; a
re-check with no pending rows; a lookup that gets no answer, which waits
at most one second although schema_wait_millis is 60 s; rejections no
type change explains, an invalid column name and an out-of-range
designated timestamp, which look nothing up; and a run longer than the
int range. Renames the test whose name said the opposite of what it
checked: the sender does flush the pending rows itself.
The I/O thread sent a schema lookup's DESCRIBE with the producer's
remaining lookup budget as the socket timeout. A send timeout on that
thread ends the connection: the loop reconnects and replays every
unacked frame. So when the server stopped reading for longer than the
budget (30 s by default, as little as 1 ms) while a DESCRIBE met a full
socket, the sender reconnected and sent its unacked rows again, which
duplicates them in tables without DEDUP. A data frame in the same spot
waits for the client's I/O timeout and rides the stall out. With
schema_wait_millis = Long.MAX_VALUE the same send waited about 24 days,
so a peer that kept its window closed went unnoticed while a DESCRIBE
was pending.

WebSocketClient.sendBinary(byte[]) now sends with the I/O timeout that
data frames and PINGs use, and takes no timeout, so no caller can pass
a budget again. The producer's wait stays bounded by its budget in
QwpSchemaCoordinator.await(), which never depended on the send timeout:
the I/O thread holds no coordinator lock while it sends, and the
coordinator drops a late reply to an abandoned request. Commit 09b61b6
fixed the same mistake for keepalive PINGs.

CursorWebSocketSchemaSendTimeoutTest drives the loop over a socket that
completes the real upgrade and then accepts nothing while stalled; the
frames each connection received are the oracle. A stall longer than the
lookup budget but shorter than the I/O timeout now ends the lookup on
its budget and keeps the connection: every frame goes out once, and a
lookup queued behind the blocked DESCRIBE gets its own reply. A stall
longer than the I/O timeout, with a finite or the unbounded budget, and
a send error still reconnect: the next connection sends the lookup
again, or the lookup fails at once when the loop abandons lookups on
disconnect, as AUTO does. A stall that ends within the budget gets its
reply on the same connection, and close() still breaks a blocked
DESCRIBE and releases the lookup.
A schema-aware sender parses DATE and timestamp text itself and sends
the value. QwpSchemaTimestampParser resolved a zone name such as BST or
Europe/Berlin with the zone data of the client's JVM, while the server
resolves the same name with its own. The two can differ: on JDK 17 and
21 a client stored "...BST" five hours away from what the server stores
for the same text, and nothing reported the difference.

The parser now takes a zone only as Z, UTC, GMT or a numeric offset,
which UTC or GMT may precede, and rejects every other name with
INVALID_VALUE. The message names the accepted forms. This removes the
NamedZones table and the zone-rule arithmetic behind it. Other
spellings of UTC, such as Zulu and Etc/UTC, are names, and the parser
rejects them too.

This commit also fixes two cases where the parser disagreed with the
server on DATE text in the yyyy-MM-ddTHH:mm:ss.SSSz layout:

- parseUtcDate() read a fixed four-character year, so it rejected
  "-0001-..." and took "-001-..." as year -1. It now reads a signed
  year as parseIso() does.
- parseDate() picked the layout from the first dash after the sign and
  so rejected "--001-...", which the server reads as year 1. It now
  hands every text outside the PG layout to parseUtcDate().

The corpus files gain rows for these cases. The runtime corpus now says
for each input whether the client matches the server or rejects a zone
name.
An application that starts a row, never calls at() or atNow(), and then
closes the sender lost every complete row it had not flushed yet. This
is the usual shape of an exception thrown between table() and at()
inside a try-with-resources block.

close() skips the check that makes flush() refuse a row in progress, and
it encoded the table buffer as it stood. With a schema-bound buffer the
encoder threw "cannot encode a schema-bound table with an incomplete
row", so close() threw and sent nothing. With an unbound buffer the
frame carried the columns of the unfinished row, a malformed batch that
the server rejected.

close0() now rolls the unfinished row back before it flushes, as
cancelRow() does, and sends the complete rows.

A pooled sender still reports the unfinished row from close(), because
its close() calls flush(). The pool then retires the sender, and
closing it sends the complete rows.
The SchemaMode javadoc said that after two rejected rows the next row
looks the schema up again. recheckRejectingSchema() needs a connected
wire, so while the connection is down such rows keep failing until the
sender reconnects. The javadoc now says so.

It also states which time zone forms the sender takes in DATE and
timestamp text, and why it rejects zone names.
recordFatal() keeps the first terminal error and ignores later calls.
close() relies on that: it compares instances to tell whether the
producer already owns the terminal. The schema-aware sender commit
deleted CursorWebSocketSendLoopErrorLatchTest, which covered it,
because the test's Unsafe.allocateInstance fixture left the new
schemaCoordinator field null. No remaining test failed when the guard
was removed.

testReconnectJvmErrorKeepsFirstLatchedTerminal drives a real loop whose
connection factory throws a JVM Error. The reconnect walk and the I/O
loop's catch both record it. The test asserts that the instance the
first call latched stays latched, and that checkUnsurfacedError() stays
silent once the producer owns it. It fails when recordFatal() drops its
first-writer guard, and when it wraps the cause again on a later call.
A schema-bound row that wrote the table's designated timestamp column
by name failed with UNSUPPORTED_FEATURE ("designated timestamp writes
are not implemented"), and the row was dropped. Client 1.3.12, the
legacy contract and ILP all store such a row: the server takes a field
named like the designated column as the row's timestamp. So code such
as timestampColumn("ts", t).atNow() broke under the default AUTO mode.

QwpSchemaBinding now routes a named write to the designated column into
the unnamed designated timestamp wire column that at() writes:

- existingColumn() maps the designated column's name, in any case, to
  that column, so every setter shares one first-value-wins duplicate
  check. A duplicate doubleArray() no longer inspects its array, and the
  column records its schema index, so later rows skip the name check
  and the schema lookup.
- A named value takes precedence over at(), as in ILP. A named write
  that leaves NULL gives no timestamp: at() replaces that NULL, through
  ColumnBuffer.replaceTrailingNullWithLong(), and atNow() leaves it for
  the server to assign.
- at() rejects a null Instant, a null unit and an unsupported unit even
  after a named write.

Sender.timestampColumn() documents the precedence and the legacy
contract's rejection of a row that names the column and calls at().
The unused QwpTableBuffer.getExistingColumnByName() is removed.
Brings in the query client's paging, row counts, timings and error
positions (#129), which OSS master now pins. The merge is clean.
Round doubles in [2^53, 2^63) (e.g. 1.5E17, 6.49E16, 1.730592031E18)
previously ran 128-bit mulShift64 with q = 0, looped in pow5Factor up to
17 times to check divisibility by 5^0, and stripped trailing digits one
per pass in Step 4.

- Add exact shift / * 5 Step 3 paths for [2^53, 2^63) (e2 in [-1, 8]),
  skipping 128-bit multiply and power-of-5 checks.
- Replace pow5Factor loop with O(1) Granlund-Montgomery divisibility
  checks via 22-entry POW5_INV/POW5_MAX tables.
- Strip trailing digits in 10^8/10^4/10^2/10 chunks in Step 4 and the
  [1, 2^53) integer path while keeping hot d2d compact for non-round
  values.
- Add boundary and round-double tests in NumbersTest.
# Conflicts:
#	core/src/main/java/io/questdb/client/Sender.java
#	core/src/main/java/io/questdb/client/cutlass/http/client/WebSocketClient.java
#	core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpWebSocketSender.java
#	core/src/test/java/io/questdb/client/test/cutlass/qwp/websocket/TestWebSocketServer.java
ColumnBuffer.truncateTo() and resetEmptyMetadata() reset
geohashPrecision to -1 whenever newValueCount reached 0. When a
client-side row rejection rolled back a geohash write on a column
whose earlier rows in the batch were all NULL, the encoder fell back
to 1-bit precision and the server rejected the batch with a precision
mismatch.

Add isGeoHashPrecisionLocked and lockGeoHashPrecision() on
ColumnBuffer. QwpSchemaBinding.targetColumn() locks the precision for
known schema GEOHASH columns, ColumnBuffer.reset() locks non-negative
precision across batches, and QwpTableBuffer.retainInProgressRow()
locks committed columns before retaining the tail row.
resetEmptyMetadata() now clears geohashPrecision only while unlocked,
and truncateTo() delegates its empty-metadata reset to it.
QwpWebSocketSender now rejects endpoints that omit X-QWP-Schema: enabled
during foreground STRICT WebSocket upgrades by throwing
QwpSchemaMismatchException. Initial connects fail fast in OFF, SYNC, and
ASYNC modes while skipping legacy endpoints in multi-endpoint walks.
Already-connected foreground senders retry on mid-session reconnects
without terminating so store-and-forward keeps buffered data intact, and
BackgroundDrainer skips schema negotiation altogether.

In AUTO mode, QwpSchemaFreshness now scopes failed-check deferrals to
CursorWebSocketSendLoop's monotonic connectionEpoch so a failed cold
lookup skips repeated waits on the same connection for one second and
clears immediately on reconnect. QwpWebSocketSender also logs a WARN
once per table when AUTO enters legacy fallback or changes fallback
reason, resetting when the table binds a schema.
@mtopolnik

Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 3085 / 3227 (95.60%)

file detail

path covered line new line coverage
🔵 io/questdb/client/Sender.java 42 49 85.71%
🔵 io/questdb/client/cutlass/qwp/client/QwpWebSocketSender.java 349 398 87.69%
🔵 io/questdb/client/cutlass/qwp/client/sf/cursor/QwpSchemaCoordinator.java 159 175 90.86%
🔵 io/questdb/client/cutlass/qwp/client/sf/cursor/CursorWebSocketSendLoop.java 98 107 91.59%
🔵 io/questdb/client/cutlass/qwp/client/WebSocketResponse.java 82 88 93.18%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpTableBuffer.java 135 145 93.10%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpSchemaTimestampFormatter.java 97 102 95.10%
🔵 io/questdb/client/std/DecimalParser.java 24 25 96.00%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpSchemaProtocol.java 129 134 96.27%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpSchemaBinding.java 1031 1058 97.45%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpSchemaTimestampParser.java 271 277 97.83%
🔵 io/questdb/client/std/RyuDouble.java 299 300 99.67%
🔵 io/questdb/client/cutlass/qwp/client/QwpWebSocketEncoder.java 18 18 100.00%
🔵 io/questdb/client/std/str/DirectUtf8Sink.java 7 7 100.00%
🔵 io/questdb/client/std/str/Utf8StringSink.java 10 10 100.00%
🔵 io/questdb/client/cutlass/line/array/AbstractArray.java 3 3 100.00%
🔵 io/questdb/client/cutlass/http/client/WebSocketClient.java 37 37 100.00%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpConstants.java 2 2 100.00%
🔵 io/questdb/client/std/str/StringSink.java 7 7 100.00%
🔵 io/questdb/client/cutlass/http/client/HttpClient.java 9 9 100.00%
🔵 io/questdb/client/cutlass/qwp/protocol/QwpSchemaResponse.java 25 25 100.00%
🔵 io/questdb/client/cairo/ColumnType.java 6 6 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpSchemaMismatchException.java 8 8 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpConnectionHealthTracker.java 1 1 100.00%
🔵 io/questdb/client/impl/ConfigSchema.java 2 2 100.00%
🔵 io/questdb/client/LineSenderSchemaException.java 9 9 100.00%
🔵 io/questdb/client/cairo/TableUtils.java 5 5 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpColumnWriter.java 5 5 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpSchemaFreshness.java 46 46 100.00%
🔵 io/questdb/client/std/Numbers.java 167 167 100.00%
🔵 io/questdb/client/std/Compat.java 2 2 100.00%

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants