func (l SecondaryLayer) ForEach(fn func(key ServiceInfo, val *FinalizerList) bool) {
	l.lock.Lock()
	e, err := l.store.SeekFirst()
	l.lock.Unlock()
	if err != io.EOF {
		k, v, err := e.Next()
		for err != io.EOF {
			if stop := fn(k, v); stop {
				return
			}
			l.lock.Lock()
			k, v, err = e.Next()
			l.lock.Unlock()
		}
		e.Close()
	}
}
ForEach runs the provided function for every element in the layer,
if function returns true, the loop stops.
package service
import (
	"io"
	"sync/atomic"
	"github.com/zenhotels/btree-2d/lockie"
	"github.com/zenhotels/btree-2d/util"
)
type SecondaryCmpFunc func(key1, key2 ServiceInfo) int
type SecondaryLayer struct {
	store  *SecondaryTree
	offset uint64
	synced *uint64  
	lock   lockie.Lockie
	cmp    SecondaryCmpFunc
}
func NewSecondaryLayer(cmp SecondaryCmpFunc) SecondaryLayer {
	var synced uint64
	return SecondaryLayer{
		synced: &synced,
		store:  NewSecondaryTree(cmp),
		offset: uint64(util.RevOffset()),
		lock:   lockie.NewLockie(),
		cmp:    cmp,
	}
}
func (l SecondaryLayer) Rev() uint64 {
	return l.store.Ver() + l.offset
}
func (l SecondaryLayer) Put(k ServiceInfo, finalizers ...func()) (added int) {
	l.lock.Lock()
	l.store.Put(k, func(oldV *FinalizerList, exists bool) (newV *FinalizerList, write bool) {
		if !exists || oldV == nil {
			if len(finalizers) == 0 {
				return nil, true
			}
			oldV = &FinalizerList{}
		}
		for i := range finalizers {
			if oldV.AddFinalizer(finalizers[i]) {
				added++
			}
		}
		return oldV, true
	})
	l.lock.Unlock()
	return
}