Skip to content

Commit acfdc1a

Browse files
EC2 Default Userclaude
andcommitted
txfix fixture worker; run the vgi writable_tx suite on every lane
TxFixWorker (vgi docs/writable_tx_fixtures.md) is built only from the public API, routed by ci/wrappers/vgi-worker-txfix. ci/run-integration.sh sets VGI_WRITABLE_TX_FIXTURES, a per-run VGI_TXFIX_STATE_DIR and VGI_WRITABLE_TX_WORKER on the launch/shm and http lanes; the Makefile lane too. VGI_REF moves to vgi v2.0 c4a9fea, which carries the suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 70799ca commit acfdc1a

7 files changed

Lines changed: 803 additions & 1 deletion

File tree

‎.github/workflows/integration.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ concurrency:
2020

2121
env:
2222
# Match the test suite to the native runner built from this exact revision.
23-
VGI_REF: 5575cffa1789b348402fa49c9370bb047fb4223d
23+
VGI_REF: c4a9fea7668b4a85d22dd439ba2888e3a409925c
2424
VGI_NATIVE_RUNNER_BRANCH: v2.0
2525
# Disable local sibling substitution: validate the released Maven dependency.
2626
VGI_RPC_JAVA_DIR: /nonexistent

‎Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ VERSIONED_TABLES_LOCATION := $(LAUNCHER_PREFIX)$(WRAPPERS)/vgi-worker-versioned-
5353
ATTACH_OPTIONS_LOCATION := $(LAUNCHER_PREFIX)$(WRAPPERS)/vgi-worker-attach-options
5454
BAD_ENUM_LOCATION := $(LAUNCHER_PREFIX)$(WRAPPERS)/vgi-worker-bad-enum
5555
BAD_PROTOCOL_LOCATION := $(LAUNCHER_PREFIX)$(WRAPPERS)/vgi-worker-bad-protocol
56+
WRITABLE_TX_LOCATION := $(LAUNCHER_PREFIX)$(WRAPPERS)/vgi-worker-txfix
5657

5758
# Every fixture-worker variable the shared suite reads, in one place so `test`
5859
# and `test-single` cannot drift apart.
@@ -74,6 +75,8 @@ BAD_PROTOCOL_LOCATION := $(LAUNCHER_PREFIX)$(WRAPPERS)/vgi-worker-bad-protoc
7475
# VGI_ATTACH_OPTIONS_WORKER: that worker serves the `attach_options_required`
7576
# catalog too, and upstream split those assertions into their own file behind
7677
# their own env var.
78+
# VGI_WRITABLE_TX_WORKER is the txfix writable-table / transaction-hook fixture
79+
# (vgi docs/writable_tx_fixtures.md), the same binary routed by its wrapper.
7780
# VGI_TEST_BRANCH_DIR is the scratch dir the multi_branch_* fixtures and the
7881
# .test files that seed them (parquet / csv) must BOTH name. The vgi Makefile
7982
# exports it, so this lane inherited it under `make test_java` and not when run
@@ -90,6 +93,8 @@ FIXTURE_ENV := \
9093
VGI_ATTACH_OPTIONS_REQUIRED_WORKER=$(ATTACH_OPTIONS_LOCATION) \
9194
VGI_BAD_ENUM_WORKER=$(BAD_ENUM_LOCATION) \
9295
VGI_BAD_PROTOCOL_WORKER=$(BAD_PROTOCOL_LOCATION) \
96+
VGI_WRITABLE_TX_FIXTURES=1 \
97+
VGI_WRITABLE_TX_WORKER=$(WRITABLE_TX_LOCATION) \
9398
VGI_REQUIRE_LAUNCHER_TRANSPORT=1
9499

95100
.PHONY: build smoke test test-crash test-http test-single clean

‎ci/run-integration.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ export VGI_SECRET_LOOKUP_FIXTURES=1
137137
# behind `require-env VGI_TEST_BRANCH_DIR`; unset, they silently skip).
138138
export VGI_TEST_BRANCH_DIR="${VGI_TEST_BRANCH_DIR:-$(mktemp -d)}"
139139
echo "branch scratch dir: $VGI_TEST_BRANCH_DIR"
140+
# The txfix writable-table / transaction-hook fixture (vgi
141+
# docs/writable_tx_fixtures.md; TxFixWorker, routed by ci/wrappers/vgi-worker-txfix)
142+
# opts the writable_tx/*.test files in on every lane; VGI_WRITABLE_TX_WORKER is set
143+
# per transport below. Its state is shared by the lane's worker processes through
144+
# files in VGI_TXFIX_STATE_DIR, private to this run so concurrent lanes on one host
145+
# never see each other's rows.
146+
export VGI_WRITABLE_TX_FIXTURES=1
147+
export VGI_TXFIX_STATE_DIR="${VGI_TXFIX_STATE_DIR:-$(mktemp -d)}"
148+
echo "txfix state dir: $VGI_TXFIX_STATE_DIR"
140149
# An empty VGI_RPC_SHM_SIZE_BYTES must not reach the C++ client (it would try to
141150
# attach a zero-size segment); only a real value enables the shm side channel.
142151
[ -n "${VGI_RPC_SHM_SIZE_BYTES:-}" ] || unset VGI_RPC_SHM_SIZE_BYTES
@@ -202,6 +211,7 @@ case "$TRANSPORT" in
202211
# strict-enum rejection (bad_enum.test). Skipped over HTTP (like
203212
# bad-protocol), so wired on the launch lane only.
204213
export VGI_BAD_ENUM_WORKER="launch:${HERE}/wrappers/vgi-worker-bad-enum"
214+
export VGI_WRITABLE_TX_WORKER="launch:${HERE}/wrappers/vgi-worker-txfix"
205215
# We are the launcher transport, so opt into the launcher-only tests
206216
# (launcher/options_smoke.test) — matches vgi's `make test_launcher`.
207217
export VGI_REQUIRE_LAUNCHER_TRANSPORT=1
@@ -245,6 +255,9 @@ case "$TRANSPORT" in
245255
export VGI_ATTACH_OPTIONS_WORKER="http://localhost:${ao_port}"
246256
export VGI_ATTACH_OPTIONS_REQUIRED_WORKER="$VGI_ATTACH_OPTIONS_WORKER"
247257
echo "attach_options http worker on ${VGI_ATTACH_OPTIONS_WORKER}"
258+
boot_http_worker "${HERE}/wrappers/vgi-worker-txfix"; tx_port="$BOOTED_PORT"
259+
export VGI_WRITABLE_TX_WORKER="http://localhost:${tx_port}"
260+
echo "txfix http worker on ${VGI_WRITABLE_TX_WORKER}"
248261
# NB: VGI_TEST_DEDICATED_WORKER stays UNSET here. The buffering crash /
249262
# pool-recovery tests SIGKILL their worker mid-process, which is only safe on
250263
# a subprocess (bare-path) transport — over http it would tear down the single

‎ci/wrappers/vgi-worker-txfix‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Routes the single example worker binary into the `txfix` catalog: the
3+
# writable-table / transaction-hook fixture (vgi docs/writable_tx_fixtures.md;
4+
# Main.java short-circuits this catalog name to TxFixWorker, a dedicated worker
5+
# built only from the SDK's public API). Worker binary named via $VGI_WORKER_BIN.
6+
export VGI_WORKER_CATALOG_NAME=txfix
7+
exec "${VGI_WORKER_BIN:?set VGI_WORKER_BIN to the example worker launcher}" "$@"

