Initialize configs correctly, move notification config (#8367)

This PR also removes deprecated tests, adds checks
to avoid races reproduced on CI/CD.
This commit is contained in:
Harshavardhana
2019-10-08 23:11:15 -07:00
committed by kannappanr
parent d2a8be6fc2
commit 6a4ef2e48e
15 changed files with 149 additions and 321 deletions

View File

@@ -21,7 +21,7 @@ import (
"crypto/tls"
"errors"
"io"
"sync"
"sync/atomic"
"time"
"net/url"
@@ -35,12 +35,10 @@ import (
// lockRESTClient is authenticable lock REST client
type lockRESTClient struct {
lockSync sync.RWMutex
host *xnet.Host
restClient *rest.Client
serverURL *url.URL
connected bool
timer *time.Timer
connected int32
}
func toLockError(err error) error {
@@ -67,42 +65,11 @@ func (client *lockRESTClient) ServiceEndpoint() string {
return client.serverURL.Path
}
// check if the host is up or if it is fine
// to make a call to the lock rest server.
func (client *lockRESTClient) isHostUp() bool {
client.lockSync.Lock()
defer client.lockSync.Unlock()
if client.connected {
return true
}
select {
case <-client.timer.C:
client.connected = true
client.timer = nil
return true
default:
}
return false
}
// Mark the host as down if there is a Network error.
func (client *lockRESTClient) markHostDown() {
client.lockSync.Lock()
defer client.lockSync.Unlock()
if !client.connected {
return
}
client.connected = false
client.timer = time.NewTimer(defaultRetryUnit * 5)
}
// Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected
// permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints()
// after verifying format.json
func (client *lockRESTClient) call(method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) {
if !client.isHostUp() {
if !client.IsOnline() {
return nil, errors.New("Lock rest server node is down")
}
@@ -116,7 +83,12 @@ func (client *lockRESTClient) call(method string, values url.Values, body io.Rea
}
if isNetworkError(err) {
client.markHostDown()
time.AfterFunc(defaultRetryUnit*5, func() {
// After 5 seconds, take this lock client
// online for a retry.
atomic.StoreInt32(&client.connected, 1)
})
atomic.StoreInt32(&client.connected, 0)
}
return nil, toLockError(err)
@@ -129,12 +101,12 @@ func (client *lockRESTClient) String() string {
// IsOnline - returns whether REST client failed to connect or not.
func (client *lockRESTClient) IsOnline() bool {
return client.connected
return atomic.LoadInt32(&client.connected) == 1
}
// Close - marks the client as closed.
func (client *lockRESTClient) Close() error {
client.connected = false
atomic.StoreInt32(&client.connected, 0)
client.restClient.Close()
return nil
}
@@ -217,8 +189,8 @@ func newlockRESTClient(peer *xnet.Host) *lockRESTClient {
if err != nil {
logger.LogIf(context.Background(), err)
return &lockRESTClient{serverURL: serverURL, host: peer, restClient: restClient, connected: false, timer: time.NewTimer(defaultRetryUnit * 5)}
return &lockRESTClient{serverURL: serverURL, host: peer, restClient: restClient, connected: 0}
}
return &lockRESTClient{serverURL: serverURL, host: peer, restClient: restClient, connected: true}
return &lockRESTClient{serverURL: serverURL, host: peer, restClient: restClient, connected: 1}
}