Skip to content

Commit

Permalink
*: s/rng/repl/ for vars of type Replica
Browse files Browse the repository at this point in the history
It's confusing to have variables named `rng` when their type is
`Replica` and not `Range` or similar. This is a large cosmetic change
that fixes a lot of those occurrences.
  • Loading branch information
jordanlewis committed Nov 4, 2016
1 parent 6a20b13 commit 499cf5e
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 548 deletions.
6 changes: 3 additions & 3 deletions pkg/storage/client_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,18 @@ func TestStoreRangeMergeStats(t *testing.T) {
if _, err := client.SendWrapped(context.Background(), rg1(store), &args); err != nil {
t.Fatal(err)
}
rngMerged := store.LookupReplica(aDesc.StartKey, nil)
replMerged := store.LookupReplica(aDesc.StartKey, nil)

// Get the range stats for the merged range and verify.
snap = store.Engine().NewSnapshot()
defer snap.Close()
msMerged, err := engine.MVCCGetRangeStats(context.Background(), snap, rngMerged.RangeID)
msMerged, err := engine.MVCCGetRangeStats(context.Background(), snap, replMerged.RangeID)
if err != nil {
t.Fatal(err)
}

// Merged stats should agree with recomputation.
if err := verifyRecomputedStats(snap, rngMerged.Desc(), msMerged, manual.UnixNano()); err != nil {
if err := verifyRecomputedStats(snap, replMerged.Desc(), msMerged, manual.UnixNano()); err != nil {
t.Errorf("failed to verify range's stats after merge: %v", err)
}
}
Expand Down
92 changes: 46 additions & 46 deletions pkg/storage/client_raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,24 @@ func TestReplicateRange(t *testing.T) {
t.Fatal(err)
}

rng, err := mtc.stores[0].GetReplica(1)
repl, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}

