Skip to content

Conversation

ptiurin
Copy link
Contributor

@ptiurin ptiurin commented Jan 23, 2025

@ptiurin ptiurin changed the title WIP: feat server side async feat(FIR-42854): Server side async query execution Jan 23, 2025
@ptiurin
Copy link
Contributor Author

ptiurin commented Jan 24, 2025

SQ failing here is due to our async/sync duplication. I'm not sure what else can be done so IMO this can be ignored.

@ptiurin ptiurin marked this pull request as ready for review January 24, 2025 11:47
@ptiurin ptiurin requested a review from a team as a code owner January 24, 2025 11:47
async def _handle_query_execution(
self, query: str, timeout_controller: TimeoutController, async_execution: bool
) -> None:
query_params: Dict[str, Any] = {"output_format": JSON_OUTPUT_FORMAT}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check the case for when not async_execution and query_params.get("async") is True?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That opens a can of worms that we are still debating. At the moment enforcing this is out of scope https://packboard.atlassian.net/browse/FIR-42854
Set async=true will probably be not allowed on the backend altogether.

"_next_set_idx",
"_set_parameters",
"_query_id",
"_query_token",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I have a feeling we should only have this logic and these field for ConnectionV2 only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored to have execute_async in CursorV2 and V1 to throw an error if this method is attempted to be used. Other internal methods are a bit difficult to separate since there's plenty of shared logic and we have them mostly in the base class. Fully separating them I feel like will lead to a "ping-pong" between base and a concrete class. Happy to sync if you feel strongly about this and we can have a look.

assert await connection.is_async_query_running(token) == True
assert await connection.is_async_query_successful(token) is None
finally:
await cursor.execute(f"DROP TABLE {table_name}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious what will happen if we have a running insert in async mode and will try to drop the table? Probably it should just wait for a table lock to get released or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it via the API. INSERT INTO dummy SELECT checksum(*) FROM GENERATE_SERIES(1, 250000000000) would keep on running, despite table dummy no longer being there. Though if there's continuous insert it might behave differently, but I have no easy way of reproducing that.

DEFAULT_API_URL: str = "api.app.firebolt.io"
PROTOCOL_VERSION_HEADER_NAME = "Firebolt-Protocol-Version"
PROTOCOL_VERSION: str = "2.1"
PROTOCOL_VERSION: str = "2.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see we did a jump here. Can you please make sure this one is also ok?
https://packboard.atlassian.net/browse/FIR-37204

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tests that confirm the behaviour described in there. I've just rerun them to be sure and everything passes.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link
Collaborator

@stepansergeevitch stepansergeevitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ptiurin ptiurin merged commit a2e3ef3 into main Jan 28, 2025
12 of 13 checks passed
@ptiurin ptiurin deleted the feat-server-side-async branch January 28, 2025 11:21
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