meta

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: 23 Imported by: 0

Documentation

Overview

Package meta provides control over meta data for InfluxDB, such as controlling databases, retention policies, users, etc.

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
)
View Source
const (
	// DefaultLeaseDuration is the default duration for leases.
	DefaultLeaseDuration = 60 * time.Second

	// DefaultLoggingEnabled determines if log messages are printed for the meta service.
	DefaultLoggingEnabled = true
)

Variables

View Source
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")
)

Functions

This section is empty.

Types

type Authorizer

type Authorizer struct {
}

func (*Authorizer) AuthorizeDatabase

func (a *Authorizer) AuthorizeDatabase(u meta.User, priv influxql.Privilege, database string) error

func (*Authorizer) AuthorizeQuery

func (a *Authorizer) AuthorizeQuery(u meta.User, query *influxql.Query, database string) error

func (*Authorizer) AuthorizeWrite

func (a *Authorizer) AuthorizeWrite(username, database string) error

type Client

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

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

func NewClient

func NewClient(config *meta.Config) *Client

NewClient returns a new *Client.

func (*Client) AddShardOwner

func (c *Client) AddShardOwner(shardID uint64, nodeID uint64) error

func (*Client) AdminUserExists

func (c *Client) AdminUserExists() bool

AdminUserExists returns true if any user has admin privilege.

func (*Client) Authenticate

func (c *Client) Authenticate(username, password string) (meta.User, 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) CreateContinuousQuery

func (c *Client) CreateContinuousQuery(database, name, query string) error

CreateContinuousQuery saves a continuous query with the given name for the given database.

func (*Client) CreateDataNode

func (c *Client) CreateDataNode(httpAddr, tcpAddr string) (*meta.NodeInfo, error)

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.

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) CreateRetentionPolicy

func (c *Client) CreateRetentionPolicy(database string, spec *meta.RetentionPolicySpec, makeDefault bool) (*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

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 bool) (meta.User, error)

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

func (*Client) Data

func (c *Client) Data() Data

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

func (*Client) DataIndex

func (c *Client) DataIndex() uint64

func (*Client) DataNode

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

Node returns a node by id.

func (*Client) DataNodeByHTTPHost

func (c *Client) DataNodeByHTTPHost(httpAddr string) (*meta.NodeInfo, error)

DataNodeByHTTPHost returns the data node with the give http bind address

func (*Client) DataNodeByTCPHost

func (c *Client) DataNodeByTCPHost(tcpAddr string) (*meta.NodeInfo, error)

DataNodeByTCPHost returns the data node with the give http bind address

func (*Client) DataNodes

func (c *Client) DataNodes() ([]meta.NodeInfo, error)

DataNodes returns the data nodes' info.

func (*Client) Database

func (c *Client) Database(name string) *meta.DatabaseInfo

Database returns info for the requested database.

func (*Client) Databases

func (c *Client) Databases() []meta.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) 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) DropContinuousQuery

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

DropContinuousQuery removes the continuous query with the given name on the given database.

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) Load

func (c *Client) Load() error

Load loads the current meta data from disk.

func (*Client) MarshalBinary

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

MarshalBinary returns a binary representation of the underlying data.

func (*Client) MetaNodeByAddr

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

MetaNodeByAddr returns the meta node's info.

func (*Client) MetaNodes

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

MetaNodes returns the meta nodes' info.

func (*Client) Open

func (c *Client) Open() error

Open a connection to a meta service cluster.

func (*Client) PrecreateShardGroups

func (c *Client) PrecreateShardGroups(from, to time.Time) error

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) Print

func (c *Client) Print()

func (*Client) PruneShardGroups

func (c *Client) PruneShardGroups() error

PruneShardGroups remove deleted shard groups from the data store.

func (*Client) RemoveShardOwner

func (c *Client) RemoveShardOwner(shardID uint64, nodeID uint64) error

func (*Client) ReplaceData

