config

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NormalBackend = 0
	AttachBackend = 1
)

Variables

View Source
var (
	// MockSchemaConfig config.
	MockSchemaConfig = &SchemaConfig{
		DB:     "sbtest",
		Tables: MockTablesConfig,
	}

	// MockTablesConfig config.
	MockTablesConfig = []*TableConfig{
		&TableConfig{
			Name:          "A",
			ShardKey:      "id",
			Partitions:    MockPartitionAConfig,
			AutoIncrement: MockAutoIncrment,
		},
		&TableConfig{
			Name:       "B",
			ShardKey:   "id",
			Partitions: MockPartitionBConfig,
		},
		&TableConfig{
			Name:       "L",
			ShardKey:   "id",
			Partitions: MockPartitionLConfig,
		},
	}

	// MockPartitionAConfig config.
	MockPartitionAConfig = []*PartitionConfig{
		&PartitionConfig{
			Table:   "A1",
			Segment: "0-2",
			Backend: "backend1",
		},
		&PartitionConfig{
			Table:   "A2",
			Segment: "2-4",
			Backend: "backend1",
		},
		&PartitionConfig{
			Table:   "A3",
			Segment: "4-8",
			Backend: "backend2",
		},
		&PartitionConfig{
			Table:   "A4",
			Segment: "8-16",
			Backend: "backend2",
		},
	}

	// MockPartitionBConfig config.
	MockPartitionBConfig = []*PartitionConfig{
		&PartitionConfig{
			Table:   "B1",
			Segment: "0-4",
			Backend: "backend2",
		},
		&PartitionConfig{
			Table:   "B2",
			Segment: "4-8",
			Backend: "backend1",
		},
		&PartitionConfig{
			Table:   "B3",
			Segment: "8-16",
			Backend: "backend2",
		},
	}

	// MockPartitionLConfig ...
	MockPartitionLConfig = []*PartitionConfig{
		&PartitionConfig{
			Table:     "L1",
			Segment:   "",
			Backend:   "backend2",
			ListValue: "2",
		},
	}

	// MockAutoIncrment.
	MockAutoIncrment = &AutoIncrement{
		Column: "autoincrement",
	}

	// MockBackends config.
	MockBackends = []*BackendConfig{
		&BackendConfig{
			Name:           "backend1",
			Address:        "127.0.0.1:3304",
			User:           "root",
			Password:       "",
			MaxConnections: 1024,
			Role:           0,
		},
	}

	// MockProxyConfig config.
	MockProxyConfig = &ProxyConfig{
		Endpoint:       ":5566",
		MaxConnections: 1024,
		MetaDir:        "/tmp/radonmeta",
		PeerAddress:    ":8080",
	}

	// MockLogConfig config.
	MockLogConfig = &LogConfig{
		Level: "DEBUG",
	}
)

Functions

func ReadVersion

func ReadVersion(metadir string) int64

ReadVersion used to read the config version from the file.

func UpdateVersion

func UpdateVersion(metadir string) error

UpdateVersion used to update the config version of the file.

func WriteConfig

func WriteConfig(path string, conf interface{}) error

WriteConfig used to write the conf to file.

Types

type AuditConfig

type AuditConfig struct {
	Mode        string `json:"mode"`
	LogDir      string `json:"audit-dir"`
	MaxSize     int    `json:"max-size"`
	ExpireHours int    `json:"expire-hours"`
}

AuditConfig tuple.

func DefaultAuditConfig

func DefaultAuditConfig() *AuditConfig

DefaultAuditConfig returns default audit config.

func (*AuditConfig) UnmarshalJSON

