Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalColumns(table string) ([]string, bool)
- func CanonicalSchemaDocument() string
- func CanonicalSchemaDocumentation() string
- func CanonicalSchemaStatements() []string
- func CanonicalTableCounts(ctx context.Context, path string) (map[string]int64, error)
- func CanonicalTableNames() []string
- func CanonicalTableRows(set facts.Set, options CanonicalLoadOptions) (map[string][][]string, error)
- type CanonicalEdge
- type CanonicalEvidence
- type CanonicalFile
- type CanonicalGraph
- type CanonicalIntegrityReport
- type CanonicalLoadOptions
- type CanonicalMutationResult
- type CanonicalPackage
- type CanonicalProbe
- type CanonicalProbeResult
- type CanonicalRepository
- type CanonicalSymbol
- type CanonicalUnresolvedReference
- type Config
- type Database
- type Delta
- type DiagnosticCheck
- type DiagnosticStatus
- type Error
- type FileRecord
- type IntegrityFinding
- type IntegrityRule
- type IntegrityViolation
- type LoadReport
- type Multiplicity
- type MutationResult
- type OutgoingReplacement
- type Path
- type Reader
- type Reference
- type ReferenceKey
- type RepositoryRecord
- type RepositoryReferenceCount
- type ScanEdge
- type ScanRows
- type SchemaKind
- type SchemaNodeTable
- type SchemaProperty
- type SchemaRelationshipTable
- type StorageDiagnosis
- type Symbol
- type TraversalNode
- type Writer
Constants ¶
const ( // CoreVersion is the native LadybugDB release paired with the Go binding. CoreVersion = "v0.13.1" // GoBindingVersion is the version of the LadybugDB Go binding. GoBindingVersion = "v0.13.1" )
const ( ReferenceKindReferences = "REFERENCES" ReferenceKindCallsDirect = "CALLS_DIRECT" )
const ( // MaxReferenceResults matches the maximum page size in the public query contract. MaxReferenceResults = 500 // MaxTraversalDepth is the maximum supported semantic traversal depth. MaxTraversalDepth = 5 // MaxTraversalResults bounds materialized traversal nodes. MaxTraversalResults = 25_000 )
const CanonicalSchemaFile = "schemas/ladybug/003-canonical.cypher"
CanonicalSchemaFile is the versioned DDL generated from this metadata.
const CanonicalSchemaVersion = 3
CanonicalSchemaVersion is the version of the definitive graph schema. It is stored in the database so a rebuild can detect an incompatible layout.
const MaxIntegritySamples = 20
MaxIntegritySamples bounds the offending rows reported per rule: a broken graph must be diagnosable without dumping the whole graph.
Variables ¶
var ( ErrUnavailable = errors.New("LadybugDB native support is unavailable") // ErrClosed reports an operation attempted after database closure. ErrClosed = errors.New("LadybugDB database is closed") // ErrInvalidPath reports an empty database path. ErrInvalidPath = errors.New("LadybugDB database path is empty") // ErrInvalidStableKey reports an empty symbol stable key. ErrInvalidStableKey = errors.New("LadybugDB symbol stable key is empty") // ErrInvalidLimit reports a non-positive or excessive result limit. ErrInvalidLimit = errors.New("LadybugDB query limit is outside the supported range") // ErrInvalidDepth reports a traversal depth outside the supported range. ErrInvalidDepth = errors.New("LadybugDB traversal depth is outside the supported range") // ErrReadOnly reports a writer requested from a read-only database. ErrReadOnly = errors.New("LadybugDB database is read-only") // ErrWriterOpen reports that the database already owns its single logical writer. ErrWriterOpen = errors.New("LadybugDB writer is already open") // ErrInvalidMutation reports a structurally invalid incremental delta. ErrInvalidMutation = errors.New("LadybugDB incremental mutation is invalid") // ErrAlreadyExists reports an attempted insertion of an existing entity. ErrAlreadyExists = errors.New("LadybugDB entity already exists") // ErrNotFound reports an update or deletion whose target does not exist. ErrNotFound = errors.New("LadybugDB entity was not found") // ErrDatabaseLocked reports that another live process holds the database. // It is separated from a generic open failure on purpose: a duplicate // Kivgraph instance and a damaged file are the same status code coming // out of the engine, and an operator needs to tell them apart. ErrDatabaseLocked = errors.New("LadybugDB database is held by another process") )
var ErrCanonicalIntegrity = errors.New("canonical graph integrity failed")
ErrCanonicalIntegrity reports that VerifyCanonicalIntegrity could not run to completion. A violated invariant is never this error: it is a finding in the returned report. Only a failure of the verification engine itself (a query that could not execute, a rule with no evaluator) is.
var ErrInvalidCanonicalDelta = errors.New("invalid canonical delta")
ErrInvalidCanonicalDelta reports a facts.Delta that cannot be applied to the canonical graph: one that fails its own facts.Delta.Validate, one aimed at a database whose GraphMetadata is not the canonical schema at its expected version, or one whose Upsert asserts an edge whose endpoint does not exist once retirement has run.
var ErrInvalidCanonicalLoad = errors.New("invalid canonical load")
ErrInvalidCanonicalLoad reports a fact set or option that cannot become a canonical bulk load.
var ErrInvalidCanonicalScan = errors.New("invalid canonical scan")
ErrInvalidCanonicalScan reports a definitive graph that cannot become a scan result. Today this is only an incompatible schema version: a rebuild stage must never try to derive a snapshot from a layout it does not understand, so ScanCanonical fails loudly before reading a single node or edge rather than misreading columns that have since moved.
Functions ¶
func CanonicalColumns ¶
CanonicalColumns returns the CSV column order of one canonical table. Node tables start with the primary key; relationship tables start with the source key and the target key, which is what LadybugDB COPY expects.
func CanonicalSchemaDocument ¶
func CanonicalSchemaDocument() string
CanonicalSchemaDocument renders the complete versioned DDL file.
func CanonicalSchemaDocumentation ¶
func CanonicalSchemaDocumentation() string
CanonicalSchemaDocumentation renders the reference document of the schema.
It is generated from the same metadata as the DDL so the documentation cannot describe a schema the database does not have.
func CanonicalSchemaStatements ¶
func CanonicalSchemaStatements() []string
CanonicalSchemaStatements renders the DDL of the canonical schema.
The statements are generated from the metadata above, so the documented schema and the created schema cannot drift.
func CanonicalTableCounts ¶
CanonicalTableCounts reports that the native build is required to read counts.
func CanonicalTableNames ¶
func CanonicalTableNames() []string
CanonicalTableNames lists every table of the schema, sorted, for diagnostics.
func CanonicalTableRows ¶
CanonicalTableRows renders a fact set as the rows of every canonical table. A table with no rows is absent from the map.
Types ¶
type CanonicalEdge ¶
type CanonicalEdge struct {
Table string
SourceKey string
TargetKey string
Confidence string
Provenance string
EvidenceKey string
SourceSnapshot int64
ResolverVersion string
}
CanonicalEdge is one relationship row, with the table it came from.
Confidence and Provenance are always populated: every edge table of the vocabulary carries both. EvidenceKey, SourceSnapshot and ResolverVersion hold the Go zero value for a structural table (CONTAINS_PACKAGE, CONTAINS_FILE, DEFINES), which has no such columns at all -- that is a schema fact declared by containmentProperties in canonical_schema.go, not a lossy read.
type CanonicalEvidence ¶
type CanonicalEvidence struct {
StableKey string
RepositoryKey string
FileKey string
StartLine int64
StartColumn int64
StartOffset int64
EndOffset int64
Text string
}
CanonicalEvidence is one Evidence row of the definitive graph.
type CanonicalFile ¶
type CanonicalFile struct {
StableKey string
RepositoryKey string
PackageKey string
Path string
Language string
ContentHash string
Generated bool
}
CanonicalFile is one File row of the definitive graph.
type CanonicalGraph ¶
type CanonicalGraph struct {
SchemaVersion int
Metadata map[string]string
Repositories []CanonicalRepository
Packages []CanonicalPackage
Files []CanonicalFile
Symbols []CanonicalSymbol
Evidence []CanonicalEvidence
Edges []CanonicalEdge
Unresolved []CanonicalUnresolvedReference
}
CanonicalGraph is the whole definitive graph, read out of the database.
func ScanCanonical ¶
func ScanCanonical(ctx context.Context, path string) (CanonicalGraph, error)
ScanCanonical reports that the native build is required to read the definitive graph.
type CanonicalIntegrityReport ¶
type CanonicalIntegrityReport struct {
Findings []IntegrityFinding
Passed bool
}
CanonicalIntegrityReport is the verdict over every rule.
func VerifyCanonicalIntegrity ¶
func VerifyCanonicalIntegrity(ctx context.Context, path string) (CanonicalIntegrityReport, error)
VerifyCanonicalIntegrity reports that the native build is required for integrity verification.
func (CanonicalIntegrityReport) Finding ¶
func (report CanonicalIntegrityReport) Finding(rule IntegrityRule) (IntegrityFinding, bool)
Finding returns one rule's outcome.
func (CanonicalIntegrityReport) Violations ¶
func (report CanonicalIntegrityReport) Violations() int64
Violations returns the total across every rule.
type CanonicalLoadOptions ¶
type CanonicalLoadOptions struct {
// SnapshotID identifies the generation this load belongs to. It is
// stamped on every semantic edge as source_snapshot.
SnapshotID int64
// ResolverVersion identifies the resolver build that produced the facts.
ResolverVersion string
}
CanonicalLoadOptions carries the provenance stamped on every semantic edge.
type CanonicalMutationResult ¶
type CanonicalMutationResult struct {
RemovedFiles int64
RemovedSymbols int64
RemovedEvidence int64
RemovedEdges int64
UpsertedNodes int64
UpsertedEdges int64
}
CanonicalMutationResult accounts for what one ApplyCanonicalDelta call actually changed. Every field is a count read back from the queries that performed the change, never an estimate derived from the delta's own input sizes: Diff legitimately repeats an unchanged Repository or Package in Upsert (facts.Delta.Validate's doc comment), and re-applying an already-applied delta legitimately retires nothing the second time around, so "what the delta named" and "what actually moved" are different numbers -- this reports the second one.
func ApplyCanonicalDelta ¶
func ApplyCanonicalDelta(ctx context.Context, path string, _ facts.Delta, _ CanonicalLoadOptions) (CanonicalMutationResult, error)
ApplyCanonicalDelta reports that the native build is required to mutate the canonical graph.
type CanonicalPackage ¶
type CanonicalPackage struct {
StableKey string
RepositoryKey string
Language string
Name string
Version string
RootPath string
ManifestPath string
Container string
}
CanonicalPackage is one Package row of the definitive graph.
type CanonicalProbe ¶
type CanonicalProbe struct {
Name string
SymbolKey string
TargetKey string
EdgeTable string
MinRows int64
}
CanonicalProbe is one read executed against a freshly built graph.
type CanonicalProbeResult ¶
CanonicalProbeResult is the outcome of one probe.
func RunCanonicalProbes ¶
func RunCanonicalProbes(ctx context.Context, path string, _ []CanonicalProbe) ([]CanonicalProbeResult, error)
RunCanonicalProbes reports that the native build is required to run probes.
type CanonicalRepository ¶
type CanonicalRepository struct {
StableKey string
Name string
RootPath string
Commit string
Branch string
Dirty bool
Languages string
}
CanonicalRepository is one Repository row of the definitive graph.
type CanonicalSymbol ¶
type CanonicalSymbol struct {
StableKey string
CanonicalIdentity string
RepositoryKey string
PackageKey string
FileKey string
Language string
Name string
QualifiedName string
Kind string
Exported bool
Signature string
StartLine int64
StartColumn int64
StartOffset int64
EndLine int64
EndOffset int64
}
CanonicalSymbol is one Symbol row of the definitive graph.
type CanonicalUnresolvedReference ¶
type CanonicalUnresolvedReference struct {
StableKey string
RepositoryKey string
FileKey string
SourceSymbolKey string
Language string
RequestedPackage string
RequestedSymbol string
Reason string
Detail string
StartLine int64
StartColumn int64
StartOffset int64
}
CanonicalUnresolvedReference is one unresolved import/reference finding. It is kept outside CanonicalEdge because it has no symbol target.
type Config ¶
type Config struct {
BufferPoolSize uint64
MaxNumThreads uint64
EnableCompression bool
ReadOnly bool
MaxDatabaseSize uint64
}
Config controls the native LadybugDB database configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns conservative defaults for a writable database.
type Database ¶
type Database interface {
Close() error
Health(context.Context) error
OpenReader(context.Context) (Reader, error)
OpenWriter(context.Context) (Writer, error)
}
Database is the Kivgraph-owned abstraction over one LadybugDB database.
type Delta ¶
type Delta struct {
AddSymbols []Symbol
UpdateSymbols []Symbol
DeleteSymbolKeys []string
AddReferences []Reference
DeleteReferences []ReferenceKey
ReplaceOutgoing []OutgoingReplacement
}
Delta describes one atomic synthetic graph update.
type DiagnosticCheck ¶
type DiagnosticCheck struct {
Name string `json:"name"`
Status DiagnosticStatus `json:"status"`
Detail string `json:"detail"`
}
DiagnosticCheck is one independently reportable storage invariant.
type DiagnosticStatus ¶
type DiagnosticStatus string
const ( DiagnosticPass DiagnosticStatus = "PASS" DiagnosticFail DiagnosticStatus = "FAIL" DiagnosticSkip DiagnosticStatus = "SKIP" )
type FileRecord ¶
type IntegrityFinding ¶
type IntegrityFinding struct {
Rule IntegrityRule
Violations int64
Samples []IntegrityViolation
Passed bool
}
IntegrityFinding is the outcome of one rule over the whole graph.
type IntegrityRule ¶
type IntegrityRule string
IntegrityRule names one canonical graph invariant.
const ( // RuleExactEdgeWithoutSource: an exact confidence semantic edge whose // source node carries no declaring structural edge of its own. RuleExactEdgeWithoutSource IntegrityRule = "exact_edge_without_source" // RuleExactEdgeWithoutTarget mirrors RuleExactEdgeWithoutSource for the // target side of the same semantic edges. RuleExactEdgeWithoutTarget IntegrityRule = "exact_edge_without_target" // RuleMissingEvidenceFile: a semantic edge names an evidence_key whose // Evidence row is missing, or is not observed in any File. RuleMissingEvidenceFile IntegrityRule = "missing_evidence_file" // RuleDuplicateStableKey: the same stable_key is used by two different // node tables, which would collide in the HotSnapshot keyspace. RuleDuplicateStableKey IntegrityRule = "duplicate_stable_key" // RuleUnknownConfidence: an edge's confidence or provenance is not one // of the values facts declares, or claims exactness from a provenance // that cannot support it. RuleUnknownConfidence IntegrityRule = "unknown_confidence" // RuleInvalidRepositoryOwner: a node's repository_key does not match // the repository reachable by walking its containment chain, or names a // Repository that does not exist. RuleInvalidRepositoryOwner IntegrityRule = "invalid_repository_ownership" )
func CanonicalIntegrityRules ¶
func CanonicalIntegrityRules() []IntegrityRule
CanonicalIntegrityRules returns every rule, in evaluation order.
type IntegrityViolation ¶
type IntegrityViolation struct {
Rule IntegrityRule
Table string
Key string
Detail string
}
IntegrityViolation identifies one offending row.
type LoadReport ¶
type LoadReport struct {
Tables map[string]int64
Nodes int64
Edges int64
StagingMS float64
CopyMS float64
}
LoadReport records what a canonical load wrote.
func LoadCanonical ¶
func LoadCanonical(ctx context.Context, path string, _ facts.Set, _ CanonicalLoadOptions) (LoadReport, error)
LoadCanonical reports that the native build is required for a canonical load.
type Multiplicity ¶
type Multiplicity string
Multiplicity is the cardinality LadybugDB enforces on a relationship.
const ( // OneToMany is a containment relation: a child has a single parent. OneToMany Multiplicity = "ONE_MANY" // ManyToOne points many rows at a single owner. ManyToOne Multiplicity = "MANY_ONE" // ManyToMany is the default for semantic relations. ManyToMany Multiplicity = "MANY_MANY" )
type MutationResult ¶
type MutationResult struct {
AddedSymbols int `json:"added_symbols"`
UpdatedSymbols int `json:"updated_symbols"`
DeletedSymbols int `json:"deleted_symbols"`
AddedReferences int `json:"added_references"`
DeletedReferences int `json:"deleted_references"`
ReplacedSources int `json:"replaced_sources"`
}
MutationResult reports committed record changes.
type OutgoingReplacement ¶
OutgoingReplacement atomically replaces both semantic relationship kinds for one source.
type Reader ¶
type Reader interface {
Close() error
GetSymbol(context.Context, string) (Symbol, bool, error)
IncomingReferences(context.Context, string, int) ([]Reference, error)
OutgoingReferences(context.Context, string, int) ([]Reference, error)
TraverseOutgoing(context.Context, string, int, int) ([]TraversalNode, error)
ShortestPath(context.Context, string, string, int) (Path, bool, error)
IncomingReferencesByRepository(context.Context, string) ([]RepositoryReferenceCount, error)
ScanAll(context.Context) (ScanRows, error)
}
Reader owns one LadybugDB connection and its prepared read statements. A Reader is safe for concurrent use; calls on one Reader execute serially.
type Reference ¶
type Reference struct {
SourceKey string
TargetKey string
Kind string
EvidenceKind string
SourceFileKey string
TargetFileKey string
}
Reference is one exact persisted REFERENCES or CALLS_DIRECT relationship.
type ReferenceKey ¶
ReferenceKey identifies every persisted relationship of one kind between two symbols.
type RepositoryRecord ¶
type RepositoryReferenceCount ¶
RepositoryReferenceCount groups incoming relationships by source repository.
type ScanRows ¶
type ScanRows struct {
Repositories []RepositoryRecord
Files []FileRecord
Symbols []Symbol
Edges []ScanEdge
}
ScanRows contains every row from the synthetic graph schema in deterministic key order. Relationships retain their exact kind and evidence fields.
type SchemaKind ¶
type SchemaKind string
SchemaKind names which on-disk table layout a StorageDiagnosis was validated against. A PASS or FAIL on "schema", "counts" or "integrity" is not interpretable without knowing which of the two schemas kivgraph doctor storage measured them against, so every StorageDiagnosis declares one.
const ( // SchemaCanonical is the schema CanonicalNodeTables and // CanonicalRelationshipTables describe: the one LoadCanonical and // `kivgraph rebuild` write, identified by its GraphMetadata node table. SchemaCanonical SchemaKind = "canonical" // SchemaSynthetic is the frozen, hand written 001 schema the ladybug // benchmarks still build and validate against. SchemaSynthetic SchemaKind = "synthetic" // SchemaUnknown means the database was never opened far enough to // tell: native support is unavailable, or the file itself could not // be inspected. Never guessed as one of the other two. SchemaUnknown SchemaKind = "unknown" )
type SchemaNodeTable ¶
type SchemaNodeTable struct {
Name string
// PrimaryKey is always a durable key produced by Kivgraph, never a display
// name and never a database generated identifier.
PrimaryKey SchemaProperty
Properties []SchemaProperty
Comment string
}
SchemaNodeTable is one node table of the canonical schema.
func CanonicalNodeTables ¶
func CanonicalNodeTables() []SchemaNodeTable
CanonicalNodeTables returns the node tables in creation order.
type SchemaProperty ¶
type SchemaProperty struct {
Name string
Type string
// Comment documents why the property exists when it is not obvious.
Comment string
}
SchemaProperty is one column of a node or relationship table.
type SchemaRelationshipTable ¶
type SchemaRelationshipTable struct {
Name string
From string
To string
Multiplicity Multiplicity
Properties []SchemaProperty
Comment string
}
SchemaRelationshipTable is one relationship table of the canonical schema.
func CanonicalRelationshipTables ¶
func CanonicalRelationshipTables() []SchemaRelationshipTable
CanonicalRelationshipTables returns the relationship tables in creation order. Every semantic edge kind of the canonical model has exactly one table.
type StorageDiagnosis ¶
type StorageDiagnosis struct {
Path string `json:"path"`
SizeBytes int64 `json:"size_bytes"`
Mode string `json:"mode"`
Readable bool `json:"readable"`
Writable bool `json:"writable"`
GoBindingVersion string `json:"go_binding_version"`
EngineVersion string `json:"engine_version,omitempty"`
StorageVersion uint64 `json:"storage_version,omitempty"`
// Schema names which on-disk table layout the checks below actually
// validated: SchemaCanonical, SchemaSynthetic, or SchemaUnknown when
// the database was never opened. Set as soon as that is known, before
// the schema check itself runs, so a FAIL still says what it FAILed
// against.
Schema SchemaKind `json:"schema"`
// SchemaVersion is the schema_version GraphMetadata.value declares.
// Only meaningful when Schema is SchemaCanonical: the synthetic
// schema carries no version marker of its own, so this stays zero.
SchemaVersion int `json:"schema_version,omitempty"`
Tables map[string]string `json:"tables,omitempty"`
Counts map[string]int64 `json:"counts,omitempty"`
Checks []DiagnosticCheck `json:"checks"`
Healthy bool `json:"healthy"`
}
StorageDiagnosis is the complete result of `kivgraph doctor storage`.
func DiagnoseStorage ¶
func DiagnoseStorage(ctx context.Context, path string) (StorageDiagnosis, error)
DiagnoseStorage reports filesystem facts and native unavailability.
Schema stays SchemaUnknown for every diagnosis this build produces: with no native binding, the database is never opened, so the schema it actually stores can never be told apart from its absence. Guessing SchemaSynthetic or SchemaCanonical here would be worse than reporting nothing; newStorageDiagnosis already sets the honest default.
func (StorageDiagnosis) Check ¶
func (diagnosis StorageDiagnosis) Check(name string) (DiagnosticCheck, bool)
Check returns one named diagnostic result.
type Symbol ¶
type Symbol struct {
StableKey string
RepositoryKey string
FileKey string
Name string
QualifiedName string
Kind string
Signature string
StartLine int64
EndLine int64
}
Symbol is the persisted synthetic symbol shape returned by stable-key lookup.
type TraversalNode ¶
TraversalNode is one distinct semantic successor at its shortest depth.