Documentation ¶
Index ¶
- Constants
- Variables
- func IndexComparator(a, b interface{}) int
- type IncreaseIndexCallback
- type Index
- type Manager
- func (m *Manager) InheritStructureDetails(referencedStructureDetails []*StructureDetails, ...) (inheritedStructureDetails *StructureDetails, newSequenceCreated bool)
- func (m *Manager) IsInPastCone(earlierStructureDetails, laterStructureDetails *StructureDetails) (isInPastCone types.TriBool)
- func (m *Manager) Sequence(sequenceID SequenceID) *objectstorage.CachedObject[*Sequence]
- func (m *Manager) Shutdown()
- func (m *Manager) UpdateStructureDetails(structureDetailsToUpdate *StructureDetails, markerToInherit *Marker) (futureMarkersUpdated, inheritFutureMarkerFurther bool)
- type ManagerOption
- type ManagerOptions
- type Marker
- type Markers
- func (m *Markers) Bytes() []byte
- func (m *Markers) Clone() (clonedMarkers *Markers)
- func (m *Markers) Delete(sequenceID SequenceID) (existed bool)
- func (m *Markers) Equals(other *Markers) (equals bool)
- func (m *Markers) ForEach(iterator func(sequenceID SequenceID, index Index) bool) (success bool)
- func (m *Markers) ForEachSorted(iterator func(sequenceID SequenceID, index Index) bool) (success bool)
- func (m *Markers) Get(sequenceID SequenceID) (index Index, exists bool)
- func (m *Markers) HighestIndex() (highestIndex Index)
- func (m *Markers) LowestIndex() (lowestIndex Index)
- func (m *Markers) Marker() (marker *Marker)
- func (m *Markers) Merge(markers *Markers)
- func (m *Markers) SequenceIDs() (sequenceIDs SequenceIDs)
- func (m *Markers) SequenceToString() (s string)
- func (m *Markers) Set(sequenceID SequenceID, index Index) (updated, added bool)
- func (m *Markers) Size() (size int)
- func (m *Markers) String() (humanReadableMarkers string)
- type ReferencedMarkers
- type ReferencingMarkers
- type Sequence
- func (s *Sequence) AddReferencingMarker(index Index, referencingMarker *Marker)
- func (s *Sequence) Bytes() []byte
- func (s *Sequence) FromBytes(data []byte) (sequence *Sequence, err error)
- func (s *Sequence) FromObjectStorage(key, value []byte) (objectstorage.StorableObject, error)
- func (s *Sequence) HighestIndex() Index
- func (s *Sequence) ID() SequenceID
- func (s *Sequence) IncreaseHighestIndex(referencedMarkers *Markers) (index Index, increased bool)
- func (s *Sequence) LowestIndex() Index
- func (s *Sequence) ObjectStorageKey() []byte
- func (s *Sequence) ObjectStorageValue() []byte
- func (s *Sequence) ReferencedMarkers(index Index) *Markers
- func (s *Sequence) ReferencingMarkers(index Index) *Markers
- func (s *Sequence) String() string
- func (s *Sequence) TryExtend(referencedPastMarkers *Markers, increaseIndexCallback IncreaseIndexCallback) (index Index, remainingReferencedPastMarkers *Markers, extended bool)
- type SequenceID
- type SequenceIDs
- type StructureDetails
Constants ¶
const IndexLength = marshalutil.Uint64Size
IndexLength represents the amount of bytes of a marshaled Index.
const MarkerLength = SequenceIDLength + IndexLength
MarkerLength represents the amount of bytes of a marshaled Marker.
const SequenceIDLength = marshalutil.Uint64Size
SequenceIDLength represents the amount of bytes of a marshaled SequenceID.
Variables ¶
var DefaultManagerOptions = &ManagerOptions{ Store: mapdb.NewMapDB(), CacheTime: 30 * time.Second, MaxPastMarkerDistance: 30, }
DefaultManagerOptions defines the default options for the Manager.
Functions ¶
func IndexComparator ¶ added in v0.8.6
func IndexComparator(a, b interface{}) int
IndexComparator is a generic comparator for Index types.
Types ¶
type IncreaseIndexCallback ¶
type IncreaseIndexCallback func(sequenceID SequenceID, currentHighestIndex Index) bool
IncreaseIndexCallback is the type of the callback function that is used to determine if a new Index is supposed to be assigned in a given Sequence.
type Index ¶
type Index uint64
Index represents the ever-increasing number of the Markers in a Sequence.
type Manager ¶
type Manager struct { Options *ManagerOptions // contains filtered or unexported fields }
Manager is the managing entity for the Marker related business logic. It is stateful and automatically stores its state in a KVStore.
func NewManager ¶
func NewManager(options ...ManagerOption) (newManager *Manager)
NewManager is the constructor of the Manager that takes a KVStore to persist its state.
func (*Manager) InheritStructureDetails ¶
func (m *Manager) InheritStructureDetails(referencedStructureDetails []*StructureDetails, increaseIndexCallback IncreaseIndexCallback) (inheritedStructureDetails *StructureDetails, newSequenceCreated bool)
InheritStructureDetails takes the StructureDetails of the referenced parents and returns new StructureDetails for the message that was just added to the DAG. It automatically creates a new Sequence and Index if necessary and returns an additional flag that indicates if a new Sequence was created. InheritStructureDetails inherits the structure details of the given parent StructureDetails.
func (*Manager) IsInPastCone ¶
func (m *Manager) IsInPastCone(earlierStructureDetails, laterStructureDetails *StructureDetails) (isInPastCone types.TriBool)
IsInPastCone checks if the earlier node is directly or indirectly referenced by the later node in the DAG.
func (*Manager) Sequence ¶ added in v0.5.4
func (m *Manager) Sequence(sequenceID SequenceID) *objectstorage.CachedObject[*Sequence]
Sequence retrieves a Sequence from the object storage.
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown shuts down the Manager and persists its state.
func (*Manager) UpdateStructureDetails ¶
func (m *Manager) UpdateStructureDetails(structureDetailsToUpdate *StructureDetails, markerToInherit *Marker) (futureMarkersUpdated, inheritFutureMarkerFurther bool)
UpdateStructureDetails updates the StructureDetails of an existing node in the DAG by propagating new Markers of its children into its future Markers. It returns two boolean flags that indicate if the future Markers were updated and if the new Marker should be propagated further to the parents of the given node.
type ManagerOption ¶ added in v0.8.6
type ManagerOption func(options *ManagerOptions)
ManagerOption represents the return type of optional parameters that can be handed into the constructor of the Manager to configure its behavior.
func WithCacheTime ¶ added in v0.8.6
func WithCacheTime(cacheTime time.Duration) ManagerOption
WithCacheTime is an option for the Manager that allows to specify how long objects should be cached in the object storage.
func WithMaxPastMarkerDistance ¶ added in v0.8.6
func WithMaxPastMarkerDistance(distance uint64) ManagerOption
WithMaxPastMarkerDistance is an Option for the Manager that allows to specify how many consecutive messages are allowed to not receive a new PastMaster before we create a new Sequence.
func WithStore ¶ added in v0.8.6
func WithStore(store kvstore.KVStore) ManagerOption
WithStore is an option for the Manager that allows to specify which storage layer is supposed to be used to persist data.
type ManagerOptions ¶ added in v0.8.6
type ManagerOptions struct { // Store is a parameter for the Manager that allows to specify which storage layer is supposed to be used to persist // data. Store kvstore.KVStore // CacheTime is a parameter for the Manager that allows to specify how long objects should be cached in the object // storage. CacheTime time.Duration // MaxPastMarkerDistance is a parameter for the Manager that allows to specify how many consecutive messages are // allowed to not receive a new PastMaster before we create a new Sequence. MaxPastMarkerDistance uint64 }
ManagerOptions is a container for all configurable parameters of the Manager.
func (*ManagerOptions) Apply ¶ added in v0.8.6
func (m *ManagerOptions) Apply(options ...ManagerOption) (managerOptions *ManagerOptions)
Apply applies the given options to the ManagerOptions object.
type Marker ¶
type Marker struct {
// contains filtered or unexported fields
}
Marker represents a coordinate in a Sequence that is identified by an ever-increasing Index.
func MarkerFromBytes ¶
MarkerFromBytes unmarshals Marker from a sequence of bytes.
func NewMarker ¶ added in v0.4.0
func NewMarker(sequenceID SequenceID, index Index) *Marker
NewMarker returns a new marker.
func (*Marker) SequenceID ¶
func (m *Marker) SequenceID() (sequenceID SequenceID)
SequenceID returns the identifier of the Sequence of the Marker.
type Markers ¶
type Markers struct {
// contains filtered or unexported fields
}
Markers represents a collection of Markers that can contain exactly one Index per SequenceID.
func NewMarkers ¶
NewMarkers creates a new collection of Markers.
func (*Markers) Delete ¶
func (m *Markers) Delete(sequenceID SequenceID) (existed bool)
Delete removes the Marker with the given SequenceID from the collection and returns a boolean flag that indicates if the element existed.
func (*Markers) ForEach ¶
func (m *Markers) ForEach(iterator func(sequenceID SequenceID, index Index) bool) (success bool)
ForEach calls the iterator for each of the contained Markers. The iteration is aborted if the iterator returns false. The method returns false if the iteration was aborted.
func (*Markers) ForEachSorted ¶ added in v0.5.7
func (m *Markers) ForEachSorted(iterator func(sequenceID SequenceID, index Index) bool) (success bool)
ForEachSorted calls the iterator for each of the contained Markers in increasing order. The iteration is aborted if the iterator returns false. The method returns false if the iteration was aborted.
func (*Markers) Get ¶
func (m *Markers) Get(sequenceID SequenceID) (index Index, exists bool)
Get returns the Index of the Marker with the given Sequence and a flag that indicates if the Marker exists.
func (*Markers) HighestIndex ¶
HighestIndex returns the highest Index of all Markers in the collection.
func (*Markers) LowestIndex ¶
LowestIndex returns the lowest Index of all Markers in the collection.
func (*Markers) Marker ¶ added in v0.5.7
Marker type casts the Markers to a Marker if it contains only 1 element.
func (*Markers) Merge ¶
Merge takes the given Markers and adds them to the collection (overwriting Markers with a lower Index if there are existing Markers with the same SequenceID).
func (*Markers) SequenceIDs ¶
func (m *Markers) SequenceIDs() (sequenceIDs SequenceIDs)
SequenceIDs returns the SequenceIDs that are having Markers in this collection.
func (*Markers) SequenceToString ¶ added in v0.5.3
SequenceToString returns a string in the form sequenceID:index;.
func (*Markers) Set ¶
func (m *Markers) Set(sequenceID SequenceID, index Index) (updated, added bool)
Set adds a new Marker to the collection and updates the Index of an existing entry if it is higher than a possible previously stored one. The method returns two boolean flags that indicate if an entry was updated and/or added.
type ReferencedMarkers ¶ added in v0.5.4
type ReferencedMarkers struct {
// contains filtered or unexported fields
}
ReferencedMarkers is a data structure that allows to denote which Marker of a Sequence references which other Markers of its parent Sequences in the Sequence DAG.
func NewReferencedMarkers ¶ added in v0.5.4
func NewReferencedMarkers(markers *Markers) (referencedMarkers *ReferencedMarkers)
NewReferencedMarkers is the constructor for the ReferencedMarkers.
func ReferencedMarkersFromBytes ¶ added in v0.5.4
func ReferencedMarkersFromBytes(parentReferencesBytes []byte) (referencedMarkers *ReferencedMarkers, consumedBytes int, err error)
ReferencedMarkersFromBytes unmarshals ReferencedMarkers from a sequence of bytes.
func (*ReferencedMarkers) Add ¶ added in v0.5.4
func (r *ReferencedMarkers) Add(index Index, referencedMarkers *Markers)
Add adds new referenced Markers to the ReferencedMarkers.
func (*ReferencedMarkers) Bytes ¶ added in v0.5.4
func (r *ReferencedMarkers) Bytes() []byte
Bytes returns a marshaled version of the ReferencingMarkers.
func (*ReferencedMarkers) Get ¶ added in v0.5.4
func (r *ReferencedMarkers) Get(index Index) (referencedMarkers *Markers)
Get returns the Markers of parent Sequences that were referenced by the given Index.
func (*ReferencedMarkers) String ¶ added in v0.5.4
func (r *ReferencedMarkers) String() (humanReadableReferencedMarkers string)
String returns a human-readable version of the ReferencedMarkers.
type ReferencingMarkers ¶ added in v0.5.4
type ReferencingMarkers struct {
// contains filtered or unexported fields
}
ReferencingMarkers is a data structure that allows to denote which Markers of child Sequences in the Sequence DAG reference a given Marker in a Sequence.
func NewReferencingMarkers ¶ added in v0.5.4
func NewReferencingMarkers() (referencingMarkers *ReferencingMarkers)
NewReferencingMarkers is the constructor for the ReferencingMarkers.
func ReferencingMarkersFromBytes ¶ added in v0.5.4
func ReferencingMarkersFromBytes(referencingMarkersBytes []byte) (referencingMarkers *ReferencingMarkers, consumedBytes int, err error)
ReferencingMarkersFromBytes unmarshals ReferencingMarkers from a sequence of bytes.
func (*ReferencingMarkers) Add ¶ added in v0.5.4
func (r *ReferencingMarkers) Add(index Index, referencingMarker *Marker)
Add adds a new referencing Marker to the ReferencingMarkers.
func (*ReferencingMarkers) Bytes ¶ added in v0.5.4
func (r *ReferencingMarkers) Bytes() []byte
Bytes returns a marshaled version of the PersistableBaseMana.
func (*ReferencingMarkers) Get ¶ added in v0.5.4
func (r *ReferencingMarkers) Get(index Index) (referencingMarkers *Markers)
Get returns the Markers of child Sequences that reference the given Index.
func (*ReferencingMarkers) String ¶ added in v0.5.4
func (r *ReferencingMarkers) String() (humanReadableReferencingMarkers string)
String returns a human-readable version of the ReferencingMarkers.
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
Sequence represents a set of ever-increasing Indexes that are encapsulating a certain part of the DAG.
func NewSequence ¶
func NewSequence(id SequenceID, referencedMarkers *Markers) *Sequence
NewSequence creates a new Sequence from the given details.
func (*Sequence) AddReferencingMarker ¶ added in v0.5.4
AddReferencingMarker register a Marker that referenced the given Index of this Sequence.
func (*Sequence) FromBytes ¶ added in v0.8.10
FromBytes unmarshals a Sequence from a sequence of bytes.
func (*Sequence) FromObjectStorage ¶ added in v0.8.10
func (s *Sequence) FromObjectStorage(key, value []byte) (objectstorage.StorableObject, error)
FromObjectStorage creates a Sequence from sequences of key and bytes.
func (*Sequence) HighestIndex ¶
HighestIndex returns the Index of the latest Marker in the Sequence.
func (*Sequence) IncreaseHighestIndex ¶
IncreaseHighestIndex increases the highest Index of the Sequence if the referencedMarkers directly reference the Marker with the highest Index. It returns the new Index and a boolean flag that indicates if the value was increased.
func (*Sequence) LowestIndex ¶
LowestIndex returns the Index of the very first Marker in the Sequence.
func (*Sequence) ObjectStorageKey ¶
ObjectStorageKey returns the key that is used to store the object in the database. It is required to match the StorableObject interface.
func (*Sequence) ObjectStorageValue ¶
ObjectStorageValue marshals the Sequence into a sequence of bytes that are used as the value part in the object storage.
func (*Sequence) ReferencedMarkers ¶ added in v0.5.4
ReferencedMarkers returns a collection of Markers that were referenced by the given Index.
func (*Sequence) ReferencingMarkers ¶ added in v0.5.4
ReferencingMarkers returns a collection of Markers that reference the given Index.
func (*Sequence) TryExtend ¶ added in v0.8.6
func (s *Sequence) TryExtend(referencedPastMarkers *Markers, increaseIndexCallback IncreaseIndexCallback) (index Index, remainingReferencedPastMarkers *Markers, extended bool)
TryExtend tries to extend the Sequence with a new Index by checking if the referenced PastMarkers contain the last assigned Index of the Sequence. It returns the new Index, the remaining Markers pointing to other Sequences and a boolean flag that indicating if a new Index was assigned.
type SequenceID ¶
type SequenceID uint64
SequenceID is the type of the identifier of a Sequence.
func SequenceIDFromBytes ¶
func SequenceIDFromBytes(data []byte) (sequenceID SequenceID, consumedBytes int, err error)
SequenceIDFromBytes unmarshals a SequenceID from a sequence of bytes.
func (SequenceID) Bytes ¶
func (a SequenceID) Bytes() (marshaledSequenceID []byte)
Bytes returns a marshaled version of the SequenceID.
func (SequenceID) String ¶
func (a SequenceID) String() (humanReadableSequenceID string)
String returns a human-readable version of the SequenceID.
type SequenceIDs ¶
type SequenceIDs map[SequenceID]types.Empty
SequenceIDs represents a collection of SequenceIDs.
func NewSequenceIDs ¶
func NewSequenceIDs(sequenceIDs ...SequenceID) (result SequenceIDs)
NewSequenceIDs creates a new collection of SequenceIDs.
func (SequenceIDs) String ¶
func (s SequenceIDs) String() (humanReadableSequenceIDs string)
String returns a human-readable version of the SequenceIDs.
type StructureDetails ¶
type StructureDetails struct { Rank uint64 `serix:"0"` PastMarkerGap uint64 `serix:"1"` IsPastMarker bool `serix:"2"` PastMarkers *Markers `serix:"3"` FutureMarkers *Markers `serix:"4"` // contains filtered or unexported fields }
StructureDetails represents a container for the complete Marker related information of a node in a DAG that are used to interact with the public API of this package.
func StructureDetailsFromBytes ¶
func StructureDetailsFromBytes(structureDetailBytes []byte) (marker *StructureDetails, consumedBytes int, err error)
StructureDetailsFromBytes unmarshals a StructureDetails from a sequence of bytes.
func (*StructureDetails) Bytes ¶
func (m *StructureDetails) Bytes() []byte
Bytes returns a marshaled version of the StructureDetails.
func (*StructureDetails) Clone ¶
func (m *StructureDetails) Clone() (clone *StructureDetails)
Clone creates a deep copy of the StructureDetails.
func (*StructureDetails) String ¶
func (m *StructureDetails) String() (humanReadableStructureDetails string)
String returns a human-readable version of the StructureDetails.