server

package
v0.0.0-...-f963794 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultQuotaBytes is the number of bytes the backend Size may
	// consume before exceeding the space quota.
	DefaultQuotaBytes = int64(2 * 1024 * 1024 * 1024) // 2GB
)

Variables

View Source
var (
	ErrEmptyKey      = errors.New("server: key is not provided")
	ErrKeyNotFound   = errors.New("server: key not found")
	ErrValueProvided = errors.New("server: value is provided")
	ErrLeaseProvided = errors.New("server: lease is provided")
	ErrTooManyOps    = errors.New("server: too many operations in txn request")
	ErrDuplicateKey  = errors.New("server: duplicate key given in txn request")
	ErrCompacted     = errors.New("server: mvcc: required revision has been compacted")
	ErrFutureRev     = errors.New("server: mvcc: required revision is a future revision")
	ErrNoSpace       = errors.New("server: mvcc: database space exceeded")

	ErrLeaseNotFound    = errors.New("server: requested lease not found")
	ErrLeaseExist       = errors.New("server: lease already exists")
	ErrLeaseTTLTooLarge = errors.New("server: too large lease TTL")

	ErrRequestTooLarge        = errors.New("server: request is too large")
	ErrRequestTooManyRequests = errors.New("server: too many requests")

	ErrRootUserNotExist     = errors.New("server: root user does not exist")
	ErrRootRoleNotExist     = errors.New("server: root user does not have root role")
	ErrUserAlreadyExist     = errors.New("server: user name already exists")
	ErrUserEmpty            = errors.New("server: user name is empty")
	ErrUserNotFound         = errors.New("server: user name not found")
	ErrRoleAlreadyExist     = errors.New("server: role name already exists")
	ErrRoleNotFound         = errors.New("server: role name not found")
	ErrAuthFailed           = errors.New("server: authentication failed, invalid user ID or password")
	ErrPermissionDenied     = errors.New("server: permission denied")
	ErrRoleNotGranted       = errors.New("server: role is not granted to the user")
	ErrPermissionNotGranted = errors.New("server: permission is not granted to the role")
	ErrAuthNotEnabled       = errors.New("server: authentication is not enabled")
	ErrInvalidAuthToken     = errors.New("server: invalid auth token")
	ErrInvalidAuthMgmt      = errors.New("server: invalid auth management")

	ErrNotCapable                 = errors.New("server: not capable")
	ErrStopped                    = errors.New("server: server stopped")
	ErrTimeout                    = errors.New("server: request timed out")
	ErrTimeoutDueToLeaderFail     = errors.New("server: request timed out, possibly due to previous leader failure")
	ErrTimeoutDueToConnectionLost = errors.New("server: request timed out, possibly due to connection lost")
	ErrUnhealthy                  = errors.New("server: unhealthy cluster")
	ErrCorrupt                    = errors.New("server: corrupt cluster")
)
View Source
var (
	ErrCanceled = errors.New("mvcc: watcher is canceled")
	ErrClosed   = errors.New("mvcc: closed")
)
View Source
var DefaultIgnores map[backend.IgnoreKey]struct{}

DefaultIgnores is a map of keys to ignore in hash checking.

View Source
var (
	ErrRevisionNotFound = errors.New("mvcc: revision not found")
)
View Source
var (
	ErrWatcherNotExist = errors.New("mvcc: watcher does not exist")
)

Functions

func NewStore

func NewStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *store

NewStore returns a new store. It is useful to create a store inside mvcc pkg. It should only be used for testing externally.

func ReportEventReceived

func ReportEventReceived(n int)

ReportEventReceived reports that an event is received. This function should be called when the external systems received an event from mvcc.Watcher.

func UpdateConsistentIndex

func UpdateConsistentIndex(be backend.Backend, index uint64)

func WriteKV

func WriteKV(be backend.Backend, kv pb.KeyValue)

Types

type ConsistentIndexGetter

type ConsistentIndexGetter interface {
	// ConsistentIndex returns the consistent index of current executing entry.
	ConsistentIndex() uint64
}

ConsistentIndexGetter is an interface that wraps the Get method. Consistent index is the offset of an entry in a consistent replicated log.

