graflo.link.reconcile¶
Keep a graph's stated relations to what its statements resolve to.
A producer may write each affirmed relation as an edge when it states it, or
leave every stated edge to reconcile; either way :func:reconcile reads every
relation statement (:func:~graflo.link.assertions.read_statements), resolves
them under the schema's slot rules (:func:~graflo.link.statements.resolve)
as_of a time, by default the graph's own
(:func:~graflo.link.assertions.graph_time), and materialises each resolved
relation slot:
- a stored edge that statements back but that does not hold is deleted;
- a value that holds and is not stored is written, through the writer, so a
merge: replaceedge replaces its source's other target. A planned value deleted while pending comes back once it is due.
An edge no statement backs is never deleted here; writing a replace edge may
still displace it, as the edge declares. On a connection that cannot delete
edges the stale ones stay and are counted as kept, and the value that holds
in a single-valued slot is written again, so it is the slot's last.
An exclusive edge whose source already holds another target is refused by the writer; the stored target stays and the refusal is reported, not raised.
A written edge carries the reserved fields its statements' assertions carry (a list field takes the union), so it is visible where they are; a value whose assertions do not all carry them is left unwritten and counted.
Attributes¶
Pair = tuple[str, str]
module-attribute
¶
(source key, target key), each as :func:entity_key gives it.
__all__ = ['ReconcileReport', 'reconcile']
module-attribute
¶
Classes¶
ReconcileReport
¶
Bases: ConfigBaseModel
What one reconcile weighed, removed and wrote, per relation.
Source code in graflo/link/reconcile.py
Attributes¶
as_of = None
class-attribute
instance-attribute
¶
conflicts = 0
class-attribute
instance-attribute
¶
kept = Field(default_factory=dict, description='Stale edges left in place: the connection cannot delete edges.')
class-attribute
instance-attribute
¶
refused = Field(default_factory=list, description='Values of an exclusive relation the stored graph refused, one line each: the source holds another target, which stays.')
class-attribute
instance-attribute
¶
removed = Field(default_factory=dict)
class-attribute
instance-attribute
¶
statements = 0
class-attribute
instance-attribute
¶
unwritten = Field(default_factory=dict, description='Values that hold but whose statements carry no reserved fields to write them with.')
class-attribute
instance-attribute
¶
written = Field(default_factory=dict, description='Values sent to the writer; those it refused are under ``refused``.')
class-attribute
instance-attribute
¶
Functions:¶
reconcile(schema, conn_conf, *, as_of=None, thread_field=None)
async
¶
Delete stated edges that do not hold and write those that do but are missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The graph's logical schema, lifted with |
required |
conn_conf
|
DBConfig
|
The graph's database. |
required |
as_of
|
datetime | None
|
When to resolve at; the graph's own time when left out. |
None
|
thread_field
|
str | None
|
As for :func: |
None
|
Source code in graflo/link/reconcile.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |