conflictdag

package
v0.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: Apache-2.0, BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrefixConflictStorage defines the storage prefix for the Conflict object storage.
	PrefixConflictStorage byte = iota
	// PrefixChildConflictStorage defines the storage prefix for the ChildConflict object storage.
	PrefixChildConflictStorage
	// PrefixConflictMemberStorage defines the storage prefix for the ConflictMember object storage.
	PrefixConflictMemberStorage
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChildConflict

type ChildConflict[ConflictID comparable] struct {
	model.StorableReference[ChildConflict[ConflictID], *ChildConflict[ConflictID], ConflictID, ConflictID] `serix:"0"`
}

ChildConflict represents the reference between a Conflict and its children.

func NewChildConflict

func NewChildConflict[ConflictID comparable](parentConflictID, childConflictID ConflictID) *ChildConflict[ConflictID]

NewChildConflict return a new ChildConflict reference from the named parent to the named child.

func (*ChildConflict[ConflictID]) ChildConflictID

func (c *ChildConflict[ConflictID]) ChildConflictID() (childConflictID ConflictID)

ChildConflictID returns the identifier of the child Conflict.

func (*ChildConflict[ConflictID]) ParentConflictID

func (c *ChildConflict[ConflictID]) ParentConflictID() (parentConflictID ConflictID)

ParentConflictID returns the identifier of the parent Conflict.

type Conflict

type Conflict[ConflictID, ConflictSetID comparable] struct {
	model.Storable[ConflictID, Conflict[ConflictID, ConflictSetID], *Conflict[ConflictID, ConflictSetID], conflict[ConflictID, ConflictSetID]] `serix:"0"`
}

Conflict represents a container for transactions and outputs spawning off from a conflicting transaction.

func NewConflict

func NewConflict[ConflictID comparable, ConflictSetID comparable](id ConflictID, parents *set.AdvancedSet[ConflictID], conflictSetIDs *set.AdvancedSet[ConflictSetID]) (new *Conflict[ConflictID, ConflictSetID])

func (*Conflict[ConflictID, ConflictSetID]) ConfirmationState

func (c *Conflict[ConflictID, ConflictSetID]) ConfirmationState() (confirmationState confirmation.State)

ConfirmationState returns the ConfirmationState of the Conflict.

func (*Conflict[ConflictID, ConflictSetID]) ConflictSetIDs

func (c *Conflict[ConflictID, ConflictSetID]) ConflictSetIDs() (conflictSetIDs *set.AdvancedSet[ConflictSetID])

ConflictSetIDs returns the identifiers of the conflict sets that this Conflict is part of.

func (*Conflict[ConflictID, ConflictSetID]) Parents

func (c *Conflict[ConflictID, ConflictSetID]) Parents() (parents *set.AdvancedSet[ConflictID])

Parents returns the parent ConflictIDs that this Conflict depends on.

func (*Conflict[ConflictID, ConflictSetID]) SetParents

func (c *Conflict[ConflictID, ConflictSetID]) SetParents(parents *set.AdvancedSet[ConflictID])

SetParents updates the parent ConflictIDs that this Conflict depends on. It returns true if the Conflict was modified.

type ConflictAcceptedEvent

type ConflictAcceptedEvent[ConflictID comparable] struct {
	// ID contains the identifier of the confirmed Conflict.
	ID ConflictID
}

ConflictAcceptedEvent is a container that acts as a dictionary for the ConflictAccepted event related parameters.

type ConflictConflictsUpdatedEvent

type ConflictConflictsUpdatedEvent[ConflictID, ConflictingResourceID comparable] struct {
	// ConflictID contains the identifier of the updated Conflict.
	ConflictID ConflictID

	// NewConflictIDs contains the set of conflicts that this Conflict was added to.
	NewConflictIDs *set.AdvancedSet[ConflictingResourceID]
}

ConflictConflictsUpdatedEvent is a container that acts as a dictionary for the ConflictConflictsUpdated event related parameters.

type ConflictCreatedEvent

type ConflictCreatedEvent[ConflictID, ConflictingResourceID comparable] struct {
	// ID contains the identifier of the newly created Conflict.
	ID ConflictID

	// ParentConflictIDs contains the identifiers of the parents of the newly created Conflict.
	ParentConflictIDs *set.AdvancedSet[ConflictID]

	// ConflictingResourceIDs contains the identifiers of the conflicting resources that this Conflict is associated to.
	ConflictingResourceIDs *set.AdvancedSet[ConflictingResourceID]
}

