예제 #1
0
파일: repo.go 프로젝트: couchbase/gometa
//
// Create a new iterator.  EndKey is inclusive.
//
func (r *Repository) NewIterator(kind RepoKind, startKey, endKey string) (*RepoIterator, error) {

	r.mutex.Lock()
	defer r.mutex.Unlock()

	k1, err := CollateString(startKey)
	if err != nil {
		return nil, err
	}

	k2, err := CollateString(endKey)
	if err != nil {
		return nil, err
	}

	// Create a snaphsot for iteration
	var FORESTDB_INMEMSEQ = fdb.SeqNum(math.MaxUint64)
	snapshot, err := r.stores[kind].SnapshotOpen(FORESTDB_INMEMSEQ)

	iter, err := snapshot.IteratorInit(k1, k2, fdb.ITR_NO_DELETES)
	if err != nil {
		return nil, err
	}
	result := &RepoIterator{iter: iter, store: snapshot}
	return result, nil
}
예제 #2
0
파일: repo.go 프로젝트: couchbase/gometa
func (r *Repository) AcquireSnapshot(kind RepoKind) (common.Txnid, *RepoIterator, error) {

	r.mutex.Lock()
	defer r.mutex.Unlock()

	if len(r.snapshots[kind]) == 0 {
		return common.Txnid(0), nil, nil
	}

	snapshot := r.snapshots[kind][len(r.snapshots[kind])-1]
	snapshot.count++

	// Create a snaphsot for iteration
	var FORESTDB_INMEMSEQ = fdb.SeqNum(math.MaxUint64)
	kvstore, err := snapshot.snapshot.SnapshotOpen(FORESTDB_INMEMSEQ)

	iter, err := kvstore.IteratorInit(nil, nil, fdb.ITR_NO_DELETES)
	if err != nil {
		return common.Txnid(0), nil, err
	}
	return snapshot.txnid, &RepoIterator{iter: iter, store: kvstore}, nil
}