A WorkingSetMachine is associated with a single persistent WorkingSet. It manages a set of DeltaRWs and RodSessions which are used to read/write deltas and ROD objects.
A WorkingSetMachine is defined in the Xc++ language as an $adt:
$adt+ WorkingSetMachine
{
void Close();
void PermanentlyDestroy();
// Functions that do not care whether there is a lock on the PSpace, or whether CSpace/PSpace has been set in TLS
const xstring& GetName() const;
PSpace* GetPSpace();
DeltaRW* CreateDeltaRW(IMoreToSend* n);
RodReader* CreateRodReader();
RodWriter* CreateRodWriter();
RodSession* CreateRodSession(IMoreToSend* n);
// Functions that require a lock on the PSpace, and CSpace/PSpace to be set in TLS
Guid GetDataSetId() const;
bool CheckCompatibleDataSetId(const Guid& peerDataSetId);
SiteId GetSiteId() const;
int64 HistoryBufferSize() const;
void GetVectorTime(VecTime& v) const;
bool IsRodObject(OID oid) const;
bool IsCustodian() const;
void GetAllocationOidhighs(xvector<OidHigh>& oidhighs) const;
void GetSubscriptionOids(xvector<OID>& oids) const;
bool ApplyingRemoteOperation() const;
UTRoot& GetUTRoot();
void SetIsCustodian(bool isCustodian);
OID AllocateRodOid();
};
void Close()
Any WorkingSet
that is successfully opened must be closed exactly once when it is no longer
required.
Every DeltaRW
, RodReader
, RodWriter
or RodSession
opened
on the working set must be closed prior to closing the working set.
Close()
must not be called with a lock on the associated CSpace
(or else there is a risk
or dead-lock).
Close()
must be called after all other functions on the WorkingSetMachine
.
void PermanentlyDestroy()
Permanently destroy the WorkingSet
.
[todo: not implemented yet]
const xstring& GetName() const
Get the name of the working set - i.e. the name that was passed to the function OpenWorkingSetMachine. The name of a working set is immutable.
PSpace* GetPSpace()
Get the PSpace associated with the WorkingSet
.
Never returns nullptr
.
A client may call this in order to lock the PSpace
in order to read/write objects in
the Universal Tree.
DeltaRW* CreateDeltaRW(IMoreToSend* n)
Creates a DeltaRW object which which can be used to send/receive messages in a session with a peer for the purposes of replication/synchronlisation of the mutable objects in the working set with the peer.
The given IMoreToSend object 'n' is notified each time there is more available to send.
Note: !OpenWorkingSet < ||(CreateDeltaRW,CreateRodReader,CreateRodWriter) < !Close
RodSession* CreateRodSession(IMoreToSend* n)
Creates a RodSession object which can be used to send/receive messages in a session with a peer for the purposes of sending and receiving ROD objects for this working set.
CreateRodSession
may be called with or without a lock on the CSpace
, and
without having set the CSpace
/PSpace
in TLS.
The given IMoreToSend object 'n' is notified each time there is more available to send.
WARNING: The implementation of this function itself locks the CSpace
(this might matter
if it can lead to a deadlock).
Guid GetDataSetId() const
Returns the DataSetId of the working set.
If the returned GUID is null then it means the working set is empty and is allowed to be synchronised with any other working set.
bool CheckCompatibleDataSetId(const Guid& peerDataSetId)
The behavior of this function is defined by the following table:
Local dataset id defined? | Peer dataset id defined? | Action |
---|---|---|
false | false | return true |
false | true | assign local dataset id from peer dataset id and return true |
true | false | return true |
true | true | return true if local and peer dataset ids are equal |
SiteId GetSiteId() const
Get the SiteId associated with this working set.
int64 HistoryBufferSize() const
Get the total number of operations (generated by any site) which have been applied to the working set.
void GetVectorTime(VecTime& v) const
Get the vectortime describing the set of operations that have been applied to the working set.
bool IsRodObject(OID oid) const
Returns true if the given OID identifiers a ROD object in the working set.
bool IsCustodian() const
Returns true if this working set is a custodian, meaning that its peers will send it ROD objects eagerly.
void GetAllocationOidhighs(xvector<OidHigh>& oidhighs) const
void GetSubscriptionOids(xvector<OID>& oids) const
bool ApplyingRemoteOperation() const
This can be called when a DGS node is invalidated to determine whether it occurred as a result of a remote operation being applied to this working set
UTRoot& GetUTRoot()
Get the UTRoot for this working set.
void SetIsCustodian(bool isCustodian)
Just after opening a WorkingSetMachine
, call this function to change whether it's a custodian.
When a WorkingSetMachine
is first opened with a call OpenWorkingSetMachine its
custodian state is true.
OID AllocateRodOid()