raft

package
v0.0.0-...-a47d1aa Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCommandResult

func DecodeCommandResult[T any](data []byte) T

func EncodeCommand

func EncodeCommand(cmd Command) []byte

func EncodeCommandResult

func EncodeCommandResult(v any) []byte

Types

type AllocCommand

type AllocCommand struct {
	Namespace string
	Resource  string
	Tokens    int64
	Version   int64
	SMResult  statemachine.Result
}

func NewAllocCommand

func NewAllocCommand(namespace, resource string, tokens, version int64) *AllocCommand

func (*AllocCommand) LocalInvoke

func (c *AllocCommand) LocalInvoke(storage *storage, entryIdx uint64) error

func (*AllocCommand) RaftInvoke

func (c *AllocCommand) RaftInvoke(ctx context.Context, nh *dragonboat.NodeHost, _ uint64, session *client.Session) (any, error)

func (*AllocCommand) Result

func (c *AllocCommand) Result() statemachine.Result

func (*AllocCommand) Type

func (c *AllocCommand) Type() CommandType

type AllocCommandResult

type AllocCommandResult struct {
	RemainingTokens int64
	CurrentVersion  int64
	OK              bool
	Err             string
}

type Command

type Command interface {
	Type() CommandType
	RaftInvoke(ctx context.Context, nh *dragonboat.NodeHost, shardID uint64, session *client.Session) (result any, err error)
	LocalInvoke(storage *storage, entryIdx uint64) error
	Result() statemachine.Result
}

func DecodeCommand

func DecodeCommand(data []byte) (Command, error)

type CommandType

type CommandType byte
const (
	View          CommandType = 1
	Alloc         CommandType = 2
	Free          CommandType = 3
	RegisterQuota CommandType = 4
)

type Config

type Config struct {
	BindAddress             string `yaml:"bind_address"`
	BindPort                int    `yaml:"bind_port"`
	BindAddressFromHostname bool   `yaml:"bind_address_from_hostname"`
	DeploymentID            uint64 `yaml:"deployment_id"`
	ReplicaID               uint64 `yaml:"replica_id"`
	ReplicaIDOverride       string `yaml:"replica_id_override"`
	ShardID                 uint64 `yaml:"shard_id"`
	Shards                  uint64 `yaml:"shards"`
	Dir                     string `yaml:"dir"`
}

func (*Config) RegisterFlagsWithPrefix

func (c *Config) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string)

type FreeCommand

type FreeCommand struct {
	Namespace string
	Resource  string
	Tokens    int64
	Version   int64
	SMResult  statemachine.Result
}

func NewFreeCommand

func NewFreeCommand(namespace, resource string, tokens, version int64) *FreeCommand

func (*FreeCommand) LocalInvoke

func (c *FreeCommand) LocalInvoke(storage *storage, entryIdx uint64) error

func (*FreeCommand) RaftInvoke

func (c *FreeCommand) RaftInvoke(ctx context.Context, nh *dragonboat.NodeHost, _ uint64, session *client.Session) (any, error)

func (*FreeCommand) Result

func (c *FreeCommand) Result() statemachine.Result

func (*FreeCommand) Type

func (c *FreeCommand) Type() CommandType

type FreeCommandResult

type FreeCommandResult struct {
	RemainingTokens int64
	CurrentVersion  int64
	OK              bool
	Err             string
}

type RegisterQuotaCommand

type RegisterQuotaCommand struct {
	Namespace string
	Resource  string
	Cfg       quota.Config
	SMResult  statemachine.Result
}

func NewRegisterQuotaCommand

func NewRegisterQuotaCommand(namespace, resource string, cfg quota.Config) *RegisterQuotaCommand

func (*RegisterQuotaCommand) LocalInvoke

func (c *RegisterQuotaCommand) LocalInvoke(storage *storage, entryIdx uint64) error

func (*RegisterQuotaCommand) RaftInvoke

func (c *RegisterQuotaCommand) RaftInvoke(ctx context.Context, nh *dragonboat.NodeHost, _ uint64, session *client.Session) (any, error)

func (*RegisterQuotaCommand) Result

func (*RegisterQuotaCommand) Type

type RegisterQuotaCommandResult

type RegisterQuotaCommandResult struct{}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(cfg Config, logger log.Logger, memberlist ports.MemberlistService) (*Storage, error)

func (*Storage) AddRaftReplica

func (s *Storage) AddRaftReplica(ctx context.Context, replicaID uint64, raftAddr string) (bool, error)

func (*Storage) AllShardsHealthy

func (s *Storage) AllShardsHealthy() bool

func (*Storage) Alloc

func (s *Storage) Alloc(ctx context.Context, namespace, resource string, tokens, version int64) (int64, int64, bool, error)

func (*Storage) AwaitHealthy

func (s *Storage) AwaitHealthy(ctx context.Context) error

func (*Storage) Free

func (s *Storage) Free(ctx context.Context, namespace, resource string, tokens, version int64) (int64, int64, bool, error)

func (*Storage) RegisterQuota

func (s *Storage) RegisterQuota(ctx context.Context, namespace, resource string, cfg quota.Config) error

func (*Storage) RemoveRaftReplica

func (s *Storage) RemoveRaftReplica(ctx context.Context, replicaID uint64) error

func (*Storage) Run

func (s *Storage) Run(ctx context.Context) error

func (*Storage) ShardHealthy

func (s *Storage) ShardHealthy(shardID uint64) bool

func (*Storage) Shutdown

func (s *Storage) Shutdown(_ context.Context) error

func (*Storage) View

func (s *Storage) View(ctx context.Context, namespace, resource string) (int64, int64, int64, error)

type ViewCommand

type ViewCommand struct {
	Namespace string
	Resource  string
	SMResult  statemachine.Result
}

func NewViewCommand

func NewViewCommand(namespace, resource string) *ViewCommand

func (*ViewCommand) LocalInvoke

func (c *ViewCommand) LocalInvoke(storage *storage, _ uint64) error

func (*ViewCommand) RaftInvoke

func (c *ViewCommand) RaftInvoke(ctx context.Context, nh *dragonboat.NodeHost, shardID uint64, _ *client.Session) (any, error)

func (*ViewCommand) Result

func (c *ViewCommand) Result() statemachine.Result

func (*ViewCommand) Type

func (c *ViewCommand) Type() CommandType

type ViewCommandResult

type ViewCommandResult struct {
	Allocated int64
	Capacity  int64
	Version   int64
	Err       string
}

Jump to

Keyboard shortcuts

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