Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 46e4d88

Browse files
Merge #307
307: sqld programs r=MarinPostma a=MarinPostma This PR implements sqld programs on the model of hrana programs. Programs take over batches in the execution of queries within sqld, since they are very flexible and let the `Database` API consumer specify how statements should be executed. The API of the sqld programs closely matches that of hrana batches, so the implementation on hrana side is changed to simply transform a hrana batch into a sqld program. On the HTTP side, batches of queries are transformed into a program that causes a rollback if any statement in the batch fails. On the replica, the programs are serialized and sent over by gRPC to the primary when we detect that they could cause a write. This PR also solves a known bug in HTTP batches that used to unconditionally execute statements in a batch even if a statement in the batch failed, and never rolledback, since the new implementation of HTTP batches ensures that a rollback is always performed if any statement in the batch fails to execute. Future work: expose a more direct access to the `Database` to the consumers Co-authored-by: ad hoc <[email protected]>
2 parents f9a70c9 + f8beda2 commit 46e4d88

File tree

22 files changed

+827
-509
lines changed

22 files changed

+827
-509
lines changed

sqld/proto/proxy.proto

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ message Column {
7575
}
7676

7777
message DisconnectMessage {
78-
bytes clientId = 1;
78+
string clientId = 1;
7979
}
8080

81-
message Ack {}
81+
message Ack { }
8282

8383
message ExecuteResults {
8484
repeated QueryResult results = 1;
@@ -91,7 +91,51 @@ message ExecuteResults {
9191
State state = 2;
9292
}
9393

94+
message Program {
95+
repeated Step steps = 1;
96+
}
97+
98+
message Step {
99+
optional Cond cond = 1;
100+
Query query = 2;
101+
}
102+
103+
message Cond {
104+
oneof cond {
105+
OkCond ok = 1;
106+
ErrCond err = 2;
107+
NotCond not = 3;
108+
AndCond and = 4;
109+
OrCond or = 5;
110+
}
111+
}
112+
113+
message OkCond {
114+
int64 step = 1;
115+
}
116+
117+
message ErrCond {
118+
int64 step = 1;
119+
}
120+
121+
message NotCond {
122+
Cond cond = 1;
123+
}
124+
125+
message AndCond {
126+
repeated Cond conds = 1;
127+
}
128+
129+
message OrCond {
130+
repeated Cond conds = 1;
131+
}
132+
133+
message ProgramReq {
134+
string client_id = 1;
135+
Program pgm = 2;
136+
}
137+
94138
service Proxy {
95-
rpc Execute(Queries) returns (ExecuteResults) {}
139+
rpc Execute(ProgramReq) returns (ExecuteResults) {}
96140
rpc Disconnect(DisconnectMessage) returns (Ack) {}
97141
}

sqld/src/batch/mod.rs

Lines changed: 0 additions & 101 deletions
This file was deleted.

sqld/src/batch/proto.rs

Lines changed: 0 additions & 132 deletions
This file was deleted.

sqld/src/database/dump_loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl DumpLoader {
2323

2424
let (ok_snd, ok_rcv) = oneshot::channel::<anyhow::Result<()>>();
2525
tokio::task::spawn_blocking(move || {
26-
let db = match open_db(path, hooks, false) {
26+
let db = match open_db(&path, hooks, false) {
2727
Ok(db) => {
2828
let _ = ok_snd.send(Ok(()));
2929
db

0 commit comments

Comments
 (0)