Skip to content

Conversation

@pavelnemirovsky
Copy link
Contributor

A proposed naive approach to be able to stick to user session across multiple queries:

Use Case the PR Should be solved :
Query #1:
CREATE TEMPORARY TABLE if not exists analyse AS SELECT * from system.numbers limit 100
Query #2:
SELECT count(*) as total from analyse

For each query same session-id should be passed.

Please review

Copy link
Contributor

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

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

LGTM! See my comments


// publish session_id if needed
if s.sessionId != "" {
rw.Header().Set("X-ClickHouse-Server-Session-Id", s.sessionId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick check didn't show any results for "X-ClickHouse-Server-Session-Id" header in CH docs. Could you pls add a comment what exactly this header is used for?

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 added this header just to make sure ChProxy acknowledged and processed correctly the value was set to session_id

Copy link
Contributor

Choose a reason for hiding this comment

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

I was confused while reading it. I think, it requires a proper comment to explain your intention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hagen1778 treat this header as ECHO Service, you pass the value of session_id and you'll want to assure that that value was accepted by server-side correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hagen1778 let's merge it already and let's enable GitHub actions to release versions properly for multiple platforms, what do u think?

main_test.go Outdated
"http POST request with session id",
"testdata/http-session-id.yml",
func(t *testing.T) {
req, err := http.NewRequest("POST", "http://127.0.0.1:9090/?query_id=45395792-a432-4b92-8cc9-536c14e1e1a9&extremes=0&session_id=default-session-id233", bytes.NewBufferString("SELECT * FROM system.numbers LIMIT 10"))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be nice to keep the line length consistent with the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted

h := c.getHost()
func newScope(req *http.Request, u *user, c *cluster, cu *clusterUser, sessionId string) *scope {

h := c.getHost()
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use if-else here to avoid unnecessary counter's increase on line 58 when session_id isn't empty?


// publish session_id if needed
if s.sessionId != "" {
rw.Header().Set("X-ClickHouse-Server-Session-Id", s.sessionId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was confused while reading it. I think, it requires a proper comment to explain your intention.

@hagen1778 hagen1778 merged commit ee67a2d into ContentSquare:master May 24, 2021
@hagen1778
Copy link
Contributor

Thanks for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants