Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce "sticky session" concept for handling temporary tables #381

Open
otan opened this issue Jan 16, 2025 · 0 comments
Open

introduce "sticky session" concept for handling temporary tables #381

otan opened this issue Jan 16, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@otan
Copy link

otan commented Jan 16, 2025

Use case

Today, things like temporary tables rely on the same connection to operate. To ensure that today, we need to ensure we start the clickhouse client with max_open_connections: 1 as per the docs, but that means down our application stack we need to keep 2 versions of clickhouse client:

  • one for the default connection pool
  • one that is a constructor to starting a new clickhouse client with max_open_connections = 1 and a fixed sticky session.

Describe the solution you'd like

This takes inspiration from the database/sql Golang package and how they handle transactions.

Basically, allow the clickhouseClient to hold a "sticky session" which can occupy the same connection pool (i.e. respect the same max_open_connections).

The API could look something like:

const chClient = createClickhouseClient(...)

// All handled in the closure.
await chClient.execStickySession(async (
  // maybe a different type that inherits the same ClickhouseClient types but indicates it is sticky? 
  chClient: ClickhouseClient,
) {
   // automatically uses the same session id for the next 2 commands
   await chClient.command(...);
   await chClient.command(...)
})

// Or explicitly.
const stickySession = await chClient.startStickySession();
try {
  ...
} finally {
   stickySession.close();
}

Describe the alternatives you've considered

We're basically passing 2 different clickhouse clients down the stack now.

@otan otan added the enhancement New feature or request label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant