Documentation ¶
Overview ¶
Copyright © 2020 Marvin
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func AddMember(client *clientv3.Client, peerAddrs []string) (*clientv3.MemberAddResponse, error)
- func CreateClient(ctx context.Context, endpoints []string, tlsCfg *tls.Config) (*clientv3.Client, error)
- func DeleteKey(client *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)
- func GetClusterLeader(client *clientv3.Client) (string, error)
- func GetKey(client *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)
- func ListMembers(client *clientv3.Client) (*clientv3.MemberListResponse, error)
- func MoveLeader(client *clientv3.Client, id uint64) (*clientv3.MoveLeaderResponse, error)
- func PutKey(client *clientv3.Client, key, value string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)
- func RemoveMember(client *clientv3.Client, id uint64) (*clientv3.MemberRemoveResponse, error)
- func StatusMember(client *clientv3.Client) (*clientv3.StatusResponse, error)
- func TxnKey(client *clientv3.Client, ops ...clientv3.Op) (*clientv3.TxnResponse, error)
- func WatchKey(client *clientv3.Client, key string, opts ...clientv3.OpOption) clientv3.WatchChan
- type Callbacks
- type Connect
- type Discovery
- type Election
- type Embed
- type Etcd
- type Instance
- type Register
Constants ¶
const ( // DefaultLeaderElectionTTLSecond is the duration that non-leader candidates will // wait to force acquire leadership DefaultLeaderElectionTTLSecond = 30 // DefaultMasterLeaderPrefixKey is the dbms-master leader election key prefix DefaultMasterLeaderPrefixKey = "/dbms-master/leader" )
const ( // DefaultDialTimeout is the maximum amount of time a dial will wait for a // connection to setup. 30s is long enough for most of the network conditions. DefaultDialTimeout = 30 * time.Second // DefaultRequestTimeout 10s is long enough for most of etcd clusters. DefaultRequestTimeout = 60 * time.Second // DefaultAutoSyncIntervalDuration is the auto sync interval duration for etcd DefaultAutoSyncIntervalDuration = 30 * time.Second )
Variables ¶
var NotFoundLeader = errors.New("not found leader")
Functions ¶
func CreateClient ¶
func CreateClient(ctx context.Context, endpoints []string, tlsCfg *tls.Config) (*clientv3.Client, error)
CreateClient creates an etcd client with some default config items.
func DeleteKey ¶
func DeleteKey(client *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)
DeleteKey delete key-value in the etcd server
func GetClusterLeader ¶ added in v0.0.14
GetClusterLeader get an etcd leader addr
func GetKey ¶
func GetKey(client *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)
GetKey gets key-value in the etcd server
func ListMembers ¶
func ListMembers(client *clientv3.Client) (*clientv3.MemberListResponse, error)
ListMembers returns a list of internal etcd members.
func MoveLeader ¶ added in v0.0.13
MoveLeader transfer an etcd member leader by the given id.
func PutKey ¶
func PutKey(client *clientv3.Client, key, value string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)
PutKey puts key-value in the etcd server
func RemoveMember ¶
RemoveMember removes an etcd member by the given id.
func StatusMember ¶ added in v0.0.14
func StatusMember(client *clientv3.Client) (*clientv3.StatusResponse, error)
StatusMember get an etcd member status
Types ¶
type Callbacks ¶
type Callbacks struct { // OnStartedLeading is called when a LeaderElector client starts leading OnStartedLeading func(ctx context.Context) error // OnStoppedLeading is called when a LeaderElector client stops leading OnStoppedLeading func(ctx context.Context) error // OnNewLeader is called when the client observes a leader that is // not the previously observed leader. This includes the first observed // leader when the client starts. OnNewLeader func(identity string) }
type Connect ¶
type Connect struct {
// contains filtered or unexported fields
}
Connect used for watch meta database conn if the database conn information occur change, then modify database conn
func NewServiceConnect ¶
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
func NewServiceDiscovery ¶
type Election ¶
type Election struct { // Lock is the resource that will be used for locking EtcdClient *clientv3.Client // LeaseDuration is the duration that non-leader candidates will // wait to force acquire leadership. This is measured against time of // last observed ack. // // A client needs to wait a full LeaseDuration without observing a change to // the record before it can attempt to take over. When all clients are // shutdown and a new set of clients are started with different names against // the same leader record, they must wait the full LeaseDuration before // attempting to acquire the lease. Thes LeaseDuration should be as short as // possible (within your tolerance for clock skew rate) to avoid a possible // long waits in the scenario. // // Core clients default this value to 15 seconds. LeaseTTL int // Callbacks are callbacks that are triggered during certain lifecycle // events of the LeaderElector Callbacks Callbacks // Prefix is the election leader key prefix Prefix string // Identity is the election instance identity Identity string // contains filtered or unexported fields }
Election implements the leader election based on etcd
func NewElection ¶
func (*Election) CurrentIsLeader ¶
CurrentIsLeader judge current node whether is leader
type Embed ¶
type Embed interface { Init(opts ...configutil.MasterOption) (err error) Run() (err error) Join() (err error) GetConfig() *configutil.MasterOptions Close() }
Embed etcd server interface
func NewETCDServer ¶
func NewETCDServer() Embed
type Etcd ¶
type Etcd struct { MasterOptions *configutil.MasterOptions Srv *embed.Etcd Config *embed.Config }
func (*Etcd) GetConfig ¶
func (e *Etcd) GetConfig() *configutil.MasterOptions
GetConfig used for return master finally config
func (*Etcd) Init ¶
func (e *Etcd) Init(opts ...configutil.MasterOption) (err error)
Init inits embed etcd start config
func (*Etcd) Join ¶
Join joins an embedded etcd server node prepareJoinEtcd prepares config needed to join an existing cluster. learn from https://github.com/pingcap/pd/blob/37efcb05f397f26c70cda8dd44acaa3061c92159/server/join/join.go#L44.
when setting `initial-cluster` explicitly to bootstrap a new cluster: - if local persistent data exist, just restart the previous cluster (in fact, it's not bootstrapping). - if local persistent data not exist, just bootstrap the cluster as a new cluster.
when setting `join` to join an existing cluster (without `initial-cluster` set): - if local persistent data exists (in fact, it's not join):
- just restart if `member` already exists (already joined before)
- read `initial-cluster` back from local persistent data to restart (just like bootstrapping)
- if local persistent data not exist:
- fetch member list from the cluster to check if we can join now.
- call `member add` to add the member info into the cluster.
- generate config for join (`initial-cluster` and `initial-cluster-state`).
- save `initial-cluster` in local persistent data for later restarting.
NOTE: A member can't join to another cluster after it has joined a previous one.
type Instance ¶ added in v0.0.8
type Instance struct { Addr string // the Role column represent the node role Role string // the State column represent the node state, options: BOUND、FREE State string // the TaskName column represent the node bound task TaskName string }
Instance register service information, used for etcd key -> value
type Register ¶
type Register struct {
// contains filtered or unexported fields
}