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

Make it possible for NewSession not to block #381

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sylwiaszunejko
Copy link
Collaborator

Idea is the following:

  • You create cluster configuration
  • You create session of it that does not actually connects to the cluster, but rather just starting this proccess.
  • If you are trying to execute query on such session, if it is not ready yeat it will throw you an NotReady error
  • Have an API that allows you to know if session is ready to execute queries

Fixes: #234

@sylwiaszunejko
Copy link
Collaborator Author

@dkropachev I've added this as a draft, I am not sure which way to go:

  • have only one API that starts connecting in the background (like in this PR)
  • have two ways to create session old one and the second one non blocking
  • also what about creating session but not initializing it before a Query is executed (the idea in this comment: Make it possible for NewSession not to block  #234 (comment))

@sylwiaszunejko sylwiaszunejko self-assigned this Jan 2, 2025
Copy link
Collaborator

@dkropachev dkropachev left a comment

Choose a reason for hiding this comment

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

Looks good, let's make it optional, by default we will preserve old behavior

session.go Outdated Show resolved Hide resolved
session.go Outdated Show resolved Hide resolved
session.go Outdated Show resolved Hide resolved
session.go Outdated Show resolved Hide resolved
session.go Outdated Show resolved Hide resolved
@sylwiaszunejko sylwiaszunejko force-pushed the create-session-non-block branch from f366782 to 8d25897 Compare January 3, 2025 11:09
For some use-cases it is helpful to be able to start the
initialization of the Session, but not neccesarly wait for
it to finish. To accomodate this need this commit adds new
non blocking API.

If the user tries to query Session that isn't initialized
yet, the new ErrSessionNotReady will be returned.
@sylwiaszunejko sylwiaszunejko force-pushed the create-session-non-block branch from 8d25897 to 2d574ef Compare January 3, 2025 11:47
@sylwiaszunejko sylwiaszunejko marked this pull request as ready for review January 3, 2025 11:47
Comment on lines +219 to +228
go func() {
if initErr := s.init(); initErr != nil {
s.sessionStateMu.Lock()
s.initErr = fmt.Errorf("gocql: unable to create session: %v", initErr)
s.sessionStateMu.Unlock()
}

s.readyCh <- s.initErr
close(s.readyCh)
}()
Copy link
Collaborator

@dkropachev dkropachev Jan 3, 2025

Choose a reason for hiding this comment

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

Can you please make this behavior optional, preserving old behavior by default.

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.

Make it possible for NewSession not to block
2 participants