diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-26 22:09:11 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-26 22:09:11 -0300 |
| commit | 320954996e921d7b34eb61f462799b5c6ab8ee09 (patch) | |
| tree | 16697bc161faf27f0b4c1ba57f6fcc24d240801b /lib/session.ml | |
| parent | b555c28c7e6c315fc0394baf213ecb08b21ed959 (diff) | |
| download | Sakura-320954996e921d7b34eb61f462799b5c6ab8ee09.tar.gz Sakura-320954996e921d7b34eb61f462799b5c6ab8ee09.zip | |
new shrunk API for RNT on sakura
Diffstat (limited to 'lib/session.ml')
| -rw-r--r-- | lib/session.ml | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/lib/session.ml b/lib/session.ml index cac181f..ba4d96d 100644 --- a/lib/session.ml +++ b/lib/session.ml @@ -1,44 +1,47 @@ -(* Session: outermost connection object. - Each user connection mints a session registered in RNT at - /system/sessions/<id>. The session owns exactly one branch at a time; - DDL / DML / DRL sublanguages operate through that branch. *) +type t = {identifier: string; branch: string; snapshot: string; commit: unit} -module Make (NT : Nt.S) = struct - module B = Branch.Make (NT) +let namespace identifier = "\\session\\" ^ identifier +let branch_path name = "\\branch\\" ^ name - let ( let* ) = Result.bind +let snapshot_of kernel branch = + let open Utilities.Result in + let* handle = RNT.lookup kernel (branch_path branch) in + let snapshot = RNT.identity handle in + RNT.release handle; Ok snapshot - class session ~(sid : string) ~(branch : B.branch) = - object - val mutable br : B.branch = branch - method id = sid - method branch = br - method snapshot = br#tip - method tip = br#tip +class session ~kernel ~identifier ~branch ~snapshot ~commit = + object + val mutable session : t = {identifier; branch; snapshot; commit} + method identifier = session.identifier + method branch = session.branch + method snapshot = session.snapshot + method namespace = namespace session.identifier - (* Switch to a different branch within the same session. *) - method set_branch (b : B.branch) = br <- b + (** Switch to a different branch within the same session. *) + method set_branch_to branch = + let open Utilities.Result in + let* snapshot = snapshot_of kernel branch in + session <- {session with branch; snapshot}; + Ok () - method close () = - let* () = br#close () in - NT.session_close sid - end + method close = RNT.remove kernel (namespace session.identifier) + end - (* Open a session on a live (mutable) branch. - Creates the branch if it does not exist yet. *) - let open_session claims ~branch_name = - let* sid = NT.session_open () in - let* branch = B.open_branch claims branch_name in - Ok (new session ~sid ~branch) +(* Open a session on a live (mutable) branch. + Creates the branch if it does not exist yet. *) +let open_session kernel ~branch_name = + let open Utilities.Result in + let* branches = RNT.list kernel "\\branch" in + let* () = + if List.mem branch_name branches then Ok () + else RNT.create kernel (branch_path branch_name) RNT.Branch + in + let* snapshot = snapshot_of kernel branch_name in + let identifier = Printf.sprintf "%016Lx" (Random.State.bits64 (Random.State.make_self_init ())) in + let* () = RNT.create kernel (namespace identifier) RNT.Namespace in + Ok (new session ~kernel ~identifier ~branch:branch_name ~snapshot ~commit:()) - (* Open a session pinned to a specific snapshot hash (detached / read-only). - Mutations through the returned branch are refused. *) - let open_snapshot_session claims ~branch_name ~snapshot_hash = - let* sid = NT.session_open () in - let* branch = B.open_snapshot claims ~branch_name ~snapshot_hash in - (* Inform RNT of the session's snapshot override so future session-path - resolution (once NamespaceReferenceManager handles /system/sessions/...) - can route queries through the pinned snapshot. *) - let* () = NT.session_set_branch sid branch_name snapshot_hash in - Ok (new session ~sid ~branch) -end +(* Open a session pinned to a specific snapshot hash (detached / read-only). + Mutations through the returned branch are refused. *) +(* let open_snapshot_session claims ~branch_name ~snapshot_hash = *) +(* Error *) |
