type Admission int32 Values
Reject | Reject passes over the key. | |
|---|---|---|
Admit | Admit keeps the key among the listed ones. |
Ask your coding agent about this page, or add the docs server to it
curl -s 'https://www.unum.cloud/docs/ustore/go/scans.md' | claude -p "How would this fit my code?"Scans, samples and measures run one task per collection their Collections names, from a start key, inclusive, towards an end key, exclusive, in a ScanDirection. BlobsScan lists up to the count it wants, BlobsSample draws keys at random, and BlobsMeasure bounds the keys and bytes a range holds without walking it; DocsScan, PagesScan, StringsScan and GraphScanVertices serve the other modalities.
A start key of Key{} walks up from the first key, and KeyUnknown walks down from the last.
A cursor walks one collection page by page, each pull resuming past the last key the one before it handed out, and a page shorter than wanted exhausts it for good. ChangesCursorInit opens a feed of the changes committed after a CommitStamp, oldest first, pinning that stamp as a snapshot does.
A cursor keeps no executor: cursor.NextPairs(..) pulls on the calling goroutine, and cursor.On(executor).NextPairs(..) blocks on the executor named for that pull.
A DocsCursor gathers the Fields of its config into typed columns, and its Next answers DocsBatches, one batch of keys and columns per executor task that found rows, none once the walk is exhausted.
first, err := database.BlobsScan(people, 100, arena, nil)
measured, err := database.BlobsMeasure(people, arena, &ustore.MeasureConfig{StartKeys: []ustore.Key{ada}, EndKeys: []ustore.Key{kent}})
last, err := database.BlobsScan(people, 10, arena, &ustore.BlobsScanConfig{
StartKeys: []ustore.Key{ustore.KeyUnknown}, Direction: ustore.ScanDescending,
})
cursor, err := database.On(executor).BlobsCursorInit(people, ustore.Key{}, nil)
defer cursor.Close()
for {
page, err := cursor.On(executor).NextPairs(1024, arena)
if err != nil || page.Len() < 1024 {
break
}
}
ages, err := database.DocsCursorInit(people, ustore.Key{}, &ustore.DocsCursorConfig{
Fields: ustore.TapeOf("age"), ColumnsTypes: []ustore.DocsFieldType{ustore.DocsFieldTypeU64},
})
defer ages.Close()
batches, err := ages.On(executor).Next(1024, arena) // batches.Keys(i) and batches.Columns(i) per batchThe configs of Compact, Save, PagesImport and the scans carry an optional ProgressCallback, called with the units finished and the units in all, never on two threads at once and never after the call is final.
Answering false cancels the call, which fails with StatusCancelled and publishes nothing, a cancelled save removing what it wrote.
A handler must not panic, since unwinding through the library’s C frames aborts the process.
deadline := time.Now().Add(30 * time.Second)
beforeTheDeadline := func(finished, total uint64) bool { return time.Now().Before(deadline) }
err := snapshot.Save("/var/lib/people-copy", beforeTheDeadline)
if errors.Is(err, ustore.StatusCancelled) {
fmt.Println("the copy was removed")
}The Predicate field of a scan or cursor config admits or passes over the keys it lists, asked on the host, and its type tells the library what one call costs:
ustore.Predicate answers one key at a time, asked before patterns or filters read any value.ustore.BatchPredicate answers a page of keys at once, asked about the keys patterns and filters kept, for handlers that pay per call.ustore.CheapBatchPredicate answers a page of keys at once, asked before patterns or filters read any value.odd := ustore.Predicate(func(key ustore.Key) bool { return key[15]%2 == 1 })
found, err := database.BlobsScan(people, 10, arena, &ustore.BlobsScanConfig{Predicate: odd})
moderated := ustore.BatchPredicate(func(keys []ustore.Key, admissions []ustore.Admission) {
for position, allowed := range moderation.Check(keys) { // one round trip for the whole page
if allowed {
admissions[position] = ustore.Admit
}
}
})
found, err = database.BlobsScan(people, 10, arena, &ustore.BlobsScanConfig{Predicate: moderated})Admissions start as ustore.Reject, and both slices live only until the handler returns.
AdmissionAdmission is whether a predicate keeps a listed key or passes over it.type Admission int32 Reject | Reject passes over the key. | |
|---|---|---|
Admit | Admit keeps the key among the listed ones. |
AdmitterAdmitter is the predicate a scan or a cursor asks about the keys it lists: a Predicate, a BatchPredicate or a CheapBatchPredicate, whose type tells the library what one call costs.type Admitter interface {
// contains filtered or unexported methods
} BatchPredicateBatchPredicate writes an Admission for every key into admissions, which start as Reject, for handlers that pay per call: it is asked once per page about every key patterns and filters kept.type BatchPredicate func(keys []Key, admissions []Admission) Both slices live only until it returns. The executor's threads may ask it at once, so it must be safe to call from several goroutines concurrently, and it must not panic.
BlobsCursorConfigBlobsCursorConfig carries the optional arguments of DatabaseOn.BlobsCursorInit.type BlobsCursorConfig struct {
EndKey *Key
Direction ScanDirection
Patterns Patterns
Predicate Admitter
} EndKey | *Key | EndKey is the key the walk stops before, or nil for no bound. |
|---|---|---|
Direction | ScanDirection | Direction is which way the walk goes from its start. |
Patterns | Patterns | Patterns keep the keys whose values match, compiled once. |
Predicate | Admitter | Predicate admits or passes over the keys of every page. |
CheapBatchPredicateCheapBatchPredicate is a BatchPredicate asked once per page before patterns or filters read any value, so it narrows those reads.type CheapBatchPredicate func(keys []Key, admissions []Admission) DocsCursorConfigDocsCursorConfig carries the optional arguments of DatabaseOn.DocsCursorInit.type DocsCursorConfig struct {
EndKey *Key
Direction ScanDirection
Filter string
Predicate Admitter
Fields Tape
ColumnsTypes []DocsFieldType
} EndKey | *Key | EndKey is the key the walk stops before, or nil for no bound. |
|---|---|---|
Direction | ScanDirection | Direction is which way the walk goes from its start. |
Filter | string | Filter is a JSONPath every document the walk hands out matches, compiled once. |
Predicate | Admitter | Predicate admits or passes over the keys of every page. |
Fields | Tape | Fields are the fields every pull gathers into the columns of its batches, the empty field being the whole document, or none for keys alone. |
ColumnsTypes | []DocsFieldType | ColumnsTypes holds the type every field converts into, one per field. |
DocsScanConfigDocsScanConfig carries the optional arguments of DatabaseOn.DocsScan.type DocsScanConfig struct {
StartKeys []Key
EndKeys []Key
Direction ScanDirection
Filter string
Predicate Admitter
Mode ScanMode
Progress ProgressCallback
} StartKeys | []Key | StartKeys are the inclusive starts of the scans, one per task, or the first key in Direction when empty. |
|---|---|---|
EndKeys | []Key | EndKeys are the keys every scan stops before, one per task, or no bound when empty. |
Direction | ScanDirection | Direction is which way every scan goes from its start. |
Filter | string | Filter is a JSONPath, or a bare root filter such as ?@.age>30, every listed document matches. |
Predicate | Admitter | Predicate admits or passes over the listed keys. |
Mode | ScanMode | Mode is in what order the keys come. |
Progress | ProgressCallback | Progress reports the scans finished, and may cancel the call. |
EachEach names one collection per task of a batch.type Each []CollectionID MeasureConfigMeasureConfig carries the optional arguments of a measure.type MeasureConfig struct {
StartKeys []Key
EndKeys []Key
Direction ScanDirection
} StartKeys | []Key | StartKeys are the inclusive starts of the ranges, one per task, or the first key in Direction when empty. |
|---|---|---|
EndKeys | []Key | EndKeys are the keys every range stops before, one per task, or no bound when empty. |
Direction | ScanDirection | Direction is which way every range goes from its start. |
MeasuredMeasured is the bounds on the entries and the space one range holds.type Measured struct {
MinCardinality, MaxCardinality uint64
MinValueBytes, MaxValueBytes uint64
MinSpaceUsage, MaxSpaceUsage uint64
} PagesCursorConfigPagesCursorConfig carries the optional arguments of DatabaseOn.PagesCursorInit.type PagesCursorConfig struct {
EndKey *Key
Direction ScanDirection
Filter string
Predicate Admitter
} EndKey | *Key | EndKey is the key the walk stops before, or nil for no bound. |
|---|---|---|
Direction | ScanDirection | Direction is which way the walk goes from its start. |
Filter | string | Filter is the expression every page the walk hands out matches, compiled once. |
Predicate | Admitter | Predicate admits or passes over the keys of every page. |
PatternsPatterns keeps the values or strings a scan or a walk lists to the ones matching, shared by every task of the call; the zero value matches everything.type Patterns struct {
Patterns Tape
Kind PatternKind
Sensitivity CaseSensitivity
Weights []float32
} Patterns | Tape | Patterns are the expressions or substrings to match. |
|---|---|---|
Kind | PatternKind | Kind is what the patterns are matched as. |
Sensitivity | CaseSensitivity | Sensitivity is whether matching folds case. |
Weights | []float32 | Weights holds one weight per substring pattern, which turns on BM25 scores, or nothing. |
PredicatePredicate admits one listed key into a scan or a walk, or passes over it, asked once per page before patterns or filters read any value.type Predicate func(key Key) bool The executor's threads may ask it at once, so it must be safe to call from several goroutines concurrently, and it must not panic.
CaseSensitivityCaseSensitivity is whether patterns compare bytes as they are or after Unicode case folding.2type CaseSensitivity int32 Cased | Cased compares bytes as they are. | |
|---|---|---|
Uncased | Uncased folds the case of both the patterns and the values. |
CaseSensitivityFromNameCaseSensitivityFromName reads a case sensitivity back from the spelling CaseSensitivity.String renders.func CaseSensitivityFromName(name string) (CaseSensitivity, error) StringString renders the case sensitivity as the library spells it.func (sensitivity CaseSensitivity) String() string ChangeKindChangeKind is what one committed change did to its key.2type ChangeKind int32 ChangeWrite | ChangeWrite wrote the whole value. | |
|---|---|---|
ChangeRemoval | ChangeRemoval removed the key. | |
ChangeChange | ChangeChange changed part of the value, as a document patch or a page edit does. |
ChangeKindFromNameChangeKindFromName reads a change kind back from the spelling ChangeKind.String renders.func ChangeKindFromName(name string) (ChangeKind, error) StringString renders the change kind as the library spells it.func (kind ChangeKind) String() string ChangesChanges is one pull of a feed, written into its arena and readable until the arena serves another call.5type Changes struct {
// contains filtered or unexported fields
} KeyKey reports the key change index touched.func (changes Changes) Key(index uint) Key KindKind reports what change index did to its key.func (changes Changes) Kind(index uint) ChangeKind LenLen reports how many changes the pull yielded, zero at the newest commit.func (changes Changes) Len() uint StampStamp reports the commit change index landed at.func (changes Changes) Stamp(index uint) CommitStamp ValueValue views the bytes change index carries in the arena, empty for a removal and for a pull through ChangesCursor.NextKeys.func (changes Changes) Value(index uint) []byte MeasurementMeasurement is the bounds a measure estimated, one per range, readable until the arena serves another call.2type Measurement struct {
// contains filtered or unexported fields
} GetGet reports the bounds of range index.func (measurement Measurement) Get(index uint) Measured LenLen reports how many ranges the call measured.func (measurement Measurement) Len() uint PagePage is one pull of a walk, written into its arena and readable until the arena serves another call.3type Page struct {
// contains filtered or unexported fields
} KeysKeys views the keys of the page in the arena.func (page Page) Keys() []Key LenLen reports how many keys the pull handed out; fewer than wanted exhausts the walk for good.func (page Page) Len() uint ValuesValues views the values of the page in the arena, one per key, empty for a keys-only pull.func (page Page) Values() Strings PatternKindPatternKind is what the strings of Patterns are matched as.2type PatternKind int32 PatternRegex | PatternRegex matches regular expressions, of which a value matches at least one somewhere. | |
|---|---|---|
PatternSubstrings | PatternSubstrings matches literal substrings, found together through Aho-Corasick. |
PatternKindFromNamePatternKindFromName reads a pattern kind back from the spelling PatternKind.String renders.func PatternKindFromName(name string) (PatternKind, error) StringString renders the pattern kind as the library spells it.func (kind PatternKind) String() string ScanDirectionScanDirection is which way a scan, a walk or a measure goes from its start key.2type ScanDirection int32 ScanAscending | ScanAscending walks up from the start key, the default. | |
|---|---|---|
ScanDescending | ScanDescending walks down from the start key. |
ScanDirectionFromNameScanDirectionFromName reads a direction back from the spelling ScanDirection.String renders.func ScanDirectionFromName(name string) (ScanDirection, error) StringString renders the direction as the library spells it.func (direction ScanDirection) String() string ScanModeScanMode is in what order a scan hands its keys over.2type ScanMode int32 ScanOrdered | ScanOrdered hands keys over in their order. | |
|---|---|---|
ScanUnordered | ScanUnordered hands keys over in any order, as fast as the engine finds them. |
ScanModeFromNameScanModeFromName reads a scan mode back from the spelling ScanMode.String renders.func ScanModeFromName(name string) (ScanMode, error) StringString renders the scan mode as the library spells it.func (mode ScanMode) String() string ScannedScanned is what a batch of scans or samples wrote into its arena, keys scan after scan, readable until the arena serves another call.3type Scanned struct {
// contains filtered or unexported fields
} KeysKeys views the keys scan task found in the arena.func (scanned Scanned) Keys(task uint) []Key LenLen reports how many scans or samples the call ran.func (scanned Scanned) Len() uint ScoresScores views the BM25 score of every key scan task found, and nothing unless the patterns carried weights.func (scanned Scanned) Scores(task uint) []float32