-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(raft):alpha leader fails to stream snapshot to new alpha nodes (#…
…9022) Certain issues arise when a snapshot is taken by the alpha leader in a cluster and a new node joins afterwards.
- Loading branch information
1 parent
9460704
commit 02e2016
Showing
9 changed files
with
244 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2023 Dgraph Labs, Inc. and Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dgraphtest | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func (hc *HTTPClient) GetCurrentSnapshotTs(group uint64) (uint64, error) { | ||
snapTsRequest := `query { | ||
state { | ||
groups { | ||
id | ||
snapshotTs | ||
} | ||
} | ||
}` | ||
params := GraphQLParams{ | ||
Query: snapTsRequest, | ||
} | ||
resp, err := hc.RunGraphqlQuery(params, true) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
var stateResp struct { | ||
State struct { | ||
Groups []struct { | ||
SnapshotTs uint64 | ||
} | ||
} | ||
} | ||
|
||
err = json.Unmarshal(resp, &stateResp) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return stateResp.State.Groups[group-1].SnapshotTs, nil | ||
} | ||
|
||
func (hc *HTTPClient) WaitForSnapshot(group, prevSnapshotTs uint64) (uint64, error) { | ||
|
||
for i := 1; i <= 100; i++ { | ||
currentSnapshotTs, err := hc.GetCurrentSnapshotTs(group) | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "error while getting current snapshot timestamp: %v", err) | ||
} | ||
if currentSnapshotTs > prevSnapshotTs { | ||
return currentSnapshotTs, nil | ||
} | ||
|
||
time.Sleep(time.Second) | ||
} | ||
return 0, errors.New("timeout excedded") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//go:build integration2 | ||
|
||
/* | ||
* Copyright 2023 Dgraph Labs, Inc. and Contributors * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/dgraph-io/dgraph/dgraphtest" | ||
"github.com/dgraph-io/dgraph/x" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSnapshotTranferAfterNewNodeJoins(t *testing.T) { | ||
conf := dgraphtest.NewClusterConfig().WithNumAlphas(3).WithNumZeros(1). | ||
WithACL(time.Hour).WithReplicas(3).WithSnapshotConfig(11, time.Second) | ||
c, err := dgraphtest.NewLocalCluster(conf) | ||
require.NoError(t, err) | ||
defer func() { c.Cleanup(t.Failed()) }() | ||
|
||
// start zero | ||
require.NoError(t, c.StartZero(0)) | ||
require.NoError(t, c.HealthCheck(true)) | ||
require.NoError(t, c.StartAlpha(0)) | ||
require.NoError(t, c.HealthCheck(false)) | ||
|
||
hc, err := c.HTTPClient() | ||
require.NoError(t, err) | ||
hc.LoginIntoNamespace(dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace) | ||
|
||
gc, cleanup, err := c.Client() | ||
require.NoError(t, err) | ||
defer cleanup() | ||
require.NoError(t, gc.LoginIntoNamespace(context.Background(), | ||
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace)) | ||
|
||
prevSnapshotTs, err := hc.GetCurrentSnapshotTs(1) | ||
require.NoError(t, err) | ||
|
||
dgraphtest.AddData(gc, "name", 1, 20) | ||
|
||
_, err = hc.WaitForSnapshot(1, prevSnapshotTs) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, c.StartAlpha(1)) | ||
require.NoError(t, c.StartAlpha(2)) | ||
|
||
// Wait for the other alpha nodes to receive the snapshot from the leader alpha. | ||
// If they are healthy, there should be no issues with the snapshot streaming | ||
time.Sleep(time.Second) | ||
require.NoError(t, c.HealthCheck(false)) | ||
} |
Oops, something went wrong.