Skip to content

graflo.db.sync

The protocol a backend implements to sync owner records into a loaded target.

The caller folds the whole sync input first and groups it by owner. The order of calls is: sync_begin, every vertex chunk (sync_ensure_vertices), then every owner chunk (sync_write_owners). Rows are in the names the target stores. Every call is safe to repeat: a chunk whose commit was not recorded is simply written again.

An owner chunk is written as one unit: for each owner whose stored sync hash differs from the one it carries, its properties are replaced, the edges it owns are deleted and its edges created, and its hash is stored last.

Classes

SyncEdgeType

Bases: BaseModel

One edge type an owner type owns, as stored, and where its owner is read.

Source code in graflo/db/sync.py
class SyncEdgeType(BaseModel):
    """One edge type an owner type owns, as stored, and where its owner is read."""

    source_class: str
    target_class: str
    relation_name: str
    match_keys_source: list[str]
    match_keys_target: list[str]
    side: Literal["source", "target", "field"]
    """The endpoint that is the owner, or ``field``: the owner is ``owner_property``."""
    owner_property: str | None = None
    """For ``side == "field"``: the edge property holding the owner's identity value."""

Attributes

match_keys_source instance-attribute
match_keys_target instance-attribute
owner_property = None class-attribute instance-attribute

For side == "field": the edge property holding the owner's identity value.

relation_name instance-attribute
side instance-attribute

The endpoint that is the owner, or field: the owner is owner_property.

source_class instance-attribute
target_class instance-attribute

SyncOwner

Bases: BaseModel

One owner record: its vertex and, per edge type, the edges it owns.

Source code in graflo/db/sync.py
class SyncOwner(BaseModel):
    """One owner record: its vertex and, per edge type, the edges it owns."""

    doc: dict[str, Any]
    """The vertex as stored, its sync hash included."""
    edges: list[list[tuple[dict[str, Any], dict[str, Any], dict[str, Any]]]]
    """``edges[i]``: ``(source keys, target keys, properties)`` of edge type ``i``."""

Attributes

doc instance-attribute

The vertex as stored, its sync hash included.

edges instance-attribute

edges[i]: (source keys, target keys, properties) of edge type i.

SyncOwnerChunk

Bases: BaseModel

Owners of one vertex type, with every edge type that type owns.

Source code in graflo/db/sync.py
class SyncOwnerChunk(BaseModel):
    """Owners of one vertex type, with every edge type that type owns."""

    chunk_id: str
    class_name: str
    match_keys: list[str]
    hash_field: str
    edge_types: list[SyncEdgeType]
    owners: list[SyncOwner]

Attributes

chunk_id instance-attribute
class_name instance-attribute
edge_types instance-attribute
hash_field instance-attribute
match_keys instance-attribute
owners instance-attribute

SyncWritten

Bases: BaseModel

What an owner chunk did: owners rewritten, and owners left as they were.

Source code in graflo/db/sync.py
class SyncWritten(BaseModel):
    """What an owner chunk did: owners rewritten, and owners left as they were."""

    written: int = 0
    skipped: int = 0

Attributes

skipped = 0 class-attribute instance-attribute
written = 0 class-attribute instance-attribute