@@ -15,15 +15,15 @@ import (
15
15
16
16
// SetGlobalConfig sets the global config. This must be called before the Start command.
17
17
func (s * SyncManager ) SetGlobalConfig (c * config.Config ) {
18
- s .lock .Lock ()
18
+ s .internalLock .Lock ()
19
19
s .projectConfig = c
20
- s .lock .Unlock ()
20
+ s .internalLock .Unlock ()
21
21
}
22
22
23
23
// GetGlobalConfig gets the global config
24
24
func (s * SyncManager ) GetGlobalConfig () * config.Config {
25
- s .lock . RLock ()
26
- defer s .lock . RUnlock ()
25
+ s .internalLock . Lock ()
26
+ defer s .internalLock . Unlock ()
27
27
return s .projectConfig
28
28
}
29
29
@@ -59,8 +59,8 @@ func makeRequest(method, token, url string, data *bytes.Buffer) error {
59
59
// SetOperationModeConfig applies the operation config to the raft log
60
60
func (s * SyncManager ) SetOperationModeConfig (token string , op * config.OperationConfig ) error {
61
61
// Acquire a lock to make sure only a single operation occurs at any given point of time
62
- s .lock .Lock ()
63
- defer s .lock .Unlock ()
62
+ s .internalLock .Lock ()
63
+ defer s .internalLock .Unlock ()
64
64
65
65
if s .raft .State () != raft .Leader {
66
66
// Marshal json into byte array
@@ -84,8 +84,8 @@ func (s *SyncManager) SetOperationModeConfig(token string, op *config.OperationC
84
84
// SetProjectConfig applies the config to the raft log
85
85
func (s * SyncManager ) SetProjectConfig (token string , project * config.Project ) error {
86
86
// Acquire a lock to make sure only a single operation occurs at any given point of time
87
- s .lock .Lock ()
88
- defer s .lock .Unlock ()
87
+ s .internalLock .Lock ()
88
+ defer s .internalLock .Unlock ()
89
89
90
90
if s .raft .State () != raft .Leader {
91
91
// Marshal json into byte array
@@ -105,7 +105,10 @@ func (s *SyncManager) SetProjectConfig(token string, project *config.Project) er
105
105
106
106
// Create a raft command
107
107
c := & model.RaftCommand {Kind : utils .RaftCommandSet , Project : project , ID : project .ID }
108
- data , _ := json .Marshal (c )
108
+ data , err := json .Marshal (c )
109
+ if err != nil {
110
+ return err
111
+ }
109
112
110
113
// Apply the command to the raft log
111
114
return s .raft .Apply (data , 0 ).Error ()
@@ -114,8 +117,8 @@ func (s *SyncManager) SetProjectConfig(token string, project *config.Project) er
114
117
// SetDeployConfig applies the config to the raft log
115
118
func (s * SyncManager ) SetDeployConfig (token string , deploy * config.Deploy ) error {
116
119
// Acquire a lock to make sure only a single operation occurs at any given point of time
117
- s .lock .Lock ()
118
- defer s .lock .Unlock ()
120
+ s .internalLock .Lock ()
121
+ defer s .internalLock .Unlock ()
119
122
120
123
if s .raft .State () != raft .Leader {
121
124
// Marshal json into byte array
@@ -139,8 +142,8 @@ func (s *SyncManager) SetDeployConfig(token string, deploy *config.Deploy) error
139
142
// DeleteConfig applies the config to the raft log
140
143
func (s * SyncManager ) DeleteConfig (token , projectID string ) error {
141
144
// Acquire a lock to make sure only a single operation occurs at any given point of time
142
- s .lock .Lock ()
143
- defer s .lock .Unlock ()
145
+ s .internalLock .Lock ()
146
+ defer s .internalLock .Unlock ()
144
147
145
148
if s .raft .State () != raft .Leader {
146
149
@@ -161,8 +164,8 @@ func (s *SyncManager) DeleteConfig(token, projectID string) error {
161
164
162
165
// GetConfig returns the config present in the state
163
166
func (s * SyncManager ) GetConfig (projectID string ) (* config.Project , error ) {
164
- s .lock . RLock ()
165
- defer s .lock . RUnlock ()
167
+ s .internalLock . Lock ()
168
+ defer s .internalLock . Unlock ()
166
169
167
170
// Iterate over all projects stored
168
171
for _ , p := range s .projectConfig .Projects {
0 commit comments