-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
recovery_test.go
100 lines (84 loc) · 2.56 KB
/
recovery_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package kvserver_test
import (
"context"
"testing"
"time"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/stretchr/testify/require"
)
func TestRecoverRangeWithNoReplicas(t *testing.T) {
defer leaktest.AfterTest(t)()
ctx := context.Background()
args := base.TestClusterArgs{
ReplicationMode: base.ReplicationManual,
}
tc := testcluster.StartTestCluster(t, 2, args)
defer tc.Stopper().Stop(ctx)
k := tc.ScratchRange(t)
desc, err := tc.AddReplicas(k, tc.Target(1))
require.NoError(t, err)
require.NoError(t, tc.TransferRangeLease(desc, tc.Target(1)))
svr := tc.Server(0)
require.NoError(t, svr.DB().Put(ctx, k, "bar"))
tc.StopServer(1)
// Sanity check that requests to the ScratchRange time out.
cCtx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond)
defer cancel()
require.Error(t, svr.DB().Put(cCtx, k, "baz"))
require.Equal(t, context.DeadlineExceeded, cCtx.Err())
// TODO: Figure out: is this necessary?
//var exp []byte
//if err := svr.DB().Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
// kvs, err := sql.ScanMetaKVs(ctx, txn, roachpb.Span{
// Key: roachpb.KeyMin,
// EndKey: roachpb.KeyMax,
// })
// if err != nil {
// return err
// }
//
// for i := range kvs {
// if err := kvs[i].Value.GetProto(&desc); err != nil {
// return err
// }
// if desc.RangeID == desc.RangeID {
// exp = kvs[i].Value.TagAndDataBytes()
// return nil
// }
// }
// return errors.Newf("r%d not found", desc.RangeID)
//}); err != nil {
// // TODO: update this
// t.Fatal(err)
//}
var store *kvserver.Store
if err := svr.GetStores().(*kvserver.Stores).VisitStores(func(inner *kvserver.Store) error {
if store == nil {
store = inner
}
return nil
}); err != nil {
// TODO: update this
t.Fatal(err)
}
storeID, nodeID := store.Ident.StoreID, store.Ident.NodeID
// TODO: Figure out: is this necessary?
//if err := store.DB().CPut(
// ctx, keys.RangeMetaKey(desc.EndKey).AsRawKey(), &desc, exp,
//); err != nil {
// t.Fatal(err)
//}
_, err = svr.Node().(*server.Node).UnsafeHealRange(
ctx,
&roachpb.UnsafeHealRangeRequest{Desc: desc, NodeID: int32(nodeID), StoreID: int32(storeID)},
)
require.NoError(t, err)
log.Info(ctx, "snapshot applied")
require.Error(t, svr.DB().Put(cCtx, k, "baz"))
}