type ConsistentWatchableKV

type ConsistentWatchableKV interface {
	WatchableKV
	// ConsistentIndex returns the current consistent index of the KV.
	ConsistentIndex() uint64
}

ConsistentWatchableKV is a WatchableKV that understands the consistency algorithm and consistent index. If the consistent index of executing entry is not larger than the consistent index of ConsistentWatchableKV, all operations in this entry are skipped and return empty response.

type FilterFunc

type FilterFunc func(e mvccpb.Event) bool

FilterFunc returns true if the given event should be filtered out.

type KV

type KV interface {
	ReadView
	WriteView

	// Read creates a read transaction.
	Read() TxnRead

	// Write creates a write transaction.
	Write() TxnWrite

	// Hash computes the hash of the KV's backend.
	Hash() (hash uint32, revision int64, err error)

	// HashByRev computes the hash of all MVCC revisions up to a given revision.
	HashByRev(rev int64) (hash uint32, revision int64, compactRev int64, err error)

	// Compact frees all superseded keys with revisions less than rev.
	Compact(rev int64) (<-chan struct{}, error)

	// Commit commits outstanding txns into the underlying backend.
	Commit()

	// Restore restores the KV store from a backend.
	Restore(b backend.Backend) error
	Close() error
}

type Lessor

type Lessor interface {
	// LeaseGrant sends LeaseGrant request to raft and apply it after committed.
	LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error)
	// LeaseRevoke sends LeaseRevoke request to raft and apply it after committed.
	LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error)

	// LeaseRenew renews the lease with given ID. The renewed TTL is returned. Or an error
	// is returned.
	LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error)

	// LeaseTimeToLive retrieves lease information.
	LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error)

	// LeaseLeases lists all leases.
	LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error)
}

type RangeOptions

type RangeOptions struct {
	Limit int64
	Rev   int64
	Count bool
}

type RangeResult

type RangeResult struct {
	KVs   []mvccpb.KeyValue
	Rev   int64
	Count int
}

type ReadView

type ReadView interface {
	// FirstRev returns the first KV revision at the time of opening the txn.
	// After a compaction, the first revision increases to the compaction
	// revision.
	FirstRev() int64

	// Rev returns the revision of the KV at the time of opening the txn.
	Rev() int64

	// Range gets the keys in the range at rangeRev.
	// The returned rev is the current revision of the KV when the operation is executed.
	// If rangeRev <=0, range gets the keys at currentRev.
	// If `end` is nil, the request returns the key.
	// If `end` is not nil and not empty, it gets the keys in range [key, range_end).
	// If `end` is not nil and empty, it gets the keys greater than or equal to key.
	// Limit limits the number of keys returned.
	// If the required rev is compacted, ErrCompacted will be returned.
	Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error)
}

type Server

type Server struct {
	Cfg ServerConfig
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg ServerConfig) (srv *Server, err error)

func (*Server) Close

func (s *Server) Close()

func (*Server) Compact

func (s *Server) Compact(ctx context.Context, r *pb.CompactionRequest) (resp *pb.CompactionResponse, err error)

func (*Server) DeleteRange

func (s *Server) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (resp *pb.DeleteRangeResponse, err error)

func (*Server) KV

func (s *Server) KV() ConsistentWatchableKV

func (*Server) LeaseGrant

func (s *Server) LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (resp *pb.LeaseGrantResponse, err error)

func (*Server) LeaseLeases

func (s *Server) LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (resp *pb.LeaseLeasesResponse, err error)

func (*Server) LeaseRenew

func (s *Server) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error)

func (*Server) LeaseRevoke

func (s *Server) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (resp *pb.LeaseRevokeResponse, err error)

func (*Server) LeaseTimeToLive

func (s *Server) LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (resp *pb.LeaseTimeToLiveResponse, err error)

func (*Server) Put

func (s *Server) Put(ctx context.Context, r *pb.PutRequest) (resp *pb.PutResponse, err error)

func (*Server) Range

func (s *Server) Range(ctx context.Context, r *pb.RangeRequest) (resp *pb.RangeResponse, err error)

func (*Server) Status