ConflictCreatedEvent is an event that gets triggered when a new Conflict was created.

type ConflictDAG

type ConflictDAG[ConflictIDType, ResourceIDType comparable] struct {
	// Events is a dictionary for events emitted by the ConflictDAG.
	Events *Events[ConflictIDType, ResourceIDType]

	// Storage is a dictionary for storage related API endpoints.
	Storage *Storage[ConflictIDType, ResourceIDType]

	// Utils is a dictionary for utility methods that simplify the interaction with the ConflictDAG.
	Utils *Utils[ConflictIDType, ResourceIDType]

	// RWMutex is a mutex that prevents that two processes simultaneously update the ConfirmationState.
	sync.RWMutex
	// contains filtered or unexported fields
}

ConflictDAG represents a generic DAG that is able to model causal dependencies between conflicts that try to access a shared set of resources.

func New

func New[ConflictIDType, ResourceIDType comparable](options ...Option) (new *ConflictDAG[ConflictIDType, ResourceIDType])

New returns a new ConflictDAG with the given options.

func (*ConflictDAG[ConflictID, ConflictingResourceID]) ConfirmationState

func (b *ConflictDAG[ConflictID, ConflictingResourceID]) ConfirmationState(conflictIDs *set.AdvancedSet[ConflictID]) (confirmationState confirmation.State)

ConfirmationState returns the ConfirmationState of the given ConflictIDs.

func (*ConflictDAG[ConflictIDType, ResourceIDType]) CreateConflict

func (b *ConflictDAG[ConflictIDType, ResourceIDType]) CreateConflict(id ConflictIDType, parents *set.AdvancedSet[ConflictIDType], conflictingResources *set.AdvancedSet[ResourceIDType]) (created bool)

CreateConflict creates a new Conflict in the ConflictDAG and returns true if the Conflict was new.

func (*ConflictDAG[ConflictID, ConflictingResourceID]) SetConflictAccepted

func (b *ConflictDAG[ConflictID, ConflictingResourceID]) SetConflictAccepted(conflictID ConflictID) (modified bool)

SetConflictAccepted sets the ConfirmationState of the given Conflict to be Accepted - it automatically sets also the conflicting conflicts to be rejected.

func (*ConflictDAG[ConflictID, ConflictingResourceID]) Shutdown

func (b *ConflictDAG[ConflictID, ConflictingResourceID]) Shutdown()

Shutdown shuts down the stateful elements of the ConflictDAG (the Storage).

func (*ConflictDAG[ConflictIDType, ConflictingResourceID]) UnconfirmedConflicts

func (b *ConflictDAG[ConflictIDType, ConflictingResourceID]) UnconfirmedConflicts(conflictIDs *set.AdvancedSet[ConflictIDType]) (pendingConflictIDs *set.AdvancedSet[ConflictIDType])

UnconfirmedConflicts takes a set of ConflictIDs and removes all the Accepted/Confirmed Conflicts (leaving only the pending or rejected ones behind).

