Skip to content

Commit 71a61d1

Browse files
author
PotatoCloud
committed
[Server::patch] config remove cluster.state block
1 parent cd4ccf9 commit 71a61d1

File tree

14 files changed

+38
-176
lines changed

14 files changed

+38
-176
lines changed

cmd/RedQueenUtil/append_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (c *appendCluster) exec() error {
1919
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
2020
defer cancel()
2121

22-
call, err := client.New(ctx, endpoints, true)
22+
call, err := client.New(ctx, endpoints)
2323
if err != nil {
2424
return err
2525
}

common/hack/unsafe.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

config.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ backend = "nuts"
2929
name = "node-1"
3030
peer-addr = "127.0.0.1:4539"
3131

32-
# state options
33-
# new, existing
34-
state = "new"
35-
3632
token = "red-queen-cluster"
3733

3834
[log]

config.toml.exam

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ backend = "nuts"
2929
name = "node-1"
3030
peer-addr = "127.0.0.1:4539"
3131

32-
# state options
33-
# new, existing
34-
state = "new"
35-
3632
token = "red-queen-cluster"
3733

3834
[log]

config/config.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package config
33
import (
44
"flag"
55
"fmt"
6-
"os"
7-
86
"github.com/BurntSushi/toml"
97
"github.com/pkg/errors"
8+
"os"
9+
"path"
1010
)
1111

1212
type ServerEnv interface {
@@ -15,7 +15,9 @@ type ServerEnv interface {
1515
}
1616

1717
type env struct {
18-
firstRun bool
18+
firstRun bool
19+
initLockFile string
20+
1921
configFile string
2022
}
2123

@@ -54,8 +56,6 @@ type ClusterBootstrap struct {
5456
}
5557

5658
type Cluster struct {
57-
// State enum: new, existing
58-
State EnumClusterState `toml:"state"`
5959
Token string `toml:"token"`
6060
Bootstrap []ClusterBootstrap `toml:"bootstrap"`
6161
}
@@ -85,7 +85,24 @@ type Config struct {
8585
}
8686

8787
func (c *Config) setupEnv() {
88-
c.env.firstRun = c.Cluster.State == ClusterStateNew
88+
c.env.initLockFile = path.Join(c.Node.DataDir, ".init.lock")
89+
90+
// write init lock
91+
if _, err := os.Stat(c.env.initLockFile); os.IsNotExist(err) {
92+
c.env.firstRun = true
93+
94+
if err = os.MkdirAll(path.Clean(c.Node.DataDir), os.ModePerm); err != nil {
95+
panic("Setup config error:" + err.Error())
96+
}
97+
98+
f, err := os.OpenFile(c.env.initLockFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
99+
if err != nil {
100+
panic("Setup config error:" + err.Error())
101+
}
102+
defer f.Close()
103+
_, _ = f.WriteString("LOCK")
104+
}
105+
89106
}
90107

91108
func (c *Config) Env() ServerEnv {
@@ -127,7 +144,6 @@ func bindServerFromArgs(cfg *Config, args ...string) error {
127144
fs.Var(newValidatorStringValue[EnumNutsRWMode](DefaultStoreNutsRWMode, &cfg.Store.Nuts.RWMode), "nuts-rw-mode", "select read & write mode, options: fileio, mmap")
128145

129146
// main config::cluster
130-
fs.Var(newValidatorStringValue[EnumClusterState](DefaultClusterState, &cfg.Cluster.State), "cluster-state", "status of the cluster at startup")
131147
fs.StringVar(&cfg.Cluster.Token, "cluster-token", "", "")
132148

133149
// main config::cluster::bootstrap(s)
@@ -168,7 +184,6 @@ func bindServerFromEnv(cfg *Config) {
168184
BindEnvVar(newValidatorStringValue[EnumNutsRWMode](DefaultStoreNutsRWMode, &cfg.Store.Nuts.RWMode), "RQ_NUTS_RW_MODE")
169185

170186
// main config::cluster
171-
BindEnvVar(newValidatorStringValue[EnumClusterState](DefaultClusterState, &cfg.Cluster.State), "RQ_CLUSTER_STATE")
172187
EnvStringVar(&cfg.Cluster.Token, "RQ_CLUSTER_TOKEN", "")
173188

174189
// main config::cluster::bootstrap(s)

config/default.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const (
2323
DefaultStoreNutsRWMode string = "fileio"
2424
)
2525

26-
// -- cluster default value
27-
28-
const (
29-
DefaultClusterState = string(ClusterStateNew)
30-
)
31-
3226
// -- log default value
3327

3428
const (

config/validator.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ func (m EnumNutsRWMode) Valid() error {
4141
}
4242
}
4343

44-
type EnumClusterState string
45-
46-
const (
47-
ClusterStateNew EnumClusterState = "new"
48-
ClusterStateExisting EnumClusterState = "existing"
49-
)
50-
51-
func (s EnumClusterState) Valid() error {
52-
switch s {
53-
case ClusterStateNew, ClusterStateExisting:
54-
return nil
55-
default:
56-
return errors.New("unknown cluster state type")
57-
}
58-
}
59-
6044
type EnumLogLogger string
6145

6246
const (
@@ -84,5 +68,5 @@ func (p FilePath) Valid() error {
8468
}
8569

8670
type stringValidator interface {
87-
EnumStoreBackend | EnumNutsRWMode | EnumClusterState | EnumLogLogger | FilePath
71+
EnumStoreBackend | EnumNutsRWMode | EnumLogLogger | FilePath
8872
}

internal/hack/unsafe.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package hack
2+
3+
import "unsafe"
4+
5+
func Bytes2String(b []byte) string {
6+
return *(*string)(unsafe.Pointer(&b))
7+
}
8+
9+
func String2Bytes(s string) []byte {
10+
return unsafe.Slice(unsafe.StringData(s), len(s))
11+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package hack_test
22

33
import (
4+
"github.com/RealFax/RedQueen/internal/hack"
45
"testing"
5-
6-
"github.com/RealFax/RedQueen/common/hack"
76
)
87

98
func TestString2Bytes(t *testing.T) {

locker/mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package locker
22

33
import (
4+
"github.com/RealFax/RedQueen/internal/hack"
45
"time"
56

6-
"github.com/RealFax/RedQueen/common/hack"
77
"github.com/RealFax/RedQueen/store"
88
)
99

0 commit comments

Comments
 (0)