예제 #1
0
func (c *compaction) newIterator() iterator.Iterator {
	s := c.s
	icmp := s.cmp

	level := c.level
	icap := 2
	if c.level == 0 {
		icap = len(c.tables[0]) + 1
	}
	its := make([]iterator.Iterator, 0, icap)

	ro := &opt.ReadOptions{
		DontFillCache: true,
	}
	strict := s.o.GetStrict(opt.StrictIterator)

	for i, tt := range c.tables {
		if len(tt) == 0 {
			continue
		}

		if level+i == 0 {
			for _, t := range tt {
				its = append(its, s.tops.newIterator(t, nil, ro))
			}
		} else {
			it := iterator.NewIndexedIterator(tt.newIndexIterator(s.tops, icmp, nil, ro), strict, true)
			its = append(its, it)
		}
	}

	return iterator.NewMergedIterator(its, icmp, true)
}
예제 #2
0
func (db *DB) newRawIterator(slice *util.Range, ro *opt.ReadOptions) iterator.Iterator {
	s := db.s

	em, fm := db.getMems()
	v := s.version()

	ti := v.getIterators(slice, ro)
	n := len(ti) + 2
	i := make([]iterator.Iterator, 0, n)
	i = append(i, em.NewIterator(slice))
	if fm != nil {
		i = append(i, fm.NewIterator(slice))
	}
	i = append(i, ti...)
	strict := s.o.GetStrict(opt.StrictIterator) || ro.GetStrict(opt.StrictIterator)
	mi := iterator.NewMergedIterator(i, s.cmp, strict)
	mi.SetReleaser(&versionReleaser{v: v})
	return mi
}