@@ -43,30 +43,71 @@ instance IOLike IO
43
43
Sessions
44
44
-------------------------------------------------------------------------------}
45
45
46
- -- | Context shared across multiple table handles, like counters and filesystem
47
- -- information.
46
+ -- | A session provides context that is shared across multiple table handles.
48
47
--
49
- -- For one, this is necessary if we want to be able to manipulate and query
50
- -- table handles, duplicate table handles, and load snapshots, all at the same
51
- -- time in the same directory.
48
+ -- Sessions are needed to support sharing between multiple table instances.
49
+ -- Sharing occurs when tables are duplicated using 'duplicate', or when tables
50
+ -- are combined using 'union'. Sharing is preserved by snapshots, using
51
+ -- 'snapshot' and 'open'.
52
+ --
53
+ -- The \"monoidal\" table types support a 'union' operation, which has the
54
+ -- constraint that the two input tables must be from the same 'Session'.
55
+ --
56
+ -- Each session places files for table data under a given directory. It is
57
+ -- not permitted to open multiple sessions for the same directory at once.
58
+ -- Instead a session should be opened once and shared for all uses of
59
+ -- tables. This restriction implies that tables cannot be shared between OS
60
+ -- processes. The restriction is enforced using file locks.
61
+ --
62
+ -- Sessions support both related and independent tables. Related tables are
63
+ -- created using 'duplicate', while independent tables can be created using
64
+ -- 'new'. It is possible to have multiple independent tables with different
65
+ -- configuration and key and value types in the same session. Similarly,
66
+ -- a session can have both \"normal\" and \"monoidal\" tables. For independent
67
+ -- tables (that are not involved in a 'union') one has a choice between using
68
+ -- multiple sessions or a shared session. Using multiple sessions requires
69
+ -- using separate directories, while a shared session will place all files
70
+ -- under one directory.
52
71
--
53
- -- Different types of tables can be live in the same session, but operations
54
- -- like 'merge' only work for __compatible__ tables: tables that belong to the
55
- -- same session, store the same key and value types, and have the same
56
- -- configuration parameters.
57
72
type Session :: (Type -> Type ) -> Type
58
73
data Session m = Session {
59
74
sessionRoot :: ! FsPath
60
75
, sessionHasFS :: ! (SomeHasFS m )
61
76
}
62
77
78
+ -- | Create either a new empty table session or open an existing table session,
79
+ -- given the path to the session directory.
80
+ --
81
+ -- A new empty table session is created if the given directory is entirely
82
+ -- empty. Otherwise it is intended to open an existing table session.
83
+ --
84
+ -- Exceptions:
85
+ --
86
+ -- * This can throw exceptions if the directory does not have the expected file
87
+ -- layout for a table session
88
+ -- * It will throw an exception if the session is already open (in the current
89
+ -- process or another OS process)
90
+ --
91
+ -- Sessions should be closed using 'closeSession' when no longer needed.
92
+ --
63
93
newSession ::
64
94
IOLike m
65
95
=> SomeHasFS m
66
- -> FsPath -- ^ Path to an empty directory.
96
+ -> FsPath -- ^ Path to the session directory
67
97
-> m (Session m )
68
98
newSession = undefined
69
99
100
+ -- | Close the table session.
101
+ --
102
+ -- This also closes any open table handles in the session. It would typically
103
+ -- be good practice however to close all table handles first rather than
104
+ -- relying on this for cleanup.
105
+ --
106
+ -- Closing a table session allows the session to be opened again elsewhere, for
107
+ -- example in a different process. Note that the session will be closed
108
+ -- automatically if the processes is terminated (in particular the session file
109
+ -- lock will be released).
110
+ --
70
111
closeSession :: IOLike m => Session m -> m ()
71
112
closeSession = undefined
72
113
0 commit comments