Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/lodastack/store/cluster" ) func main() { opts := cluster.Options{ // store bind TCP listen Bind: "127.0.0.1:9000", // store data dir DataDir: "/tmp/store", // any node in exist cluster JoinAddr: "10.0.0.1:9000", } cs, err := cluster.NewService(opts) if err != nil { fmt.Printf("new store service failed: %s", err) } if err := cs.Open(); err != nil { fmt.Printf("failed to open cluster service failed: %s", err) } // If join was specified, make the join request. nodes, err := cs.Nodes() if err != nil { fmt.Printf("get nodes failed: %s", err) } // if exist a raftdb, or exist a cluster, don't join any leader. if opts.JoinAddr != "" && len(nodes) <= 1 { if err := cs.JoinCluster(opts.JoinAddr, opts.Bind); err != nil { fmt.Printf("failed to join node at %s: %s", opts.JoinAddr, err) } } }
Output:
Index ¶
- type Options
- type Service
- func (s *Service) Addr() string
- func (s *Service) Backup() ([]byte, error)
- func (s *Service) Batch(rows []model.Row) error
- func (s *Service) Close() error
- func (s *Service) CreateBucket(name []byte) error
- func (s *Service) CreateBucketIfNotExist(name []byte) error
- func (s *Service) DelSession(key interface{}) error
- func (s *Service) GetSession(key interface{}) interface{}
- func (s *Service) Join(addr string) error
- func (s *Service) JoinCluster(server, addr string) error
- func (s *Service) Nodes() ([]string, error)
- func (s *Service) Open() error
- func (s *Service) Peers() (map[string]map[string]string, error)
- func (s *Service) PublishAPIAddr(apiAddr string, delay time.Duration, timeout time.Duration) error
- func (s *Service) Remove(addr string) error
- func (s *Service) RemoveBucket(name []byte) error
- func (s *Service) RemoveKey(bucket, key []byte) error
- func (s *Service) Restore(Backupfile string) error
- func (s *Service) SetPeer(raftAddr, apiAddr string) error
- func (s *Service) SetSession(key, value interface{}) error
- func (s *Service) Statistics(tags map[string]string) []model.Statistic
- func (s *Service) Update(bucket []byte, key []byte, value []byte) error
- func (s *Service) View(bucket, key []byte) ([]byte, error)
- func (s *Service) ViewPrefix(bucket, keyPrefix []byte) (map[string][]byte, error)
- func (s *Service) WaitForLeader(timeout time.Duration) (string, error)
- type Store
- type Transport
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { // Bind address to use for the cluster raft service. Bind string // DataDir is the directory where the data stores. DataDir string // JoinAddr, which cluster to join. // Optional. JoinAddr string // Logger logs store status. // Default write to stdout. // Optional. Logger log.Logger }
Options are the options to be used when initializing a cluster service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service allows access to the cluster and associated meta data, via distributed consensus.
func NewService ¶
NewService returns a new instance of the cluster service.
func (*Service) Batch ¶
Batch update values for given keys in given buckets, via distributed consensus.
func (*Service) CreateBucket ¶
CreateBucket will create bucket via the cluster.
func (*Service) CreateBucketIfNotExist ¶
CreateBucketIfNotExist will create bucket via the cluster if not exist.
func (*Service) DelSession ¶
DelSession delete the session from given key.
func (*Service) GetSession ¶
func (s *Service) GetSession(key interface{}) interface{}
GetSession returns the session value for the given key.
func (*Service) JoinCluster ¶
JoinCluster joins the cluster via TCP, reachable at addr, to the cluster.
func (*Service) PublishAPIAddr ¶
PublishAPIAddr public API addr in cluster
func (*Service) RemoveBucket ¶
RemoveBucket will remove bucket via the cluster.
func (*Service) SetPeer ¶
SetPeer will set the mapping between raftAddr and apiAddr for the entire cluster.
func (*Service) SetSession ¶
SetSession set the session.
func (*Service) Statistics ¶
Statistics returns statistics for periodic monitoring.
func (*Service) ViewPrefix ¶
ViewPrefix returns the value for the keys has the keyPrefix.
type Store ¶
type Store interface { // Leader returns the leader of the consensus system. Leader() string // Join joins the node, reachable at addr, to the cluster. Join(addr string) error // Remove removes a node from the store, specified by addr. Remove(addr string) error // UpdateAPIPeers updates the API peers on the store. UpdateAPIPeers(peers map[string]string) error // Create a bucket, via distributed consensus. CreateBucket(name []byte) error // Create a bucket via distributed consensus if not exist. CreateBucketIfNotExist(name []byte) error // Remove a bucket, via distributed consensus. RemoveBucket(name []byte) error // Get returns the value for the given key. View(bucket, key []byte) ([]byte, error) // ViewPrefix returns the value for the keys has the keyPrefix. ViewPrefix(bucket, keyPrefix []byte) (map[string][]byte, error) // Set sets the value for the given key, via distributed consensus. Update(bucket []byte, key []byte, value []byte) error // RemoveKey removes the key from the bucket. RemoveKey(bucket, key []byte) error // Batch update values for given keys in given buckets, via distributed consensus. Batch(rows []model.Row) error // GetSession returns the sression value for the given key. GetSession(key interface{}) interface{} // SetSession sets the value for the given key, via distributed consensus. SetSession(key, value interface{}) error // DelSession delete the value for the given key, via distributed consensus. DelSession(key interface{}) error // Backup database. Backup() ([]byte, error) // Restore restores backup data file. Restore(backupfile string) error // APIPeers return the map of Raft addresses to API addresses. APIPeers() (map[string]string, error) // Nodes returns the list of current peers. Nodes() ([]string, error) // WaitForLeader blocks until a leader is detected, or the timeout expires. WaitForLeader(timeout time.Duration) (string, error) // Close closes the store. If wait is true, waits for a graceful shutdown. Close(wait bool) error // Statistics returns statistics for periodic monitoring. Statistics(tags map[string]string) []model.Statistic }
Store represents a store of information, managed via consensus.