Documentation
¶
Index ¶
- type Batch
- type DB
- func (db *DB) Del(ctx context.Context, key multiraftbase.Key) error
- func (db *DB) Get(ctx context.Context, key multiraftbase.Key) (KeyValue, error)
- func (db *DB) GetSender() Sender
- func (db *DB) Put(ctx context.Context, key multiraftbase.Key, value multiraftbase.Value) error
- func (db *DB) Run(ctx context.Context, b *Batch) error
- type KeyValue
- type Result
- type Sender
- type SenderFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct { // Results contains an entry for each operation added to the batch. The order // of the results matches the order the operations were added to the // batch. For example: // // b := db.NewBatch() // b.Put("a", "1") // b.Put("b", "2") // _ = db.Run(b) // // string(b.Results[0].Rows[0].Key) == "a" // // string(b.Results[1].Rows[0].Key) == "b" Results []Result // The Header which will be used to send the resulting BatchRequest. // To be modified directly. Header multiraftbase.Header // contains filtered or unexported fields }
Batch provides for the parallel execution of a number of database operations. Operations are added to the Batch and then the Batch is executed via either DB.Run, Txn.Run or Txn.Commit.
TODO(pmattis): Allow a timestamp to be specified which is applied to all operations within the batch.
func (*Batch) AddRawRequest ¶
func (b *Batch) AddRawRequest(req multiraftbase.Request)
AddRawRequest adds the specified requests to the batch. No responses will be allocated for them, and using any of the non-raw operations will result in an error when running the batch.
func (*Batch) Get ¶
func (b *Batch) Get(key multiraftbase.Key)
Get retrieves the value for a key. A new result will be appended to the batch which will contain a single row.
r, err := db.Get("a") // string(r.Rows[0].Key) == "a"
key can be either a byte slice or a string.
func (*Batch) MustPErr ¶
func (b *Batch) MustPErr() *multiraftbase.Error
MustPErr returns the structured error resulting from a failed execution of the batch, asserting that that error is non-nil.
func (*Batch) Put ¶
func (b *Batch) Put(key multiraftbase.Key, value multiraftbase.Value)
Put sets the value for a key.
A new result will be appended to the batch which will contain a single row and Result.Err will indicate success or failure.
key can be either a byte slice or a string. value can be any key type, a proto.Message or any Go primitive type (bool, int, etc).
func (*Batch) RawResponse ¶
func (b *Batch) RawResponse() *multiraftbase.BatchResponse
RawResponse returns the BatchResponse which was the result of a successful execution of the batch, and nil otherwise.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a database handle to a single cockroach cluster. A DB is safe for concurrent use by multiple goroutines.
func (*DB) Get ¶
Get retrieves the value for a key, returning the retrieved key/value or an error. It is not considered an error for the key not to exist.
r, err := db.Get("a") // string(r.Key) == "a"
key can be either a byte slice or a string.
func (*DB) Put ¶
func (db *DB) Put(ctx context.Context, key multiraftbase.Key, value multiraftbase.Value) error
Put sets the value for a key.
key can be either a byte slice or a string. value can be any key type, a proto.Message or any Go primitive type (bool, int, etc).
func (*DB) Run ¶
Run executes the operations queued up within a batch. Before executing any of the operations the batch is first checked to see if there were any errors during its construction (e.g. failure to marshal a proto message).
The operations within a batch are run in parallel and the order is non-deterministic. It is an unspecified behavior to modify and retrieve the same key within a batch.
Upon completion, Batch.Results will contain the results for each operation. The order of the results matches the order the operations were added to the batch.
type KeyValue ¶
type KeyValue struct { Key multiraftbase.Key Value *multiraftbase.Value // Timestamp will always be zero }
KeyValue represents a single key/value pair. This is similar to roachpb.KeyValue except that the value may be nil.
func (*KeyValue) PrettyValue ¶
PrettyValue returns a human-readable version of the value as a string.
type Result ¶
type Result struct { // Err contains any error encountered when performing the operation. Err error // Rows contains the key/value pairs for the operation. The number of rows // returned varies by operation. For Get, Put, CPut, Inc and Del the number // of rows returned is the number of keys operated on. For Scan the number of // rows returned is the number or rows matching the scan capped by the // maxRows parameter. For DelRange Rows is nil. Rows []KeyValue // Keys is set by some operations instead of returning the rows themselves. Keys []multiraftbase.Key PgInfos []multiraftbase.PgInfo // contains filtered or unexported fields }
Result holds the result for a single DB or Txn operation (e.g. Get, Put, etc).
type Sender ¶
type Sender interface {
Send(context.Context, multiraftbase.BatchRequest) (*multiraftbase.BatchResponse, *multiraftbase.Error)
}
Sender is the interface used to call into a Cockroach instance. If the returned *roachpb.Error is not nil, no response should be returned.
type SenderFunc ¶
type SenderFunc func(context.Context, multiraftbase.BatchRequest) (*multiraftbase.BatchResponse, *multiraftbase.Error)
SenderFunc is an adapter to allow the use of ordinary functions as Senders.
func (SenderFunc) Send ¶
func (f SenderFunc) Send( ctx context.Context, ba multiraftbase.BatchRequest, ) (*multiraftbase.BatchResponse, *multiraftbase.Error)
Send calls f(ctx, c).