func (s *Server) Status() (ds backend.Status)

func (*Server) Txn

func (s *Server) Txn(ctx context.Context, r *pb.TxnRequest) (resp *pb.TxnResponse, err error)

type ServerConfig

type ServerConfig struct {
	Name               string
	DataDir            string
	BootstrapTimeout   time.Duration
	AutoCompactionMode string
	QuotaBackendBytes  int64
}

func (*ServerConfig) ReqTimeout

func (c *ServerConfig) ReqTimeout() time.Duration

ReqTimeout returns timeout for request to finish.

func (*ServerConfig) SnapDir

func (c *ServerConfig) SnapDir() string

type TxnRead

type TxnRead interface {
	ReadView
	// End marks the transaction is complete and ready to commit.
	End()
}

TxnRead represents a read-only transaction with operations that will not block other read transactions.

type TxnWrite

type TxnWrite interface {
	TxnRead
	WriteView
	// Changes gets the changes made since opening the write txn.
	Changes() []mvccpb.KeyValue
}

TxnWrite represents a transaction that can modify the store.

func NewReadOnlyTxnWrite

func NewReadOnlyTxnWrite(txn TxnRead) TxnWrite

type WatchID

type WatchID int64

type WatchResponse

type WatchResponse struct {
	// WatchID is the WatchID of the watcher this response sent to.
	WatchID WatchID

	// Events contains all the events that needs to send.
	Events []mvccpb.Event

	// Revision is the revision of the KV when the watchResponse is created.
	// For a normal response, the revision should be the same as the last
	// modified revision inside Events. For a delayed response to a unsynced
	// watcher, the revision is greater than the last modified revision
	// inside Events.
	Revision int64

	// CompactRevision is set when the watcher is cancelled due to compaction.
	CompactRevision int64
}

type WatchStream

type WatchStream interface {
	// Watch creates a watcher. The watcher watches the events happening or
	// happened on the given key or range [key, end) from the given startRev.
	//
	// The whole event history can be watched unless compacted.
	// If `startRev` <=0, watch observes events after currentRev.
	//
	// The returned `id` is the ID of this watcher. It appears as WatchID
	// in events that are sent to the created watcher through stream channel.
	//
	Watch(key, end []byte, startRev int64, fcs ...FilterFunc) WatchID

	// Chan returns a chan. All watch response will be sent to the returned chan.
	Chan() <-chan WatchResponse

	// RequestProgress requests the progress of the watcher with given ID. The response
	// will only be sent if the watcher is currently synced.
	// The responses will be sent through the WatchRespone Chan attached
	// with this stream to ensure correct ordering.
	// The responses contains no events. The revision in the response is the progress
	// of the watchers since the watcher is currently synced.
	RequestProgress(id WatchID)

	// Cancel cancels a watcher by giving its ID. If watcher does not exist, an error will be
	// returned.
	Cancel(id WatchID) error

	// Close closes Chan and release all related resources.
	Close()

	// Rev returns the current revision of the KV the stream watches on.
	Rev() int64
}

type Watchable

type Watchable interface {
	// NewWatchStream returns a WatchStream that can be used to
	// watch events happened or happening on the KV.
	NewWatchStream() WatchStream
}

Watchable is the interface that wraps the NewWatchStream function.

type WatchableKV

type WatchableKV interface {
	KV
	Watchable
}

WatchableKV is a KV that can be watched.

type WriteView

type WriteView interface {
	// DeleteRange deletes the given range from the store.
	// A deleteRange increases the rev of the store if any key in the range exists.
	// The number of key deleted will be returned.
	// The returned rev is the current revision of the KV when the operation is executed.
	// It also generates one event for each key delete in the event history.
	// if the `end` is nil, deleteRange deletes the key.
	// if the `end` is not nil, deleteRange deletes the keys in range [key, range_end).
	DeleteRange(key, end []byte) (n, rev int64)

	// Put puts the given key, value into the store.
	// A put also increases the rev of the store, and generates one event in the event history.
	// The returned rev is the current revision of the KV when the operation is executed.
	Put(key, value []byte, lease lease.LeaseID) (rev int64)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL