raftmeta

package
v0.0.0-...-0ae59ff Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNumPendingProposals = 1000
	DefaultAddr                = "127.0.0.1:2347"
	DefaultElectionTick        = 100
	DefaultHeartbeatTick       = 1
	DefaultMaxSizePerMsg       = 4096
	DefaultMaxInflightMsgs     = 256
)
View Source
const (
	CREATE_DATABASE_PATH                       = "/create_database"
	DROP_DATABASE_PATH                         = "/drop_database"
	CREATE_SHARD_GROUP_PATH                    = "/create_shard_group"
	CREATE_DATA_NODE_PATH                      = "/create_data_node"
	DROP_RETENTION_POLICY_PATH                 = "/drop_retention_policy"
	DELETE_DATA_NODE_PATH                      = "/delete_data_node"
	CREATE_RETENTION_POLICY_PATH               = "/create_retention_policy"
	UPDATE_RETENTION_POLICY_PATH               = "/update_retention_policy"
	CREATE_USER_PATH                           = "/create_user"
	DROP_USER_PATH                             = "/drop_user"
	UPDATE_USER_PATH                           = "/upate_user"
	SET_PRIVILEGE_PATH                         = "/set_privilege"
	SET_ADMIN_PRIVILEGE                        = "/set_admin_privilege"
	AUTHENTICATE_PATH                          = "/authenticate"
	DROP_SHARD_PATH                            = "/drop_shard"
	TRUNCATE_SHARD_GROUPS_PATH                 = "/truncate_shard_groups"
	PRUNE_SHARD_GROUPS_PATH                    = "/prune_shard_groups"
	DELETE_SHARD_GROUP_PATH                    = "/delete_shard_group"
	PRECREATE_SHARD_GROUPS_PATH                = "/precreate_shard_groups"
	CREATE_DATABASE_WITH_RETENTION_POLICY_PATH = "/create_database_with_policy"
	CREATE_CONTINUOUS_QUERY_PATH               = "/create_continuous_query"
	DROP_CONTINUOUS_QUERY_PATH                 = "/drop_continuous_queyr"
	CREATE_SUBSCRIPTION_PATH                   = "/create_subscription"
	DROP_SUBSCRIPTION_PATH                     = "/drop_subscription"
	DATA_PATH                                  = "/data"
	PING_PATH                                  = "/ping"
	ACQUIRE_LEASE_PATH                         = "/acquire_lease"
	ADD_SHARD_OWNER                            = "/add_shard_owner"
	REMOVE_SHARD_OWNER                         = "/remove_shard_owner"
)

Variables

This section is empty.

Functions

func Request

func Request(url string, data []byte) error

func WriteResp

func WriteResp(w http.ResponseWriter, v interface{}) error

Types

type AcquireLeaseReq

type AcquireLeaseReq struct {
	Name   string
	NodeId uint64
}

type AcquireLeaseResp

type AcquireLeaseResp struct {
	CommonResp
	Lease meta.Lease
}

type AddShardOwnerReq

type AddShardOwnerReq struct {
	ShardID uint64
	NodeID  uint64
}

type AddShardOwnerResp

type AddShardOwnerResp struct {
	CommonResp
}

type AuthenticateReq

type AuthenticateReq struct {
	UserName string
	Password string
}

type AuthenticateResp

type AuthenticateResp struct {
	CommonResp
	UserInfo meta.UserInfo
}

type Checksum

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

type CommonResp

type CommonResp struct {
	RetCode int    `json:"ret_code"`
	RetMsg  string `json:"ret_msg"`
}

type Config

type Config struct {
	NumPendingProposals int    `toml:"num-pending-proposals"`
	Tracing             bool   `toml:"tracing"`
	MyAddr              string `toml:"my-addr"`
	Peers               []Peer `toml:"peers"`
	RaftId              uint64 `toml:"raft-id"`
	TickTimeMs          int    `toml:"tick-time-ms"`
	ElectionTick        int    `toml:"election-tick"`
	HeartbeatTick       int    `toml:"heartbeat-tick"`
	MaxSizePerMsg       uint64 `toml:"max-size-per-msg"`
	MaxInflightMsgs     int    `toml:"max-inflight-msgs"`

	WalDir              string `toml:"wal-dir"`
	SnapshotIntervalSec int    `toml:"snapshot-interval"`
	ChecksumIntervalSec int    `toml:"checksum-interval"`
	RetentionAutoCreate bool   `toml:"retention-auto-create"`
}

func NewConfig

func NewConfig() Config

NewConfig returns an instance of Config with defaults.

func (*Config) FromToml

func (c *Config) FromToml(input string) error

FromToml loads the config from TOML.

func (*Config) FromTomlFile

func (c *Config) FromTomlFile(fpath string) error

FromTomlFile loads the config from a TOML file.

type CreateContinuousQueryReq

type CreateContinuousQueryReq struct {
	Database string
	Name     string
	Query    string
}

CreateContinuousQuery

type CreateContinuousQueryResp

type CreateContinuousQueryResp struct {
	CommonResp
}

type CreateDataNodeReq

type CreateDataNodeReq struct {
	HttpAddr string
	TcpAddr  string
}

type CreateDataNodeResp

type CreateDataNodeResp struct {
	CommonResp
	NodeInfo meta.NodeInfo
}

type CreateDatabaseReq

type CreateDatabaseReq struct {
	Name string
}

type CreateDatabaseResp

type CreateDatabaseResp struct {
	CommonResp
	DbInfo meta.DatabaseInfo
}

type CreateDatabaseWithRetentionPolicyReq

type CreateDatabaseWithRetentionPolicyReq struct {
	Name string
	Rps  RetentionPolicySpec
}

type CreateDatabaseWithRetentionPolicyResp

type CreateDatabaseWithRetentionPolicyResp struct {
	CommonResp
	DbInfo meta.DatabaseInfo
}

type CreateRetentionPolicyReq

type CreateRetentionPolicyReq struct {
	Database    string
	Rps         RetentionPolicySpec
	MakeDefault bool
}

type CreateRetentionPolicyResp

type CreateRetentionPolicyResp struct {
	CommonResp
	RetentionPolicyInfo meta.RetentionPolicyInfo
}

type CreateShardGroupReq

type CreateShardGroupReq struct {
	Database  string
	Policy    string
	Timestamp int64
}

type CreateShardGroupResp

type CreateShardGroupResp struct {
	CommonResp
	ShardGroupInfo meta.ShardGroupInfo
}

type CreateSubscriptionReq

type CreateSubscriptionReq struct {
	Database     string
	Rp           string
	Name         string
	Mode         string
	Destinations []string
}

CreateSubscription

type CreateSubscriptionResp

type CreateSubscriptionResp struct {
	CommonResp
}

type CreateUserReq

type CreateUserReq struct {
	Name     string
	Password string
	Admin    bool
}

type CreateUserResp

type CreateUserResp struct {
	CommonResp
	UserInfo meta.UserInfo
}

type DataResp

type DataResp struct {
	CommonResp
	Data []byte
}

type DeleteDataNodeReq

type DeleteDataNodeReq struct {
	Id uint64
}

type DeleteDataNodeResp

type DeleteDataNodeResp struct {
	CommonResp
}

type DeleteShardGroupReq

type DeleteShardGroupReq struct {
	Database string
	Policy   string
	Id       uint64
}

DeleteShardGroup

type DeleteShardGroupResp

type DeleteShardGroupResp struct {
	CommonResp
}

type DropContinuousQueryReq

type DropContinuousQueryReq struct {
	Database string
	Name     string
}

DropContinuousQuery

type DropContinuousQueryResp

type DropContinuousQueryResp struct {
	CommonResp
}

type DropDatabaseReq

type DropDatabaseReq struct {
	Name string
}

type DropDatabaseResp

type DropDatabaseResp struct {
	CommonResp
}

type DropRetentionPolicyReq

type DropRetentionPolicyReq struct {
	Database string
	Policy   string
}

type DropRetentionPolicyResp

type DropRetentionPolicyResp struct {
	CommonResp
}

type DropShardReq

type DropShardReq struct {
	Id uint64
}

type DropShardResp

type DropShardResp struct {
	CommonResp
}

type DropSubscriptionReq

type DropSubscriptionReq struct {
	Database string
	Rp       string
	Name     string
}

DropSubscription

type DropSubscriptionResp

type DropSubscriptionResp struct {
	CommonResp
}

type DropUserReq

type DropUserReq struct {
	Name string
}

type DropUserResp

type DropUserResp struct {
	CommonResp
}

type IPRange

type IPRange struct {
	Lower, Upper net.IP
}

type Linearizabler

type Linearizabler struct {
	Node *RaftNode
	// contains filtered or unexported fields
}

func NewLinearizabler

func NewLinearizabler(node *RaftNode) *Linearizabler

func (*Linearizabler) ReadLoop

func (l *Linearizabler) ReadLoop()

func (*Linearizabler) ReadNotify

func (l *Linearizabler) ReadNotify(ctx context.Context) error

func (*Linearizabler) Stop

func (l *Linearizabler) Stop()

type MetaClient

type MetaClient interface {
	MarshalBinary() ([]byte, error)
	ReplaceData(data *imeta.Data) error
	Data() imeta.Data
	CreateContinuousQuery(database, name, query string) error
	CreateDatabase(name string) (*meta.DatabaseInfo, error)
	CreateDatabaseWithRetentionPolicy(name string, spec *meta.RetentionPolicySpec) (*meta.DatabaseInfo, error)
	CreateRetentionPolicy(database string, spec *meta.RetentionPolicySpec, makeDefault bool) (*meta.RetentionPolicyInfo, error)
	CreateShardGroup(database, policy string, timestamp time.Time) (*meta.ShardGroupInfo, error)
	CreateSubscription(database, rp, name, mode string, destinations []string) error
	CreateUser(name, password string, admin bool) (meta.User, error)
	CreateDataNode(httpAddr, tcpAddr string) (*meta.NodeInfo, error)
	DeleteDataNode(id uint64) error
	Authenticate(username, password string) (meta.User, error)
	PruneShardGroups() error
	DeleteShardGroup(database, policy string, id uint64) error
	PrecreateShardGroups(from, to time.Time) error

	AddShardOwner(shardID, nodeID uint64) error
	RemoveShardOwner(shardID, nodeID uint64) error
	DropShard(id uint64) error
	DropContinuousQuery(database, name string) error
	DropDatabase(name string) error
	DropRetentionPolicy(database, name string) error
	DropSubscription(database, rp, name string) error
	DropUser(name string) error
	SetAdminPrivilege(username string, admin bool) error
	SetPrivilege(username, database string, p influxql.Privilege) error
	TruncateShardGroups(t time.Time) error
	UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
	UpdateUser(name, password string) error
}

type MetaService

type MetaService struct {
	Logger *zap.Logger
	Addr   string
	Node   *RaftNode

	Linearizabler interface {
		ReadNotify(ctx context.Context) error
	}
	// contains filtered or unexported fields
}

func NewMetaService

func NewMetaService(addr string, cli *imeta.Client, node *RaftNode, l *Linearizabler) *MetaService

func (*MetaService) AcquireLease

func (s *MetaService) AcquireLease(w http.ResponseWriter, r *http.Request)

func (*MetaService) AddShardOwner

func (s *MetaService) AddShardOwner(w http.ResponseWriter, r *http.Request)

func (*MetaService) Authenticate