func (c *Client) ReplaceData(data *Data) error

func (*Client) RetentionPolicy

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

RetentionPolicy returns the requested retention policy info.

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 *Data) error

SetData overwrites the underlying data in the meta store.

func (*Client) SetPrivilege

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

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

func (*Client) ShardGroupByTimestamp

func (c *Client) ShardGroupByTimestamp(database, policy string, timestamp time.Time) *meta.ShardGroupInfo

func (*Client) ShardGroupsByTimeRange

func (c *Client) ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta.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 *meta.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 []meta.ShardInfo, err error)

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

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 *meta.RetentionPolicyUpdate, makeDefault bool) error

UpdateRetentionPolicy updates a retention policy.

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) (meta.User, error)

User returns the user with the given name, or meta.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) (*influxql.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]influxql.Privilege, error)

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

func (*Client) Users

func (c *Client) Users() []meta.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 closed when the metastore data has changed.

func (*Client) WithLogger

func (c *Client) WithLogger(log *zap.Logger)

WithLogger sets the logger for the client.

type Config

type Config struct {
	Dir string `toml:"dir"`

	RetentionAutoCreate bool `toml:"retention-autocreate"`
	LoggingEnabled      bool `toml:"logging-enabled"`
}

Config represents the meta configuration.

func NewConfig

func NewConfig() *Config

NewConfig builds a new configuration with default values.

func (*Config) Diagnostics

func (c *Config) Diagnostics() (*diagnostics.Diagnostics, error)

Diagnostics returns a diagnostics representation of a subset of the Config.

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the config is invalid.

type Data

type Data struct {
	meta.Data
	MetaNodes []meta.NodeInfo
	DataNodes []meta.NodeInfo

	MaxNodeID uint64
}

Data represents the top level collection of all metadata.

func (*Data) AddShardOwner

func (data *Data) AddShardOwner(id, nodeID uint64)

func (*Data) Clone

func (data *Data) Clone() *Data

Clone returns a copy of data with a new version.

func (*Data) CloneNodes

func (data *Data) CloneNodes(src []meta.NodeInfo) []meta.NodeInfo

func (*Data) CreateDataNode

func (data *Data) CreateDataNode(host, tcpHost string) error

CreateDataNode adds a node to the metadata.

func (*Data) CreateMetaNode

func (data *Data) CreateMetaNode(httpAddr, tcpAddr string) error

CreateMetaNode will add a new meta node to the metastore

func (*Data) CreateShardGroup

func (data *Data) CreateShardGroup(database, policy string, timestamp time.Time) error

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

func (*Data) DataNode

func (data *Data) DataNode(id uint64) *meta.NodeInfo

DataNode returns a node by id.

func (*Data) DeleteDataNode

func (data *Data) DeleteDataNode(id uint64) error

DeleteDataNode removes a node from the Meta store.

If necessary, DeleteDataNode reassigns ownership of any shards that would otherwise become orphaned by the removal of the node from the cluster.

func (*Data) DeleteMetaNode

func (data *Data) DeleteMetaNode(id uint64) error

DeleteMetaNode will remove the meta node from the store

func (*Data) MarshalBinary

func (data *Data) MarshalBinary() ([]byte, error)

MarshalBinary encodes the metadata to a binary format.

func (*Data) MetaNode

func (data *Data) MetaNode(id uint64) *meta.NodeInfo

MetaNode returns a node by id.

func (*Data) RemoveShardOwner

func (data *Data) RemoveShardOwner(id, nodeID uint64)

func (*Data) UnmarshalBinary

func (data *Data) UnmarshalBinary(buf []byte) error

UnmarshalBinary decodes the object from a binary format.

type DataJson

type DataJson struct {
	Data      []byte
	MetaNodes []meta.NodeInfo
	DataNodes []meta.NodeInfo
	MaxNodeID uint64
}

Jump to

Keyboard shortcuts

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