Skip to content

Commit fd5f377

Browse files
authored
Merge pull request #66 from zilliztech/dev
Support fallback to distributed lock for object storage services that do not support condition write
2 parents 418df11 + 6b420c7 commit fd5f377

39 files changed

Lines changed: 2570 additions & 3350 deletions

common/config/configuration.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package config
1818

1919
import (
20-
"gopkg.in/yaml.v3"
2120
"os"
2221
"strings"
22+
23+
"gopkg.in/yaml.v3"
2324
)
2425

2526
// MetaConfig stores the metadata storage configuration.
@@ -80,6 +81,31 @@ type RetentionPolicyConfig struct {
8081
TTL int `yaml:"ttl"` // Time to live for truncated segments before eligible for GC
8182
}
8283

84+
// FencePolicyConfig stores the fence policy configuration.
85+
type FencePolicyConfig struct {
86+
ConditionWrite string `yaml:"conditionWrite"`
87+
}
88+
89+
func (f *FencePolicyConfig) IsConditionWriteEnabled() bool {
90+
return strings.EqualFold(f.ConditionWrite, "enable")
91+
}
92+
93+
func (f *FencePolicyConfig) IsConditionWriteDisabled() bool {
94+
return strings.EqualFold(f.ConditionWrite, "disable")
95+
}
96+
97+
func (f *FencePolicyConfig) IsConditionWriteAuto() bool {
98+
return strings.EqualFold(f.ConditionWrite, "auto")
99+
}
100+
101+
func (f *FencePolicyConfig) SetConditionWriteEnableOrNot(enable bool) {
102+
if enable {
103+
f.ConditionWrite = "enable"
104+
} else {
105+
f.ConditionWrite = "disable"
106+
}
107+
}
108+
83109
// LogFileConfig stores the log file configuration.
84110
type LogFileConfig struct {
85111
RootPath string `yaml:"rootPath"`
@@ -203,6 +229,7 @@ type LogstoreConfig struct {
203229
SegmentCompactionPolicy SegmentCompactionPolicy `yaml:"segmentCompactionPolicy"`
204230
SegmentReadPolicy SegmentReadPolicyConfig `yaml:"segmentReadPolicy"`
205231
RetentionPolicy RetentionPolicyConfig `yaml:"retentionPolicy"`
232+
FencePolicy FencePolicyConfig `yaml:"fencePolicy"`
206233
}
207234

208235
type StorageConfig struct {
@@ -316,6 +343,9 @@ func getDefaultWoodpeckerConfig() WoodpeckerConfig {
316343
RetentionPolicy: RetentionPolicyConfig{
317344
TTL: 259200, // 72 hours
318345
},
346+
FencePolicy: FencePolicyConfig{
347+
ConditionWrite: "auto",
348+
},
319349
},
320350
Storage: StorageConfig{
321351
Type: "default",

common/config/configuration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestNewConfiguration(t *testing.T) {
5656
assert.Equal(t, int64(16000000), config.Woodpecker.Logstore.SegmentReadPolicy.MaxBatchSize)
5757
assert.Equal(t, 32, config.Woodpecker.Logstore.SegmentReadPolicy.MaxFetchThreads)
5858
assert.Equal(t, 259200, config.Woodpecker.Logstore.RetentionPolicy.TTL) // 72h = 259200s
59+
assert.Equal(t, "auto", config.Woodpecker.Logstore.FencePolicy.ConditionWrite)
5960
assert.Equal(t, "minio", config.Woodpecker.Storage.Type)
6061
assert.Equal(t, "/var/lib/woodpecker", config.Woodpecker.Storage.RootPath)
6162
assert.Equal(t, "info", config.Log.Level)
@@ -127,6 +128,7 @@ func TestNewConfiguration(t *testing.T) {
127128
assert.Equal(t, int64(16000000), defaultConfig.Woodpecker.Logstore.SegmentReadPolicy.MaxBatchSize)
128129
assert.Equal(t, 32, defaultConfig.Woodpecker.Logstore.SegmentReadPolicy.MaxFetchThreads)
129130
assert.Equal(t, 259200, defaultConfig.Woodpecker.Logstore.RetentionPolicy.TTL) // 72h = 259200s
131+
assert.Equal(t, "auto", defaultConfig.Woodpecker.Logstore.FencePolicy.ConditionWrite)
130132
assert.Equal(t, "default", defaultConfig.Woodpecker.Storage.Type)
131133
assert.Equal(t, "/tmp/woodpecker", defaultConfig.Woodpecker.Storage.RootPath)
132134
assert.Equal(t, "info", defaultConfig.Log.Level)

common/etcd/etcd_server.go

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,7 @@ func InitEtcdServer(
4949
if useEmbedEtcd {
5050
var initError error
5151
initOnce.Do(func() {
52-
path := configPath
53-
var cfg *embed.Config
54-
if len(path) > 0 {
55-
cfgFromFile, err := embed.ConfigFromFile(path)
56-
if err != nil {
57-
initError = err
58-
}
59-
cfg = cfgFromFile
60-
} else {
61-
cfg = embed.NewConfig()
62-
}
63-
cfg.Dir = dataDir
64-
cfg.LogOutputs = []string{logPath}
65-
cfg.LogLevel = logLevel
66-
e, err := embed.StartEtcd(cfg)
67-
if err != nil {
68-
log.Printf("failed to init embedded Etcd server %v", err)
69-
initError = err
70-
}
71-
etcdServer = e
72-
log.Printf("finish init Etcd config path:%s, dataDir:%s", path, dataDir)
52+
initError = StartEtcdServerUnsafe(useEmbedEtcd, configPath, dataDir, logPath, logLevel)
7353
})
7454
return initError
7555
}
@@ -88,3 +68,37 @@ func StopEtcdServer() {
8868
})
8969
}
9070
}
71+
72+
func StartEtcdServerUnsafe(useEmbedEtcd bool,
73+
configPath string,
74+
dataDir string,
75+
logPath string,
76+
logLevel string) error {
77+
var initError error
78+
path := configPath
79+
var cfg *embed.Config
80+
if len(path) > 0 {
81+
cfgFromFile, err := embed.ConfigFromFile(path)
82+
if err != nil {
83+
initError = err
84+
}
85+
cfg = cfgFromFile
86+
} else {
87+
cfg = embed.NewConfig()
88+
}
89+
cfg.Dir = dataDir
90+
cfg.LogOutputs = []string{logPath}
91+
cfg.LogLevel = logLevel
92+
e, err := embed.StartEtcd(cfg)
93+
if err != nil {
94+
log.Printf("failed to init embedded Etcd server %v", err)
95+
initError = err
96+
}
97+
etcdServer = e
98+
log.Printf("finish init Etcd config path:%s, dataDir:%s", path, dataDir)
99+
return initError
100+
}
101+
102+
func ShutdownEtcdServerUnsafe() {
103+
etcdServer.Close()
104+
}

common/minio/minio_checker.go

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

0 commit comments

Comments
 (0)