func (s *MetaService) Authenticate(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateContinuousQuery

func (s *MetaService) CreateContinuousQuery(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateDataNode

func (s *MetaService) CreateDataNode(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateDatabase

func (s *MetaService) CreateDatabase(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateDatabaseWithRetentionPolicy

func (s *MetaService) CreateDatabaseWithRetentionPolicy(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateRetentionPolicy

func (s *MetaService) CreateRetentionPolicy(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateShardGroup

func (s *MetaService) CreateShardGroup(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateSubscription

func (s *MetaService) CreateSubscription(w http.ResponseWriter, r *http.Request)

func (*MetaService) CreateUser

func (s *MetaService) CreateUser(w http.ResponseWriter, r *http.Request)

func (*MetaService) Data

func (s *MetaService) Data(w http.ResponseWriter, r *http.Request)

func (*MetaService) DeleteDataNode

func (s *MetaService) DeleteDataNode(w http.ResponseWriter, r *http.Request)

func (*MetaService) DeleteShardGroup

func (s *MetaService) DeleteShardGroup(w http.ResponseWriter, r *http.Request)

func (*MetaService) DropContinuousQuery

func (s *MetaService) DropContinuousQuery(w http.ResponseWriter, r *http.Request)

func (*MetaService) DropDatabase

func (s *MetaService) DropDatabase(w http.ResponseWriter, r *http.Request)

func (*MetaService) DropRetentionPolicy

func (s *MetaService) DropRetentionPolicy(w http.ResponseWriter, r *http.Request)

func (*MetaService) DropShard

func (s *MetaService) DropShard(w http.ResponseWriter, r *http.Request)

func (*MetaService) DropSubscription

func (s *MetaService) DropSubscription(w http.ResponseWriter, r *http.Request)

func (*MetaService) DropUser

func (s *MetaService) DropUser(w http.ResponseWriter, r *http.Request)

func (*MetaService) InitRouter

func (s *MetaService) InitRouter()

func (*MetaService) Ping

func (s *MetaService) Ping(w http.ResponseWriter, r *http.Request)

func (*MetaService) PrecreateShardGroups

func (s *MetaService) PrecreateShardGroups(w http.ResponseWriter, r *http.Request)

func (*MetaService) ProposeAndWait

func (s *MetaService) ProposeAndWait(msgType int, data []byte, retData interface{}) error

func (*MetaService) PruneShardGroups

func (s *MetaService) PruneShardGroups(w http.ResponseWriter, r *http.Request)

func (*MetaService) RemoveShardOwner

func (s *MetaService) RemoveShardOwner(w http.ResponseWriter, r *http.Request)

func (*MetaService) SetAdminPrivilege

func (s *MetaService) SetAdminPrivilege(w http.ResponseWriter, r *http.Request)

func (*MetaService) SetPrivilege

func (s *MetaService) SetPrivilege(w http.ResponseWriter, r *http.Request)

func (*MetaService) Start

func (s *MetaService) Start()

func (*MetaService) Stop

func (s *MetaService) Stop()

func (*MetaService) TruncateShardGroups

func (s *MetaService) TruncateShardGroups(w http.ResponseWriter, r *http.Request)

func (*MetaService) UpdateRetentionPolicy

func (s *MetaService) UpdateRetentionPolicy(w http.ResponseWriter, r *http.Request)

func (*MetaService) UpdateUser

func (s *MetaService) UpdateUser(w http.ResponseWriter, r *http.Request)

func (*MetaService) WithLogger

func (s *MetaService) WithLogger(log *zap.Logger)

type Peer

type Peer struct {
	Addr   string `toml:"addr"`
	RaftId uint64 `toml:"raft-id"`
}

type PingResp

type PingResp struct {
	CommonResp
	Index uint64
}

type PrecreateShardGroupsReq

type PrecreateShardGroupsReq struct {
	From time.Time
	To   time.Time
}

PrecreateShardGroups

type PrecreateShardGroupsResp

type PrecreateShardGroupsResp struct {
	CommonResp
}

type PruneShardGroupsResp

type PruneShardGroupsResp struct {
	CommonResp
}

type RaftNode

type RaftNode struct {
	ID   uint64
	Node raft.Node

	MetaCli MetaClient

	//raft集群内部配置状态
	RaftConfState *raftpb.ConfState

	//TODO: 这个状态可以消除掉
	RaftCtx *internal.RaftContext

	//存储本地raft节点的配置信息
	RaftConfig *raft.Config

	//来自配置文件的配置信息
	Config Config

	//用于存储raft日志和snapshot
	Storage *raftwal.DiskStorage

	//节点之间的通信模块
	Transport interface {
		SetPeers(peers map[uint64]string)
		SetPeer(id uint64, addr string)
		DeletePeer(id uint64)
		ClonePeers() map[uint64]string
		SendMessage(messages []raftpb.Message)
		JoinCluster(ctx *internal.RaftContext, peers []raft.Peer) error
	}

	Done chan struct{}

	//only for test
	ApplyCallBack func(proposal *internal.Proposal, index uint64)

	Logger *zap.Logger
	// contains filtered or unexported fields
}

func NewRaftNode

func NewRaftNode(config Config) *RaftNode

func (*RaftNode) AppliedIndex

func (s *RaftNode) AppliedIndex() uint64

func (*RaftNode) ConfState

func (s *RaftNode) ConfState() *raftpb.ConfState

func (*RaftNode) HandleMessage

func (s *RaftNode) HandleMessage(w http.ResponseWriter, r *http.Request)

func (*RaftNode) HandleUpdateCluster

func (s *RaftNode) HandleUpdateCluster(w http.ResponseWriter, r *http.Request)

func (*RaftNode) InitAndStartNode

func (s *RaftNode) InitAndStartNode()

func (*RaftNode) PastLife

func (s *RaftNode) PastLife() (idx uint64, restart bool, rerr error)

func (*RaftNode) Propose

func (s *RaftNode) Propose(ctx context.Context, data []byte) error

func (*RaftNode) ProposeAndWait

func (s *RaftNode) ProposeAndWait(ctx context.Context, proposal *internal.Proposal, retData interface{}) error

func (*RaftNode) ProposeConfChange

func (s *RaftNode) ProposeConfChange(ctx context.Context, cc raftpb.ConfChange) error

func (*RaftNode) ReadIndex

func (s *RaftNode) ReadIndex(ctx context.Context, rctx []byte) error

func (*RaftNode) ReadState

func (s *RaftNode) ReadState() <-chan raft.ReadState

func (*RaftNode) RecvRaftRPC

func (s *RaftNode) RecvRaftRPC(ctx context.Context, m raftpb.Message) error

func (*RaftNode) Run

func (s *RaftNode) Run()

func (*RaftNode) SetConfState

func (s *RaftNode) SetConfState(cs *raftpb.ConfState)

func (*RaftNode) Stop

func (s *RaftNode) Stop()

func (*RaftNode) WaitIndex

func (s *RaftNode) WaitIndex(index uint64) <-chan struct{}

func (*RaftNode) WithLogger

func (s *RaftNode) WithLogger(log *zap.Logger)

type RemoveShardOwnerReq

type RemoveShardOwnerReq struct {
	ShardID uint64
	NodeID  uint64
}

type RemoveShardOwnerResp

type RemoveShardOwnerResp struct {
	CommonResp
}

type RetentionPolicySpec

type RetentionPolicySpec struct {
	Name               string
	ReplicaN           int
	Duration           time.Duration
	ShardGroupDuration time.Duration
}

type SetAdminPrivilegeReq

type SetAdminPrivilegeReq struct {
	UserName string
	Admin    bool
}

type SetAdminPrivilegeResp

type SetAdminPrivilegeResp struct {
	CommonResp
}

type SetPrivilegeReq

type SetPrivilegeReq struct {
	UserName  string
	Database  string
	Privilege influxql.Privilege
}

type SetPrivilegeResp

type SetPrivilegeResp struct {
	CommonResp
}

type Transport

type Transport struct {
	Logger *zap.Logger

	PeersAddr map[uint64]string
	Node      interface {
		RecvRaftRPC(ctx context.Context, m raftpb.Message) error
	}
	// contains filtered or unexported fields
}

func NewTransport

func NewTransport() *Transport

func (*Transport) ClonePeers

func (t *Transport) ClonePeers() map[uint64]string

func (*Transport) DeletePeer

func (t *Transport) DeletePeer(id uint64)

func (*Transport) JoinCluster

func (t *Transport) JoinCluster(ctx *internal.RaftContext, peers []raft.Peer) error

func (*Transport) Peer

func (t *Transport) Peer(id uint64) (string, bool)

func (*Transport) RecvMessage

func (t *Transport) RecvMessage(message raftpb.Message)

func (*Transport) SendMessage

func (t *Transport) SendMessage(messages []raftpb.Message)

func (*Transport) SetPeer

func (t *Transport) SetPeer(id uint64, addr string)

func (*Transport) SetPeers

func (t *Transport) SetPeers(peers map[uint64]string)

func (*Transport) WithLogger

func (t *Transport) WithLogger(log *zap.Logger)

type TruncateShardGroupsReq

type TruncateShardGroupsReq struct {
	Time time.Time
}

type TruncateShardGroupsResp

type TruncateShardGroupsResp struct {
	CommonResp
}

type UpdateRetentionPolicyReq

type UpdateRetentionPolicyReq struct {
	Database    string
	Name        string
	Rps         RetentionPolicySpec
	MakeDefault bool
}

type UpdateRetentionPolicyResp

type UpdateRetentionPolicyResp struct {
	CommonResp
}

type UpdateUserReq

type UpdateUserReq struct {
	Name     string
	Password string
}

type UpdateUserResp

type UpdateUserResp struct {
	CommonResp
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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