[Draft] Proposal: User Managed Session #1612
mattisonchao
started this conversation in
Proposal
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Let users manage Oxia sessions themselves. Today the Go client creates one session per shard behind the scenes and keeps it alive for as long as the client runs;
Ephemeral()puts attach records to it. A user managed session is one the application controls directly:The server already does most of this. The proposal adds:
CreateSession,KeepAliveandCloseSessionRPCs.GetSession, a new RPC that returns a session's timeout, remaining time and client identity.Listthat returns the keys attached to a session.The first user is oxia-etcd, which serves the etcd v3 API on Oxia: an etcd lease maps directly onto a user managed session.
Motivation
An etcd lease and an Oxia session are the same thing. A client creates an ID with a TTL and keeps it alive. When the ID expires or is revoked, the keys attached to it are deleted.
LeaseGrant(TTL)CreateSession(session_timeout_ms)LeaseKeepAlive(ID)KeepAlive(session_id)LeaseRevoke(ID)CloseSession(session_id)Put(key, lease=ID)Putwithsession_idLeaseTimeToLive(ID)LeaseTimeToLive(ID, keys=true)Because these gaps exist, oxia-etcd implements leases itself. It stores each lease as a plain record and tracks the expiry in its own memory. This has two costs:
The timeout cap also matters on its own: the Kubernetes API server grants Event leases with the event TTL, which is 1 hour by default.
User managed sessions are useful beyond etcd too. Any application can share one lease-like lifetime across several processes, such as a job's workers whose records should disappear together.
Design
Client API
A new
Sessionhandle in the Go client:Ephemeral()is unchanged. It keeps using the client's internal sessions.WithSessionrequires a matching partition key. A put withWithSession(s)must carry the same partition key as the session, otherwise the client rejects it.GetSessionsession.deadline), so the remaining time isdeadline - now.ErrSessionNotFound, asKeepAlivedoes.Listing a session's keys
ListRequestgets an optional session ID:ShadowKey(session, key)under the session key; expiry uses these entries to find the records to delete. The server scans only that session's range (shadowKeysRange), unescapes the keys and applies the[start, end)bounds.Listalready streams its results in batches.Listacross all shards with a session ID is rejected, and so is combiningsession_idwithsecondary_index_name.Configurable maximum session timeout
constant.MaxSessionTimeoutbecomes a data server setting, defaulting to the current 5 minutes. The protocol needs no change:session_timeout_msis auint32, which already allows about 49 days.A long timeout means a dead client's records stay around longer. That's the same trade-off etcd users make when they pick a lease TTL.
How oxia-etcd would use it
LeaseGrantCreateSessionLeaseKeepAliveOpenSession(id).KeepAliveLeaseRevokeOpenSession(id).CloseLeaseTimeToLiveInfoLeaseTimeToLive(keys=true)Info, thenListwithUseSession, merged into one responseLeaseLeasesPut(key, lease=ID)PutwithWithSessionBecause sessions are shared by ID, every gateway can serve every lease, so the gateways no longer need an active/standby split for leases.
LeaseTimeToLive(keys=true)makes two calls. If the session expires between them, the key list may come back short. etcd can return the same result just before a lease expires, so the gateway doesn't retry.Non-goals
ListSessions. oxia-etcd keeps its own lease records, so it can answerLeaseLeaseswithout it.Related
Open questions
GetSessionalso return the number of attached keys?All reactions