14.4.4. Synchronisation: delta representation
In this more technical chapter we describe how the various operations should be represented in terms of deltas, to synchronise changes with peers. We describe the change to the users’ bubble in terms of assignment statements in bot rules.
Notice that we only create deltas for single role- and context instances, even if, for example, we remove all instances of a role in a context. This is because we record the deltas with the role instance representations themselves. Furthermore, not all users may have the same instances for a particular role type in a context instance (this may arise as a user role has a perspective on a remote role that is defined with a filter).
14.4.4.1. Create a bound context
create context <context type> bound to <role type> in <context expression>
Represent this with:
-
For each context instance produced by <context expression>, a UniverseRoleDelta
-
whose id identifies that context instance
-
where roleType equals <role type>
-
and where the new role instance is in roleInstances
-
and deltaType is ConstructEmptyRole.
-
-
Pair each UniverseRoleDelta with a ContextDelta.
-
For each newly created context instance a UniverseContextDelta, where
-
the id identifies the new context instance
-
the contextType is the context type
-
the deltaType is UniverseContextDeltaType.
-
-
For the external role of each newly created context instance, create a UniverseRoleDelta whose deltaType is ConstructExternalRole.
-
For each pair of UniverseRoleDelta’s (that of the binder and the bound external role) a RoleBindingDelta
-
whose id identifies the new role instance in the context;
-
whose binding identifies the new external role.
-
14.4.4.2. Delete a bound context
delete <role type> from <context expression>
<role type> is a context role. Represent this, for each context instance, for each role instance of <role type> in that context instance:
-
A UniverseRoleDelta:
-
whose id identifies that context instance
-
where roleType equals <role type>
-
and where the role instance is in roleInstances
-
and deltaType is RemoveRoleInstance.
-
Notice that we do not generate ContextDelta’s, nor UniverseContextDelta’s. The receiver checks whether any binders of the external role of the context remain. If not, he’ll remove it.
14.4.4.3. Remove a bound context
remove <role expression>
We handle this in exactly the same way as for deleting a role type (with UniverseRoleDelta’s) but we limit ourselves to the role instances identified by <role expression> and their bound contexts.
14.4.4.4. Create an unbound context
create context <context type> bound to <role type> in <context expression>
Represent this with:
-
For each newly created context instance a UniverseContextDelta, where
-
the id identifies the new context instance
-
the contextType is the context type
-
the deltaType is UniverseContextDeltaType.
-
-
For the external role of each newly created context instance, create a UniverseRoleDelta whose deltaType is ConstructExternalRole.
Notice that, in contrast to creating a bound context, we do not create a UniverseRoleDelta for the context role, nor a ContextDelta to represent its connection to the context instance, nor a RoleBindingDelta to represent the binding between context role and external role.
14.4.4.5. Remove an unbound context
remove <role expression>
The sender establishes that we handle an unbound role by finding that it is an external role and there are no binders. If there are binders, deleting an instance from a DBQ Role is a no-op.
It then represents this with a UniverseRoleDelta:
-
whose (context) id is the context of the external role
-
where roleType equals the type of the instances
-
and where the role instance is in roleInstances
-
and deltaType is RemoveUnboundExternalRoleInstance.
The receiver determines that we handle an unbound role from the deltaType. If the instance has no binders (on his side), he removes the external role and its context.
14.4.4.6. Delete an unbound context
delete <role type> from <context expression>
The sender recognises the fact that we want to remove an unbound context from the role type. However, we now want to remove every unbound context from the given contexts. So we generate a UniverseRoleDelta like above, but only for every role instance that can be retrieved from the database that has no binders. As long as it has binders, deleting an instance from a DBQ Role is a no-op.