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
- Variables
- func DefaultHost(hostname, addr string) (string, error)
- type BaseCallback
- type Client
- func (c *Client) AddPt(ptId uint32)
- func (c *Client) AdminUserExists() bool
- func (c *Client) AlterShardKey(database, retentionPolicy, mst string, shardKey *meta2.ShardKeyInfo) error
- func (c *Client) Authenticate(username, password string) (u meta2.User, e error)
- func (c *Client) Close() error
- func (c *Client) ClusterID() uint64
- func (c *Client) CompareHashAndPlainPwd(hashed, plaintext string) error
- func (c *Client) CreateDataNode(writeHost, queryHost string) (uint64, uint64, error)
- func (c *Client) CreateDatabase(name string) (*meta2.DatabaseInfo, error)
- func (c *Client) CreateDatabaseWithRetentionPolicy(name string, spec *meta2.RetentionPolicySpec, shardKey *meta2.ShardKeyInfo) (*meta2.DatabaseInfo, error)
- func (c *Client) CreateMeasurement(database string, retentionPolicy string, mst string, ...) (*meta2.MeasurementInfo, error)
- func (c *Client) CreateMetaNode(httpAddr, tcpAddr string) (*meta2.NodeInfo, error)
- func (c *Client) CreateRetentionPolicy(database string, spec *meta2.RetentionPolicySpec, makeDefault bool) (*meta2.RetentionPolicyInfo, error)
- func (c *Client) CreateShardGroup(database, policy string, timestamp time.Time) (*meta2.ShardGroupInfo, error)
- func (c *Client) CreateSubscription(database, rp, name, mode string, destinations []string) error
- func (c *Client) CreateUser(name, password string, admin, rwuser bool) (meta2.User, error)
- func (c *Client) DBPtView(database string) (meta2.DBPtInfos, error)
- func (c *Client) Data() meta2.Data
- func (c *Client) DataNode(id uint64) (*meta2.DataNode, error)
- func (c *Client) DataNodeByHTTPHost(httpAddr string) (*meta2.DataNode, error)
- func (c *Client) DataNodeByTCPHost(tcpAddr string) (*meta2.DataNode, error)
- func (c *Client) DataNodes() ([]meta2.DataNode, error)
- func (c *Client) Database(name string) (*meta2.DatabaseInfo, error)
- func (c *Client) Databases() map[string]*meta2.DatabaseInfo
- func (c *Client) DeleteDataNode(id uint64) error
- func (c *Client) DeleteIndexGroup(database, policy string, id uint64) error
- func (c *Client) DeleteMetaNode(id uint64) error
- func (c *Client) DeleteShardGroup(database, policy string, id uint64) error
- func (c *Client) DropDatabase(name string) error
- func (c *Client) DropRetentionPolicy(database, name string) error
- func (c *Client) DropShard(id uint64) error
- func (c *Client) DropSubscription(database, rp, name string) error
- func (c *Client) DropUser(name string) error
- func (c *Client) FieldKeys(database string, ms influxql.Measurements) (map[string]map[string]int32, error)
- func (c *Client) GetAliveShards(database string, sgi *meta2.ShardGroupInfo) []int
- func (c *Client) GetMeasurements(m *influxql.Measurement) ([]*meta2.MeasurementInfo, error)
- func (c *Client) GetShardDurationInfo(index uint64) (*meta2.ShardDurationResponse, error)
- func (c *Client) GetShardRangeInfo(db string, rp string, shardID uint64) (*meta2.ShardTimeRangeInfo, error)
- func (c *Client) InitMetaClient(joinPeers []string, tlsEn bool, storageNodeInfo *StorageNodeInfo) (uint64, uint64, error)
- func (c *Client) IsLeader() bool
- func (c *Client) JoinMetaServer(httpAddr, rpcAddr, tcpAddr string) (*meta2.NodeInfo, error)
- func (c *Client) MarkDatabaseDelete(name string) error
- func (c *Client) MarkMeasurementDelete(database, measurement string) error
- func (c *Client) MarkRetentionPolicyDelete(database, name string) error
- func (c *Client) MarshalBinary() ([]byte, error)
- func (c *Client) MatchMeasurements(database string, ms influxql.Measurements) (map[string]*meta2.MeasurementInfo, error)
- func (c *Client) Measurement(database string, rpName string, mstName string) (*meta2.MeasurementInfo, error)
- func (c *Client) Measurements(database string, ms influxql.Measurements) ([]string, error)
- func (c *Client) MetaNodeByAddr(addr string) *meta2.NodeInfo
- func (c *Client) MetaNodes() ([]meta2.NodeInfo, error)
- func (c *Client) MetaServers() []string
- func (c *Client) NodeID() uint64
- func (c *Client) Open() error
- func (c *Client) Peers() []string
- func (c *Client) Ping(checkAllMetaServers bool) error
- func (c *Client) PruneGroupsCommand(shardGroup bool) error
- func (c *Client) PruneShardGroups() error
- func (c *Client) PtIds() []uint32
- func (c *Client) QueryTagKeys(database string, ms influxql.Measurements, cond influxql.Expr) (map[string]map[string]struct{}, error)
- func (c *Client) ReportShardLoads(dbPTStats []*proto2.DBPtStatus) error
- func (c *Client) RetentionPolicy(database, name string) (rpi *meta2.RetentionPolicyInfo, err error)
- func (c *Client) RetryGetShardAuxInfo(cmd *proto2.Command) ([]byte, error)
- func (c *Client) Schema(database string, retentionPolicy string, mst string) (fields map[string]int32, dimensions map[string]struct{}, err error)
- func (c *Client) SendRPCMsg(currentServer int, msg *message.MetaMessage, callback transport.Callback) error
- func (c *Client) SetAdminPrivilege(username string, admin bool) error
- func (c *Client) SetData(data *meta2.Data) error
- func (c *Client) SetDefaultRetentionPolicy(database, name string) error
- func (c *Client) SetMetaServers(a []string)
- func (c *Client) SetPrivilege(username, database string, p originql.Privilege) error
- func (c *Client) SetTLS(v bool)
- func (c *Client) SetTier(tier string) error
- func (c *Client) ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta2.ShardGroupInfo, err error)
- func (c *Client) ShardIDs() []uint64
- func (c *Client) ShardOwner(shardID uint64) (database, policy string, sgi *meta2.ShardGroupInfo)
- func (c *Client) ShardsByTimeRange(sources influxql.Sources, tmin, tmax time.Time) (a []meta2.ShardInfo, err error)
- func (c *Client) ShowRetentionPolicies(database string) (models.Rows, error)
- func (c *Client) ShowShardGroups() models.Rows
- func (c *Client) ShowShards() models.Rows
- func (c *Client) ShowSubscriptions() models.Rows
- func (c *Client) TagKeys(database string) map[string]set.Set
- func (c *Client) TruncateShardGroups(t time.Time) error
- func (c *Client) UpdateRetentionPolicy(database, name string, rpu *meta2.RetentionPolicyUpdate, makeDefault bool) error
- func (c *Client) UpdateSchema(database string, retentionPolicy string, mst string, ...) error
- func (c *Client) UpdateShardInfoTier(shardID uint64, tier uint64, dbName, rpName string) error
- func (c *Client) UpdateUser(name, password string) error
- func (c *Client) User(name string) (meta2.User, error)
- func (c *Client) UserCount() int
- func (c *Client) UserPrivilege(username, database string) (*originql.Privilege, error)
- func (c *Client) UserPrivileges(username string) (map[string]originql.Privilege, error)
- func (c *Client) Users() []meta2.UserInfo
- func (c *Client) WaitForDataChanged() chan struct{}
- type CreateNodeCallback
- type DBPTCtx
- type ErrRedirect
- type ExecuteAndReportCallback
- type FieldKey
- type FieldKeys
- type GetShardInfoCallback
- type JoinCallback
- type LoadCtx
- type MetaClient
- type Node
- type Peers
- type PeersCallback
- type PingCallback
- type SnapshotCallback
- type StorageNodeInfo
Constants ¶
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 )
const (
ClockFileName = "clock"
)
Variables ¶
var (
ErrNameTooLong = errors.New("database name should fewer than 64 characters")
)
var LogicClock uint64
Functions ¶
func DefaultHost ¶
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 (*Client) AdminUserExists ¶
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 ¶
Authenticate returns a UserInfo if the username and password match an existing entry.
func (*Client) CompareHashAndPlainPwd ¶
compares a hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.
func (*Client) CreateDataNode ¶
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 (*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 ¶
CreateSubscription creates a subscription against the given database and retention policy.
func (*Client) CreateUser ¶
CreateUser adds a user with the given name and password and admin status.
func (*Client) DataNodeByHTTPHost ¶
DataNodeByHTTPHost returns the data node with the give http bind address
func (*Client) DataNodeByTCPHost ¶
DataNodeByTCPHost returns the data node with the give http bind address
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 ¶
DeleteDataNode deletes a data node from the cluster.
func (*Client) DeleteIndexGroup ¶
func (*Client) DeleteMetaNode ¶
func (*Client) DeleteShardGroup ¶
DeleteShardGroup removes a shard group from a database and retention policy by id.
func (*Client) DropDatabase ¶
DropDatabase deletes a database.
func (*Client) DropRetentionPolicy ¶
DropRetentionPolicy drops a retention policy from a database.
func (*Client) DropSubscription ¶
DropSubscription removes the named subscription from the given database and retention policy.
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 (*Client) InitMetaClient ¶
func (*Client) JoinMetaServer ¶
JoinMetaServer will add the passed in tcpAddr to the raft peers and add a MetaNode to the metastore
func (*Client) MarkDatabaseDelete ¶
func (*Client) MarkMeasurementDelete ¶
func (*Client) MarkRetentionPolicyDelete ¶
func (*Client) MarshalBinary ¶
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 (*Client) Measurements ¶
func (*Client) MetaNodeByAddr ¶
MetaNodeByAddr returns the meta node's info.
func (*Client) MetaServers ¶
func (*Client) Ping ¶
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 ¶
PyStore send command to PyMeta. NO need to waitForIndex.
func (*Client) PruneShardGroups ¶
PruneShardGroups remove deleted shard groups from the data store.
func (*Client) QueryTagKeys ¶
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 (*Client) SendRPCMsg ¶
func (*Client) SetAdminPrivilege ¶
SetAdminPrivilege sets or unsets admin privilege to the given username.
func (*Client) SetDefaultRetentionPolicy ¶
SetDefaultRetentionPolicy sets a database's default retention policy.
func (*Client) SetMetaServers ¶
SetMetaServers updates the meta servers on the client.
func (*Client) SetPrivilege ¶
SetPrivilege sets a privilege for the given user on the given database.
func (*Client) SetTLS ¶
SetTLS sets whether the client should use TLS when connecting. This function is not safe for concurrent use.
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) 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 (*Client) ShowShardGroups ¶
func (*Client) ShowShards ¶
func (*Client) ShowSubscriptions ¶
func (*Client) TruncateShardGroups ¶
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 (*Client) UpdateShardInfoTier ¶
func (*Client) UpdateUser ¶
UpdateUser updates the password of an existing user.
func (*Client) UserPrivilege ¶
UserPrivilege returns the privilege for the given user on the given database.
func (*Client) UserPrivileges ¶
UserPrivileges returns the privileges for a user mapped by database name.
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 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 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 ¶
func (*Node) LoadLogicalClock ¶
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