Documentation ¶
Overview ¶
Package client is the Go client for GoshawkDB. This is a fully featured client, supporting retry and nested transactions.
This client is available under the Apache License, Version 2.0. A copy of this License is included in this repository, or available from http://www.apache.org/licenses/LICENSE-2.0
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a connection to the GoshawkDB server. A connection may only be used by one go-routine at a time.
func NewConnection ¶
func NewConnection(hostPort string, clientCertAndKeyPEM, clusterCertPEM []byte) (*Connection, error)
Create a new connection. The hostPort parameter can be either hostname:port or ip:port. If port is not provided the default port of 7894 is used. This will block until a connection is established and ready to use, or an error occurs. The clientCertAndKeyPEM parameter should be the client certificate followed by private key in PEM format. The clusterCert parameter is the cluster certificate. This is optional, but recommended: without it, the client will not be able to verify the server to which it connects.
func (*Connection) RunTransaction ¶
func (conn *Connection) RunTransaction(fun func(*Txn) (interface{}, error)) (interface{}, *Stats, error)
Run a transaction. The transaction is the function supplied, and the function is invoked potentially several times until it completes successfully: either committing or choosing to abort. The function should therefore be referentially transparent. Returning any non-nil error will cause the transaction to be aborted with the only exception that returning Restart when the transaction has identified a restart is required will cause the transaction to be immediately restarted.
The function final results are returned by this function, along with statistics regarding how the transaction proceeded.
This function automatically detects and creates nested transactions: it is perfectly safe and expected to call RunTransaction from within a transaction.
func (*Connection) Shutdown ¶
func (conn *Connection) Shutdown()
Shutdown the connection. This will block until the connection is closed.
type Object ¶
type Object struct { // The unique Id of the object. Id *common.VarUUId // contains filtered or unexported fields }
Object represents an object in the database. Objects are linked to Connections: if you're using multiple Connections, it is not permitted to use the same Object in both connections; instead, you should retrieve the same Object Id through both connections. However, within the same Connection, Objects may be reused and pointer equality will work as expected. This is true for also nested transactions.
func (*Object) References ¶
Returns the list of Objects to which the current object refers. If an error is returned, the current transaction should immediately be restarted (return the error Restart)
func (*Object) Set ¶
Sets the value and references of the current object. If the value contains any references to other objects, they must be explicitly declared as references otherwise on retrieval you will not be able to navigate to them. Note that the order of references is stable. If an error is returned, the current transaction should immediately be restarted (return the error Restart)
type Stats ¶
type Stats struct { // Any objects that were loaded from the RM as part of this transaction are recorded Loads map[common.VarUUId]time.Duration // Every time the local transaction payload is submitted to the RM // for validation and possible commitment, the time it took to // perform the submission is added here. Thus as a single // transaction may be submitted multiple times, so there may be // multiple elements in this list. Nested transactions never appear // here as nested transactions are client-side only. Submissions []time.Duration // The id of the transaction. TxnId *common.TxnId }
A Stats object is created for each root transaction and shared with any nested transactions. It records some details about how the transaction progressed.
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
A Txn object holds the state of the current transaction and is supplied to your transaction functions. Through this object you can interact with the GoshawkDB object store.
func (*Txn) CreateObject ¶
Create a new object and set its value and references. If an error is returned, the current transaction should immediately be restarted (return the error Restart)
func (*Txn) GetObject ¶
Fetches the object specified by its unique object id. Note this will fail unless the client has already navigated the object graph at least as far as any object that has a reference to the object id. This method is not normally necessary: it is generally preferred to use the References of objects to navigate.
func (*Txn) GetRootObject ¶
Returns the database Root Object. The Root Object is known to all clients and represents the root of the object graph. For an object to be reachable, there must be a path to it from the Root Object. If an error is returned, the current transaction should immediately be restarted (return the error Restart)
type TxnFunResult ¶
type TxnFunResult int
const ( // If you return Retry as the result (not error) of a transaction // then a retry transaction is performed. Retry TxnFunResult = iota // If the transaction detects that it needs to be restarted as soon // as possible then all methods on Object will return Restart as an // error. You should detect this and return Restart as an error in // the transaction function, allowing the transaction function to // be restarted promptly. Restart TxnFunResult = iota )
func (TxnFunResult) Error ¶
func (tfr TxnFunResult) Error() string