aboutsummaryrefslogtreecommitdiffstats
path: root/include/LifecycleManager.h
blob: 914ce0ac31d2722ae90d99d12d0e449f028f9c65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "Api.h"
#include "ObjectManager.h"

/**
 * @file LifecycleManager.h
 * @brief Declares monitoring, pinning, cleanup, and contention operations.
 */

namespace nt
{
    /** @brief Manages runtime lifecycle concerns for registry objects. */
    class NT_API LifecycleManager
    {
    public:
        /**
         * @brief Starts monitoring an object's lifecycle.
         *
         * If the object is not being monitored already, monitor the lifecycle
         * by updating the handle count. Maybe also look at the reference count
         * and kill some categories of disposable objects no longer referenced
         * by other objects, like transactions.
         *
         * One use case is preventing compaction/pruning of history while
         * cursors depend on old database snapshots, for example. Think of
         * other use cases later.
         *
         * @param object Object to monitor.
         */
        void Monitor(ObjectManager::registry* object);

        /**
         * @brief Serializes contention for changes to mutable references.
         *
         * This can be used for the HEAD of a branch to serialize access. If the
         * object does not cause contention, such as a relation, then this can
         * approve the operation because relations and multigroups are immutable
         * snapshots. Transactions also do not cause contention.
         *
         * The objects that do cause contention are mutable reference states in
         * shared sessions. Examples include the HEAD of a branch, namespace
         * collisions, multi-branch atomic commits (which may damage isolation),
         * and garbage collection of old state when old-enough history is removed
         * to save space.
         *
         * @param object Object to check for contention.
         * @return True when the operation may proceed.
         */
        const bool Contention(ObjectManager::registry* object);

        /**
         * @brief Stops monitoring an object.
         *
         * The inverse of Monitor. Maybe garbage collect here also if the
         * counters go to zero.
         *
         * @param object Object to stop monitoring.
         */
        void Unmonitor(ObjectManager::registry* object);
    };
}