Skip to content

Commit 8f454d4

Browse files
committed
Adding support for resilient single server mode
1 parent fa45c04 commit 8f454d4

15 files changed

+102
-48
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ REPODIR := $(ORGDIR)/$(REPONAME)
1919
REPOPATH := $(ORGPATH)/$(REPONAME)
2020

2121
GOPATH := $(GOBUILDDIR)
22-
GOVERSION := 1.9.0-alpine
22+
GOVERSION := 1.9.1-alpine
2323

2424
ifndef GOOS
2525
GOOS := linux

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ var (
7979
startAgent []bool
8080
startDBserver []bool
8181
startCoordinator []bool
82+
startResilientSingle []bool
8283
startLocalSlaves bool
8384
mode string
8485
dataDir string
@@ -121,7 +122,7 @@ func init() {
121122
f.BoolVar(&showVersion, "version", false, "If set, show version and exit")
122123

123124
f.StringSliceVar(&masterAddresses, "starter.join", nil, "join a cluster with master at given address")
124-
f.StringVar(&mode, "starter.mode", "cluster", "Set the mode of operation to use (cluster|single)")
125+
f.StringVar(&mode, "starter.mode", "cluster", "Set the mode of operation to use (cluster|single|resilientsingle)")
125126
f.BoolVar(&startLocalSlaves, "starter.local", false, "If set, local slaves will be started to create a machine local (test) cluster")
126127
f.StringVar(&ownAddress, "starter.address", "", "address under which this server is reachable, needed for running in docker or in single mode")
127128
f.StringVar(&id, "starter.id", "", "Unique identifier of this peer")
@@ -137,6 +138,7 @@ func init() {
137138
f.BoolSliceVar(&startAgent, "cluster.start-agent", nil, "should an agent instance be started")
138139
f.BoolSliceVar(&startDBserver, "cluster.start-dbserver", nil, "should a dbserver instance be started")
139140
f.BoolSliceVar(&startCoordinator, "cluster.start-coordinator", nil, "should a coordinator instance be started")
141+
f.BoolSliceVar(&startResilientSingle, "cluster.start-single", nil, "should a (resilient) single server instance be started")
140142

141143
f.StringVar(&arangodPath, "server.arangod", "/usr/sbin/arangod", "Path of arangod")
142144
f.StringVar(&arangodJSPath, "server.js-dir", "/usr/share/arangodb3/js", "Path of arango JS folder")
@@ -504,6 +506,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
504506
StartAgent: getOptionalBool("cluster.start-agent", startAgent),
505507
StartDBserver: getOptionalBool("cluster.start-dbserver", startDBserver),
506508
StartCoordinator: getOptionalBool("cluster.start-coordinator", startCoordinator),
509+
StartResilientSingle: getOptionalBool("cluster.start-single", startResilientSingle),
507510
ServerStorageEngine: serverStorageEngine,
508511
JwtSecret: jwtSecret,
509512
SslKeyFile: sslKeyFile,

service/arangod_config_builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func createArangodConf(log *logging.Logger, bsCfg BootstrapConfig, myHostDir, my
8080
case ServerTypeDBServer:
8181
threads = "4"
8282
v8Contexts = "4"
83-
case ServerTypeCoordinator, ServerTypeSingle:
83+
case ServerTypeCoordinator, ServerTypeSingle, ServerTypeResilientSingle:
8484
threads = "16"
8585
v8Contexts = "4"
8686
}
@@ -246,6 +246,13 @@ func createArangodArgs(log *logging.Logger, config Config, clusterConfig Cluster
246246
optionPair{"--foxx.queues", "true"},
247247
optionPair{"--server.statistics", "true"},
248248
)
249+
case ServerTypeResilientSingle:
250+
options = append(options,
251+
optionPair{"--foxx.queues", "true"},
252+
optionPair{"--server.statistics", "true"},
253+
optionPair{"--replication.auto-failover", "true"},
254+
optionPair{"--cluster.my-role", "SINGLE"},
255+
)
249256
}
250257
if serverType != ServerTypeAgent && serverType != ServerTypeSingle {
251258
for _, p := range clusterConfig.AllAgents() {

service/bootstrap_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type BootstrapConfig struct {
3434
StartAgent *bool // If not nil, sets if starter starts a agent, otherwise default handling applies
3535
StartDBserver *bool // If not nil, sets if starter starts a dbserver, otherwise default handling applies
3636
StartCoordinator *bool // If not nil, sets if starter starts a coordinator, otherwise default handling applies
37+
StartResilientSingle *bool // If not nil, sets if starter starts a resilient single, otherwise default handling applies
3738
ServerStorageEngine string // mmfiles | rocksdb
3839
JwtSecret string // JWT secret used for arangod communication
3940
SslKeyFile string // Path containing an x509 certificate + private key to be used by the servers.

service/bootstrap_master.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ func (s *Service) bootstrapMaster(ctx context.Context, runner Runner, config Con
4949
hasAgent := boolFromRef(bsCfg.StartAgent, !s.mode.IsSingleMode())
5050
hasDBServer := boolFromRef(bsCfg.StartDBserver, true)
5151
hasCoordinator := boolFromRef(bsCfg.StartCoordinator, true)
52+
hasResilientSingle := boolFromRef(bsCfg.StartResilientSingle, s.mode.IsResilientSingleMode())
5253
s.myPeers.Initialize(
53-
NewPeer(s.id, config.OwnAddress, s.announcePort, 0, config.DataDir, hasAgent, hasDBServer, hasCoordinator, s.IsSecure()),
54+
NewPeer(s.id, config.OwnAddress, s.announcePort, 0, config.DataDir, hasAgent, hasDBServer, hasCoordinator, hasResilientSingle, s.IsSecure()),
5455
bsCfg.AgencySize)
5556
s.learnOwnAddress = config.OwnAddress == ""
5657

service/bootstrap_slave.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ func (s *Service) bootstrapSlave(peerAddress string, runner Runner, config Confi
4242
s.log.Fatalf("Failed to get HTTP server port: %#v", err)
4343
}
4444
encoded, err := json.Marshal(HelloRequest{
45-
DataDir: config.DataDir,
46-
SlaveID: s.id,
47-
SlaveAddress: config.OwnAddress,
48-
SlavePort: hostPort,
49-
IsSecure: s.IsSecure(),
50-
Agent: copyBoolRef(bsCfg.StartAgent),
51-
DBServer: copyBoolRef(bsCfg.StartDBserver),
52-
Coordinator: copyBoolRef(bsCfg.StartCoordinator),
45+
DataDir: config.DataDir,
46+
SlaveID: s.id,
47+
SlaveAddress: config.OwnAddress,
48+
SlavePort: hostPort,
49+
IsSecure: s.IsSecure(),
50+
Agent: copyBoolRef(bsCfg.StartAgent),
51+
DBServer: copyBoolRef(bsCfg.StartDBserver),
52+
Coordinator: copyBoolRef(bsCfg.StartCoordinator),
53+
ResilientSingle: copyBoolRef(bsCfg.StartResilientSingle),
5354
})
5455
if err != nil {
5556
s.log.Fatalf("Failed to encode Hello request: %#v", err)

service/cluster_config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ func (p ClusterConfig) HaveEnoughAgents() bool {
154154
return count >= p.AgencySize
155155
}
156156

157+
// HaveEnoughResilientSingles returns true when the number of peers that have an resilient single server
158+
// is equal to 2.
159+
func (p ClusterConfig) HaveEnoughResilientSingles() bool {
160+
count := 0
161+
for _, x := range p.AllPeers {
162+
if x.HasResilientSingle() {
163+
count++
164+
}
165+
}
166+
return count >= 2
167+
}
168+
157169
// IsSecure returns true if any of the peers is secure.
158170
func (p ClusterConfig) IsSecure() bool {
159171
for _, x := range p.AllPeers {

service/mode.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ package service
2525
type ServiceMode string
2626

2727
const (
28-
ServiceModeCluster = ServiceMode("cluster")
29-
ServiceModeSingle = ServiceMode("single")
28+
ServiceModeCluster = ServiceMode("cluster")
29+
ServiceModeSingle = ServiceMode("single")
30+
ServiceModeResilientSingle = ServiceMode("resilientsingle")
3031
)
3132

3233
// IsClusterMode returns true when the service is running in cluster mode.
@@ -38,3 +39,8 @@ func (m ServiceMode) IsClusterMode() bool {
3839
func (m ServiceMode) IsSingleMode() bool {
3940
return m == "single"
4041
}
42+
43+
// IsResilientSingleMode returns true when the service is running in resilient single server mode.
44+
func (m ServiceMode) IsResilientSingleMode() bool {
45+
return m == "resilientsingle"
46+
}

service/passthrough.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
func (o *PassthroughOption) valueForServerType(serverType ServerType) []string {
6565
var result []string
6666
switch serverType {
67-
case ServerTypeSingle:
67+
case ServerTypeSingle, ServerTypeResilientSingle:
6868
result = o.Values.All
6969
case ServerTypeCoordinator:
7070
result = o.Values.Coordinators

service/peer.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,29 @@ import (
3535

3636
// Peer contains all persistent settings of a starter.
3737
type Peer struct {
38-
ID string // Unique of of the peer
39-
Address string // IP address of arangodb peer server
40-
Port int // Port number of arangodb peer server
41-
PortOffset int // Offset to add to base ports for the various servers (agent, coordinator, dbserver)
42-
DataDir string // Directory holding my data
43-
HasAgentFlag bool `json:"HasAgent"` // If set, this peer is running an agent
44-
HasDBServerFlag *bool `json:"HasDBServer,omitempty"` // If set or is nil, this peer is running a dbserver
45-
HasCoordinatorFlag *bool `json:"HasCoordinator,omitempty"` // If set or is nil, this peer is running a coordinator
46-
IsSecure bool // If set, servers started by this peer are using an SSL connection
38+
ID string // Unique of of the peer
39+
Address string // IP address of arangodb peer server
40+
Port int // Port number of arangodb peer server
41+
PortOffset int // Offset to add to base ports for the various servers (agent, coordinator, dbserver)
42+
DataDir string // Directory holding my data
43+
HasAgentFlag bool `json:"HasAgent"` // If set, this peer is running an agent
44+
HasDBServerFlag *bool `json:"HasDBServer,omitempty"` // If set or is nil, this peer is running a dbserver
45+
HasCoordinatorFlag *bool `json:"HasCoordinator,omitempty"` // If set or is nil, this peer is running a coordinator
46+
HasResilientSingleFlag bool `json:"HasResilientSingle,omitempty"` // If set, this peer is running a resilient single server
47+
IsSecure bool // If set, servers started by this peer are using an SSL connection
4748
}
4849

4950
// NewPeer initializes a new Peer instance with given values.
50-
func NewPeer(id, address string, port, portOffset int, dataDir string, hasAgent, hasDBServer, hasCoordinator, isSecure bool) Peer {
51+
func NewPeer(id, address string, port, portOffset int, dataDir string, hasAgent, hasDBServer, hasCoordinator, hasResilientSingle, isSecure bool) Peer {
5152
p := Peer{
52-
ID: id,
53-
Address: address,
54-
Port: port,
55-
PortOffset: portOffset,
56-
DataDir: dataDir,
57-
HasAgentFlag: hasAgent,
58-
IsSecure: isSecure,
53+
ID: id,
54+
Address: address,
55+
Port: port,
56+
PortOffset: portOffset,
57+
DataDir: dataDir,
58+
HasAgentFlag: hasAgent,
59+
IsSecure: isSecure,
60+
HasResilientSingleFlag: hasResilientSingle,
5961
}
6062
if !hasDBServer {
6163
p.HasDBServerFlag = boolRef(false)
@@ -75,6 +77,9 @@ func (p Peer) HasDBServer() bool { return p.HasDBServerFlag == nil || *p.HasDBSe
7577
// HasCoordinator returns true if this peer is running a coordinator
7678
func (p Peer) HasCoordinator() bool { return p.HasCoordinatorFlag == nil || *p.HasCoordinatorFlag }
7779

80+
// HasResilientSingle returns true if this peer is running an resilient single server
81+
func (p Peer) HasResilientSingle() bool { return p.HasResilientSingleFlag }
82+
7883
// CreateStarterURL creates a URL to the relative path to the starter on this peer.
7984
func (p Peer) CreateStarterURL(relPath string) string {
8085
addr := net.JoinHostPort(p.Address, strconv.Itoa(p.Port+p.PortOffset))

0 commit comments

Comments
 (0)