metaclient

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

nolint

Copyright (c) 2013-2016 Errplane Inc. This code is originally from: https://github.com/influxdata/influxdb/blob/1.7/services/meta/client.go

2022.01.23 change http to rpc Add TagKeys,FieldKeys etc. Copyright 2022 Huawei Cloud Computing Technologies Co., Ltd.

Index

Constants

View Source
const (

	// SaltBytes is the number of bytes used for salts.
	SaltBytes = 32

	// ShardGroupDeletedExpiration is the amount of time before a shard group info will be removed from cached
	// data after it has been marked deleted (2 weeks).
	ShardGroupDeletedExpiration = -2 * 7 * 24 * time.Hour
	IndexGroupDeletedExpiration = -2 * 7 * 24 * time.Hour

	RPCReqTimeout       = 10 * time.Second
	HttpReqTimeout      = 10 * time.Second
	HttpSnapshotTimeout = 4 * time.Second
)
View Source
const (
	ClockFileName = "clock"
)

Variables

View Source
var (
	ErrNameTooLong = errors.New("database name should fewer than 64 characters")
)
View Source
var LogicClock uint64

Functions

func DefaultHost

func DefaultHost(hostname, addr string) (string, error)

Types

type BaseCallback

type BaseCallback struct {
}

func (*BaseCallback) GetCodec

func (c *BaseCallback) GetCodec() transport.Codec

func (*BaseCallback) Trans2MetaMsg

func (c *BaseCallback) Trans2MetaMsg(data interface{}) (*message.MetaMessage, error)

type Client

type Client struct {
	ShardDurations map[uint64]*meta2.ShardDurationInfo

	ShardTier uint64
	// contains filtered or unexported fields
}

Client is used to execute commands on and read data from a meta service cluster.

var DefaultMetaClient *Client

func NewClient

func NewClient(weakPwdPath string, retentionAutoCreate bool, maxConcurrentWriteLimit int) *Client

NewClient returns a new *Client.

func (*Client) AddPt

func (c *Client) AddPt(ptId uint32)

func (*Client) AdminUserExists

func (c *Client) AdminUserExists() bool

AdminUserExists returns true if any user has admin privilege.

func (*Client) AlterShardKey

func (c *Client) AlterShardKey(database, retentionPolicy, mst string, shardKey *meta2.ShardKeyInfo) error

func (*Client) Authenticate

func (c *Client) Authenticate(username, password string) (u meta2.User, e error)

Authenticate returns a UserInfo if the username and password match an existing entry.

func (*Client) Close

func (c *Client) Close() error

Close the meta service cluster connection.

func (*Client) ClusterID

func (c *Client) ClusterID() uint64

ClusterID returns the ID of the cluster it's connected to.

func (*Client) CompareHashAndPlainPwd

func (c *Client) CompareHashAndPlainPwd(hashed, plaintext string) error

compares a hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.

func (*Client) CreateDataNode

func (c *Client) CreateDataNode(writeHost, queryHost string) (uint64, uint64, error)

CreateDataNode will create a new data node in the metastore

func (*Client) CreateDatabase

func (c *Client) CreateDatabase(name string) (*meta2.DatabaseInfo, error)

CreateDatabase creates a database or returns it if it already exists.

func (*Client) CreateDatabaseWithRetentionPolicy

func (c *Client) CreateDatabaseWithRetentionPolicy(name string, spec *meta2.RetentionPolicySpec, shardKey *meta2.ShardKeyInfo) (*meta2.DatabaseInfo, error)

CreateDatabaseWithRetentionPolicy creates a database with the specified retention policy.

When creating a database with a retention policy, the retention policy will always be set to default. Therefore if the caller provides a retention policy that already exists on the database, but that retention policy is not the default one, an error will be returned.

This call is only idempotent when the caller provides the exact same retention policy, and that retention policy is already the default for the database.

func (*Client) CreateMeasurement

