-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Periodically persist routing table snapshots #650
Open
aarshkshah1992
wants to merge
1
commit into
feat/persist-restore-RT
Choose a base branch
from
feat/persist-routing-table
base: feat/persist-restore-RT
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,15 @@ import ( | |
|
||
test "github.com/libp2p/go-libp2p-kad-dht/internal/testing" | ||
pb "github.com/libp2p/go-libp2p-kad-dht/pb" | ||
"github.com/libp2p/go-libp2p-kad-dht/persist" | ||
kb "github.com/libp2p/go-libp2p-kbucket" | ||
record "github.com/libp2p/go-libp2p-record" | ||
swarmt "github.com/libp2p/go-libp2p-swarm/testing" | ||
bhost "github.com/libp2p/go-libp2p/p2p/host/basic" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/ipfs/go-datastore" | ||
dssync "github.com/ipfs/go-datastore/sync" | ||
detectrace "github.com/ipfs/go-detect-race" | ||
u "github.com/ipfs/go-ipfs-util" | ||
ma "github.com/multiformats/go-multiaddr" | ||
|
@@ -387,6 +390,56 @@ func TestValueSetInvalid(t *testing.T) { | |
testSetGet("valid", true, "newer", nil) | ||
} | ||
|
||
func TestRoutingTableSnapshot(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
sdstore := dssync.MutexWrap(datastore.NewMapDatastore()) | ||
snapShotter, err := persist.NewDatastoreSnapshotter(sdstore, "rand") | ||
require.NoError(t, err) | ||
snapShotterOpt := Snapshotter(snapShotter, 100*time.Millisecond) | ||
|
||
// start 4 other dht's we can connect to & add to our RT | ||
dhts := setupDHTS(t, ctx, 4) | ||
defer func() { | ||
for i := 0; i < 4; i++ { | ||
dhts[i].Close() | ||
defer dhts[i].host.Close() | ||
} | ||
}() | ||
|
||
// connect them with each other | ||
connect(t, ctx, dhts[0], dhts[1]) | ||
connect(t, ctx, dhts[1], dhts[2]) | ||
connect(t, ctx, dhts[2], dhts[3]) | ||
|
||
// create dht with snapshotter & connect it to one of the above dht's | ||
selfDht := setupDHT(ctx, t, false, snapShotterOpt) | ||
require.True(t, selfDht.routingTable.Size() == 0) | ||
defer selfDht.Close() | ||
defer selfDht.host.Close() | ||
|
||
connect(t, ctx, selfDht, dhts[0]) | ||
|
||
for selfDht.routingTable.Size() != 4 { | ||
<-selfDht.ForceRefresh() | ||
} | ||
|
||
// assert snapshot & close dht | ||
time.Sleep(500 * time.Millisecond) // wait for one snapshot | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 500ms when a snapshot should happen every 100ms? Just want to make sure I'm not missing anything |
||
snapshotPeers, err := snapShotter.Load() | ||
require.Len(t, snapshotPeers, 4) | ||
var peerIds []peer.ID | ||
for i := range snapshotPeers { | ||
peerIds = append(peerIds, snapshotPeers[i].ID) | ||
} | ||
require.Len(t, peerIds, 4) | ||
|
||
require.NoError(t, err) | ||
for _, d := range dhts { | ||
require.Contains(t, peerIds, d.self) | ||
} | ||
} | ||
|
||
func TestContextShutDown(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe rename to
TestRoutingTableSnapshotStore
or something unless you're going to just extend this test when you test snapshot restoring.