ketch

package module
v0.0.0-...-e3d0b79 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2017 License: MPL-2.0 Imports: 24 Imported by: 0

README

Ketch

Ketch is a Go library and set of utilities to manage a cluster of replicated databases. Ketch provided enhanced reliability by configuring synchronous replication to a majority within a quorum group and reconfiguring the group around failures. The protocol for reconfiguring quorum groups is documented in the KetchProtocol.pdf file that accompanies this project.

Quorum Group

Project Status

This project is under development and not ready for production use. Contact watercraftsoftware@gmail.com for current status and plans. The project is currently offered under the Mozzila 2.0 licence.

Building

go install

Usage

Ketch has been tested with independent Postgres servers that bind to different IPs within the same Linux host. Here are example entries for /etc/hosts:

127.0.2.1	server1
127.0.2.2	server2
127.0.2.3	server3
127.0.2.4	server4

Note, a minimum of four servers is recommended to provide availability in a Ketch configuration.

The CLI interfaces in Ketch can take a combination of environment variables and command line arguments. Here I'm setting environment variables that are common to all four server instances:

# export KETCH_MEMBER_LIST=server1,server2,server3,server4
# export KETCH_DB_BIN_DIR=/usr/lib/postgresql/9.5/bin

And now I can start the servers:

# ketch --api-server server1 --data-dir ~/db/server1 run &
# ketch --api-server server2 --data-dir ~/db/server2 run &
# ketch --api-server server3 --data-dir ~/db/server3 run &
# ketch --api-server server4 --data-dir ~/db/server4 run &

We use ketchctl to create a database instance in the cluster:

# cat examples/samplereplica.yaml
data:
- attributes:
    name: mydb1
    quorumGroupSize: 3
    dbConfig:
      username: myuser
      password: mypassword
      port: 5432
      closedPort: 5433
  type: replica
# ketchctl login -s server1
# ketchctl create replica -f examples/samplereplica.yaml
...

After a short time the database can be used in the normal way:

# psql -h server1 -U myuser mydb1

Pending a planned integration with SkyDNS you should be able to locate the service with the database name:

# psql -h mydb1.mydomain.com -U myuser mydb1

Ketchctl is also used to query local resources: runtime, server, epoch, replica, and dbmbr. For example, you can view the list of connected instances of the ketch server:

# ketchctl get server
data:
- attributes:
    endpoint:
      addr: 127.0.2.1
      port: 7459
    id: 6fbacbae-2954-4472-9795-e59945f4d4b5
    name: server1
  id: 6fbacbae-2954-4472-9795-e59945f4d4b5
  type: server
- attributes:
    endpoint:
      addr: 127.0.2.2
      port: 7459
    id: 23becdbc-20db-4ddd-892c-31a77a0a1714
    name: server2
  id: 23becdbc-20db-4ddd-892c-31a77a0a1714
  type: server
...

Replicas represent the local copies of a database and have a 1-1 relation with dbmgr's which are non-persisted objects that track execution of Postgres servers and utilities. Epochs server both the epoch and lease parts of the Ketch protocol. Runtime is a singleton that persists state related to the local instance.

All Ketch state is stored under the '--data-dir' directory. Ketch objects are stored in a Bolt database called ketch.db while Postgres data is stored under a subdirectory named by the Replica ID. Postgres socket/lock files are stored directly under the '--data-dir' directory. Though a Replica object in Ketch may be deleted for safety in the protocol, Postgres data is always preserved for debugging and recovery.

Documentation

Index

Constants

View Source
const (
	DBDirMode  os.FileMode = 0700
	DBFileMode os.FileMode = 0600
	DBPWExt    string      = "pw"
)

Variables

This section is empty.

Functions

func Locate

func Locate(fields logrus.Fields) logrus.Fields

Locate() Add file and line to logrus fields

Types

type Config

type Config struct {
	// Logger to send logs to
	Log *logrus.Logger

	// ListConfig is the HashiCorp Memberlist configuration to use.
	ListConfig *memberlist.Config

	// DataDir is the directory to store all data for this instance of Ketch.
	DataDir string

	// DBBinDir is the directory for database executables.
	DBBinDir string
}

Config Configuration for Ketch service.

type DBMgr

type DBMgr struct {
	ResourceMgr
}

func (*DBMgr) GetList

func (m *DBMgr) GetList() api.ResourceList

func (*DBMgr) InitResource

func (m *DBMgr) InitResource(in api.Resource) (error, int)

func (*DBMgr) UpdateAfterLoad

func (m *DBMgr) UpdateAfterLoad(resource api.Resource) bool

type EpochMgr

type EpochMgr struct {
	ResourceMgr
}

func (*EpochMgr) GetList

func (m *EpochMgr) GetList() api.ResourceList

func (*EpochMgr) InitResource

func (m *EpochMgr) InitResource(in api.Resource) (error, int)

func (*EpochMgr) UpdateAfterLoad

func (m *EpochMgr) UpdateAfterLoad(resource api.Resource) bool

type ExitStatus

type ExitStatus struct {
	X__e_termination int16
	X__e_exit        int16
}

Structures for reading utmp

type Ketch

type Ketch struct {

	// Read/write lock to protect Ketch state
	sync.RWMutex
	// contains filtered or unexported fields
}

Ketch State of Ketch service.

func Create

func Create(config *Config) (*Ketch, error)

Create Build ketch Ketch object from config.

func (*Ketch) CreateResources

func (k *Ketch) CreateResources(myType api.Type, list api.ResourceList) (api.ResourceList, error, int)

CreateResources creates resources from a list. Returns the list created, error and http status

func (*Ketch) GetBroadcasts

func (k *Ketch) GetBroadcasts(overhead, limit int) [][]byte

func (*Ketch) GetResources

func (k *Ketch) GetResources(myType api.Type) api.ResourceList

GetResources returns list of resources.

func (*Ketch) GetUptime

func (k *Ketch) GetUptime()

GetUptime sets uptime seconds since boot. We use this value for leases as it is monotonically increasing. On system restart all acceptor lease values are reset, compromising availability for safety.

func (*Ketch) Join

func (k *Ketch) Join(list []string) (int, error)

Join Sync state with list of candidate Ketch members. Returns number of members successfully joined. Wrapper around Memberlist Join()

func (*Ketch) LocalState

func (k *Ketch) LocalState(join bool) []byte

func (*Ketch) Members

func (k *Ketch) Members() []*memberlist.Node

Members Return list of Ketch members. Wrapper around Memberlist Members()

func (*Ketch) MergeRemoteState

func (k *Ketch) MergeRemoteState(buf []byte, join bool)

func (*Ketch) NodeMeta

func (k *Ketch) NodeMeta(limit int) []byte

func (*Ketch) NotifyMsg

func (k *Ketch) NotifyMsg(buf []byte)

type ReplicaMgr

type ReplicaMgr struct {
	ResourceMgr
}

func (*ReplicaMgr) GetList

func (m *ReplicaMgr) GetList() api.ResourceList

func (*ReplicaMgr) InitResource

func (m *ReplicaMgr) InitResource(in api.Resource) (error, int)

func (*ReplicaMgr) UpdateAfterLoad

func (m *ReplicaMgr) UpdateAfterLoad(resource api.Resource) bool

type ResourceMgr

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

func (*ResourceMgr) ClearResources

func (m *ResourceMgr) ClearResources()

ClearResources clears all resources of the specified type.

func (*ResourceMgr) CreateResources

func (m *ResourceMgr) CreateResources(list api.ResourceList) (api.ResourceList, error, int)

CreateResources creates resources from a list. Returns the list created, error and http status

func (*ResourceMgr) GetResources

func (m *ResourceMgr) GetResources() api.ResourceList

GetResources returns list of resources.

func (*ResourceMgr) Init

func (m *ResourceMgr) Init(k *Ketch, instance ResourceMgrInstance)

Links up an instance of the resource manager

func (*ResourceMgr) LoadResources

func (m *ResourceMgr) LoadResources()

LoadResources loads existing resources from database into Ketch. Called locked.

func (*ResourceMgr) RefreshResources

func (m *ResourceMgr) RefreshResources()

RefreshResources calls resource specific getList() to refresh resources.

type ResourceMgrInstance

type ResourceMgrInstance interface {
	InitResource(api.Resource) (error, int)
	GetList() api.ResourceList
	UpdateAfterLoad(api.Resource) bool
}

type ResourceMgrInterface

type ResourceMgrInterface interface {
	Init(ketch Ketch, myType api.Type, instance ResourceMgrInstance)
	RefreshResources()
	GetResources() api.ResourceList
	ClearResources()
	CreateResources(list api.ResourceList) (api.ResourceList, error, int)
	LoadResources()
}

type RuntimeMgr

type RuntimeMgr struct {
	ResourceMgr
}

func (*RuntimeMgr) GetList

func (m *RuntimeMgr) GetList() api.ResourceList

func (*RuntimeMgr) InitResource

func (m *RuntimeMgr) InitResource(in api.Resource) (error, int)

func (*RuntimeMgr) UpdateAfterLoad

func (m *RuntimeMgr) UpdateAfterLoad(in api.Resource) bool

type ServerMgr

type ServerMgr struct {
	ResourceMgr
}

func (*ServerMgr) GetList

func (m *ServerMgr) GetList() api.ResourceList

func (*ServerMgr) InitResource

func (m *ServerMgr) InitResource(in api.Resource) (error, int)

func (*ServerMgr) UpdateAfterLoad

func (m *ServerMgr) UpdateAfterLoad(resource api.Resource) bool

type TimeVal

type TimeVal struct {
	Sec  int32
	Usec int32
}

type Utmp

type Utmp struct {
	Type              int16
	Pad_cgo_0         [2]byte
	Pid               int32
	Line              [32]byte
	Id                [4]byte
	User              [32]byte
	Host              [256]byte
	Exit              ExitStatus
	Session           int32
	Tv                TimeVal
	Addr_v6           [4]int32
	X__glibc_reserved [20]byte
}

Directories

Path Synopsis
cmd
ketch command
ketchctl command

Jump to

Keyboard shortcuts

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