func (c *Client) CreateMeasurement(database string, retentionPolicy string, mst string, shardKey *meta2.ShardKeyInfo, indexR *meta2.IndexRelation) (*meta2.MeasurementInfo, error)

func (*Client) CreateMetaNode

func (c *Client) CreateMetaNode(httpAddr, tcpAddr string) (*meta2.NodeInfo, error)

func (*Client) CreateRetentionPolicy

func (c *Client) CreateRetentionPolicy(database string, spec *meta2.RetentionPolicySpec, makeDefault bool) (*meta2.RetentionPolicyInfo, error)

CreateRetentionPolicy creates a retention policy on the specified database.

func (*Client) CreateShardGroup

func (c *Client) CreateShardGroup(database, policy string, timestamp time.Time) (*meta2.ShardGroupInfo, error)

CreateShardGroup creates a shard group on a database and policy for a given timestamp.

func (*Client) CreateSubscription

func (c *Client) CreateSubscription(database, rp, name, mode string, destinations []string) error

CreateSubscription creates a subscription against the given database and retention policy.

func (*Client) CreateUser

func (c *Client) CreateUser(name, password string, admin, rwuser bool) (meta2.User, error)

CreateUser adds a user with the given name and password and admin status.

func (*Client) DBPtView

func (c *Client) DBPtView(database string) (meta2.DBPtInfos, error)

func (*Client) Data

func (c *Client) Data() meta2.Data

Data returns a Clone of the underlying data in the meta store.

func (*Client) DataNode

func (c *Client) DataNode(id uint64) (*meta2.DataNode, error)

DataNode returns a node by id.

func (*Client) DataNodeByHTTPHost

func (c *Client) DataNodeByHTTPHost(httpAddr string) (*meta2.DataNode, error)

DataNodeByHTTPHost returns the data node with the give http bind address

func (*Client) DataNodeByTCPHost

func (c *Client) DataNodeByTCPHost(tcpAddr string) (*meta2.DataNode, error)

DataNodeByTCPHost returns the data node with the give http bind address

func (*Client) DataNodes

func (c *Client) DataNodes() ([]meta2.DataNode, error)

DataNodes returns the data nodes' info.

func (*Client) Database

func (c *Client) Database(name string) (*meta2.DatabaseInfo, error)

Database returns info for the requested database.

func (*Client) Databases

func (c *Client) Databases() map[string]*meta2.DatabaseInfo

Databases returns a list of all database infos.

func (*Client) DeleteDataNode

func (c *Client) DeleteDataNode(id uint64) error

DeleteDataNode deletes a data node from the cluster.

func (*Client) DeleteIndexGroup

func (c *Client) DeleteIndexGroup(database, policy string, id uint64) error

func (*Client) DeleteMetaNode

func (c *Client) DeleteMetaNode(id uint64) error

func (*Client) DeleteShardGroup

func (c *Client) DeleteShardGroup(database, policy string, id uint64) error

DeleteShardGroup removes a shard group from a database and retention policy by id.

func (*Client) DropDatabase

func (c *Client) DropDatabase(name string) error

DropDatabase deletes a database.

func (*Client) DropRetentionPolicy

func (c *Client) DropRetentionPolicy(database, name string) error

DropRetentionPolicy drops a retention policy from a database.

func (*Client) DropShard

func (c *Client) DropShard(id uint64) error

DropShard deletes a shard by ID.

func (*Client) DropSubscription

func (c *Client) DropSubscription(database, rp, name string) error

DropSubscription removes the named subscription from the given database and retention policy.

func (*Client) DropUser

func (c *Client) DropUser(name string) error

DropUser removes the user with the given name.

func (*Client) FieldKeys

func (c *Client) FieldKeys(database string, ms influxql.Measurements) (map[string]map[string]int32, error)

func (*Client) GetAliveShards

func (c *Client) GetAliveShards(database string, sgi *meta2.ShardGroupInfo) []int

func (*Client) GetMeasurements

