1
0
Fork 0

Merge pull request #1100 from rqlite/e2e-key-error

HTTP server now up faster, Store may not be ready
master
Philip O'Toole 2 years ago committed by GitHub
commit 6c837046fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,6 +104,8 @@ func (j *Joiner) Do(joinAddrs []string, id, addr string, voter bool) (string, er
if err == nil { if err == nil {
// Success! // Success!
return joinee, nil return joinee, nil
} else {
j.logger.Printf("failed to join via node at %s: %s", a, err)
} }
} }
if i+1 < j.numAttempts { if i+1 < j.numAttempts {
@ -166,14 +168,14 @@ func (j *Joiner) join(joinAddr, id, addr string, voter bool) (string, error) {
// protocol a registered node is actually using. // protocol a registered node is actually using.
if strings.HasPrefix(fullAddr, "https://") { if strings.HasPrefix(fullAddr, "https://") {
// It's already HTTPS, give up. // It's already HTTPS, give up.
return "", fmt.Errorf("failed to join, node returned: %s: (%s)", resp.Status, string(b)) return "", fmt.Errorf("%s: (%s)", resp.Status, string(b))
} }
j.logger.Print("join via HTTP failed, trying via HTTPS") j.logger.Print("join via HTTP failed, trying via HTTPS")
fullAddr = rurl.EnsureHTTPS(fullAddr) fullAddr = rurl.EnsureHTTPS(fullAddr)
continue continue
default: default:
return "", fmt.Errorf("failed to join, node returned: %s: (%s)", resp.Status, string(b)) return "", fmt.Errorf("%s: (%s)", resp.Status, string(b))
} }
} }
} }

@ -329,15 +329,17 @@ class Node(object):
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
return '' return ''
def wait_for_leader(self, timeout=TIMEOUT): def wait_for_leader(self, timeout=TIMEOUT, log=True):
lr = None lr = None
t = 0 t = 0
while lr == None or lr['addr'] == '': while lr == None or lr['addr'] == '':
if t > timeout: if t > timeout:
if log:
self.dump_log("dumping log due to timeout waiting for leader")
raise Exception('rqlite node failed to detect leader within %d seconds' % timeout) raise Exception('rqlite node failed to detect leader within %d seconds' % timeout)
try: try:
lr = self.status()['store']['leader'] lr = self.status()['store']['leader']
except requests.exceptions.ConnectionError: except (KeyError, requests.exceptions.ConnectionError):
pass pass
time.sleep(1) time.sleep(1)
t+=1 t+=1
@ -347,6 +349,13 @@ class Node(object):
raise Exception('leader is available but node reports not ready') raise Exception('leader is available but node reports not ready')
return lr return lr
def expect_leader_fail(self, timeout=TIMEOUT):
try:
self.wait_for_leader(self, timeout, log=False)
except:
return True
return false
def db_applied_index(self): def db_applied_index(self):
return int(self.status()['store']['db_applied_index']) return int(self.status()['store']['db_applied_index'])
@ -1102,7 +1111,7 @@ class TestAuthJoin(unittest.TestCase):
n1 = Node(RQLITED_PATH, '1', auth=self.auth_file.name) n1 = Node(RQLITED_PATH, '1', auth=self.auth_file.name)
n1.start(join=n0.APIAddr()) n1.start(join=n0.APIAddr())
self.assertRaises(Exception, n1.wait_for_leader) # Join should fail due to lack of auth. self.assertTrue(n1.expect_leader_fail()) # Join should fail due to lack of auth.
n2 = Node(RQLITED_PATH, '2', auth=self.auth_file.name) n2 = Node(RQLITED_PATH, '2', auth=self.auth_file.name)
n2.start(join=n0.APIAddr(), join_as="foo") n2.start(join=n0.APIAddr(), join_as="foo")

Loading…
Cancel
Save