mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
feat(dsql): speak DSQL's dialect and keep its transaction limits (#6185)
* feat(dsql): speak DSQL's dialect and keep its transaction limits The third part of the DSQL data plane, after #6102 and #6143: the cluster's database answers the way Aurora DSQL does, as measured on AWS. CREATE [UNIQUE] INDEX ASYNC answers a job_id, with sys.jobs and sys.wait_for_job; a plain CREATE INDEX is refused. What DSQL refuses is refused with its SQLSTATE and message: what the statement shows (TRUNCATE, DO, LISTEN, VACUUM, sequence caches, isolation levels, locking clauses, advisory locks, ADD CONSTRAINT) in DsqlStatements, and what only the catalog can tell (column types, a function's language, temporary and partitioned tables, triggers) inside the database, by event triggers, since the statement alone cannot say. A transaction runs one DDL statement, never with DML, and modifies at most 3,000 rows, a cascade's included. Its age follows what was measured with a client that only reads: the client's next message after 300 seconds ends it with 54000 and closes the connection with 08P01, an idle one is ended unasked 15 seconds later, a statement running across the limit completes and then fails with 54000, and a failed transaction left idle as long is closed with 25P03. A first model, the age checked at the next statement, was dropped once the reading client showed DSQL's own timer. A write conflict is DSQL's 40001 OC000, and an error's context keeps the statement a cascade ran while dropping what sys functions ran. * fix(dsql): close the dialect's gaps found in review, as measured on DSQL Measured on Aurora DSQL before each change: - set_config of default_transaction_isolation or transaction_isolation, a quoted SET of one and ALTER ROLE ... SET of one answer 0A000 "not supported"; ALTER DATABASE ... SET or RESET is AlterDatabaseSet. - CREATE TABLE AS, SELECT INTO and materialized views are CreateTableAs, refused by the event trigger so a function body cannot reach them either. - An expression key, or a domain over jsonb or bytea, is refused like the type itself, named as declared: the check reads the index's own columns and follows a domain to its base type. - CREATE, ALTER and DROP ROLE and GRANT or REVOKE of a role are DDL. PostgreSQL fires no event trigger for them, so they run through sys.run_role_ddl, which counts them first, under PostgreSQL's tags. - A statement past the transaction age limit fails with 54000, in a transaction block or not, nothing its transaction wrote is kept, and the rest of its query, a COMMIT included, does not run. The age limit is reworked as the review asked. Each session has one check scheduled at a time, on the endpoint's scheduler and by the injected Clock, cancelled when the transaction or the connection ends; a failed transaction's idle wait restarts after every client message. At the limit a statement still running is cancelled with the client's own cancel request, and its 57014 reaches the client as DSQL's 54000. DSQL lets the statement finish and fails it then; stopping it at the limit ends the same way. Two other ways were tried and dropped: dropping a late statement's answer in the relay let a COMMIT in the same query commit, and a mark the endpoint writes for the database to check is invisible to the client's repeatable read snapshot. The age test now moves the clock and holds a row instead of sleeping, and shares its cluster setup with the data plane test through DsqlClusterFixture. Also fixed: a -- comment ends at a carriage return, a quoted advisory lock name is refused, CACHE is read from tokens rather than the raw text, a BEGIN queued behind a long statement starts once that statement is answered, tables that predate the counting triggers get them, and sys.create_index_async runs one index statement and nothing else. sys.wait_for_job with an unknown id keeps waiting, as DSQL's does.
This commit is contained in:
1 parent
6355474ad2
commit
42fd858311
12 files changed
+2220
-309
No files matched your search
@@ -143,7 +143,7 @@ class DsqlCompatTest {
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void adminSignsInWithTheSdksToken() throws Exception {
|
||||
void adminSignsInWithTheSdksTokenAndTheDatabaseSpeaksDsql() throws Exception {
|
||||
String token = dsql.utilities().generateDbConnectAdminAuthToken(b -> b.hostname(endpoint).region(REGION));
|
||||
|
||||
try (Connection connection = connect("admin", token); Statement statement = connection.createStatement()) {
|
||||
@@ -152,12 +152,19 @@ class DsqlCompatTest {
|
||||
assertThat(row.getString(1)).isEqualTo("admin");
|
||||
assertThat(row.getString(2)).isEqualTo("repeatable read");
|
||||
}
|
||||
statement.execute("CREATE TABLE compat_orders (id int PRIMARY KEY, n int)");
|
||||
statement.execute("INSERT INTO compat_orders VALUES (1, 7)");
|
||||
try (ResultSet row = statement.executeQuery("SELECT n FROM compat_orders WHERE id = 1")) {
|
||||
assertThat(row.next()).isTrue();
|
||||
assertThat(row.getInt(1)).isEqualTo(7);
|
||||
statement.execute("CREATE TABLE compat_orders (id uuid PRIMARY KEY, n int)");
|
||||
String jobId;
|
||||
try (ResultSet job = statement.executeQuery("CREATE INDEX ASYNC compat_orders_n ON compat_orders (n)")) {
|
||||
assertThat(job.next()).isTrue();
|
||||
jobId = job.getString("job_id");
|
||||
}
|
||||
try (ResultSet waited = statement.executeQuery("CALL sys.wait_for_job('" + jobId + "')")) {
|
||||
assertThat(waited.next()).isTrue();
|
||||
assertThat(waited.getBoolean(1)).isTrue();
|
||||
}
|
||||
assertThatThrownBy(() -> statement.execute("TRUNCATE compat_orders"))
|
||||
.isInstanceOf(SQLException.class)
|
||||
.hasMessageContaining("unsupported statement: Truncate");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user