func (c *Client) GetMeasurements(m *influxql.Measurement) ([]*meta2.MeasurementInfo, error)

func (*Client) GetShardDurationInfo

func (c *Client) GetShardDurationInfo(index uint64) (*meta2.ShardDurationResponse, error)

func (*Client) GetShardRangeInfo

func (c *Client) GetShardRangeInfo(db string, rp string, shardID uint64) (*meta2.ShardTimeRangeInfo, error)

func (*Client) InitMetaClient

func (c *Client) InitMetaClient(joinPeers []string, tlsEn bool, storageNodeInfo *StorageNodeInfo) (uint64, uint64, error)

func (*Client) IsLeader

func (c *Client) IsLeader() bool

IsLeader - should get rid of this

func (*Client) JoinMetaServer

func (c *Client) JoinMetaServer(httpAddr, rpcAddr, tcpAddr string) (*meta2.NodeInfo, error)

JoinMetaServer will add the passed in tcpAddr to the raft peers and add a MetaNode to the metastore

func (*Client) MarkDatabaseDelete

func (c *Client) MarkDatabaseDelete(name string) error

func (*Client) MarkMeasurementDelete

func (c *Client) MarkMeasurementDelete(database, measurement string) error

func (*Client) MarkRetentionPolicyDelete

func (c *Client) MarkRetentionPolicyDelete(database, name string) error

func (*Client) MarshalBinary

func (c *Client) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the underlying data.

func (*Client) MatchMeasurements

func (c *Client) MatchMeasurements(database string, ms influxql.Measurements) (map[string]*meta2.MeasurementInfo, error)

func (*Client) Measurement

func (c *Client) Measurement(database string, rpName string, mstName string) (*meta2.MeasurementInfo, error)

func (*Client) Measurements

func (c *Client) Measurements(database string, ms influxql.Measurements) ([]string, error)

func (*Client) MetaNodeByAddr

func (c *Client) MetaNodeByAddr(addr string) *meta2.NodeInfo

MetaNodeByAddr returns the meta node's info.

func (*Client) MetaNodes

func (c *Client) MetaNodes() ([]meta2.NodeInfo, error)

MetaNodes returns the meta nodes' info.

func (*Client) MetaServers

func (c *Client) MetaServers() []string

func (*Client) NodeID

func (c *Client) NodeID() uint64

NodeID GetNodeID returns the client's node ID.

func (*Client) Open

func (c *Client) Open() error

Open a connection to a meta service cluster.

func (*Client) Peers

func (c *Client) Peers() []string

Peers returns the TCPHost addresses of all the metaservers

func (*Client) Ping

func (c *Client) Ping(checkAllMetaServers bool) error

Ping will hit the ping endpoint for the metaservice and return nil if it returns 200. If checkAllMetaServers is set to true, it will hit the ping endpoint and tell it to verify the health of all metaservers in the cluster

func (*Client) PruneGroupsCommand

func (c *Client) PruneGroupsCommand(shardGroup bool) error

PyStore send command to PyMeta. NO need to waitForIndex.

func (*Client) PruneShardGroups

func (c *Client) PruneShardGroups() error

PruneShardGroups remove deleted shard groups from the data store.

func (*Client) PtIds

func (c *Client) PtIds() []uint32

func (*Client) QueryTagKeys

func (c *Client) QueryTagKeys(database string, ms influxql.Measurements, cond influxql.Expr) (map[string]map[string]struct{}, error)

func (*Client) ReportShardLoads

func (c *Client) ReportShardLoads(dbPTStats []*proto2.DBPtStatus) error

func (*Client) RetentionPolicy

func (c *Client) RetentionPolicy(database, name string) (rpi *meta2.RetentionPolicyInfo, err error)

RetentionPolicy returns the requested retention policy info.

func (*Client) RetryGetShardAuxInfo

func (c *Client) RetryGetShardAuxInfo(cmd *proto2.Command) ([]byte, error)