func (*ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictParents

func (b *ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictParents(id ConflictIDType, removedConflictIDs *set.AdvancedSet[ConflictIDType], addedConflictID ConflictIDType) (updated bool)

UpdateConflictParents changes the parents of a Conflict after a fork (also updating the corresponding references).

func (*ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictingResources

func (b *ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictingResources(id ConflictIDType, conflictingResourceIDs *set.AdvancedSet[ResourceIDType]) (updated bool)

UpdateConflictingResources adds the Conflict to the named conflicts - it returns true if the conflict membership was modified during this operation.

type ConflictMember

type ConflictMember[ConflictSetID comparable, ConflictID comparable] struct {
	model.StorableReference[ConflictMember[ConflictSetID, ConflictID], *ConflictMember[ConflictSetID, ConflictID], ConflictSetID, ConflictID] `serix:"0"`
}

ConflictMember represents the reference between a Conflict and its contained Conflict.

func NewConflictMember

func NewConflictMember[ConflictSetID comparable, ConflictID comparable](conflictSetID ConflictSetID, conflictID ConflictID) (new *ConflictMember[ConflictSetID, ConflictID])

NewConflictMember return a new ConflictMember reference from the named conflict to the named Conflict.

func (*ConflictMember[ConflictSetID, ConflictID]) ConflictID

func (c *ConflictMember[ConflictSetID, ConflictID]) ConflictID() (conflictID ConflictID)

ConflictID returns the identifier of the Conflict.

func (*ConflictMember[ConflictSetID, ConflictID]) ConflictSetID

func (c *ConflictMember[ConflictSetID, ConflictID]) ConflictSetID() (conflictSetID ConflictSetID)

ConflictSetID returns the identifier of Conflict set.

type ConflictParentsUpdatedEvent

type ConflictParentsUpdatedEvent[ConflictID, ConflictingResourceID comparable] struct {
	// ConflictID contains the identifier of the updated Conflict.
	ConflictID ConflictID

	// AddedConflict contains the forked parent Conflict that replaces the removed parents.
	AddedConflict ConflictID

	// RemovedConflicts contains the parent ConflictIDs that were replaced by the newly forked Conflict.
	RemovedConflicts *set.AdvancedSet[ConflictID]

	// ParentsConflictIDs contains the updated list of parent ConflictIDs.
	ParentsConflictIDs *set.AdvancedSet[ConflictID]
}

ConflictParentsUpdatedEvent is a container that acts as a dictionary for the ConflictParentsUpdated event related parameters.

type ConflictRejectedEvent

type ConflictRejectedEvent[ConflictID comparable] struct {
	// ID contains the identifier of the rejected Conflict.
	ID ConflictID
}

ConflictRejectedEvent is a container that acts as a dictionary for the ConflictRejected event related parameters.

type Events

type Events[ConflictID, ConflictingResourceID comparable] struct {
	// ConflictCreated is an event that gets triggered whenever a new Conflict is created.
	ConflictCreated *event.Event[*ConflictCreatedEvent[ConflictID, ConflictingResourceID]]

	// ConflictConflictsUpdated is an event that gets triggered whenever the ConflictIDs of a Conflict are updated.
	ConflictConflictsUpdated *event.Event[*ConflictConflictsUpdatedEvent[ConflictID, ConflictingResourceID]]

	// ConflictParentsUpdated is an event that gets triggered whenever the parent ConflictIDs of a Conflict are updated.
	ConflictParentsUpdated *event.Event[*ConflictParentsUpdatedEvent[ConflictID, ConflictingResourceID]]

	// ConflictAccepted is an event that gets triggered whenever a Conflict is confirmed.
	ConflictAccepted *event.Event[*ConflictAcceptedEvent[ConflictID]]

	// ConflictRejected is an event that gets triggered whenever a Conflict is rejected.
	ConflictRejected *event.Event[*ConflictRejectedEvent[ConflictID]]
}

Events is a container that acts as a dictionary for the events of a ConflictDAG.

type Option

type Option func(*options)

Option represents a configurable parameter for the ConflictDAG that modifies its behavior.

func WithCacheTimeProvider

func WithCacheTimeProvider(cacheTimeProvider *database.CacheTimeProvider) Option

WithCacheTimeProvider is an Option for the ConflictDAG that allows to configure which CacheTimeProvider is supposed to be used.

func WithChildConflictCacheTime

func WithChildConflictCacheTime(childConflictCacheTime time.Duration) Option

WithChildConflictCacheTime is an Option for the ConflictDAG that allows to configure how long ChildConflict objects stay cached after they have been released.

func WithConflictCacheTime

func WithConflictCacheTime(conflictCacheTime time.Duration) Option

WithConflictCacheTime is an Option for the ConflictDAG that allows to configure how long Conflict objects stay cached after they have been released.

func WithConflictMemberCacheTime

func WithConflictMemberCacheTime(conflictMemberCacheTime time.Duration) Option

WithConflictMemberCacheTime is an Option for the ConflictDAG that allows to configure how long ConflictMember objects stay cached after they have been released.

func WithMergeToMaster

func WithMergeToMaster(mergeToMaster bool) Option

WithMergeToMaster is an Option for the ConflictDAG that allows to configure whether the ConflictDAG should merge confirmed Conflicts to the MasterConflict.

func WithStore

func WithStore(store kvstore.KVStore) Option

WithStore is an Option for the ConflictDAG that allows to configure which KVStore is supposed to be used to persist data (the default option is to use a MapDB).

type Storage

type Storage[ConflictID comparable, ConflictSetID comparable] struct {
	// contains filtered or unexported fields
}

Storage is a ConflictDAG component that bundles the storage related API.

func (*Storage[ConflictID, ConflictSetID]) CachedChildConflict

func (s *Storage[ConflictID, ConflictSetID]) CachedChildConflict(parentConflictID, childConflictID ConflictID, computeIfAbsentCallback ...func(parentConflictID, childConflictID ConflictID) *ChildConflict[ConflictID]) *objectstorage.CachedObject[*ChildConflict[ConflictID]]

CachedChildConflict retrieves the CachedObject representing the named ChildConflict. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing ChildConflict.

func (*Storage[ConflictID, ConflictSetID]) CachedChildConflicts

func (s *Storage[ConflictID, ConflictSetID]) CachedChildConflicts(conflictID ConflictID) (cachedChildConflicts objectstorage.CachedObjects[*ChildConflict[ConflictID]])

CachedChildConflicts retrieves the CachedObjects containing the ChildConflict references approving the named Conflict.

func (*Storage[ConflictID, ConflictSetID]) CachedConflict

func (s *Storage[ConflictID, ConflictSetID]) CachedConflict(conflictID ConflictID, computeIfAbsentCallback ...func(conflictID ConflictID) *Conflict[ConflictID, ConflictSetID]) (cachedConflict *objectstorage.CachedObject[*Conflict[ConflictID, ConflictSetID]])

CachedConflict retrieves the CachedObject representing the named Conflict. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing Conflict.

func (*Storage[ConflictID, ConflictSetID]) CachedConflictMember

func (s *Storage[ConflictID, ConflictSetID]) CachedConflictMember(conflictSetID ConflictSetID, conflictID ConflictID, computeIfAbsentCallback ...func(conflictSetID ConflictSetID, conflictID ConflictID) *ConflictMember[ConflictSetID, ConflictID]) *objectstorage.CachedObject[*ConflictMember[ConflictSetID, ConflictID]]

CachedConflictMember retrieves the CachedObject representing the named ConflictMember. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing ConflictMember.

func (*Storage[ConflictID, ConflictSetID]) CachedConflictMembers

func (s *Storage[ConflictID, ConflictSetID]) CachedConflictMembers(conflictID ConflictSetID) (cachedConflictMembers objectstorage.CachedObjects[*ConflictMember[ConflictSetID, ConflictID]])

CachedConflictMembers retrieves the CachedObjects containing the ConflictMember references related to the named conflict.

func (*Storage[ConflictID, ConflictSetID]) Prune

func (s *Storage[ConflictID, ConflictSetID]) Prune() (err error)

Prune resets the database and deletes all entities.

func (*Storage[ConflictID, ConflictSetID]) Shutdown

func (s *Storage[ConflictID, ConflictSetID]) Shutdown()

Shutdown shuts down the KVStores used to persist data.

type Utils

type Utils[ConflictID comparable, ConflictSetID comparable] struct {
	// contains filtered or unexported fields
}

Utils is a ConflictDAG component that bundles utility related API to simplify common interactions with the ConflictDAG.

func (*Utils[ConflictID, ConflictSetID]) ForEachChildConflictID

func (u *Utils[ConflictID, ConflictSetID]) ForEachChildConflictID(conflictID ConflictID, callback func(childConflictID ConflictID))

func (*Utils[ConflictID, ConflictSetID]) ForEachConflict

func (u *Utils[ConflictID, ConflictSetID]) ForEachConflict(consumer func(conflict *Conflict[ConflictID, ConflictSetID]))

ForEachConflict iterates over every existing Conflict in the entire Storage.

func (*Utils[ConflictID, ConflictSetID]) ForEachConflictingConflictID

func (u *Utils[ConflictID, ConflictSetID]) ForEachConflictingConflictID(conflictID ConflictID, callback func(conflictingConflictID ConflictID) bool)

ForEachConflictingConflictID executes the callback for each Conflict that is conflicting with the named Conflict.

func (*Utils[ConflictID, ConflictSetID]) ForEachConnectedConflictingConflictID

func (u *Utils[ConflictID, ConflictSetID]) ForEachConnectedConflictingConflictID(conflictID ConflictID, callback func(conflictingConflictID ConflictID))

ForEachConnectedConflictingConflictID executes the callback for each Conflict that is directly or indirectly connected to the named Conflict through a chain of intersecting conflicts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL