Remove gossip communication layer
This commit is contained in:
parent
2cef779106
commit
88ccfa08db
3 changed files with 0 additions and 133 deletions
|
@ -20,7 +20,6 @@ var flags = map[string]string{
|
|||
"size": `A size in MB which determines the minimum or maximum file size for streaming data file storage. This is used for specifying maximum cached data sizes when using remote streaming storage. (default "5")`,
|
||||
"sync": `A time duration to use when syncing data to persistent storage. To sync data with every write specify '0', otherwise the data will be persisted asynchronously after the specified duration. (default "0s")`,
|
||||
"shrink": `A time duration to use when shrinking data on persistent storage. To shrink data asynchronously after a repeating period of time, specify a duration. Disabled by default. (default "0s")`,
|
||||
"join": `A comma-separated list of addresses to use when a new node is joining an existing cluster. For the first node in a cluster, --join should NOT be specified.`,
|
||||
}
|
||||
|
||||
var usage = map[string][]string{
|
||||
|
@ -49,10 +48,4 @@ var usage = map[string][]string{
|
|||
"--db-shrink 30m",
|
||||
"--db-shrink 24h",
|
||||
},
|
||||
"join": {
|
||||
"--join 10.0.0.1",
|
||||
"--join 10.0.0.1:33693",
|
||||
"--join 10.0.0.1:33693,10.0.0.2:33693",
|
||||
"--join 89.13.7.33:33693,example.com:33693",
|
||||
},
|
||||
}
|
||||
|
|
13
cli/start.go
13
cli/start.go
|
@ -21,7 +21,6 @@ import (
|
|||
|
||||
"github.com/abcum/surreal/db"
|
||||
"github.com/abcum/surreal/log"
|
||||
"github.com/abcum/surreal/tcp"
|
||||
"github.com/abcum/surreal/web"
|
||||
)
|
||||
|
||||
|
@ -40,11 +39,6 @@ var startCmd = &cobra.Command{
|
|||
return
|
||||
}
|
||||
|
||||
if err = tcp.Setup(opts); err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = web.Setup(opts); err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
|
@ -60,11 +54,6 @@ var startCmd = &cobra.Command{
|
|||
return
|
||||
}
|
||||
|
||||
if err = tcp.Exit(); err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = db.Exit(); err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
|
@ -97,8 +86,6 @@ func init() {
|
|||
|
||||
startCmd.PersistentFlags().DurationVar(&opts.Query.Timeout, "query-timeout", 0, "")
|
||||
|
||||
startCmd.PersistentFlags().StringSliceVarP(&opts.Node.Join, "join", "j", nil, flag("join"))
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key"))
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.Node.Host, "bind", "b", "0.0.0.0", "The hostname or ip address to listen for connections on.")
|
||||
|
|
113
tcp/tcp.go
113
tcp/tcp.go
|
@ -1,113 +0,0 @@
|
|||
// Copyright © 2016 Abcum Ltd
|
||||
//
|
||||
// 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.
|
||||
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/abcum/surreal/cnf"
|
||||
"github.com/abcum/surreal/log"
|
||||
|
||||
"github.com/hashicorp/serf/serf"
|
||||
)
|
||||
|
||||
var srf *serf.Serf
|
||||
|
||||
var listeners []*listener
|
||||
|
||||
type listener struct {
|
||||
name string
|
||||
call func([]byte)
|
||||
}
|
||||
|
||||
// Setup sets up the server for remote connections
|
||||
func Setup(opts *cnf.Options) (err error) {
|
||||
|
||||
log.WithPrefix("tcp").Infof("Starting tcp server on %s", opts.Conn.Tcp)
|
||||
|
||||
chn := make(chan serf.Event)
|
||||
|
||||
cfg := serf.DefaultConfig()
|
||||
cfg.EventCh = chn
|
||||
cfg.NodeName = opts.Node.UUID
|
||||
cfg.LogOutput = ioutil.Discard
|
||||
cfg.ReconnectTimeout = 60 * time.Second
|
||||
cfg.TombstoneTimeout = 60 * time.Second
|
||||
|
||||
cfg.MemberlistConfig.LogOutput = ioutil.Discard
|
||||
|
||||
cfg.MemberlistConfig.SecretKey = opts.DB.Key
|
||||
cfg.MemberlistConfig.BindPort = opts.Port.Tcp
|
||||
cfg.MemberlistConfig.AdvertisePort = opts.Port.Tcp
|
||||
|
||||
srf, err = serf.Create(cfg)
|
||||
if len(opts.Node.Join) > 0 {
|
||||
if _, err := srf.Join(opts.Node.Join, true); err != nil {
|
||||
log.Infoln(err)
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
for evt := range chn {
|
||||
switch evt.EventType() {
|
||||
case serf.EventMemberReap:
|
||||
msg := evt.(serf.MemberEvent)
|
||||
for _, member := range msg.Members {
|
||||
log.WithPrefix("tcp").Debugf("Cluster member reaped: %s:%d", member.Addr, member.Port)
|
||||
}
|
||||
case serf.EventMemberJoin:
|
||||
msg := evt.(serf.MemberEvent)
|
||||
for _, member := range msg.Members {
|
||||
log.WithPrefix("tcp").Debugf("Cluster member joined: %s:%d", member.Addr, member.Port)
|
||||
}
|
||||
case serf.EventMemberLeave:
|
||||
msg := evt.(serf.MemberEvent)
|
||||
for _, member := range msg.Members {
|
||||
log.WithPrefix("tcp").Debugf("Cluster member exited: %s:%d", member.Addr, member.Port)
|
||||
}
|
||||
case serf.EventMemberFailed:
|
||||
msg := evt.(serf.MemberEvent)
|
||||
for _, member := range msg.Members {
|
||||
log.WithPrefix("tcp").Debugf("Cluster member failed: %s:%d", member.Addr, member.Port)
|
||||
}
|
||||
case serf.EventUser:
|
||||
msg := evt.(serf.UserEvent)
|
||||
log.WithPrefix("tcp").Debugf("Received user event: %v with payload %s", msg.Name, msg.Payload)
|
||||
case serf.EventQuery:
|
||||
msg := evt.(*serf.Query)
|
||||
log.WithPrefix("tcp").Debugf("Received query event: %v with payload %s", msg.Name, msg.Payload)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Log successful start
|
||||
|
||||
log.WithPrefix("tcp").Infof("Started tcp server on %s", opts.Conn.Tcp)
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func Send(name string, data []byte) {
|
||||
srf.UserEvent(name, data, false)
|
||||
}
|
||||
|
||||
// Exit tears down the server gracefully
|
||||
func Exit() (err error) {
|
||||
log.WithPrefix("tcp").Infof("Gracefully shutting down %s protocol", "tcp")
|
||||
return srf.Leave()
|
||||
}
|
Loading…
Reference in a new issue