func (c *AuditConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON interface on AuditConfig.

type AutoIncrement added in v1.0.6

type AutoIncrement struct {
	Column string `json:"column"`
}

AutoIncrement tuple.

type BackendConfig

type BackendConfig struct {
	Name           string `json:"name"`
	Address        string `json:"address"`
	Replica        string `json:"replica-address"`
	User           string `json:"user"`
	Password       string `json:"password"`
	DBName         string `json:"database"`
	Charset        string `json:"charset"`
	MaxConnections int    `json:"max-connections"`
	Role           int    `json:"role"`
}

BackendConfig tuple.

type BackendsConfig

type BackendsConfig struct {
	Backends []*BackendConfig `json:"backends"`
}

BackendsConfig tuple.

func ReadBackendsConfig

func ReadBackendsConfig(data string) (*BackendsConfig, error)

ReadBackendsConfig used to read the backend config from the data.

type Config

type Config struct {
	Proxy   *ProxyConfig   `json:"proxy"`
	Audit   *AuditConfig   `json:"audit"`
	Router  *RouterConfig  `json:"router"`
	Log     *LogConfig     `json:"log"`
	Monitor *MonitorConfig `json:"monitor"`
	Scatter *ScatterConfig `json:"scatter"`
}

Config tuple.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig used to load the config from file.

type LogConfig

type LogConfig struct {
	Level string `json:"level"`
}

LogConfig tuple.

func DefaultLogConfig

func DefaultLogConfig() *LogConfig

DefaultLogConfig returns default log config.

func (*LogConfig) UnmarshalJSON

func (c *LogConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON interface on LogConfig.

type MonitorConfig added in v1.0.1

type MonitorConfig struct {
	MonitorAddress string `json:"monitor-address"`
}

MonitorConfig tuple

func DefaultMonitorConfig added in v1.0.1

func DefaultMonitorConfig() *MonitorConfig

DefaultMonitorConfig returns default monitor config.

func (*MonitorConfig) UnmarshalJSON added in v1.0.1

func (c *MonitorConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON interface on MonitorConfig.

type PartitionConfig

type PartitionConfig struct {
	Table     string `json:"table"`
	Segment   string `json:"segment"`
	Backend   string `json:"backend"`
	ListValue string `json:"listvalue"`
}

PartitionConfig tuple.

type ProxyConfig

type ProxyConfig struct {
	IPS                 []string `json:"allowip"`
	MetaDir             string   `json:"meta-dir"`
	Endpoint            string   `json:"endpoint"`
	TwopcEnable         bool     `json:"twopc-enable"`
	LoadBalance         int      `json:"load-balance"`           // 0 -- disable balance, 1 -- enable balance to replica
	LowerCaseTableNames int      `json:"lower-case-table-names"` // 0 -- case sensitive, 1 -- case insensitive

	MaxConnections   int    `json:"max-connections"`
	MaxResultSize    int    `json:"max-result-size"`
	MaxJoinRows      int    `json:"max-join-rows"`
	DDLTimeout       int    `json:"ddl-timeout"`
	QueryTimeout     int    `json:"query-timeout"`
	PeerAddress      string `json:"peer-address,omitempty"`
	LongQueryTime    int    `json:"long-query-time"`
	StreamBufferSize int    `json:"stream-buffer-size"`
	IdleTxnTimeout   uint32 `json:"kill-idle-transaction"` //is consistent with the official 8.0 kill_idle_transaction

	//If autocommit-false-is-txn=true (false by default), a client connection with cmd: set autocommit=0
	//is treated as start a transaction, e.g. begin, start transaction.
	AutocommitFalseIsTxn bool `json:"autocommit-false-is-txn"`
}

ProxyConfig tuple.

func DefaultProxyConfig

func DefaultProxyConfig() *ProxyConfig

DefaultProxyConfig returns default proxy config.

func (*ProxyConfig) UnmarshalJSON

func (c *ProxyConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON interface on ProxyConfig.

type RouterConfig

type RouterConfig struct {
	Slots  int `json:"slots-readonly"`
	Blocks int `json:"blocks-readonly"`
}

RouterConfig tuple.

func DefaultRouterConfig

func DefaultRouterConfig() *RouterConfig

DefaultRouterConfig returns the default router config.

func (*RouterConfig) UnmarshalJSON

func (c *RouterConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON interface on RouterConfig.

type ScatterConfig added in v1.0.2

type ScatterConfig struct {
	XaCheckInterval int    `json:"xa-check-interval"`
	XaCheckDir      string `json:"xa-check-dir"`
	XaCheckRetrys   int    `json:"xa-check-retrys"`
}

ScatterConfig tuple.

func DefaultScatterConfig added in v1.0.2

func DefaultScatterConfig() *ScatterConfig

DefaultScatterConfig returns default ScatterConfig config.

func (*ScatterConfig) UnmarshalJSON added in v1.0.2

func (c *ScatterConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON interface on XaCheckConfig.

type SchemaConfig

type SchemaConfig struct {
	DB     string         `json:"database"`
	Tables []*TableConfig `json:"tables"`
}

SchemaConfig tuple.

type TableConfig

type TableConfig struct {
	Name          string             `json:"name"`
	Slots         int                `json:"slots-readonly"`
	Blocks        int                `json:"blocks-readonly"`
	ShardType     string             `json:"shardtype"`
	ShardKey      string             `json:"shardkey"`
	Partitions    []*PartitionConfig `json:"partitions"`
	AutoIncrement *AutoIncrement     `json:"auto-increment,omitempty"`
}

TableConfig tuple.

func ReadTableConfig

func ReadTableConfig(data string) (*TableConfig, error)

ReadTableConfig used to read the table config from the data.

type Version

type Version struct {
	Ts int64 `json:"version"`
}

Version tuple.

Jump to

Keyboard shortcuts

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