Skip to content

ref(reader): Move reader instantiation to snuba.environment - #780

Merged
tkaemming merged 3 commits into
masterfrom
reader-environment
Feb 19, 2020
Merged

tkaemming merged 3 commits into
masterfrom
reader-environment

Conversation

@tkaemming

Copy link
Copy Markdown
Contributor

This removes the reader parameter from raw_query, since there is no way to actually set it without modifications to parse_and_run_query and correspondingly split_query and it's inner functions.

The HTTP reader will have state (the HTTP connection pool), so reinstantiating it on each call to parse_and_run_query isn't ideal — it will be better to instantiate a Reader instance and reuse it. Since the ClickHouse cluster address is a global setting, it (unfortunately) seems appropriate to make this global state, similar to the native driver pool.

I think that in the future, we'll want the table storages themselves to provide the writer and reader interfaces (since I assume we'll want table storages to be able to reference different ClickHouse clusters) but that seems like a reasonably far future.

@tkaemming
tkaemming requested a review from a team February 14, 2020 23:24
Comment thread snuba/environment.py
client_settings={"readonly": True},
)

reader: Reader[ClickhouseQuery] = NativeDriverReader(clickhouse_ro)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will be reused only on split queries or any other request that runs more than one query. Is this correct ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is a global and instantiated at startup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I guess we will have to ensure thread safety as well when we get to the http reader if that is stateful right ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes

@tkaemming
tkaemming merged commit 0b4af54 into master Feb 19, 2020
@tkaemming
tkaemming deleted the reader-environment branch February 19, 2020 21:45
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