func (*Client) Schema

func (c *Client) Schema(database string, retentionPolicy string, mst string) (fields map[string]int32,
	dimensions map[string]struct{}, err error)

func (*Client) SendRPCMsg

func (c *Client) SendRPCMsg(currentServer int, msg *message.MetaMessage, callback transport.Callback) error

func (*Client) SetAdminPrivilege

func (c *Client) SetAdminPrivilege(username string, admin bool) error

SetAdminPrivilege sets or unsets admin privilege to the given username.

func (*Client) SetData

func (c *Client) SetData(data *meta2.Data) error

SetData overwrites the underlying data in the meta store.

func (*Client) SetDefaultRetentionPolicy

func (c *Client) SetDefaultRetentionPolicy(database, name string) error

SetDefaultRetentionPolicy sets a database's default retention policy.

func (*Client) SetMetaServers

func (c *Client) SetMetaServers(a []string)

SetMetaServers updates the meta servers on the client.

func (*Client) SetPrivilege

func (c *Client) SetPrivilege(username, database string, p originql.Privilege) error

SetPrivilege sets a privilege for the given user on the given database.

func (*Client) SetTLS

func (c *Client) SetTLS(v bool)

SetTLS sets whether the client should use TLS when connecting. This function is not safe for concurrent use.

func (*Client) SetTier

func (c *Client) SetTier(tier string) error

func (*Client) ShardGroupsByTimeRange

func (c *Client) ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta2.ShardGroupInfo, err error)

ShardGroupsByTimeRange returns a list of all shard groups on a database and policy that may contain data for the specified time range. Shard groups are sorted by start time.

func (*Client) ShardIDs

func (c *Client) ShardIDs() []uint64

ShardIDs returns a list of all shard ids.

func (*Client) ShardOwner

func (c *Client) ShardOwner(shardID uint64) (database, policy string, sgi *meta2.ShardGroupInfo)

ShardOwner returns the owning shard group info for a specific shard.

func (*Client) ShardsByTimeRange

func (c *Client) ShardsByTimeRange(sources influxql.Sources, tmin, tmax time.Time) (a []meta2.ShardInfo, err error)

ShardsByTimeRange returns a slice of shards that may contain data in the time range.

func (*Client) ShowRetentionPolicies

func (c *Client) ShowRetentionPolicies(database string) (models.Rows, error)

func (*Client) ShowShardGroups

func (c *Client) ShowShardGroups() models.Rows

func (*Client) ShowShards

func (c *Client) ShowShards() models.Rows

func (*Client) ShowSubscriptions

func (c *Client) ShowSubscriptions() models.Rows

func (*Client) TagKeys

func (c *Client) TagKeys(database string) map[string]set.Set

func (*Client) TruncateShardGroups

func (c *Client) TruncateShardGroups(t time.Time) error

TruncateShardGroups truncates any shard group that could contain timestamps beyond t.

func (*Client) UpdateRetentionPolicy

func (c *Client) UpdateRetentionPolicy(database, name string, rpu *meta2.RetentionPolicyUpdate, makeDefault bool) error

UpdateRetentionPolicy updates a retention policy.

func (*Client) UpdateSchema

func (c *Client) UpdateSchema(database string, retentionPolicy string, mst string, fieldToCreate []*proto2.FieldSchema) error

func (*Client) UpdateShardInfoTier

func (c *Client) UpdateShardInfoTier(shardID uint64, tier uint64, dbName, rpName string) error

func (*Client) UpdateUser

func (c *Client) UpdateUser(name, password string) error

UpdateUser updates the password of an existing user.

func (*Client) User

func (c *Client) User(name string) (meta2.User, error)

User returns the user with the given name, or ErrUserNotFound.

func (*Client) UserCount

func (c *Client) UserCount() int

UserCount returns the number of users stored.

func (*Client) UserPrivilege

func (c *Client) UserPrivilege(username, database string) (*originql.Privilege, error)

