Esempio n. 1
0
// Builds table from src iterator.
func (t *tOps) createFrom(src iterator.Iterator) (f *tFile, n int, err error) {
	w, err := t.create()
	if err != nil {
		return f, n, err
	}

	defer func() {
		if err != nil {
			w.drop()
		}
	}()

	for src.Next() {
		err = w.append(src.Key(), src.Value())
		if err != nil {
			return
		}
	}
	err = src.Error()
	if err != nil {
		return
	}

	n = w.tw.EntriesLen()
	f, err = w.finish()
	return
}
Esempio n. 2
0
func (h *blockHarness) eoi(pref string, iter iterator.Iterator) {
	if iter.Next() {
		h.t.Fatalf("block: %sNext: expect eoi", pref)
	} else if err := iter.Error(); err != nil {
		h.t.Fatalf("block: %sNext: expect eoi but got error, err=%v", pref, err)
	}
}
Esempio n. 3
0
func (h *blockHarness) last(iter iterator.Iterator) {
	if len(h.kv) == 0 {
		if iter.Last() {
			h.t.Fatalf("block: Last: expect eoi, key=%q", iter.Key())
		}
	} else {
		if !iter.Last() {
			h.t.Fatalf("block: Last: eoi, err=%v", iter.Error())
		}
	}
}
Esempio n. 4
0
func TestDb_ClosedIsClosed(t *testing.T) {
	h := newDbHarness(t)
	db := h.db

	var iter, iter2 iterator.Iterator
	var snap *Snapshot
	func() {
		defer h.close()

		h.put("k", "v")
		h.getVal("k", "v")

		iter = db.NewIterator(nil, h.ro)
		iter.Seek([]byte("k"))
		testKeyVal(t, iter, "k->v")

		var err error
		snap, err = db.GetSnapshot()
		if err != nil {
			t.Fatal("GetSnapshot: got error: ", err)
		}

		h.getValr(snap, "k", "v")

		iter2 = snap.NewIterator(nil, h.ro)
		iter2.Seek([]byte("k"))
		testKeyVal(t, iter2, "k->v")

		h.put("foo", "v2")
		h.delete("foo")

		// closing DB
		iter.Release()
		iter2.Release()
	}()

	assertErr(t, db.Put([]byte("x"), []byte("y"), h.wo), true)
	_, err := db.Get([]byte("k"), h.ro)
	assertErr(t, err, true)

	if iter.Valid() {
		t.Errorf("iter.Valid should false")
	}
	assertErr(t, iter.Error(), false)
	testKeyVal(t, iter, "->")
	if iter.Seek([]byte("k")) {
		t.Errorf("iter.Seek should false")
	}
	assertErr(t, iter.Error(), true)

	assertErr(t, iter2.Error(), false)

	_, err = snap.Get([]byte("k"), h.ro)
	assertErr(t, err, true)

	_, err = db.GetSnapshot()
	assertErr(t, err, true)

	iter3 := db.NewIterator(nil, h.ro)
	assertErr(t, iter3.Error(), true)

	iter3 = snap.NewIterator(nil, h.ro)
	assertErr(t, iter3.Error(), true)

	assertErr(t, db.Delete([]byte("k"), h.wo), true)

	_, err = db.GetProperty("leveldb.stats")
	assertErr(t, err, true)

	_, err = db.SizeOf([]util.Range{{[]byte("a"), []byte("z")}})
	assertErr(t, err, true)

	assertErr(t, db.CompactRange(util.Range{}), true)

	assertErr(t, db.Close(), true)
}
Esempio n. 5
0
func (h *blockHarness) prev(pref string, iter iterator.Iterator) {
	if !iter.Prev() {
		h.t.Fatalf("block: %sPrev: eoi, err=%v", pref, iter.Error())
	}
}
Esempio n. 6
0
func (h *blockHarness) next(pref string, iter iterator.Iterator) {
	if !iter.Next() {
		h.t.Fatalf("block: %sNext: eoi, err=%v", pref, iter.Error())
	}
}