// DatabaseInfo represents information about a database in the system.
type DatabaseInfo struct {
Name string
DefaultRetentionPolicy string
RetentionPolicies []RetentionPolicyInfo
ContinuousQueries []ContinuousQueryInfo
}
RetentionPolicyInfo 定义:
// RetentionPolicyInfo represents metadata about a retention policy.
type RetentionPolicyInfo struct {
Name string
ReplicaN int
Duration time.Duration
ShardGroupDuration time.Duration
ShardGroups []ShardGroupInfo
Subscriptions []SubscriptionInfo
}
ShardGroupInfo 定义:
// ShardGroupInfo represents metadata about a shard group. The DeletedAt field is important
// because it makes it clear that a ShardGroup has been marked as deleted, and allow the system
// to be sure that a ShardGroup is not simply missing. If the DeletedAt is set, the system can
// safely delete any associated shards.
type ShardGroupInfo struct {
ID uint64
StartTime time.Time
EndTime time.Time
DeletedAt time.Time
Shards []ShardInfo
TruncatedAt time.Time
}
ShardInfo 定义:
// ShardInfo represents metadata about a shard.
type ShardInfo struct {
ID uint64
Owners []ShardOwner
}
ShardOwner 定义:
// ShardOwner represents a node that owns a shard.
type ShardOwner struct {
NodeID uint64
}
ShardOwner主要用于集群,其中NodeId用于标识集群的节点ID,在InfluxDB 1.1社区版本中集群已经不支持了,该字段无效。
SubscriptionInfo 定义:
// SubscriptionInfo hold the subscription information
type SubscriptionInfo struct {
Name string
Mode string
Destinations []string
}
ContinuousQueryInfo 定义:
// ContinuousQueryInfo represents metadata about a continuous query.
type ContinuousQueryInfo struct {
Name string
Query string
}
UserInfo 定义:
// UserInfo represents metadata about a user in the system.
type UserInfo struct {
Name string
Hash string
Admin bool
Privileges map[string]influxql.Privilege
}
其它
meta文件解析示例代码:
package main
import (
"os"
"fmt"
"io/ioutil"
"github.com/influxdata/influxdb/services/meta"
)
func Load(metaFile string) error {
cacheData:= &meta.Data{
Index: 1,
}
//file := filepath.Join(c.path, metaFile)
f, err := os.Open(metaFile)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
if err != nil {
return err
}
if err := cacheData.UnmarshalBinary(data); err != nil {
return err
}
//fmt.Println(data)
//fmt.Println("=======================")
fmt.Println("Term :",cacheData.Term)
fmt.Println("Index :",cacheData.Index)
fmt.Println("Databases :")
//fmt.Println(cacheData.Databases)
for k,dbInfo := range cacheData.Databases {
//fmt.Println(k,dbInfo)
fmt.Println("k =",k)
fmt.Println(dbInfo.Name,dbInfo.DefaultRetentionPolicy)
for _,rPolicy := range dbInfo.RetentionPolicies {
//fmt.Println(rPolicy)
fmt.Println(rPolicy.Name,rPolicy.ReplicaN,rPolicy.Duration,rPolicy.ShardGroupDuration)
fmt.Println("-------------ShardGroups---------------")
//fmt.Println(rPolicy.ShardGroups)
for shardIdx,shardGroup := range rPolicy.ShardGroups {
//fmt.Println(shardGroup)
fmt.Println("shardIdx =",shardIdx)
fmt.Println("ID :",shardGroup.ID)
fmt.Println("StartTime :",shardGroup.StartTime)
fmt.Println("EndTime :",shardGroup.EndTime)
fmt.Println("DeletedAt :",shardGroup.DeletedAt)
//fmt.Println("Shards :",shardGroup.Shards)
fmt.Printf("Shards :")
for _,shard := range shardGroup.Shards {
fmt.Println(shard.ID,shard.Owners)
}