if err := rng.ChangeReplicas(
if err := repl.ChangeReplicas(
context.Background(),
roachpb.ADD_REPLICA,
roachpb.ReplicaDescriptor{
NodeID: mtc.stores[1].Ident.NodeID,
StoreID: mtc.stores[1].Ident.StoreID,
},
rng.Desc(),
repl.Desc(),
); err != nil {
t.Fatal(err)
}
// Verify no intent remains on range descriptor key.
key := keys.RangeDescriptorKey(rng.Desc().StartKey)
key := keys.RangeDescriptorKey(repl.Desc().StartKey)
desc := roachpb.RangeDescriptor{}
if ok, err := engine.MVCCGetProto(context.Background(), mtc.stores[0].Engine(), key, mtc.stores[0].Clock().Now(), true, nil, &desc); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -377,11 +377,11 @@ func TestRestoreReplicas(t *testing.T) {

// Both replicas have a complete list in Desc.Replicas
for i, store := range mtc.stores {
rng, err := store.GetReplica(1)
repl, err := store.GetReplica(1)
if err != nil {
t.Fatal(err)
}
desc := rng.Desc()
desc := repl.Desc()
if len(desc.Replicas) != 2 {
t.Fatalf("store %d: expected 2 replicas, found %d", i, len(desc.Replicas))
}
Expand Down Expand Up @@ -416,26 +416,26 @@ func TestFailedReplicaChange(t *testing.T) {
mtc.Start(t, 2)
defer mtc.Stop()

rng, err := mtc.stores[0].GetReplica(1)
repl, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}

if err := rng.ChangeReplicas(
if err := repl.ChangeReplicas(
context.Background(),
roachpb.ADD_REPLICA,
roachpb.ReplicaDescriptor{
NodeID: mtc.stores[1].Ident.NodeID,
StoreID: mtc.stores[1].Ident.StoreID,
},
rng.Desc(),
repl.Desc(),
); !testutils.IsError(err, "boom") {
t.Fatalf("did not get expected error: %v", err)
}

// After the aborted transaction, r.Desc was not updated.
// TODO(bdarnell): expose and inspect raft's internal state.
if replicas := rng.Desc().Replicas; len(replicas) != 1 {
if replicas := repl.Desc().Replicas; len(replicas) != 1 {
t.Fatalf("expected 1 replica, found %v", replicas)
}

Expand All @@ -447,14 +447,14 @@ func TestFailedReplicaChange(t *testing.T) {
// are pushable by making the transaction abandoned.
mtc.manualClock.Increment(10 * base.DefaultHeartbeatInterval.Nanoseconds())

if err := rng.ChangeReplicas(
if err := repl.ChangeReplicas(
context.Background(),
roachpb.ADD_REPLICA,
roachpb.ReplicaDescriptor{
NodeID: mtc.stores[1].Ident.NodeID,
StoreID: mtc.stores[1].Ident.StoreID,
},
rng.Desc(),
repl.Desc(),
); err != nil {
t.Fatal(err)
}
Expand All @@ -481,7 +481,7 @@ func TestReplicateAfterTruncation(t *testing.T) {
mtc := startMultiTestContext(t, 2)
defer mtc.Stop()

rng, err := mtc.stores[0].GetReplica(1)
repl, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -493,7 +493,7 @@ func TestReplicateAfterTruncation(t *testing.T) {
}

// Get that command's log index.
index, err := rng.GetLastIndex()
index, err := repl.GetLastIndex()
if err != nil {
t.Fatal(err)
}
Expand All @@ -512,14 +512,14 @@ func TestReplicateAfterTruncation(t *testing.T) {
}

// Now add the second replica.
if err := rng.ChangeReplicas(
if err := repl.ChangeReplicas(
context.Background(),
roachpb.ADD_REPLICA,
roachpb.ReplicaDescriptor{
NodeID: mtc.stores[1].Ident.NodeID,
StoreID: mtc.stores[1].Ident.StoreID,
},
rng.Desc(),
repl.Desc(),
); err != nil {
t.Fatal(err)
}
Expand All @@ -537,13 +537,13 @@ func TestReplicateAfterTruncation(t *testing.T) {
return nil
})

rng2, err := mtc.stores[1].GetReplica(1)
repl2, err := mtc.stores[1].GetReplica(1)
if err != nil {
t.Fatal(err)
}

util.SucceedsSoon(t, func() error {
if mvcc, mvcc2 := rng.GetMVCCStats(), rng2.GetMVCCStats(); mvcc2 != mvcc {
if mvcc, mvcc2 := repl.GetMVCCStats(), repl2.GetMVCCStats(); mvcc2 != mvcc {
return errors.Errorf("expected stats on new range:\n%+v\not equal old:\n%+v", mvcc2, mvcc)
}
return nil
Expand Down Expand Up @@ -576,7 +576,7 @@ func TestSnapshotAfterTruncation(t *testing.T) {
defer leaktest.AfterTest(t)()
mtc := startMultiTestContext(t, 3)
defer mtc.Stop()
rng, err := mtc.stores[0].GetReplica(1)
repl, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -609,7 +609,7 @@ func TestSnapshotAfterTruncation(t *testing.T) {

mtc.waitForValues(key, []int64{incAB, incA, incAB})

index, err := rng.GetLastIndex()
index, err := repl.GetLastIndex()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -681,7 +681,7 @@ func TestConcurrentRaftSnapshots(t *testing.T) {
defer leaktest.AfterTest(t)()
mtc := startMultiTestContext(t, 5)
defer mtc.Stop()
rng, err := mtc.stores[0].GetReplica(1)
repl, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -715,7 +715,7 @@ func TestConcurrentRaftSnapshots(t *testing.T) {

mtc.waitForValues(key, []int64{incAB, incA, incA, incAB, incAB})

index, err := rng.GetLastIndex()
index, err := repl.GetLastIndex()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -857,11 +857,11 @@ func TestRefreshPendingCommands(t *testing.T) {
}

// Get the last increment's log index.
rng, err := mtc.stores[0].GetReplica(1)
repl, err := mtc.stores[0].GetReplica(1)
if err != nil {
t.Fatal(err)
}
index, err := rng.GetLastIndex()
index, err := repl.GetLastIndex()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1364,11 +1364,11 @@ func runReplicateRestartAfterTruncation(t *testing.T, removeBeforeTruncateAndReA
// Truncate the logs.
{
// Get the last increment's log index.
rng, err := mtc.stores[0].GetReplica(rangeID)
repl, err := mtc.stores[0].GetReplica(rangeID)
if err != nil {
t.Fatal(err)
}
index, err := rng.GetLastIndex()
index, err := repl.GetLastIndex()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1812,14 +1812,14 @@ func TestRangeDescriptorSnapshotRace(t *testing.T) {
defer stopper.Stop()
// Call Snapshot() in a loop and ensure it never fails.
work := func(key roachpb.RKey) error {
rng := mtc.stores[0].LookupReplica(key, nil)
if rng == nil {
repl := mtc.stores[0].LookupReplica(key, nil)
if repl == nil {
return errors.Errorf("failed to look up replica for %s", key)
}
if _, err := rng.GetSnapshot(context.Background()); err != nil {
return errors.Wrapf(err, "failed to snapshot range %s: %s", rng, key)
if _, err := repl.GetSnapshot(context.Background()); err != nil {
return errors.Wrapf(err, "failed to snapshot range %s: %s", repl, key)
}
rng.CloseOutSnap()
repl.CloseOutSnap()
return nil
}

Expand All @@ -1844,26 +1844,26 @@ func TestRangeDescriptorSnapshotRace(t *testing.T) {
// initial range. The bug that this test was designed to find
// usually occurred within the first 5 iterations.
for i := 20; i > 0; i-- {
rng := mtc.stores[0].LookupReplica(roachpb.RKeyMin, nil)
if rng == nil {
repl := mtc.stores[0].LookupReplica(roachpb.RKeyMin, nil)
if repl == nil {
t.Fatal("failed to look up min range")
}
desc := rng.Desc()
desc := repl.Desc()
args := adminSplitArgs(roachpb.KeyMin, []byte(fmt.Sprintf("A%03d", i)))
if _, err := rng.AdminSplit(context.Background(), args, desc); err != nil {
if _, err := repl.AdminSplit(context.Background(), args, desc); err != nil {
t.Fatal(err)
}
}

// Split again, carving chunks off the beginning of the final range.
for i := 0; i < 20; i++ {
rng := mtc.stores[0].LookupReplica(roachpb.RKey("Z"), nil)
if rng == nil {
repl := mtc.stores[0].LookupReplica(roachpb.RKey("Z"), nil)
if repl == nil {
t.Fatal("failed to look up max range")
}
desc := rng.Desc()
desc := repl.Desc()
args := adminSplitArgs(roachpb.KeyMin, []byte(fmt.Sprintf("B%03d", i)))
if _, err := rng.AdminSplit(context.Background(), args, desc); err != nil {
if _, err := repl.AdminSplit(context.Background(), args, desc); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -2715,18 +2715,18 @@ func TestTransferRaftLeadership(t *testing.T) {
}
}

rng := store0.LookupReplica(keys.MustAddr(key), nil)
if rng == nil {
repl := store0.LookupReplica(keys.MustAddr(key), nil)
if repl == nil {
t.Fatalf("no replica found for key '%s'", key)
}
mtc.replicateRange(rng.RangeID, 1, 2)
mtc.replicateRange(repl.RangeID, 1, 2)

getArgs := getArgs([]byte("a"))
if _, pErr := client.SendWrappedWith(context.Background(), store0, roachpb.Header{RangeID: rng.RangeID}, &getArgs); pErr != nil {
if _, pErr := client.SendWrappedWith(context.Background(), store0, roachpb.Header{RangeID: repl.RangeID}, &getArgs); pErr != nil {
t.Fatalf("expect get nil, actual get %v ", pErr)
}

status := rng.RaftStatus()
status := repl.RaftStatus()
if status != nil && status.Lead != 1 {
t.Fatalf("raft leader should be 1, but got status %+v", status)
}
Expand All @@ -2739,7 +2739,7 @@ func TestTransferRaftLeadership(t *testing.T) {
if _, pErr := client.SendWrappedWith(
context.Background(),
store1,
roachpb.Header{RangeID: rng.RangeID},
roachpb.Header{RangeID: repl.RangeID},
&getArgs,
); pErr == nil {
break
Expand All @@ -2753,7 +2753,7 @@ func TestTransferRaftLeadership(t *testing.T) {
}
// Wait for raft leadership transferring to be finished.
util.SucceedsSoon(t, func() error {
status = rng.RaftStatus()
status = repl.RaftStatus()
if status.Lead != 2 {
return errors.Errorf("expected raft leader be 2; got %d", status.Lead)
}
Expand Down
Loading

0 comments on commit 499cf5e

Please sign in to comment.