UserPrivilege returns the privilege for the given user on the given database.

func (*Client) UserPrivileges

func (c *Client) UserPrivileges(username string) (map[string]originql.Privilege, error)

UserPrivileges returns the privileges for a user mapped by database name.

func (*Client) Users

func (c *Client) Users() []meta2.UserInfo

Users returns a slice of UserInfo representing the currently known users.

func (*Client) WaitForDataChanged

func (c *Client) WaitForDataChanged() chan struct{}

WaitForDataChanged returns a channel that will get a stuct{} when the metastore data has changed.

type CreateNodeCallback

type CreateNodeCallback struct {
	BaseCallback

	NodeStartInfo *meta.NodeStartInfo
}

func (*CreateNodeCallback) Handle

func (c *CreateNodeCallback) Handle(data interface{}) error

type DBPTCtx

type DBPTCtx struct {
	DBPTStat     *proto2.DBPtStatus
	RpStatusPool sync.Pool
}

func (*DBPTCtx) GetDBPTStat

func (r *DBPTCtx) GetDBPTStat() *proto2.DBPtStatus

func (*DBPTCtx) GetRpStat

func (r *DBPTCtx) GetRpStat() []*proto2.RpShardStatus

type ErrRedirect

type ErrRedirect struct {
	Host string
}

func (ErrRedirect) Error

func (e ErrRedirect) Error() string

type ExecuteAndReportCallback

type ExecuteAndReportCallback struct {
	BaseCallback

	Typ   uint8
	Index uint64

	ErrCommand *errCommand
}

Execute & Report

func (*ExecuteAndReportCallback) Handle

func (c *ExecuteAndReportCallback) Handle(data interface{}) error

type FieldKey

type FieldKey struct {
	Field     string
	FieldType int32
}

type FieldKeys

type FieldKeys []FieldKey

func (FieldKeys) Len

func (a FieldKeys) Len() int

func (FieldKeys) Less

func (a FieldKeys) Less(i, j int) bool

func (FieldKeys) Swap

func (a FieldKeys) Swap(i, j int)

type GetShardInfoCallback

type GetShardInfoCallback struct {
	BaseCallback

	Data []byte
}

func (*GetShardInfoCallback) Handle

func (c *GetShardInfoCallback) Handle(data interface{}) error

type JoinCallback

type JoinCallback struct {
	BaseCallback

	NodeInfo *meta.NodeInfo
}

func (*JoinCallback) Handle

func (c *JoinCallback) Handle(data interface{}) error

type LoadCtx

type LoadCtx struct {
	LoadCh    chan *DBPTCtx
	ReportCtx sync.Pool
}

func (*LoadCtx) GetReportCtx

func (ctx *LoadCtx) GetReportCtx() *DBPTCtx

func (*LoadCtx) PutReportCtx

func (ctx *LoadCtx) PutReportCtx(dbPTCtx *DBPTCtx)

type MetaClient

