session

package
v1.24.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package session provides access to session registry.

Index

Constants

View Source
const LogicalSessionTimeoutMinutes = int32(30)

LogicalSessionTimeoutMinutes is the session timeout in minutes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores sessions.

func NewRegistry

func NewRegistry(timeout time.Duration, l *slog.Logger) *Registry

NewRegistry returns a new registry.

func (*Registry) AddCursor

func (r *Registry) AddCursor(ctx context.Context, userID UserID, sessionID uuid.UUID, cursorID int64)

AddCursor adds the cursor with its user ID and session ID. If the session does not exist, a new session is created implicitly.

func (*Registry) Collect

func (r *Registry) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*Registry) CreateOrUpdateByLSID

func (r *Registry) CreateOrUpdateByLSID(ctx context.Context, spec wirebson.AnyDocument) (UserID, uuid.UUID, error)

CreateOrUpdateByLSID fetches `lsid` field from spec and updates the last used time of that session. If the `lsid` is not a valid UUID, it returns an error. If a session does not exist, a new session is created implicitly. If `lsid` field is not present, a session is created with an empty session ID.

It returns the user ID and the session ID.

func (*Registry) CreateOrUpdateSessions

func (r *Registry) CreateOrUpdateSessions(ctx context.Context, sessionIDs []uuid.UUID)

CreateOrUpdateSessions updates the last used time of the sessions. If a session does not exist, a new session is created implicitly.

func (*Registry) DeleteAllSessions

func (r *Registry) DeleteAllSessions() []int64

DeleteAllSessions removes all sessions of all users and returns all cursors of removed sessions.

func (*Registry) DeleteCursor

func (r *Registry) DeleteCursor(userID UserID, cursorID int64, db string) error

DeleteCursor removes the cursor. If the cursor does not exist, it does nothing. It returns an error if the cursor was not created by the same user.

func (*Registry) DeleteExpired

func (r *Registry) DeleteExpired() []int64

DeleteExpired removes ended sessions and expired session from the registry and returns cursors of the deleted sessions.

func (*Registry) DeleteSessionsByIDs

func (r *Registry) DeleteSessionsByIDs(userID UserID, sessionIDs []uuid.UUID) []int64

DeleteSessionsByIDs removes sessions and returns cursors of the deleted sessions. If a session does not exist, it does nothing.

func (*Registry) DeleteSessionsByUserIDs

func (r *Registry) DeleteSessionsByUserIDs(userIDs []UserID) []int64

DeleteSessionsByUserIDs removes sessions of the specified user IDs and returns cursors of deleted sessions. If a user ID does not exist, it does nothing.

func (*Registry) Describe

func (r *Registry) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*Registry) EndSessions

func (r *Registry) EndSessions(ctx context.Context, sessionIDs []uuid.UUID)

EndSessions marks sessions as ended. If a session does not exist, it does nothing.

func (*Registry) NewSession

func (r *Registry) NewSession(ctx context.Context) uuid.UUID

NewSession creates a new session and adds it to the registry.

func (*Registry) Stop

func (r *Registry) Stop()

Stop stops registry and deletes all sessions.

func (*Registry) ValidateCursor

func (r *Registry) ValidateCursor(userID UserID, sessionID uuid.UUID, cursorID int64) error

ValidateCursor checks if the cursor is created by the same session and the same user. If the cursor does not exist, there is nothing to check and no error is returned.

type UserID

type UserID [sha256.Size]byte

UserID is the output computed by SHA256 function.

func GetUIDFromUsername

func GetUIDFromUsername(db, username string) UserID

GetUIDFromUsername returns the hash of <username>@<database>. If the username is empty, it returns a hash of an empty string.

func (UserID) String

func (s UserID) String() string

String returns the base64 encoded string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL