Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a0a0d89
Let QWP senders send batches of any size
bluestreak01 Nov 11, 2026
d5028e5
Test strict split frames and pooled lease reuse
bluestreak01 Nov 11, 2026
ce20002
Test discarding a transaction during an outage
bluestreak01 Nov 12, 2026
fa1c788
Discard transactions without waiting on the server
bluestreak01 Nov 12, 2026
4749d5d
Decide strict mode from the auto-flush triggers
bluestreak01 Nov 12, 2026
a6ed998
Keep refused rows out of strict transactions
bluestreak01 Nov 12, 2026
83eec1e
Commit transaction=on in parts at client buffer
bluestreak01 Nov 12, 2026
384bf16
Accept rows after reset() of a refused transaction
bluestreak01 Nov 24, 2026
5c7f3ed
Discard transactions without aborting the sender
bluestreak01 Nov 24, 2026
b0d8e45
Size pooled strict transactions to their share
bluestreak01 Nov 24, 2026
3f71138
Count every spelling of a table at the row limit
bluestreak01 Nov 24, 2026
db7d1c5
Track a partly sent split frame by frame
bluestreak01 Nov 26, 2026
6ce369a
Merge branch 'main' into vi_qwp_large_txn
bluestreak01 Nov 26, 2026
6648cbe
Test the strict default cap and discard waits
bluestreak01 Nov 26, 2026
54aac15
Never let a late-learned cap split a strict txn
bluestreak01 Nov 26, 2026
a46fcf2
Refuse servers without X-QWP-Max-Uncommitted-Rows in strict mode
bluestreak01 Nov 29, 2026
34116f5
Size shared strict budgets by live registered rings
bluestreak01 Nov 29, 2026
949b3b0
Advertise X-QWP-Max-Uncommitted-Rows in strict SelfSufficientFramesTe…
bluestreak01 Nov 29, 2026
ccba9ea
Fix reset() rollback-unsupported warning to advise rollback() instead…
bluestreak01 Nov 30, 2026
e010cd8
Only refuse older servers for explicit transaction=strict
bluestreak01 Nov 30, 2026
b12177f
Latch pending rollback when rollback() fails to publish
bluestreak01 Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,16 @@ The ingest side also accepts store-and-forward and reconnection tuning keys (`au
`sf_max_total_bytes` caps the unacknowledged data all pooled senders buffer together — 128 MiB of memory by default,
10 GiB of disk with `sf_dir` — so a larger `sender_pool_max` adds connections, not buffer memory. The only overshoot
is the minimum working set every live sender keeps: two segments (`2 × sf_max_segment_bytes`, 8 MiB by default).
A strict transaction (`transaction=strict`, or no auto-flush trigger) stays in that buffer until the server commits
it, and every pooled sender may hold one at once, so a strict transaction that spans more than one segment can use
only its sender's share: `sf_max_total_bytes / sender_pool_max`, one segment less with `sf_dir`. A larger one fails
with `TransactionTooLargeException`. So does one that holds more rows of a table than the server's
`qwp.max.uncommitted.rows` when the sender learns that limit only after accepting them, as before its first connection:
the server refuses such a transaction rather than commit it in parts, and `rollback()` discards it. Explicit
`transaction=strict` requires a server that advertises `X-QWP-Max-Uncommitted-Rows`; against older servers the sender
fails at connect with `QwpStrictTransactionMismatchException` rather than commit in parts (use `transaction=on` there).
A sender that is strict only because it has no auto-flush trigger still connects to older servers with a warning and
client-side limits (assuming 1,000,000 uncommitted rows per table).
`sf_durability=periodic` checkpoints mmap-published data in the background; `sf_sync_interval_millis` defaults to `5000`
in that mode. The interval is a target cadence: JVM scheduling and storage-sync latency add to the actual loss window.
Use `request_durable_ack=on` when end-to-end server durability is also required. See the
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/io/questdb/client/QuestDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ static QuestDB connect(CharSequence configurationString, HttpTokenProvider token
* {@link Sender#close()} on the returned instance to release it back to
* the pool. {@code close()} on a pooled Sender flushes pending rows
* before returning to the pool; a real disconnect only happens at
* {@link #close()} on this {@code QuestDB} handle.
* {@link #close()} on this {@code QuestDB} handle. A Sender in strict
* transactional mode ({@code transaction=strict}, or a WebSocket config
* with no auto-flush trigger, such as {@code auto_flush=off}) commits only
* on {@link Sender#flush()}, so its {@code close()} discards the rows it
* did not flush instead.
* <p>
* Allocation: zero at steady state -- the returned instance is a
* pre-allocated decorator backed by a pre-allocated underlying Sender.
Expand Down
233 changes: 206 additions & 27 deletions core/src/main/java/io/questdb/client/Sender.java

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions core/src/main/java/io/questdb/client/SenderError.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ public enum Category {
* consecutive times with no ack progress — replaying it cannot succeed.
*/
PROTOCOL_VIOLATION,
/**
* The server cannot commit a strict transaction as one: a table of it would
* reach the server's {@code qwp.max.uncommitted.rows}, where the server commits
* on its own, because the sender accepted the transaction's rows before it
* learned that limit. Wire {@code 0x0F}. The server discarded the rows it had
* received. When the producer rolled the transaction back, the sender discards
* its frames and reports nothing; when the producer committed it, the sender
* halts with this category, and the frames stay in the store-and-forward log.
*/
TRANSACTION_TOO_LARGE,
/**
* Rows this client had durably buffered will never be sent, and no retry
* will change that. The only category with no server involvement: the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public abstract class WebSocketClient implements QuietCloseable {
private static final String QWP_CONTENT_ENCODING_HEADER_NAME = "X-QWP-Content-Encoding:";
private static final String QWP_DURABLE_ACK_HEADER_NAME = "X-QWP-Durable-Ack:";
private static final String QWP_MAX_BATCH_SIZE_HEADER_NAME = "X-QWP-Max-Batch-Size:";
private static final String QWP_MAX_UNCOMMITTED_ROWS_HEADER_NAME = "X-QWP-Max-Uncommitted-Rows:";
private static final String QWP_ROLLBACK_HEADER_NAME = "X-QWP-Rollback:";
// Token the server echoes in X-QWP-Rollback when it accepts the rollback
// control frame on this connection.
private static final String QWP_ROLLBACK_TOKEN_ENABLED = "enabled";
private static final String QWP_VERSION_HEADER_NAME = "X-QWP-Version:";
private static final ThreadLocal<MessageDigest> SHA1_DIGEST = ThreadLocal.withInitial(() -> {
try {
Expand Down Expand Up @@ -148,6 +153,9 @@ public abstract class WebSocketClient implements QuietCloseable {
// Requested durable-ack tier set (DurableAckTiers bitmask), sent as
// X-QWP-Request-Durable-Ack: <DurableAckTiers.requestHeaderValue>
private int qwpDurableAckTiers = DurableAckTiers.NONE;
// When true, the upgrade request carries X-QWP-Request-Rollback: true, asking
// the server to confirm that it accepts the rollback control frame.
private boolean qwpRequestRollback;
// Receive buffer (native memory)
private long recvBufPtr;
private int recvBufSize;
Expand All @@ -170,6 +178,11 @@ public abstract class WebSocketClient implements QuietCloseable {
// not advertise the header (older builds), in which case the sender falls
// back to its locally configured budget.
private int serverMaxBatchSize;
// Server's per-table cap on rows a deferred-commit group may hold before the
// server commits them on its own (qwp.max.uncommitted.rows), extracted from
// X-QWP-Max-Uncommitted-Rows on the 101 upgrade response. 0 when the server
// did not advertise it (older builds).
private long serverMaxUncommittedRows;
// Zstd compression level the server actually applied for this connection,
// extracted from the echoed X-QWP-Content-Encoding response header.
// 0 means "no zstd" -- either the server picked raw, the header was absent
Expand All @@ -178,6 +191,11 @@ public abstract class WebSocketClient implements QuietCloseable {
// the wire said without re-clamping so a misconfigured server is observable.
private int serverNegotiatedZstdLevel;
private int serverQwpVersion = 1;
// Set during upgrade response validation when the client asked for rollback
// (qwpRequestRollback) and the server confirmed it with X-QWP-Rollback:
// enabled. A server that does not confirm treats the rollback control frame
// as an empty deferred frame, so the client must never send it there.
private boolean serverRollbackEnabled;
private String upgradeRejectRole;
// WWW-Authenticate value(s) from the most recent rejected upgrade, joined with ", " when the server sent
// several, or null when absent. Lets a 401 carrying "Bearer error=insufficient_scope" be told apart from an
Expand Down Expand Up @@ -412,6 +430,16 @@ public int getServerMaxBatchSize() {
return serverMaxBatchSize;
}

/**
* Server's per-table limit on rows a deferred-commit group may hold before
* the server commits them on its own ({@code qwp.max.uncommitted.rows}), taken
* from the {@code X-QWP-Max-Uncommitted-Rows} response header on the 101
* upgrade. Returns {@code 0} when the server did not advertise the header.
*/
public long getServerMaxUncommittedRows() {
return serverMaxUncommittedRows;
}

/**
* Zstd level the server actually applied for this connection, parsed
* from the echoed {@code X-QWP-Content-Encoding} response header.
Expand Down Expand Up @@ -494,6 +522,16 @@ public boolean isServerDurableAckEnabled() {
return serverDurableAckEnabled;
}

/**
* Returns true when the client asked for rollback support via
* {@link #setQwpRequestRollback} and the 101 upgrade response confirmed it
* with {@code X-QWP-Rollback: enabled}. Meaningful only after
* {@link #upgrade} returns.
*/
public boolean isServerRollbackEnabled() {
return serverRollbackEnabled;
}

/**
* Receives and processes WebSocket frames.
*
Expand Down Expand Up @@ -670,6 +708,16 @@ public void setQwpMaxVersion(int maxVersion) {
this.qwpMaxVersion = maxVersion;
}

/**
* When {@code true}, the upgrade request carries
* {@code X-QWP-Request-Rollback: true}. A server that accepts the rollback
* control frame confirms it with {@code X-QWP-Rollback: enabled}; see
* {@link #isServerRollbackEnabled()}.
*/
public void setQwpRequestRollback(boolean requestRollback) {
this.qwpRequestRollback = requestRollback;
}

/**
* Sets the requested durable-ack tier set ({@link DurableAckTiers}
* bitmask) for the opt-in X-QWP-Request-Durable-Ack upgrade header. When
Expand Down Expand Up @@ -795,6 +843,9 @@ public void upgrade(CharSequence path, int timeout, CharSequence authorizationHe
sendBuffer.putAscii(DurableAckTiers.requestHeaderValue(qwpDurableAckTiers));
sendBuffer.putAscii("\r\n");
}
if (qwpRequestRollback) {
sendBuffer.putAscii("X-QWP-Request-Rollback: true\r\n");
}
if (authorizationHeader != null) {
sendBuffer.putAscii("Authorization: ");
sendBuffer.putAscii(authorizationHeader);
Expand Down Expand Up @@ -912,6 +963,22 @@ private static String extractDurableAckEcho(String response) {
return null;
}

private static String extractHeaderValue(String response, String headerName) {
int headerLen = headerName.length();
int responseLen = response.length();
for (int i = 0; i <= responseLen - headerLen; i++) {
if (response.regionMatches(true, i, headerName, 0, headerLen)) {
int valueStart = i + headerLen;
int lineEnd = response.indexOf('\r', valueStart);
if (lineEnd < 0) {
lineEnd = responseLen;
}
return response.substring(valueStart, lineEnd).trim();
}
}
return null;
}

private static int extractMaxBatchSize(String response) {
int headerLen = QWP_MAX_BATCH_SIZE_HEADER_NAME.length();
int responseLen = response.length();
Expand All @@ -934,6 +1001,18 @@ private static int extractMaxBatchSize(String response) {
return 0;
}

private static long extractMaxUncommittedRows(String response) {
String value = extractHeaderValue(response, QWP_MAX_UNCOMMITTED_ROWS_HEADER_NAME);
if (value == null) {
return 0;
}
try {
return Math.max(Long.parseLong(value), 0);
} catch (NumberFormatException e) {
return 0;
}
}

private static int extractQwpVersion(String response) {
int headerLen = QWP_VERSION_HEADER_NAME.length();
int responseLen = response.length();
Expand Down Expand Up @@ -1541,6 +1620,17 @@ private void validateUpgradeResponse(int headerEnd) {
// sender falls back to its locally configured byte budget in that case.
serverMaxBatchSize = extractMaxBatchSize(response);

// Extract X-QWP-Max-Uncommitted-Rows (optional). Older servers omit it;
// strict transactional senders reject such servers at connect rather than
// risk silent partial commits, while non-strict senders ignore the cap.
serverMaxUncommittedRows = extractMaxUncommittedRows(response);

// Extract the X-QWP-Rollback confirmation (optional). Only a client that
// asked for rollback may treat it as granted: the server echoes it only
// on request, and an older server never sends it.
serverRollbackEnabled = qwpRequestRollback
&& QWP_ROLLBACK_TOKEN_ENABLED.equalsIgnoreCase(extractHeaderValue(response, QWP_ROLLBACK_HEADER_NAME));

// Extract X-QWP-Content-Encoding (optional). Surfaces what level the
// server actually applied -- which may differ from what this client
// asked for if the server has qwp.egress.compression.force.level set
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*+*****************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2026 QuestDB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

package io.questdb.client.cutlass.qwp.client;

import io.questdb.client.cutlass.http.client.HttpClientException;

/**
* The server completed the WebSocket upgrade (HTTP 101) but did not confirm a
* required client capability (such as durable ack or strict transactions).
* <p>
* Extends {@link HttpClientException} directly (not
* {@link io.questdb.client.cutlass.http.client.WebSocketUpgradeException}) so a
* genuine capability gap stays distinct from a transient 421 role reject across
* mixed-endpoint sweeps. Sync and off initial connects fail fast; an async
* initial connect latches a terminal error before sending any frame; after a
* sender has connected once, foreground reconnects ride out a temporary
* capability gap under store-and-forward Invariant B (for example during a
* rolling upgrade); orphan drainers apply a bounded settle budget before
* quarantining the slot.
*/
public abstract class QwpCapabilityMismatchException extends HttpClientException {
private final String host;
private final int port;

protected QwpCapabilityMismatchException(String host, int port, String message) {
super(message);
this.host = host;
this.port = port;
}

/**
* Short human-readable name of the missing server capability (for example
* {@code "durable-ack"} or {@code "strict-transaction"}), used in log and
* sentinel messages.
*/
public abstract String getCapabilityName();

/**
* Short error prefix (for example {@code "durable-ack-mismatch"} or
* {@code "strict-transaction-mismatch"}), used in {@code SenderError}
* messages and logs.
*/
public abstract String getErrorPrefix();

public String getHost() {
return host;
}

public int getPort() {
return port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static ConnectionHealth.Failure classify(Throwable failure, long nowMilli
? failure(ConnectionHealth.FailureClass.ROLE_REJECTED, 0, t, nowMillis)
: failure(ConnectionHealth.FailureClass.OTHER, Math.max(0, e.getStatusCode()), t, nowMillis);
}
if (t instanceof QwpVersionMismatchException || t instanceof QwpDurableAckMismatchException) {
if (t instanceof QwpVersionMismatchException || t instanceof QwpCapabilityMismatchException) {
return failure(ConnectionHealth.FailureClass.OTHER, 0, t, nowMillis);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

package io.questdb.client.cutlass.qwp.client;

import io.questdb.client.cutlass.http.client.HttpClientException;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -42,9 +41,7 @@
* requested set and what the server echoed, or that it sent no header.
* {@link #getRole()} is {@code null} for this denial.
*/
public final class QwpDurableAckMismatchException extends HttpClientException {
private final String host;
private final int port;
public final class QwpDurableAckMismatchException extends QwpCapabilityMismatchException {
private final String role;

/**
Expand All @@ -53,7 +50,7 @@ public final class QwpDurableAckMismatchException extends HttpClientException {
* value, or {@code null} when the server sent no such header.
*/
public QwpDurableAckMismatchException(String host, int port, int requestedTiers, @Nullable String serverEcho) {
super("WebSocket upgrade failed: server does not support durable ack [host=");
super(host, port, "WebSocket upgrade failed: server does not support durable ack [host=");
put(host).put(", port=").put(port)
.put(", requested=").put(DurableAckTiers.configValue(requestedTiers))
.put(", echoed=");
Expand All @@ -63,29 +60,27 @@ public QwpDurableAckMismatchException(String host, int port, int requestedTiers,
put("<no X-QWP-Durable-Ack header>");
}
put(']');
this.host = host;
this.port = port;
this.role = null;
}

public QwpDurableAckMismatchException(String host, int port, String role) {
super("WebSocket upgrade failed: server does not support durable ack [host=");
super(host, port, "WebSocket upgrade failed: server does not support durable ack [host=");
put(host).put(", port=").put(port);
if (role != null) {
put(", role=").put(role);
}
put(']');
this.host = host;
this.port = port;
this.role = role;
}

public String getHost() {
return host;
@Override
public String getCapabilityName() {
return "durable-ack";
}

public int getPort() {
return port;
@Override
public String getErrorPrefix() {
return "durable-ack-mismatch";
}

/**
Expand Down
Loading
Loading