type MetaClient interface {
	CreateMeasurement(database string, retentionPolicy string, mst string, shardKey *meta2.ShardKeyInfo, indexR *meta2.IndexRelation) (*meta2.MeasurementInfo, error)
	AlterShardKey(database, retentionPolicy, mst string, shardKey *meta2.ShardKeyInfo) error
	CreateDatabase(name string) (*meta2.DatabaseInfo, error)
	CreateDatabaseWithRetentionPolicy(name string, spec *meta2.RetentionPolicySpec, shardKey *meta2.ShardKeyInfo) (*meta2.DatabaseInfo, error)
	CreateRetentionPolicy(database string, spec *meta2.RetentionPolicySpec, makeDefault bool) (*meta2.RetentionPolicyInfo, error)
	CreateSubscription(database, rp, name, mode string, destinations []string) error
	CreateUser(name, password string, admin, rwuser bool) (meta2.User, error)
	Databases() map[string]*meta2.DatabaseInfo
	Database(name string) (*meta2.DatabaseInfo, error)
	DataNode(id uint64) (*meta2.DataNode, error)
	DataNodes() ([]meta2.DataNode, error)
	DeleteDataNode(id uint64) error
	DeleteMetaNode(id uint64) error
	DropShard(id uint64) error
	DropDatabase(name string) error
	DropRetentionPolicy(database, name string) error
	DropSubscription(database, rp, name string) error
	DropUser(name string) error
	MetaNodes() ([]meta2.NodeInfo, error)
	RetentionPolicy(database, name string) (rpi *meta2.RetentionPolicyInfo, err error)
	SetAdminPrivilege(username string, admin bool) error
	SetPrivilege(username, database string, p originql.Privilege) error
	ShardsByTimeRange(sources influxql.Sources, tmin, tmax time.Time) (a []meta2.ShardInfo, err error)
	ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta2.ShardGroupInfo, err error)
	TruncateShardGroups(t time.Time) error
	UpdateRetentionPolicy(database, name string, rpu *meta2.RetentionPolicyUpdate, makeDefault bool) error
	UpdateUser(name, password string) error
	UserPrivilege(username, database string) (*originql.Privilege, error)
	UserPrivileges(username string) (map[string]originql.Privilege, error)
	Users() []meta2.UserInfo
	MarkDatabaseDelete(name string) error
	MarkRetentionPolicyDelete(database, name string) error
	MarkMeasurementDelete(database, mst string) error
	DBPtView(database string) (meta2.DBPtInfos, error)
	ShardOwner(shardID uint64) (database, policy string, sgi *meta2.ShardGroupInfo)
	Measurement(database string, rpName string, mstName string) (*meta2.MeasurementInfo, error)
	Schema(database string, retentionPolicy string, mst string) (fields map[string]int32, dimensions map[string]struct{}, err error)
	GetMeasurements(m *influxql.Measurement) ([]*meta2.MeasurementInfo, error)
	TagKeys(database string) map[string]set.Set
	FieldKeys(database string, ms influxql.Measurements) (map[string]map[string]int32, error)
	QueryTagKeys(database string, ms influxql.Measurements, cond influxql.Expr) (map[string]map[string]struct{}, error)
	MatchMeasurements(database string, ms influxql.Measurements) (map[string]*meta2.MeasurementInfo, error)
	Measurements(database string, ms influxql.Measurements) ([]string, error)
	ShowShards() models.Rows
	ShowShardGroups() models.Rows
	ShowSubscriptions() models.Rows
	ShowRetentionPolicies(database string) (models.Rows, error)
	GetAliveShards(database string, sgi *meta2.ShardGroupInfo) []int
}

MetaClient is an interface for accessing meta data.

type Node

type Node struct {
	ID    uint64
	Clock uint64
	// contains filtered or unexported fields
}

func NewNode

func NewNode(path string) *Node

func (*Node) LoadLogicalClock

func (n *Node) LoadLogicalClock() error

type Peers

type Peers []string

func (Peers) Append

func (peers Peers) Append(p ...string) Peers

func (Peers) Contains

func (peers Peers) Contains(peer string) bool

func (Peers) Unique

func (peers Peers) Unique() Peers

type PeersCallback

type PeersCallback struct {
	BaseCallback

	Peers []string
}

func (*PeersCallback) Handle

func (c *PeersCallback) Handle(data interface{}) error

type PingCallback

type PingCallback struct {
	BaseCallback

	Leader []byte
}

func (*PingCallback) Handle

func (c *PingCallback) Handle(data interface{}) error

type SnapshotCallback

type SnapshotCallback struct {
	BaseCallback

	Data []byte
}

func (*SnapshotCallback) Handle

func (c *SnapshotCallback) Handle(data interface{}) error

type StorageNodeInfo

type StorageNodeInfo struct {
	InsertAddr string
	SelectAddr string
}

Jump to

Keyboard shortcuts

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