mirror of https://github.com/status-im/consul.git
Makes the iterator naming more consistent.
This commit is contained in:
parent
ffe531c55f
commit
3782fc53cb
|
@ -400,11 +400,11 @@ func (s *consulSnapshot) persistNodes(sink raft.SnapshotSink,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register each node
|
// Register each node
|
||||||
for ni := nodes.Next(); ni != nil; ni = nodes.Next() {
|
for node := nodes.Next(); node != nil; node = nodes.Next() {
|
||||||
node := ni.(*structs.Node)
|
n := node.(*structs.Node)
|
||||||
req := structs.RegisterRequest{
|
req := structs.RegisterRequest{
|
||||||
Node: node.Node,
|
Node: n.Node,
|
||||||
Address: node.Address,
|
Address: n.Address,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the node itself
|
// Register the node itself
|
||||||
|
@ -414,13 +414,13 @@ func (s *consulSnapshot) persistNodes(sink raft.SnapshotSink,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register each service this node has
|
// Register each service this node has
|
||||||
services, err := s.state.Services(node.Node)
|
services, err := s.state.Services(n.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for si := services.Next(); si != nil; si = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
req.Service = si.(*structs.ServiceNode).ToNodeService()
|
|
||||||
sink.Write([]byte{byte(structs.RegisterRequestType)})
|
sink.Write([]byte{byte(structs.RegisterRequestType)})
|
||||||
|
req.Service = service.(*structs.ServiceNode).ToNodeService()
|
||||||
if err := encoder.Encode(&req); err != nil {
|
if err := encoder.Encode(&req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -428,13 +428,13 @@ func (s *consulSnapshot) persistNodes(sink raft.SnapshotSink,
|
||||||
|
|
||||||
// Register each check this node has
|
// Register each check this node has
|
||||||
req.Service = nil
|
req.Service = nil
|
||||||
checks, err := s.state.Checks(node.Node)
|
checks, err := s.state.Checks(n.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for ci := checks.Next(); ci != nil; ci = checks.Next() {
|
for check := checks.Next(); check != nil; check = checks.Next() {
|
||||||
req.Check = ci.(*structs.HealthCheck)
|
|
||||||
sink.Write([]byte{byte(structs.RegisterRequestType)})
|
sink.Write([]byte{byte(structs.RegisterRequestType)})
|
||||||
|
req.Check = check.(*structs.HealthCheck)
|
||||||
if err := encoder.Encode(&req); err != nil {
|
if err := encoder.Encode(&req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -445,14 +445,14 @@ func (s *consulSnapshot) persistNodes(sink raft.SnapshotSink,
|
||||||
|
|
||||||
func (s *consulSnapshot) persistSessions(sink raft.SnapshotSink,
|
func (s *consulSnapshot) persistSessions(sink raft.SnapshotSink,
|
||||||
encoder *codec.Encoder) error {
|
encoder *codec.Encoder) error {
|
||||||
iter, err := s.state.Sessions()
|
sessions, err := s.state.Sessions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for si := iter.Next(); si != nil; si = iter.Next() {
|
for session := sessions.Next(); session != nil; session = sessions.Next() {
|
||||||
sink.Write([]byte{byte(structs.SessionRequestType)})
|
sink.Write([]byte{byte(structs.SessionRequestType)})
|
||||||
if err := encoder.Encode(si.(*structs.Session)); err != nil {
|
if err := encoder.Encode(session.(*structs.Session)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,14 +461,14 @@ func (s *consulSnapshot) persistSessions(sink raft.SnapshotSink,
|
||||||
|
|
||||||
func (s *consulSnapshot) persistACLs(sink raft.SnapshotSink,
|
func (s *consulSnapshot) persistACLs(sink raft.SnapshotSink,
|
||||||
encoder *codec.Encoder) error {
|
encoder *codec.Encoder) error {
|
||||||
iter, err := s.state.ACLs()
|
acls, err := s.state.ACLs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for ai := iter.Next(); ai != nil; ai = iter.Next() {
|
for acl := acls.Next(); acl != nil; acl = acls.Next() {
|
||||||
sink.Write([]byte{byte(structs.ACLRequestType)})
|
sink.Write([]byte{byte(structs.ACLRequestType)})
|
||||||
if err := encoder.Encode(ai.(*structs.ACL)); err != nil {
|
if err := encoder.Encode(acl.(*structs.ACL)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -477,14 +477,14 @@ func (s *consulSnapshot) persistACLs(sink raft.SnapshotSink,
|
||||||
|
|
||||||
func (s *consulSnapshot) persistKVs(sink raft.SnapshotSink,
|
func (s *consulSnapshot) persistKVs(sink raft.SnapshotSink,
|
||||||
encoder *codec.Encoder) error {
|
encoder *codec.Encoder) error {
|
||||||
iter, err := s.state.KVs()
|
entries, err := s.state.KVs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for ki := iter.Next(); ki != nil; ki = iter.Next() {
|
for entry := entries.Next(); entry != nil; entry = entries.Next() {
|
||||||
sink.Write([]byte{byte(structs.KVSRequestType)})
|
sink.Write([]byte{byte(structs.KVSRequestType)})
|
||||||
if err := encoder.Encode(ki.(*structs.DirEntry)); err != nil {
|
if err := encoder.Encode(entry.(*structs.DirEntry)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -493,22 +493,22 @@ func (s *consulSnapshot) persistKVs(sink raft.SnapshotSink,
|
||||||
|
|
||||||
func (s *consulSnapshot) persistTombstones(sink raft.SnapshotSink,
|
func (s *consulSnapshot) persistTombstones(sink raft.SnapshotSink,
|
||||||
encoder *codec.Encoder) error {
|
encoder *codec.Encoder) error {
|
||||||
iter, err := s.state.Tombstones()
|
stones, err := s.state.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for ti := iter.Next(); ti != nil; ti = iter.Next() {
|
for stone := stones.Next(); stone != nil; stone = stones.Next() {
|
||||||
sink.Write([]byte{byte(structs.TombstoneRequestType)})
|
sink.Write([]byte{byte(structs.TombstoneRequestType)})
|
||||||
|
|
||||||
// For historical reasons, these are serialized in the snapshots
|
// For historical reasons, these are serialized in the snapshots
|
||||||
// as KV entries. We want to keep the snapshot format compatible
|
// as KV entries. We want to keep the snapshot format compatible
|
||||||
// with pre-0.6 versions for now.
|
// with pre-0.6 versions for now.
|
||||||
stone := ti.(*state.Tombstone)
|
s := stone.(*state.Tombstone)
|
||||||
fake := &structs.DirEntry{
|
fake := &structs.DirEntry{
|
||||||
Key: stone.Key,
|
Key: s.Key,
|
||||||
RaftIndex: structs.RaftIndex{
|
RaftIndex: structs.RaftIndex{
|
||||||
ModifyIndex: stone.Index,
|
ModifyIndex: s.Index,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := encoder.Encode(fake); err != nil {
|
if err := encoder.Encode(fake); err != nil {
|
||||||
|
|
|
@ -475,18 +475,18 @@ func TestFSM_SnapshotRestore(t *testing.T) {
|
||||||
func() {
|
func() {
|
||||||
snap := fsm2.state.Snapshot()
|
snap := fsm2.state.Snapshot()
|
||||||
defer snap.Close()
|
defer snap.Close()
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
stone := iter.Next().(*state.Tombstone)
|
stone := stones.Next().(*state.Tombstone)
|
||||||
if stone == nil {
|
if stone == nil {
|
||||||
t.Fatalf("missing tombstone")
|
t.Fatalf("missing tombstone")
|
||||||
}
|
}
|
||||||
if stone.Key != "/remove" || stone.Index != 12 {
|
if stone.Key != "/remove" || stone.Index != 12 {
|
||||||
t.Fatalf("bad: %v", stone)
|
t.Fatalf("bad: %v", stone)
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if stones.Next() != nil {
|
||||||
t.Fatalf("unexpected extra tombstones")
|
t.Fatalf("unexpected extra tombstones")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -1023,11 +1023,11 @@ func TestFSM_TombstoneReap(t *testing.T) {
|
||||||
// Verify the tombstones are gone
|
// Verify the tombstones are gone
|
||||||
snap := fsm.state.Snapshot()
|
snap := fsm.state.Snapshot()
|
||||||
defer snap.Close()
|
defer snap.Close()
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if stones.Next() != nil {
|
||||||
t.Fatalf("unexpected extra tombstones")
|
t.Fatalf("unexpected extra tombstones")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -590,14 +590,14 @@ func TestLeader_ReapTombstones(t *testing.T) {
|
||||||
func() {
|
func() {
|
||||||
snap := state.Snapshot()
|
snap := state.Snapshot()
|
||||||
defer snap.Close()
|
defer snap.Close()
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if iter.Next() == nil {
|
if stones.Next() == nil {
|
||||||
t.Fatalf("missing tombstones")
|
t.Fatalf("missing tombstones")
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if stones.Next() != nil {
|
||||||
t.Fatalf("unexpected extra tombstones")
|
t.Fatalf("unexpected extra tombstones")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -607,11 +607,11 @@ func TestLeader_ReapTombstones(t *testing.T) {
|
||||||
testutil.WaitForResult(func() (bool, error) {
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
snap := state.Snapshot()
|
snap := state.Snapshot()
|
||||||
defer snap.Close()
|
defer snap.Close()
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return iter.Next() == nil, nil
|
return stones.Next() == nil, nil
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
})
|
})
|
||||||
|
|
|
@ -464,8 +464,7 @@ func (s *StateStore) deleteNodeTxn(tx *memdb.Txn, idx uint64, nodeID string) err
|
||||||
}
|
}
|
||||||
var sids []string
|
var sids []string
|
||||||
for service := services.Next(); service != nil; service = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
svc := service.(*structs.ServiceNode)
|
sids = append(sids, service.(*structs.ServiceNode).ServiceID)
|
||||||
sids = append(sids, svc.ServiceID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the delete in a separate loop so we don't trash the iterator.
|
// Do the delete in a separate loop so we don't trash the iterator.
|
||||||
|
@ -483,8 +482,7 @@ func (s *StateStore) deleteNodeTxn(tx *memdb.Txn, idx uint64, nodeID string) err
|
||||||
}
|
}
|
||||||
var cids []string
|
var cids []string
|
||||||
for check := checks.Next(); check != nil; check = checks.Next() {
|
for check := checks.Next(); check != nil; check = checks.Next() {
|
||||||
hc := check.(*structs.HealthCheck)
|
cids = append(cids, check.(*structs.HealthCheck).CheckID)
|
||||||
cids = append(cids, hc.CheckID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the delete in a separate loop so we don't trash the iterator.
|
// Do the delete in a separate loop so we don't trash the iterator.
|
||||||
|
@ -596,13 +594,13 @@ func (s *StateStore) Services() (uint64, structs.Services, error) {
|
||||||
// tags.
|
// tags.
|
||||||
unique := make(map[string]map[string]struct{})
|
unique := make(map[string]map[string]struct{})
|
||||||
for service := services.Next(); service != nil; service = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
sn := service.(*structs.ServiceNode)
|
svc := service.(*structs.ServiceNode)
|
||||||
tags, ok := unique[sn.ServiceName]
|
tags, ok := unique[svc.ServiceName]
|
||||||
if !ok {
|
if !ok {
|
||||||
unique[sn.ServiceName] = make(map[string]struct{})
|
unique[svc.ServiceName] = make(map[string]struct{})
|
||||||
tags = unique[sn.ServiceName]
|
tags = unique[svc.ServiceName]
|
||||||
}
|
}
|
||||||
for _, tag := range sn.ServiceTags {
|
for _, tag := range svc.ServiceTags {
|
||||||
tags[tag] = struct{}{}
|
tags[tag] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -618,8 +616,8 @@ func (s *StateStore) Services() (uint64, structs.Services, error) {
|
||||||
return idx, results, nil
|
return idx, results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceNodes returns the nodes associated with a given service.
|
// ServiceNodes returns the nodes associated with a given service name.
|
||||||
func (s *StateStore) ServiceNodes(service string) (uint64, structs.ServiceNodes, error) {
|
func (s *StateStore) ServiceNodes(serviceName string) (uint64, structs.ServiceNodes, error) {
|
||||||
tx := s.db.Txn(false)
|
tx := s.db.Txn(false)
|
||||||
defer tx.Abort()
|
defer tx.Abort()
|
||||||
|
|
||||||
|
@ -627,13 +625,13 @@ func (s *StateStore) ServiceNodes(service string) (uint64, structs.ServiceNodes,
|
||||||
idx := maxIndexTxn(tx, s.getWatchTables("ServiceNodes")...)
|
idx := maxIndexTxn(tx, s.getWatchTables("ServiceNodes")...)
|
||||||
|
|
||||||
// List all the services.
|
// List all the services.
|
||||||
services, err := tx.Get("services", "service", service)
|
services, err := tx.Get("services", "service", serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
||||||
}
|
}
|
||||||
var results structs.ServiceNodes
|
var results structs.ServiceNodes
|
||||||
for s := services.Next(); s != nil; s = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
results = append(results, s.(*structs.ServiceNode))
|
results = append(results, service.(*structs.ServiceNode))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the address details.
|
// Fill in the address details.
|
||||||
|
@ -661,10 +659,10 @@ func (s *StateStore) ServiceTagNodes(service, tag string) (uint64, structs.Servi
|
||||||
|
|
||||||
// Gather all the services and apply the tag filter.
|
// Gather all the services and apply the tag filter.
|
||||||
var results structs.ServiceNodes
|
var results structs.ServiceNodes
|
||||||
for s := services.Next(); s != nil; s = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
sn := s.(*structs.ServiceNode)
|
svc := service.(*structs.ServiceNode)
|
||||||
if !serviceTagFilter(sn, tag) {
|
if !serviceTagFilter(svc, tag) {
|
||||||
results = append(results, sn)
|
results = append(results, svc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,8 +786,7 @@ func (s *StateStore) deleteServiceTxn(tx *memdb.Txn, idx uint64, watches *DumbWa
|
||||||
}
|
}
|
||||||
var cids []string
|
var cids []string
|
||||||
for check := checks.Next(); check != nil; check = checks.Next() {
|
for check := checks.Next(); check != nil; check = checks.Next() {
|
||||||
hc := check.(*structs.HealthCheck)
|
cids = append(cids, check.(*structs.HealthCheck).CheckID)
|
||||||
cids = append(cids, hc.CheckID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the delete in a separate loop so we don't trash the iterator.
|
// Do the delete in a separate loop so we don't trash the iterator.
|
||||||
|
@ -1046,7 +1043,7 @@ func (s *StateStore) deleteCheckTxn(tx *memdb.Txn, idx uint64, watches *DumbWatc
|
||||||
// The results are compounded into a CheckServiceNodes, and the index returned
|
// The results are compounded into a CheckServiceNodes, and the index returned
|
||||||
// is the maximum index observed over any node, check, or service in the result
|
// is the maximum index observed over any node, check, or service in the result
|
||||||
// set.
|
// set.
|
||||||
func (s *StateStore) CheckServiceNodes(service string) (uint64, structs.CheckServiceNodes, error) {
|
func (s *StateStore) CheckServiceNodes(serviceName string) (uint64, structs.CheckServiceNodes, error) {
|
||||||
tx := s.db.Txn(false)
|
tx := s.db.Txn(false)
|
||||||
defer tx.Abort()
|
defer tx.Abort()
|
||||||
|
|
||||||
|
@ -1054,15 +1051,15 @@ func (s *StateStore) CheckServiceNodes(service string) (uint64, structs.CheckSer
|
||||||
idx := maxIndexTxn(tx, s.getWatchTables("CheckServiceNodes")...)
|
idx := maxIndexTxn(tx, s.getWatchTables("CheckServiceNodes")...)
|
||||||
|
|
||||||
// Query the state store for the service.
|
// Query the state store for the service.
|
||||||
services, err := tx.Get("services", "service", service)
|
services, err := tx.Get("services", "service", serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the results.
|
// Return the results.
|
||||||
var results structs.ServiceNodes
|
var results structs.ServiceNodes
|
||||||
for s := services.Next(); s != nil; s = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
results = append(results, s.(*structs.ServiceNode))
|
results = append(results, service.(*structs.ServiceNode))
|
||||||
}
|
}
|
||||||
return s.parseCheckServiceNodes(tx, idx, results, err)
|
return s.parseCheckServiceNodes(tx, idx, results, err)
|
||||||
}
|
}
|
||||||
|
@ -1071,7 +1068,7 @@ func (s *StateStore) CheckServiceNodes(service string) (uint64, structs.CheckSer
|
||||||
// service, filtering out services that don't contain the given tag. The results
|
// service, filtering out services that don't contain the given tag. The results
|
||||||
// are compounded into a CheckServiceNodes, and the index returned is the maximum
|
// are compounded into a CheckServiceNodes, and the index returned is the maximum
|
||||||
// index observed over any node, check, or service in the result set.
|
// index observed over any node, check, or service in the result set.
|
||||||
func (s *StateStore) CheckServiceTagNodes(service, tag string) (uint64, structs.CheckServiceNodes, error) {
|
func (s *StateStore) CheckServiceTagNodes(serviceName, tag string) (uint64, structs.CheckServiceNodes, error) {
|
||||||
tx := s.db.Txn(false)
|
tx := s.db.Txn(false)
|
||||||
defer tx.Abort()
|
defer tx.Abort()
|
||||||
|
|
||||||
|
@ -1079,17 +1076,17 @@ func (s *StateStore) CheckServiceTagNodes(service, tag string) (uint64, structs.
|
||||||
idx := maxIndexTxn(tx, s.getWatchTables("CheckServiceNodes")...)
|
idx := maxIndexTxn(tx, s.getWatchTables("CheckServiceNodes")...)
|
||||||
|
|
||||||
// Query the state store for the service.
|
// Query the state store for the service.
|
||||||
services, err := tx.Get("services", "service", service)
|
services, err := tx.Get("services", "service", serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the results, filtering by tag.
|
// Return the results, filtering by tag.
|
||||||
var results structs.ServiceNodes
|
var results structs.ServiceNodes
|
||||||
for s := services.Next(); s != nil; s = services.Next() {
|
for service := services.Next(); service != nil; service = services.Next() {
|
||||||
sn := s.(*structs.ServiceNode)
|
svc := service.(*structs.ServiceNode)
|
||||||
if !serviceTagFilter(sn, tag) {
|
if !serviceTagFilter(svc, tag) {
|
||||||
results = append(results, sn)
|
results = append(results, svc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s.parseCheckServiceNodes(tx, idx, results, err)
|
return s.parseCheckServiceNodes(tx, idx, results, err)
|
||||||
|
|
|
@ -286,11 +286,11 @@ func TestStateStore_ReapTombstones(t *testing.T) {
|
||||||
// Make sure the tombstones are actually gone.
|
// Make sure the tombstones are actually gone.
|
||||||
snap := s.Snapshot()
|
snap := s.Snapshot()
|
||||||
defer snap.Close()
|
defer snap.Close()
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if stones.Next() != nil {
|
||||||
t.Fatalf("unexpected extra tombstones")
|
t.Fatalf("unexpected extra tombstones")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -686,8 +686,8 @@ func TestStateStore_DeleteNode(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if s := services.Next(); s != nil {
|
if service := services.Next(); service != nil {
|
||||||
t.Fatalf("bad: %#v", s)
|
t.Fatalf("bad: %#v", service)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Associated health check was removed.
|
// Associated health check was removed.
|
||||||
|
@ -695,8 +695,8 @@ func TestStateStore_DeleteNode(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if c := checks.Next(); c != nil {
|
if check := checks.Next(); check != nil {
|
||||||
t.Fatalf("bad: %#v", c)
|
t.Fatalf("bad: %#v", check)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indexes were updated.
|
// Indexes were updated.
|
||||||
|
@ -735,12 +735,12 @@ func TestStateStore_Node_Snapshot(t *testing.T) {
|
||||||
if idx := snap.LastIndex(); idx != 2 {
|
if idx := snap.LastIndex(); idx != 2 {
|
||||||
t.Fatalf("bad index: %d", idx)
|
t.Fatalf("bad index: %d", idx)
|
||||||
}
|
}
|
||||||
iter, err := snap.Nodes()
|
nodes, err := snap.Nodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
node := iter.Next().(*structs.Node)
|
node := nodes.Next().(*structs.Node)
|
||||||
if node == nil {
|
if node == nil {
|
||||||
t.Fatalf("unexpected end of nodes")
|
t.Fatalf("unexpected end of nodes")
|
||||||
}
|
}
|
||||||
|
@ -752,7 +752,7 @@ func TestStateStore_Node_Snapshot(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", node)
|
t.Fatalf("bad: %#v", node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if nodes.Next() != nil {
|
||||||
t.Fatalf("unexpected extra nodes")
|
t.Fatalf("unexpected extra nodes")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1276,12 +1276,12 @@ func TestStateStore_Service_Snapshot(t *testing.T) {
|
||||||
if idx := snap.LastIndex(); idx != 4 {
|
if idx := snap.LastIndex(); idx != 4 {
|
||||||
t.Fatalf("bad index: %d", idx)
|
t.Fatalf("bad index: %d", idx)
|
||||||
}
|
}
|
||||||
iter, err := snap.Services("node1")
|
services, err := snap.Services("node1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
for i := 0; i < len(ns); i++ {
|
for i := 0; i < len(ns); i++ {
|
||||||
svc := iter.Next().(*structs.ServiceNode)
|
svc := services.Next().(*structs.ServiceNode)
|
||||||
if svc == nil {
|
if svc == nil {
|
||||||
t.Fatalf("unexpected end of services")
|
t.Fatalf("unexpected end of services")
|
||||||
}
|
}
|
||||||
|
@ -1291,7 +1291,7 @@ func TestStateStore_Service_Snapshot(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v != %#v", svc, ns[i])
|
t.Fatalf("bad: %#v != %#v", svc, ns[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if services.Next() != nil {
|
||||||
t.Fatalf("unexpected extra services")
|
t.Fatalf("unexpected extra services")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3070,8 +3070,8 @@ func TestStateStore_KVS_Snapshot_Restore(t *testing.T) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
var dump structs.DirEntries
|
var dump structs.DirEntries
|
||||||
for ki := iter.Next(); ki != nil; ki = iter.Next() {
|
for entry := iter.Next(); entry != nil; entry = iter.Next() {
|
||||||
dump = append(dump, ki.(*structs.DirEntry))
|
dump = append(dump, entry.(*structs.DirEntry))
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(dump, entries) {
|
if !reflect.DeepEqual(dump, entries) {
|
||||||
t.Fatalf("bad: %#v", dump)
|
t.Fatalf("bad: %#v", dump)
|
||||||
|
@ -3094,10 +3094,8 @@ func TestStateStore_KVS_Snapshot_Restore(t *testing.T) {
|
||||||
if idx != 7 {
|
if idx != 7 {
|
||||||
t.Fatalf("bad index: %d", idx)
|
t.Fatalf("bad index: %d", idx)
|
||||||
}
|
}
|
||||||
for i, entry := range res {
|
if !reflect.DeepEqual(res, entries) {
|
||||||
if !reflect.DeepEqual(entry, entries[i]) {
|
t.Fatalf("bad: %#v", res)
|
||||||
t.Fatalf("bad: %#v", entry)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the index was updated.
|
// Check that the index was updated.
|
||||||
|
@ -3264,13 +3262,13 @@ func TestStateStore_Tombstone_Snapshot_Restore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the snapshot.
|
// Verify the snapshot.
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
var dump []*Tombstone
|
var dump []*Tombstone
|
||||||
for ti := iter.Next(); ti != nil; ti = iter.Next() {
|
for stone := stones.Next(); stone != nil; stone = stones.Next() {
|
||||||
dump = append(dump, ti.(*Tombstone))
|
dump = append(dump, stone.(*Tombstone))
|
||||||
}
|
}
|
||||||
if len(dump) != 1 {
|
if len(dump) != 1 {
|
||||||
t.Fatalf("bad %#v", dump)
|
t.Fatalf("bad %#v", dump)
|
||||||
|
@ -3316,11 +3314,11 @@ func TestStateStore_Tombstone_Snapshot_Restore(t *testing.T) {
|
||||||
// But make sure the tombstone is actually gone.
|
// But make sure the tombstone is actually gone.
|
||||||
snap := s.Snapshot()
|
snap := s.Snapshot()
|
||||||
defer snap.Close()
|
defer snap.Close()
|
||||||
iter, err := snap.Tombstones()
|
stones, err := snap.Tombstones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if iter.Next() != nil {
|
if stones.Next() != nil {
|
||||||
t.Fatalf("unexpected extra tombstones")
|
t.Fatalf("unexpected extra tombstones")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -3665,8 +3663,8 @@ func TestStateStore_Session_Snapshot_Restore(t *testing.T) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
var dump structs.Sessions
|
var dump structs.Sessions
|
||||||
for si := iter.Next(); si != nil; si = iter.Next() {
|
for session := iter.Next(); session != nil; session = iter.Next() {
|
||||||
dump = append(dump, si.(*structs.Session))
|
dump = append(dump, session.(*structs.Session))
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(dump, sessions) {
|
if !reflect.DeepEqual(dump, sessions) {
|
||||||
t.Fatalf("bad: %#v", dump)
|
t.Fatalf("bad: %#v", dump)
|
||||||
|
@ -4332,8 +4330,8 @@ func TestStateStore_ACL_Snapshot_Restore(t *testing.T) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
var dump structs.ACLs
|
var dump structs.ACLs
|
||||||
for ai := iter.Next(); ai != nil; ai = iter.Next() {
|
for acl := iter.Next(); acl != nil; acl = iter.Next() {
|
||||||
dump = append(dump, ai.(*structs.ACL))
|
dump = append(dump, acl.(*structs.ACL))
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(dump, acls) {
|
if !reflect.DeepEqual(dump, acls) {
|
||||||
t.Fatalf("bad: %#v", dump)
|
t.Fatalf("bad: %#v", dump)
|
||||||
|
|
Loading…
Reference in New Issue