Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultHost(hostname, addr string) (string, error)
- type Client
- func (c *Client) AcquireLease(name string) (l *meta.Lease, err error)
- func (c *Client) AddShardOwner(id, nodeid uint64) error
- func (c *Client) CheckMetaServers() error
- func (c *Client) Close() error
- func (c *Client) ClusterID() uint64
- func (c *Client) CommitPendingShardOwner(id, nodeid uint64) error
- func (c *Client) CreateContinuousQuery(database, name, query string) error
- func (c *Client) CreateDataNode(httpAddr, tcpAddr string) (*NodeInfo, error)
- func (c *Client) CreateDatabase(name string) (*meta.DatabaseInfo, error)
- func (c *Client) CreateDatabaseWithRetentionPolicy(name string, spec *meta.RetentionPolicySpec) (*meta.DatabaseInfo, error)
- func (c *Client) CreateMetaNode(httpAddr, tcpAddr string) (*NodeInfo, error)
- func (c *Client) CreateRetentionPolicy(database string, spec *meta.RetentionPolicySpec) (*meta.RetentionPolicyInfo, error)
- func (c *Client) CreateShardGroup(database, policy string, timestamp time.Time) (*meta.ShardGroupInfo, error)
- func (c *Client) CreateSubscription(database, rp, name, mode string, destinations []string) error
- func (c *Client) Data() *Data
- func (c *Client) DataNode(id uint64) (*NodeInfo, error)
- func (c *Client) DataNodeByHTTPHost(httpAddr string) (*NodeInfo, error)
- func (c *Client) DataNodeByTCPHost(tcpAddr string) (*NodeInfo, error)
- func (c *Client) DataNodes() (NodeInfos, error)
- func (c *Client) Database(name string) (*meta.DatabaseInfo, error)
- func (c *Client) Databases() ([]meta.DatabaseInfo, error)
- func (c *Client) DeleteDataNode(id uint64) error
- func (c *Client) DeleteMetaNode(id uint64) error
- func (c *Client) DeleteShardGroup(database, policy string, id uint64) error
- func (c *Client) DropContinuousQuery(database, name string) error
- func (c *Client) DropDatabase(name string) error
- func (c *Client) DropRetentionPolicy(database, name string) error
- func (c *Client) DropSubscription(database, rp, name string) error
- func (c *Client) JoinMetaServer(httpAddr, tcpAddr string) (*NodeInfo, error)
- func (c *Client) Leave() error
- func (c *Client) Logger() *log.Logger
- func (c *Client) MarshalBinary() ([]byte, error)
- func (c *Client) MetaNodeByAddr(addr string) *NodeInfo
- func (c *Client) MetaNodes() (NodeInfos, error)
- func (c *Client) MetaServers() []string
- func (c *Client) NodeID() uint64
- func (c *Client) Open() error
- func (c *Client) Path() string
- func (c *Client) Ping(checkAllMetaServers bool) error
- func (c *Client) PrecreateShardGroups(from, to time.Time) error
- func (c *Client) RemovePendingShardOwner(id, nodeid uint64) error
- func (c *Client) RemoveShardOwner(id, nodeid uint64) error
- func (c *Client) RetentionPolicy(database, name string) (rpi *meta.RetentionPolicyInfo, err error)
- func (c *Client) SetData(data *Data) error
- func (c *Client) SetDefaultRetentionPolicy(database, name string) error
- func (c *Client) SetHTTPClient(httpClient *http.Client)
- func (c *Client) SetLogger(l *log.Logger)
- func (c *Client) SetMetaServers(a []string)
- func (c *Client) SetPath(path string)
- func (c *Client) SetTLS(v bool)
- func (c *Client) ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a meta.ShardGroupInfos, err error)
- func (c *Client) ShardIDs() []uint64
- func (c *Client) ShardOwner(shardID uint64) (database, policy string, si *meta.ShardInfo)
- func (c *Client) ShardPendingOwners() uint64arr
- func (c *Client) ShardsByTimeRange(sources influxql.Sources, tmin, tmax time.Time) (a []meta.ShardInfo, err error)
- func (c *Client) TLS() bool
- func (c *Client) UpdateDataNode(id uint64, host, tcpHost string) error
- func (c *Client) UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate) error
- func (c *Client) WaitForDataChanged() chan struct{}
- type Config
- type Data
- func (data *Data) AddPendingShardOwner(id uint64)
- func (data *Data) AddShardOwner(shardID, nodeID uint64) error
- func (data *Data) Clone() *Data
- func (data *Data) CreateDataNode(host, tcpHost string) error
- func (data *Data) CreateMetaNode(host, tcpHost string) error
- func (data *Data) CreateShardGroup(database, policy string, timestamp time.Time) error
- func (data *Data) DataNode(id uint64) *NodeInfo
- func (data *Data) DeleteDataNode(id uint64) error
- func (data *Data) DeleteMetaNode(id uint64) error
- func (data *Data) ImportData(buf []byte) error
- func (data *Data) MarshalBinary() ([]byte, error)
- func (data *Data) MetaNode(id uint64) *NodeInfo
- func (data *Data) PruneShard(si *meta.ShardInfo, nodeID uint64) ([]meta.ShardOwner, error)
- func (data *Data) RemovePendingShardOwner(id uint64)
- func (data *Data) RemoveShardOwner(shardID, nodeID uint64) error
- func (data *Data) SetMetaNode(nodeID uint64, host, tcpHost string) error
- func (data *Data) ShardLocation(shardID uint64) (*meta.ShardInfo, error)
- func (data *Data) TruncateShardsGrops(sg *meta.ShardGroupInfo) error
- func (data *Data) UnmarshalBinary(buf []byte) error
- func (data *Data) UpdateDataNode(nodeID uint64, host, tcpHost string) error
- func (data *Data) UpdateShard(shardID uint64, newOwners []meta.ShardOwner) error
- type Lease
- type Leases
- type NodeInfo
- type NodeInfos
- type Peers
- type Service
- func (s *Service) Close() error
- func (s *Service) Err() <-chan error
- func (s *Service) HTTPAddr() string
- func (s *Service) Open() error
- func (s *Service) RaftAddr() string
- func (s *Service) RemoteHTTPAddr(addr string) string
- func (s *Service) RemoteRaftAddr() string
- func (s *Service) ResetStore(st *store)
- func (s *Service) SetVersion(version string)
- func (s *Service) Version() string
- func (s *Service) WithLogger(log zap.Logger)
- type ShardOwners
Constants ¶
const ( // DefaultEnabled is the default state for the meta service to run DefaultEnabled = true // DefaultHostname is the default hostname if one is not provided. DefaultHostname = "localhost" // DefaultRaftBindAddress is the default address to bind to. DefaultRaftBindAddress = ":8088" // DefaultHTTPBindAddress is the default address to bind the API to. DefaultHTTPBindAddress = ":8091" // DefaultHeartbeatTimeout is the default heartbeat timeout for the store. DefaultHeartbeatTimeout = 1000 * time.Millisecond // DefaultElectionTimeout is the default election timeout for the store. DefaultElectionTimeout = 1000 * time.Millisecond // DefaultLeaderLeaseTimeout is the default leader lease for the store. DefaultLeaderLeaseTimeout = 500 * time.Millisecond // DefaultCommitTimeout is the default commit timeout for the store. DefaultCommitTimeout = 50 * time.Millisecond // DefaultRaftPromotionEnabled is the default for auto promoting a node to a raft node when needed DefaultRaftPromotionEnabled = true // DefaultLeaseDuration is the default duration for leases. DefaultLeaseDuration = 60 * time.Second // DefaultLoggingEnabled determines if log messages are printed for the meta service DefaultLoggingEnabled = true )
const ( // DefaultRetentionPolicyReplicaN is the default value of RetentionPolicyInfo.ReplicaN. DefaultRetentionPolicyReplicaN = 1 // DefaultRetentionPolicyDuration is the default value of RetentionPolicyInfo.Duration. DefaultRetentionPolicyDuration = time.Duration(0) // DefaultRetentionPolicyName is the default name for auto generated retention policies. DefaultRetentionPolicyName = "autogen" // MinRetentionPolicyDuration represents the minimum duration for a policy. MinRetentionPolicyDuration = time.Hour )
const ( // MuxHeader is header that used in tcp pakcage that help tcp distinguish // different service. MuxHeader = 8 )
Variables ¶
var ( errors.New("meta service unavailable") // ErrService is returned when the meta service returns an error. ErrService = errors.New("meta service error") )ErrServiceUnavailable =
var ( // ErrStoreOpen is returned when opening an already open store. ErrStoreOpen = errors.New("store already open") // ErrStoreClosed is returned when closing an already closed store. ErrStoreClosed = errors.New("raft store already closed") )
var ( // ErrNodeExists is returned when creating an already existing node. ErrNodeExists = errors.New("node already exists") // ErrNodeNotFound is returned when mutating a node that doesn't exist. ErrNodeNotFound = errors.New("node not found") // ErrNodesRequired is returned when at least one node is required for an operation. // This occurs when creating a shard group. ErrNodesRequired = errors.New("at least one node required") // ErrNodeIDRequired is returned when using a zero node id. ErrNodeIDRequired = errors.New("node id must be greater than 0") // ErrNodeUnableToDropFinalNode is returned if the node being dropped is the last // node in the cluster ErrNodeUnableToDropFinalNode = errors.New("unable to drop the final node in a cluster") )
var ( // ErrDatabaseExists is returned when creating an already existing database. ErrDatabaseExists = errors.New("database already exists") // ErrDatabaseNotExists is returned when operating on a not existing database. ErrDatabaseNotExists = errors.New("database does not exist") // ErrDatabaseNameRequired is returned when creating a database without a name. ErrDatabaseNameRequired = errors.New("database name required") )
var ( // ErrRetentionPolicyExists is returned when creating an already existing policy. ErrRetentionPolicyExists = errors.New("retention policy already exists") // ErrRetentionPolicyDefault is returned when attempting a prohibited operation // on a default retention policy. ErrRetentionPolicyDefault = errors.New("retention policy is default") // ErrRetentionPolicyNameRequired is returned when creating a policy without a name. ErrRetentionPolicyNameRequired = errors.New("retention policy name required") // ErrRetentionPolicyNameExists is returned when renaming a policy to // the same name as another existing policy. ErrRetentionPolicyNameExists = errors.New("retention policy name already exists") // ErrRetentionPolicyDurationTooLow is returned when updating a retention // policy that has a duration lower than the allowed minimum. ErrRetentionPolicyDurationTooLow = fmt.Errorf("retention policy duration must be at least %v", MinRetentionPolicyDuration) // ErrRetentionPolicyConflict is returned when creating a retention policy conflicts // with an existing policy. ErrRetentionPolicyConflict = errors.New("retention policy conflicts with an existing policy") // ErrReplicationFactorTooLow is returned when the replication factor is not in an // acceptable range. ErrReplicationFactorTooLow = errors.New("replication factor must be greater than 0") )
var ( // ErrShardGroupExists is returned when creating an already existing shard group. ErrShardGroupExists = errors.New("shard group already exists") // ErrShardGroupNotFound is returned when mutating a shard group that doesn't exist. ErrShardGroupNotFound = errors.New("shard group not found") // ErrShardNotReplicated is returned if the node requested to be dropped has // the last copy of a shard present and the force keyword was not used ErrShardNotReplicated = errors.New("shard not replicated") )
var ( // ErrContinuousQueryExists is returned when creating an already existing continuous query. ErrContinuousQueryExists = errors.New("continuous query already exists") // ErrContinuousQueryNotFound is returned when removing a continuous query that doesn't exist. ErrContinuousQueryNotFound = errors.New("continuous query not found") )
var ( // ErrSubscriptionExists is returned when creating an already existing subscription. ErrSubscriptionExists = errors.New("subscription already exists") // ErrSubscriptionNotFound is returned when removing a subscription that doesn't exist. ErrSubscriptionNotFound = errors.New("subscription not found") )
var ( // ErrUserExists is returned when creating an already existing user. ErrUserExists = errors.New("user already exists") // ErrUserNotFound is returned when mutating a user that doesn't exist. ErrUserNotFound = errors.New("user not found") // ErrUsernameRequired is returned when creating a user without a username. ErrUsernameRequired = errors.New("username required") // ErrAuthenticate is returned when authentication fails. ErrAuthenticate = errors.New("authentication failed") )
Functions ¶
func DefaultHost ¶
DefaultHost return defaultHost
Types ¶
type Client ¶
Client is used to execute commands on and read data from a meta service cluster.
func (*Client) AcquireLease ¶
AcquireLease attempts to acquire the specified lease. A lease is a logical concept that can be used by anything that needs to limit execution to a single node. E.g., the CQ service on all nodes may ask for the "ContinuousQuery" lease. Only the node that acquires it will run CQs. NOTE: Leases are not managed through the CP system and are not fully consistent. Any actions taken after acquiring a lease must be idempotent.
func (*Client) AddShardOwner ¶
AddShardOwner adds shardOwner.
func (*Client) CheckMetaServers ¶
CheckMetaServers checks meta nodes status.
func (*Client) CommitPendingShardOwner ¶
CommitPendingShardOwner commits pending shardOwner.
func (*Client) CreateContinuousQuery ¶
CreateContinuousQuery creates continue query in cluster.
func (*Client) CreateDataNode ¶
CreateDataNode will create a new data node in the metastore
func (*Client) CreateDatabase ¶
func (c *Client) CreateDatabase(name string) (*meta.DatabaseInfo, error)
CreateDatabase creates a database or returns it if it already exists
func (*Client) CreateDatabaseWithRetentionPolicy ¶
func (c *Client) CreateDatabaseWithRetentionPolicy(name string, spec *meta.RetentionPolicySpec) (*meta.DatabaseInfo, error)
CreateDatabaseWithRetentionPolicy creates a database with the specified retention policy.
func (*Client) CreateMetaNode ¶
CreateMetaNode creates meta node.
func (*Client) CreateRetentionPolicy ¶
func (c *Client) CreateRetentionPolicy(database string, spec *meta.RetentionPolicySpec) (*meta.RetentionPolicyInfo, error)
CreateRetentionPolicy creates a retention policy on the specified database.
func (*Client) CreateShardGroup ¶
func (c *Client) CreateShardGroup(database, policy string, timestamp time.Time) (*meta.ShardGroupInfo, error)
CreateShardGroup creates a shard group on a database and policy for a given timestamp.
func (*Client) CreateSubscription ¶
CreateSubscription creats subscription in cluster.
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) (*meta.DatabaseInfo, error)
Database returns info for the requested database.
func (*Client) Databases ¶
func (c *Client) Databases() ([]meta.DatabaseInfo, error)
Databases returns a list of all database infos.
func (*Client) DeleteDataNode ¶
DeleteDataNode deletes a data node from the cluster.
func (*Client) DeleteMetaNode ¶
DeleteMetaNode deletes meta node from meta store according to nodeID.
func (*Client) DeleteShardGroup ¶
DeleteShardGroup removes a shard group from a database and retention policy by id.
func (*Client) DropContinuousQuery ¶
DropContinuousQuery drops continue query in cluster.
func (*Client) DropDatabase ¶
DropDatabase deletes a database.
func (*Client) DropRetentionPolicy ¶
DropRetentionPolicy drops a retention policy from a database.
func (*Client) DropSubscription ¶
DropSubscription drops subscription in cluster.
func (*Client) JoinMetaServer ¶
JoinMetaServer will add the passed in tcpAddr to the raft peers and add a MetaNode to the metastore
func (*Client) MarshalBinary ¶
MarshalBinary marshals data into a bianry form.
func (*Client) MetaNodeByAddr ¶
MetaNodeByAddr returns the meta node's info.
func (*Client) MetaServers ¶
MetaServers returns all meta node info in cluster.
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) PrecreateShardGroups ¶
PrecreateShardGroups creates shard groups whose endtime is before the 'to' time passed in, but is yet to expire before 'from'. This is to avoid the need for these shards to be created when data for the corresponding time range arrives. Shard creation involves Raft consensus, and precreation avoids taking the hit at write-time.
func (*Client) RemovePendingShardOwner ¶
RemovePendingShardOwner removes a pending shardOwner according to shardID and nodeID.
func (*Client) RemoveShardOwner ¶
RemoveShardOwner removes shardOwner according to shardID and nodeID.
func (*Client) RetentionPolicy ¶
func (c *Client) RetentionPolicy(database, name string) (rpi *meta.RetentionPolicyInfo, err error)
RetentionPolicy returns the requested retention policy info.
func (*Client) SetDefaultRetentionPolicy ¶
SetDefaultRetentionPolicy sets a database's default retention policy.
func (*Client) SetHTTPClient ¶
SetHTTPClient sets httpClient.
func (*Client) SetMetaServers ¶
SetMetaServers updates the meta servers on the client.
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 meta.ShardGroupInfos, 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 ¶
ShardOwner returns the owning shard group info for a specific shard.
func (*Client) ShardPendingOwners ¶
func (c *Client) ShardPendingOwners() uint64arr
ShardPendingOwners returns an array of all pending ShardOwners.
func (*Client) ShardsByTimeRange ¶
func (c *Client) ShardsByTimeRange(sources influxql.Sources, tmin, tmax time.Time) (a []meta.ShardInfo, err error)
ShardsByTimeRange returns a slice of shards that may contain data in the time range.
func (*Client) UpdateDataNode ¶
UpdateDataNode updates data node info according nodeID.
func (*Client) UpdateRetentionPolicy ¶
func (c *Client) UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate) error
UpdateRetentionPolicy updates a retention policy.
func (*Client) WaitForDataChanged ¶
func (c *Client) WaitForDataChanged() chan struct{}
WaitForDataChanged will return a channel that will get closed when the metastore data has changed
type Config ¶
type Config struct { Enabled bool `toml:"enabled"` Dir string `toml:"dir"` // RemoteHostname is the hostname portion to use when registering meta node // addresses. This hostname must be resolvable from other nodes. RemoteHostname string `toml:"-"` // this is deprecated. Should use the address from run/config.go BindAddress string `toml:"bind-address"` // HTTPBindAddress is the bind address for the metaservice HTTP API HTTPBindAddress string `toml:"http-bind-address"` HTTPSEnabled bool `toml:"https-enabled"` HTTPSCertificate string `toml:"https-certificate"` // JoinPeers if specified gives other metastore servers to join this server to the cluster JoinPeers []string `toml:"-"` RetentionAutoCreate bool `toml:"retention-autocreate"` ElectionTimeout toml.Duration `toml:"election-timeout"` HeartbeatTimeout toml.Duration `toml:"heartbeat-timeout"` LeaderLeaseTimeout toml.Duration `toml:"leader-lease-timeout"` CommitTimeout toml.Duration `toml:"commit-timeout"` ClusterTracing bool `toml:"cluster-tracing"` RaftPromotionEnabled bool `toml:"raft-promotion-enabled"` LoggingEnabled bool `toml:"logging-enabled"` PprofEnabled bool `toml:"pprof-enabled"` LeaseDuration toml.Duration `toml:"lease-duration"` }
Config represents the meta configuration.
func (*Config) ApplyEnvOverrides ¶
ApplyEnvOverrides apply the environment configuration on top of the config.
type Data ¶
type Data struct { // This is coupled with influxdb's implementation, but the structure is pretty // stable, hence we can use it. *meta.Data MetaNodes NodeInfos DataNodes NodeInfos MaxNodeID uint64 ClusterID uint64 }
Data represents the top level collection of all metadata.
func (*Data) AddPendingShardOwner ¶
AddPendingShardOwner adds a pending shardOwner according to nodeID.
func (*Data) AddShardOwner ¶
AddShardOwner will update a shards labelled by shardID in this node if such shards ownby this newly adding node
func (*Data) CreateDataNode ¶
CreateDataNode adds a node to the metadata.
func (*Data) CreateMetaNode ¶
CreateMetaNode creats a meta node info according to host and tcpHost. NodeID are automaitically generated by program itself.
func (*Data) CreateShardGroup ¶
CreateShardGroup creates a shard group on a database and policy for a given timestamp.
func (*Data) DeleteDataNode ¶
DeleteDataNode removes a node from the Meta store.
If necessary, DeleteDataNode reassigns ownerhip of any shards that would otherwise become orphaned by the removal of the node from the cluster.
func (*Data) DeleteMetaNode ¶
DeleteMetaNode remove a meta node info from metastore according to nodeID. Data resides in that node will be also removed. It is buggy for now. Improvement is scheduled in future. TODO.
func (*Data) ImportData ¶
ImportData imports a binary form data as metastore data. Return error if such binary form is invalid.
func (*Data) MarshalBinary ¶
MarshalBinary marshals data into a binary form.
func (*Data) PruneShard ¶
PruneShard prunes shard according to nodeID.
func (*Data) RemovePendingShardOwner ¶
RemovePendingShardOwner removes a pending shardOwner according to nodeID.
func (*Data) RemoveShardOwner ¶
RemoveShardOwner will remove all shards in this node if such shard owned by this node
func (*Data) SetMetaNode ¶
SetMetaNode adds a meta node with a pre-specified nodeID.
func (*Data) ShardLocation ¶
ShardLocation return NodeInfos which is the o of the Shard
func (*Data) TruncateShardsGrops ¶
func (data *Data) TruncateShardsGrops(sg *meta.ShardGroupInfo) error
TruncateShardsGrops truncates shardsGroup according to shardsGroupID
func (*Data) UnmarshalBinary ¶
UnmarshalBinary decodes the object from a binary format.
func (*Data) UpdateDataNode ¶
UpdateDataNode updates a data node info according to is nodeID.
func (*Data) UpdateShard ¶
func (data *Data) UpdateShard(shardID uint64, newOwners []meta.ShardOwner) error
UpdateShard will update ShardOwner of a Shard according to ShardID
type Lease ¶
type Lease struct { Name string `json:"name"` Expiration time.Time `json:"expiration"` Owner uint64 `json:"owner"` }
Lease is a lease distributed over cluster.
type Leases ¶
type Leases struct {
// contains filtered or unexported fields
}
Leases is a wrapper for many leases.
type Peers ¶
type Peers []string
Peers represents meta node's peer host addres
type Service ¶
type Service struct { RaftListener net.Listener Logger zap.Logger Node *influxcloud.Node // contains filtered or unexported fields }
Service provides cluster service.
func (*Service) RemoteHTTPAddr ¶
RemoteHTTPAddr returns a remote httpAddr according to a addr.
func (*Service) RemoteRaftAddr ¶
RemoteRaftAddr returns a remote raft httpAddr.
func (*Service) WithLogger ¶
WithLogger sets the internal logger to the logger passed in
type ShardOwners ¶
type ShardOwners []meta.ShardOwner
ShardOwners is an array ot ShardOwner.
func (ShardOwners) Len ¶
func (so ShardOwners) Len() int
func (ShardOwners) Less ¶
func (so ShardOwners) Less(i, j int) bool
func (ShardOwners) Swap ¶
func (so ShardOwners) Swap(i, j int)