-
Notifications
You must be signed in to change notification settings - Fork 103
[sql-12] sessions: make ListSession methods SQL ready #970
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
Changes from all commits
c71df78
0023002
6c36b01
01410f7
d2b077b
14cb0be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,10 @@ func newSessionRPCServer(cfg *sessionRpcServerConfig) (*sessionRpcServer, | |
// requests. This includes resuming all non-revoked sessions. | ||
func (s *sessionRpcServer) start(ctx context.Context) error { | ||
// Start up all previously created sessions. | ||
sessions, err := s.cfg.db.ListSessions(nil) | ||
sessions, err := s.cfg.db.ListSessionsByState( | ||
session.StateCreated, | ||
session.StateInUse, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("error listing sessions: %v", err) | ||
} | ||
|
@@ -126,12 +129,6 @@ func (s *sessionRpcServer) start(ctx context.Context) error { | |
continue | ||
} | ||
|
||
if sess.State != session.StateInUse && | ||
sess.State != session.StateCreated { | ||
|
||
continue | ||
} | ||
|
||
if sess.Expiry.Before(time.Now()) { | ||
continue | ||
} | ||
|
@@ -345,24 +342,13 @@ func (s *sessionRpcServer) AddSession(ctx context.Context, | |
}, nil | ||
} | ||
|
||
// resumeSession tries to start an existing session if it is not expired, not | ||
// revoked and a LiT session. | ||
// resumeSession tries to start the given session if it is not expired. | ||
func (s *sessionRpcServer) resumeSession(ctx context.Context, | ||
sess *session.Session) error { | ||
|
||
pubKey := sess.LocalPublicKey | ||
pubKeyBytes := pubKey.SerializeCompressed() | ||
|
||
// We only start non-revoked, non-expired LiT sessions. Everything else | ||
// we just skip. | ||
if sess.State != session.StateInUse && | ||
sess.State != session.StateCreated { | ||
|
||
log.Debugf("Not resuming session %x with state %d", pubKeyBytes, | ||
sess.State) | ||
return nil | ||
} | ||
Comment on lines
-356
to
-364
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safe to assume that the passed in session will not have an revoked/expired state? I see that all current calls to If you think it's best to still remove this, then the function comment should be updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool yeah currently all the session passed to this method will already be in the Created/InUse state since it is either called from GOod call - will update the comment 👍 |
||
|
||
// Don't resume an expired session. | ||
if sess.Expiry.Before(time.Now()) { | ||
log.Debugf("Not resuming session %x with expiry %s", | ||
|
@@ -536,7 +522,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context, | |
func (s *sessionRpcServer) ListSessions(_ context.Context, | ||
_ *litrpc.ListSessionsRequest) (*litrpc.ListSessionsResponse, error) { | ||
|
||
sessions, err := s.cfg.db.ListSessions(nil) | ||
sessions, err := s.cfg.db.ListAllSessions() | ||
if err != nil { | ||
return nil, fmt.Errorf("error fetching sessions: %v", err) | ||
} | ||
|
@@ -1259,9 +1245,7 @@ func (s *sessionRpcServer) ListAutopilotSessions(_ context.Context, | |
_ *litrpc.ListAutopilotSessionsRequest) ( | ||
*litrpc.ListAutopilotSessionsResponse, error) { | ||
|
||
sessions, err := s.cfg.db.ListSessions(func(s *session.Session) bool { | ||
return s.Type == session.TypeAutopilot | ||
}) | ||
sessions, err := s.cfg.db.ListSessionsByType(session.TypeAutopilot) | ||
if err != nil { | ||
return nil, fmt.Errorf("error fetching sessions: %v", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this really tests that the sessions are sorted by creation time, as one could argue they're just sorted by the order they were added here. So I would ensure that one of the latter sessions we add, say s3, has a creation time prior to s2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main reason for incrementing the timestamps is to have deterministic results from ListSessions. We are just testing ListSessions as a whole, not that the results are ordered.