Documentation ¶
Index ¶
- Constants
- Variables
- type CompressionType
- type Cursor
- type Database
- type DatabaseConfig
- type Document
- func (d *Document) Destroy() error
- func (s *Document) Free()
- func (s *Document) Get(path string, size *int) unsafe.Pointer
- func (s *Document) GetInt(path string) int64
- func (s *Document) GetObject(path string) unsafe.Pointer
- func (s *Document) GetString(path string, size *int) string
- func (s *Document) IsEmpty() bool
- func (s *Document) Set(path string, val interface{}) bool
- func (s *Document) SetInt(path string, val int64) bool
- func (s *Document) SetString(path, val string) bool
- type Environment
- func (env *Environment) BeginTx() (*Transaction, error)
- func (env *Environment) Close() error
- func (env *Environment) Error() error
- func (s *Environment) Free()
- func (s *Environment) Get(path string, size *int) unsafe.Pointer
- func (s *Environment) GetInt(path string) int64
- func (s *Environment) GetObject(path string) unsafe.Pointer
- func (s *Environment) GetString(path string, size *int) string
- func (s *Environment) IsEmpty() bool
- func (env *Environment) NewDatabase(config DatabaseConfig) (*Database, error)
- func (env *Environment) Open() error
- func (s *Environment) Set(path string, val interface{}) bool
- func (s *Environment) SetInt(path string, val int64) bool
- func (s *Environment) SetString(path, val string) bool
- type FieldType
- type Order
- type Schema
- type Transaction
- type TxStatus
- type UpsertFunc
Constants ¶
const ( // CursorPrefix uses for setting cursor prefix CursorPrefix = "prefix" // CursorOrder uses for setting cursor order CursorOrder = "order" )
const EnvironmentPath = "sophia.path"
Variables ¶
var ErrCursorClosed = errors.New("usage of closed Cursor")
ErrCursorClosed will be returned in case of closed cursor usage
var ErrEnvironmentClosed = errors.New("usage of closed environment")
var ErrNotFound = errors.New("document not found")
ErrNotFound error constant for 'NotFount' cases
Functions ¶
This section is empty.
Types ¶
type CompressionType ¶
type CompressionType byte
CompressionType type of compression for content
const ( CompressionTypeNone CompressionType = iota CompressionTypeLZ4 CompressionTypeZSTD )
CompressionType constants for different types of compression
func (CompressionType) String ¶
func (t CompressionType) String() string
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor iterates over key-values in a database.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is used for accessing a database. Take it's name from sophia. Usually object with same features is called 'table'.
func (*Database) Document ¶
Document creates a Document for a single or multi-statement transactions
type DatabaseConfig ¶
type DatabaseConfig struct { // Name of database. // It will be used to set and get values specific to this base. Name string // Schema of database. // It is used to describe the keys and values that will be stored in the database. Schema *Schema // CacheSize precalculated memory usage (cache size) for expected storage capacity and write rates. // See more http://sophia.systems/v2.2/admin/memory_requirements.html CompactionCacheSize int64 // CompactionNodeSize set a node file size in bytes. // Node file can grow up to two times the size before the old node file is being split. CompactionNodeSize int64 // CompactionNodeSize set size of a page to use. CompactionPageSize int64 // CompactionPageChecksum check checksum during compaction. DisableCompactionPageChecksum bool // CompactionExpirePeriod set expire check process period in seconds. CompactionExpirePeriod int64 // CompactionGcWm when this value reaches a compaction, operation is scheduled. // Garbage collection starts when watermark value reaches a certain percent of duplicates. CompactionGCWatermark int64 // CompactionGCPeriod run check for a gc every CompactionGCPeriod seconds. CompactionGCPeriod int64 // DisableMmapMode can be set to disable mmap mode. // By default Sophia uses pread(2) to read data from disk. // Using mmap mode, Sophia handles all requests by directly accessing memory-mapped node files memory. // // It is a good idea to try this mode, even if your dataset is rather small // or you need to handle a large ratio of read request with a predictable pattern. // // Disadvantage of mmap mode, in comparison to RAM Storage, // is a possible unpredictable latency behaviour and a OS cache warmup period after recovery. DisableMmapMode bool // DirectIO can be set to enable O_DIRECT to see what actual read // performance might be, if we avoid using file system cache. // // When a database size is lower then RAM, it probably sits in file system cache and all operations do very little actual IO. // In some sense, when a database grows in size load scenario might change from from CPU bound to IO bound. // It is possible to set DirectIO=true and MmapMode=false to get it. // DirectIO=true and MmapMode=true will cause panic. DirectIO bool // DisableSync can be set to disable sync node file on compaction completion. DisableSync bool // Expire can be set to enable or disable key expire. Expire bool // Compression specify compression driver. Supported: lz4, zstd, none (default). Compression CompressionType // Upsert is a function that will be called on every upsert operation. // If it was not set during the configuration database, upsert operation will not be available Upsert UpsertFunc // UpsertArg an argument which is additionally passed every call UpsertArg interface{} }
DatabaseConfig a structure for the description of the database to be created.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a representation of a row in a database. Destroy should be called after Document usage.
func (*Document) Destroy ¶
Destroy call C function that releases all resources associated with the Document
func (*Document) Free ¶
func (s *Document) Free()
Free frees allocated memory for all C variables, that were in this store This always should be called to prevent memory leaks
func (*Document) GetString ¶
GetString returns string without extra allocations. We can use C pointer to string to make Go string without allocation. C memory will be freed on Document Destroy() call. So for long-term usage you should to make copy of string to avoid data corruption.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment is used to configure the database before opening. Take it's name from sophia Usually object with same features are called 'database'
func NewEnvironment ¶
func NewEnvironment() (*Environment, error)
NewEnvironment creates a new environment for opening a database. Receivers must call Close() on the returned Environment.
func (*Environment) BeginTx ¶
func (env *Environment) BeginTx() (*Transaction, error)
BeginTx starts an Transaction Commit() or Rollback() should be called to release resources.
func (*Environment) Close ¶
func (env *Environment) Close() error
Close closes the environment and frees its associated memory. You must call Close on any Environment created with NewEnvironment.
func (*Environment) Free ¶
func (s *Environment) Free()
Free frees allocated memory for all C variables, that were in this store This always should be called to prevent memory leaks
func (*Environment) GetString ¶
GetString returns string without extra allocations. We can use C pointer to string to make Go string without allocation. C memory will be freed on Document Destroy() call. So for long-term usage you should to make copy of string to avoid data corruption.
func (*Environment) NewDatabase ¶
func (env *Environment) NewDatabase(config DatabaseConfig) (*Database, error)
NewDatabase creates new database in environment with given configuration. At least database's name should be defined. Another options aren't required. Database configuration can't be changed after Environment's Open() was called.
func (*Environment) Open ¶
func (env *Environment) Open() error
Open opens environment At a minimum path must be specified and one db declared
type FieldType ¶
type FieldType byte
FieldType type of key or value in a row
type Order ¶
type Order string
Order string type of sophia cursor order
const ( GreaterThan Order = ">" GT Order = GreaterThan GreaterThanEqual Order = ">=" GTE Order = GreaterThanEqual LessThan Order = "<" LT Order = LessThan LessThanEqual Order = "<=" LTE Order = LessThanEqual )
Constants for sophia cursor order They are used while creating cursor to select it's direction
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is a structure for configuring fields which record will contain
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction multi-statement transaction is automatically processed when Set(), Delete(), Upsert(), Get() are used on a transactional object. The BeginTx() function is used to start a multi-statement transaction. During transaction, no updates are written to the database files until a Commit() is called. On commit, all modifications that were made are written to the log file in a single batch. To discard any changes made during transaction operation, Rollback() function should be used. No nested transactions are supported. There are no limit on a number of concurrent transactions. Any number of databases can be involved in a multi-statement transaction.
func (*Transaction) Commit ¶
func (tx *Transaction) Commit() TxStatus
Commit commits the transaction and returns it's status. Any error happened during multi-statement transaction does not rollback a transaction.
func (*Transaction) Rollback ¶
func (tx *Transaction) Rollback() error
Rollback rollbacks transaction and destroy transaction object.
type TxStatus ¶
type TxStatus int
TxStatus transactional status
const ( // TxError means that transaction has been completed with error TxError TxStatus = -1 // TxOk means that transaction has been completed TxOk TxStatus = 0 // TxRollback status means that transaction has been rollbacked by another concurrent transaction TxRollback TxStatus = 1 // TxLock status means that transaction is not finished and waiting for concurrent transaction to complete. // In that case commit should be retried later or transaction can be rollbacked. TxLock TxStatus = 2 )
type UpsertFunc ¶
type UpsertFunc func(count int, src []unsafe.Pointer, srcSize []uint32, upsert []unsafe.Pointer, upsertSize []uint32, result []unsafe.Pointer, resultSize []uint32, arg unsafe.Pointer) int
UpsertFunc golang equivalent of upsert_callback. Should return 0 in case of success, otherwise -1.