type DataDirectory struct {
Path string
MaxBytes uint64
} Fields
Path | string | Path is the directory, which must exist. |
|---|---|---|
MaxBytes | uint64 | MaxBytes caps the bytes the files may take there, zero being unlimited. |
Ask your coding agent about this page, or add the docs server to it
curl -s 'https://www.unum.cloud/docs/ustore/go/quickstart.md' | claude -p "How would this fit my code?"The program opens a database in memory, writes a blob, a document and an edge in one transaction, and reads them back. Collections are created by name and modality before a transaction writes into them, and every read lands in an arena.
package main
import (
"errors"
"fmt"
"log"
ustore "github.com/unum-cloud/ustore/golang"
)
func main() {
database, err := ustore.DatabaseInitRam(nil)
if err != nil {
log.Fatal(err)
}
defer database.Close()
avatar, titanic := ustore.KeyFromUint64(1), ustore.KeyFromUint64(2)
posters, err := database.CollectionCreate("posters", ustore.ModalityBlobs)
if err != nil {
log.Fatal(err)
}
movies, err := database.CollectionCreate("movies", ustore.ModalityDocs)
if err != nil {
log.Fatal(err)
}
similar, err := database.CollectionCreate("similar", ustore.ModalityGraph)
if err != nil {
log.Fatal(err)
}
// One transaction writes a blob, a document and an edge, and commits all three or none.
transaction, err := database.TransactionInit()
if err != nil {
log.Fatal(err)
}
defer transaction.Close()
err = errors.Join(
transaction.BlobsWrite(posters, []ustore.Key{avatar}, ustore.TapeOf("\x89PNG"), nil),
transaction.DocsWrite(movies, []ustore.Key{avatar}, ustore.TapeOf(`{"title":"Avatar","year":2009}`), nil),
transaction.GraphWriteEdges(similar, []ustore.Edge{{Source: avatar, Target: titanic, ID: ustore.EdgeIDDefault}}, nil),
)
if err != nil {
log.Fatal(err)
}
if _, err := transaction.Commit(ustore.DurabilityBuffered); err != nil {
log.Fatal(err)
}
// Reads at the head see the commit: the poster, the year and the one edge leaving Avatar.
arena, err := ustore.NewArena(nil)
if err != nil {
log.Fatal(err)
}
defer arena.Close()
poster, err := database.BlobsRead(posters, []ustore.Key{avatar}, arena, nil)
if err != nil {
log.Fatal(err)
}
value, _ := poster.Get(0)
fmt.Printf("%q ", value)
movie, err := database.DocsRead(movies, []ustore.Key{avatar}, arena, &ustore.DocsReadConfig{Fields: ustore.TapeOf("year")})
if err != nil {
log.Fatal(err)
}
year, _ := movie.Get(0)
fmt.Printf("%s ", year)
edges, err := database.GraphReadEdges(similar, []ustore.Key{avatar}, ustore.VertexRoleSource, arena)
if err != nil {
log.Fatal(err)
}
fmt.Println(edges.Edges(0)[0].Target == titanic)
}golang/example_test.go compiles and runs this program on every go test.
DataDirectoryDataDirectory is a directory a database spreads its files over, with the bytes they may take in it.type DataDirectory struct {
Path string
MaxBytes uint64
} Path | string | Path is the directory, which must exist. |
|---|---|---|
MaxBytes | uint64 | MaxBytes caps the bytes the files may take there, zero being unlimited. |
DatabaseInitRamConfigDatabaseInitRamConfig carries the optional arguments of DatabaseInitRam and DatabaseOpenRam.type DatabaseInitRamConfig struct {
Executor *Executor
Isolation Isolation
CPUClassCeiling CPUClass
MemoryLimit uint64
CommitConflictsLimit uint64
} Executor | *Executor | Executor runs the open, nil the calling goroutine. |
|---|---|---|
Isolation | Isolation | Isolation is how transactions see each other's writes. |
CPUClassCeiling | CPUClass | CPUClassCeiling is the newest class the database's kernels may run as; zero sets no ceiling. |
MemoryLimit | uint64 | MemoryLimit caps the bytes of keys and values the database holds, past which a write answers StatusCapacityExhausted; zero takes 16 GiB. |
CommitConflictsLimit | uint64 | CommitConflictsLimit is the conflicts a commit of the database's own absorbs before it answers StatusWriteConflict; zero derives 12 per logical core. |
DatabaseOpenLeveldbConfigDatabaseOpenLeveldbConfig carries the optional arguments of DatabaseOpenLeveldb.type DatabaseOpenLeveldbConfig struct {
Executor *Executor
MemoryLimit uint64
BackgroundThreads uint64
} Executor | *Executor | Executor runs the open, nil the calling goroutine. |
|---|---|---|
MemoryLimit | uint64 | MemoryLimit caps the host memory the engine caches and buffers in, a quarter for the block cache and a quarter for the write buffer; zero takes 1 GiB. |
BackgroundThreads | uint64 | BackgroundThreads is zero or one, as LevelDB compacts on one thread, and more answers StatusUnsupported. |
DatabaseOpenNvmeConfigDatabaseOpenNvmeConfig carries the optional arguments of DatabaseOpenNvme, where every zero size or count keeps the engine's default.type DatabaseOpenNvmeConfig struct {
Executor *Executor
DataDirectories []DataDirectory
Compactions *Executor
MemoryLimit uint64
TransactionMaxBytes uint64
TransactionMaxDeltas uint64
CollectionConcurrencyLimit uint64
CollectionCacheLimit uint64
CollectionMemoryRunsMaxBytes uint64
CollectionMemoryRunsMaxDeltas uint64
CollectionLevelEnlargeFactor uint64
CollectionValueSize uint64
CollectionValueMaxSize uint64
CPUClassCeiling CPUClass
CommitConflictsLimit uint64
} Executor | *Executor | Executor runs the open, nil the calling goroutine; an NVMe executor moves the bytes. |
|---|---|---|
DataDirectories | []DataDirectory | DataDirectories spread the volumes beyond the directory. |
Compactions | *Executor | Compactions is the executor merges run on. |
MemoryLimit | uint64 | MemoryLimit caps the bytes the engine keeps in memory. |
TransactionMaxBytes | uint64 | TransactionMaxBytes caps the bytes one transaction buffers. |
TransactionMaxDeltas | uint64 | TransactionMaxDeltas caps the changes one transaction buffers. |
CollectionConcurrencyLimit | uint64 | CollectionConcurrencyLimit caps the calls one collection serves at once. |
CollectionCacheLimit | uint64 | CollectionCacheLimit caps the bytes one collection caches. |
CollectionMemoryRunsMaxBytes | uint64 | CollectionMemoryRunsMaxBytes caps the bytes of one collection's memory runs. |
CollectionMemoryRunsMaxDeltas | uint64 | CollectionMemoryRunsMaxDeltas caps the changes of one collection's memory runs. |
CollectionLevelEnlargeFactor | uint64 | CollectionLevelEnlargeFactor is how much larger each level grows than the one above it. |
CollectionValueSize | uint64 | CollectionValueSize is the value size the collections are tuned for. |
CollectionValueMaxSize | uint64 | CollectionValueMaxSize caps the size of one value. |
CPUClassCeiling | CPUClass | CPUClassCeiling is the newest class the database's kernels may run as; zero sets no ceiling. |
CommitConflictsLimit | uint64 | CommitConflictsLimit is the conflicts a commit of the database's own absorbs before it answers StatusWriteConflict; zero derives 12 per logical core. |
DatabaseOpenRocksdbConfigDatabaseOpenRocksdbConfig carries the optional arguments of DatabaseOpenRocksdb and DatabaseViewRocksdb.type DatabaseOpenRocksdbConfig struct {
Executor *Executor
DataDirectories []DataDirectory
MemoryLimit uint64
BackgroundThreads uint64
} Executor | *Executor | Executor runs the open, nil the calling goroutine. |
|---|---|---|
DataDirectories | []DataDirectory | DataDirectories spread the files beyond the directory. |
MemoryLimit | uint64 | MemoryLimit caps the host memory the engine caches and buffers in, a quarter for one block cache and a quarter for one write buffer manager; zero takes 1 GiB. |
BackgroundThreads | uint64 | BackgroundThreads sizes the pool the database owns for its flushes and compactions; zero takes 2. |
DatabaseViewNvmeConfigDatabaseViewNvmeConfig carries the optional arguments of DatabaseViewNvme, where every zero size keeps the engine's default.type DatabaseViewNvmeConfig struct {
Executor *Executor
DataDirectories []DataDirectory
MemoryLimit uint64
CollectionConcurrencyLimit uint64
CollectionCacheLimit uint64
CPUClassCeiling CPUClass
} Executor | *Executor | Executor runs the open, nil the calling goroutine; an NVMe executor moves the bytes. |
|---|---|---|
DataDirectories | []DataDirectory | DataDirectories are the volumes beyond the directory, as the database was opened with. |
MemoryLimit | uint64 | MemoryLimit caps the bytes the engine keeps in memory. |
CollectionConcurrencyLimit | uint64 | CollectionConcurrencyLimit caps the calls one collection serves at once. |
CollectionCacheLimit | uint64 | CollectionCacheLimit caps the bytes one collection caches. |
CPUClassCeiling | CPUClass | CPUClassCeiling is the newest class the database's kernels may run as; zero sets no ceiling. |
NvmeOptionsNvmeOptions is how the threads of an NVMe executor move bytes between the drives and memory, where every zero size or count keeps the engine's default.type NvmeOptions struct {
Transport Transport
QueueDepth uint64
RequestBufferBytes uint64
RequestBuffersCount uint64
StreamBufferBytes uint64
StreamBuffersCount uint64
Paths []string
} Transport | Transport | Transport is how bytes move between the files and memory. |
|---|---|---|
QueueDepth | uint64 | QueueDepth counts the submissions a channel holds at once. |
RequestBufferBytes | uint64 | RequestBufferBytes sizes each request buffer of a channel. |
RequestBuffersCount | uint64 | RequestBuffersCount counts the request buffers of each channel. |
StreamBufferBytes | uint64 | StreamBufferBytes sizes each streaming buffer of a channel. |
StreamBuffersCount | uint64 | StreamBuffersCount counts the streaming buffers of each channel. |
Paths | []string | Paths are the data directories, raw media or SPDK namespaces of the databases the executor will open, read only during the call: the memory domain they share places the threads when no memory domain is named, and their fewest hardware queues give the default thread count. |
DatabaseDeferredOnDatabaseDeferredOn is the receiver whose verbs submit their calls to an executor and answer a Deferred, offering the verbs of DatabaseOn with the same arguments.21type DatabaseDeferredOn struct {
// contains filtered or unexported fields
} The library reads a deferred call's inputs until the call is final, so the slices a verb is handed must not change until then; the caller keeps its arena until then, as for a blocking verb.
*× 4Clear submits DatabaseOn.Clear.func (on DatabaseDeferredOn) Clear(
mode DropMode,
) (*Deferred[struct{}], error) | Symbol |
|---|
Clear |
Compact |
Describe |
Flush |
CollectionCreateCollectionCreate submits DatabaseOn.CollectionCreate.func (on DatabaseDeferredOn) CollectionCreate(
name string,
modality Modality,
) (*Deferred[CollectionID], error) CollectionDropCollectionDrop submits DatabaseOn.CollectionDrop.func (on DatabaseDeferredOn) CollectionDrop(
collection CollectionID,
mode DropMode,
) (*Deferred[struct{}], error) CompactPlanFinishCompactPlanFinish submits DatabaseOn.CompactPlanFinish.func (on DatabaseDeferredOn) CompactPlanFinish(
plan *CompactPlan,
) (*Deferred[struct{}], error) BlobsRemoveBlobsRemove submits DatabaseOn.BlobsRemove.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) BlobsRemove(
collections Collections,
keys []Key,
config *RemoveConfig,
) (*Deferred[struct{}], error) BlobsWriteBlobsWrite submits DatabaseOn.BlobsWrite.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) BlobsWrite(
collections Collections,
keys []Key,
values Tape,
config *WriteConfig,
) (*Deferred[struct{}], error) DocsRemoveDocsRemove submits DatabaseOn.DocsRemove.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) DocsRemove(
collections Collections,
keys []Key,
config *RemoveConfig,
) (*Deferred[struct{}], error) DocsWriteDocsWrite submits DatabaseOn.DocsWrite.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) DocsWrite(
collections Collections,
keys []Key,
values Tape,
config *DocsWriteConfig,
) (*Deferred[struct{}], error) GraphRemoveEdgesGraphRemoveEdges submits DatabaseOn.GraphRemoveEdges.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) GraphRemoveEdges(
collections Collections,
edges []Edge,
config *WriteConfig,
) (*Deferred[struct{}], error) GraphRemoveVerticesGraphRemoveVertices submits DatabaseOn.GraphRemoveVertices.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) GraphRemoveVertices(
collections Collections,
vertices []Key,
config *GraphRemoveVerticesConfig,
) (*Deferred[struct{}], error) GraphWriteEdgesGraphWriteEdges submits DatabaseOn.GraphWriteEdges.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) GraphWriteEdges(
collections Collections,
edges []Edge,
config *WriteConfig,
) (*Deferred[struct{}], error) GraphWriteVerticesGraphWriteVertices submits DatabaseOn.GraphWriteVertices.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) GraphWriteVertices(
collections Collections,
vertices []Key,
config *WriteConfig,
) (*Deferred[struct{}], error) PagesImportPagesImport submits DatabaseOn.PagesImport.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesImport(
collections Collections,
keys []Key,
values Tape,
config *PagesImportConfig,
) (*Deferred[struct{}], error) PagesInsertPagesInsert submits DatabaseOn.PagesInsert.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesInsert(
collections Collections,
keys []Key,
values Tape,
arena *Arena,
config *PagesInsertConfig,
) (*Deferred[Inserted], error) PagesMovePagesMove submits DatabaseOn.PagesMove.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesMove(
collections Collections,
keys, elements []Key,
config *PagesMoveConfig,
) (*Deferred[struct{}], error) PagesRemovePagesRemove submits DatabaseOn.PagesRemove.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesRemove(
collections Collections,
keys []Key,
config *PagesRemoveConfig,
) (*Deferred[struct{}], error) PagesRemoveAttributesPagesRemoveAttributes submits DatabaseOn.PagesRemoveAttributes.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesRemoveAttributes(
collections Collections,
keys, elements []Key,
fields Tape,
config *WriteConfig,
) (*Deferred[struct{}], error) PagesSetAttributesPagesSetAttributes submits DatabaseOn.PagesSetAttributes.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesSetAttributes(
collections Collections,
keys, elements []Key,
fields, values Tape,
config *WriteConfig,
) (*Deferred[struct{}], error) PagesSplicePagesSplice submits DatabaseOn.PagesSplice.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) PagesSplice(
collections Collections,
keys, elements []Key,
textStarts, textLengths []uint64,
values Tape,
config *WriteConfig,
) (*Deferred[struct{}], error) StringsRemoveStringsRemove submits DatabaseOn.StringsRemove.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) StringsRemove(
collections Collections,
strings Tape,
config *StringsRemoveConfig,
) (*Deferred[struct{}], error) StringsWriteStringsWrite submits DatabaseOn.StringsWrite.Inherited from deferredWrites[Handle]
func (on DatabaseDeferredOn) StringsWrite(
collections Collections,
strings Tape,
values []Key,
config *WriteConfig,
) (*Deferred[struct{}], error) EngineEngine is the engine serving a database.2type Engine int32 EngineRam | EngineRam keeps everything in memory, imaged into a directory on demand. | |
|---|---|---|
EngineRocksDB | EngineRocksDB serves a RocksDB directory. | |
EngineLevelDB | EngineLevelDB serves a LevelDB directory. | |
EngineNvme | EngineNvme is the in-tree NVMe engine. |
EngineFromNameEngineFromName reads an engine back from the spelling Engine.String renders.func EngineFromName(name string) (Engine, error) StringString renders the engine as the library spells it.func (engine Engine) String() string