‎vgi-example-worker/src/main/java/farm/query/vgi/example/Main.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ public static void main(String[] args) {
301301
}
302302
String implVer = System.getenv("VGI_WORKER_IMPLEMENTATION_VERSION");
303303
String dataSpec = System.getenv("VGI_WORKER_DATA_VERSION_SPEC");
304+
if (farm.query.vgi.example.txfix.TxFixWorker.CATALOG_NAME.equals(catalogName)) {
305+
// Writable-table / transaction-hook fixture (vgi docs/writable_tx_fixtures.md): a
306+
// dedicated worker built only from public API, nothing of the example catalog.
307+
farm.query.vgi.example.txfix.TxFixWorker.build().runFromArgs(args);
308+
return;
309+
}
304310
if (farm.query.vgi.example.table.AttachOptionsFixture.CATALOG_NAME.equals(catalogName)) {
305311
// Dedicated attach_options worker mode: register only echo_attach_options
306312
// and the 20 declared option specs. ATTACH 'attach_options' AS … must
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright 2026 Query Farm LLC - https://query.farm
2+
3+
package farm.query.vgi.example.txfix;
4+
5+
import java.io.IOException;
6+
import java.net.URLDecoder;
7+
import java.net.URLEncoder;
8+
import java.nio.channels.FileChannel;
9+
import java.nio.channels.FileLock;
10+
import java.nio.charset.StandardCharsets;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.StandardOpenOption;
14+
import java.security.MessageDigest;
15+
import java.util.ArrayList;
16+
import java.util.HexFormat;
17+
import java.util.LinkedHashMap;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.TreeMap;
21+
import java.util.concurrent.locks.ReentrantLock;
22+
import java.util.function.Function;
23+
24+
/**
25+
* The txfix fixture's state, shared by every worker process: one file per {@code token}
26+
* partition under {@code $VGI_TXFIX_STATE_DIR} (default {@code <tmp>/vgi-txfix}), read and
27+
* rewritten under an exclusive file lock (plus an in-process lock, since a JVM cannot hold
28+
* two overlapping file locks).
29+
*/
30+
final class TxFixState {
31+
32+
/** One {@code items} row. */
33+
record Row(int id, String name, Long qty) {
34+
Map<String, Object> asMap() {
35+
Map<String, Object> m = new LinkedHashMap<>();
36+
m.put("id", id);
37+
m.put("name", name);
38+
m.put("qty", qty);
39+
return m;
40+
}
41+
}
42+
43+
/** One event-log entry. */
44+
record Event(long seq, String kind, String txId, boolean ok) {}
45+
46+
static final List<Row> INITIAL = List.of(new Row(1, "a", 10L), new Row(2, "b", 20L), new Row(3, "c", 30L));
47+
48+
private static final ReentrantLock IN_PROCESS = new ReentrantLock();
49+
50+
/** One token's state, loaded for the duration of {@link #withPartition}. */
51+
static final class Partition {
52+
final TreeMap<Integer, Row> committed = new TreeMap<>();
53+
final Map<String, TreeMap<Integer, Row>> staged = new LinkedHashMap<>();
54+
final List<Event> events = new ArrayList<>();
55+
long seq;
56+
57+
void reset() {
58+
committed.clear();
59+
for (Row r : INITIAL) committed.put(r.id(), r);
60+
staged.clear();
61+
events.clear();
62+
seq = 0;
63+
}
64+
65+
/** The rows a scan in {@code txId} sees: committed, overlaid with its staged changes. */
66+
TreeMap<Integer, Row> view(String txId) {
67+
TreeMap<Integer, Row> out = new TreeMap<>(committed);
68+
if (txId != null && staged.containsKey(txId)) out.putAll(staged.get(txId));
69+
return out;
70+
}
71+
72+
void event(String kind, String txId, boolean ok) {
73+
events.add(new Event(++seq, kind, txId, ok));
74+
}
75+
}
76+
77+
private TxFixState() {}
78+
79+
static Path dir() {
80+
String d = System.getenv("VGI_TXFIX_STATE_DIR");
81+
return d != null && !d.isBlank() ? Path.of(d) : Path.of(System.getProperty("java.io.tmpdir"), "vgi-txfix");
82+
}
83+
84+
private static String partitionName(String token) {
85+
try {
86+
byte[] digest = MessageDigest.getInstance("SHA-256").digest(
87+
(token == null ? "\0null" : "t:" + token).getBytes(StandardCharsets.UTF_8));
88+
return HexFormat.of().formatHex(digest, 0, 16);
89+
} catch (java.security.NoSuchAlgorithmException e) {
90+
throw new IllegalStateException(e);
91+
}
92+
}
93+
94+
/** Run {@code body} on the token's partition under its lock, saving whatever it changed. */
95+
static <T> T withPartition(String token, Function<Partition, T> body) {
96+
Path dir = dir();
97+
String name = partitionName(token);
98+
IN_PROCESS.lock();
99+
try {
100+
Files.createDirectories(dir);
101+
try (FileChannel lockChannel = FileChannel.open(dir.resolve(name + ".lock"),
102+
StandardOpenOption.CREATE, StandardOpenOption.WRITE);
103+
FileLock ignored = lockChannel.lock()) {
104+
Path file = dir.resolve(name + ".state");
105+
Partition p = new Partition();
106+
if (Files.exists(file)) load(p, Files.readAllLines(file, StandardCharsets.UTF_8));
107+
else p.reset();
108+
T result = body.apply(p);
109+
Path tmp = dir.resolve(name + ".state.tmp");
110+
Files.write(tmp, save(p), StandardCharsets.UTF_8);
111+
Files.move(tmp, file, java.nio.file.StandardCopyOption.REPLACE_EXISTING,
112+
java.nio.file.StandardCopyOption.ATOMIC_MOVE);
113+
return result;
114+
}
115+
} catch (IOException e) {
116+
throw new IllegalStateException("txfix: state I/O failed: " + e.getMessage(), e);
117+
} finally {
118+
IN_PROCESS.unlock();
119+
}
120+
}
121+
122+
private static String enc(String s) {
123+
return s == null ? "\\N" : URLEncoder.encode(s, StandardCharsets.UTF_8);
124+
}
125+
126+
private static String dec(String s) {
127+
return "\\N".equals(s) ? null : URLDecoder.decode(s, StandardCharsets.UTF_8);
128+
}
129+
130+
private static Long decLong(String s) {
131+
return "\\N".equals(s) ? null : Long.valueOf(s);
132+
}
133+
134+
private static List<String> save(Partition p) {
135+
List<String> out = new ArrayList<>();
136+
out.add("seq\t" + p.seq);
137+
for (Row r : p.committed.values()) {
138+
out.add("row\t" + r.id() + "\t" + enc(r.name()) + "\t" + (r.qty() == null ? "\\N" : r.qty()));
139+
}
140+
for (Map.Entry<String, TreeMap<Integer, Row>> e : p.staged.entrySet()) {
141+
for (Row r : e.getValue().values()) {
142+
out.add("staged\t" + e.getKey() + "\t" + r.id() + "\t" + enc(r.name()) + "\t"
143+
+ (r.qty() == null ? "\\N" : r.qty()));
144+
}
145+
}
146+
for (Event ev : p.events) {
147+
out.add("event\t" + ev.seq() + "\t" + ev.kind() + "\t" + enc(ev.txId()) + "\t" + ev.ok());
148+
}
149+
return out;
150+
}
151+
152+
private static void load(Partition p, List<String> lines) {
153+
for (String line : lines) {
154+
String[] f = line.split("\t", -1);
155+
switch (f[0]) {
156+
case "seq" -> p.seq = Long.parseLong(f[1]);
157+
case "row" -> p.committed.put(Integer.parseInt(f[1]),
158+
new Row(Integer.parseInt(f[1]), dec(f[2]), decLong(f[3])));
159+
case "staged" -> p.staged.computeIfAbsent(f[1], k -> new TreeMap<>()).put(Integer.parseInt(f[2]),
160+
new Row(Integer.parseInt(f[2]), dec(f[3]), decLong(f[4])));
161+
case "event" -> p.events.add(new Event(Long.parseLong(f[1]), f[2], dec(f[3]),
162+
Boolean.parseBoolean(f[4])));
163+
default -> { }
164+
}
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)