Ejemplo n.º 1
0
func (kv *KeyValue) Find(start, end string) sorted.Iterator {
	var releaseGate func() // nil if unused
	if kv.Gate != nil {
		kv.Gate.Start()
		releaseGate = kv.Gate.Done
	}
	var rows *sql.Rows
	var err error
	if end == "" {
		rows, err = kv.DB.Query(kv.sql("SELECT k, v FROM /*TPRE*/rows WHERE k >= ? ORDER BY k "), start)
	} else {
		rows, err = kv.DB.Query(kv.sql("SELECT k, v FROM /*TPRE*/rows WHERE k >= ? AND k < ? ORDER BY k "), start, end)
	}
	if err != nil {
		log.Printf("unexpected query error: %v", err)
		return &iter{err: err}
	}

	it := &iter{
		kv:          kv,
		rows:        rows,
		closeCheck:  leak.NewChecker(),
		releaseGate: releaseGate,
	}
	return it
}
Ejemplo n.º 2
0
func (kv *KeyValue) Find(start, end string) sorted.Iterator {
	if kv.Serial {
		kv.mu.Lock()
		// TODO(mpl): looks like sqlite considers the db locked until we've closed
		// the iterator, so we can't do anything else until then. We should probably
		// move that Unlock to the closing of the iterator. Investigating.
		defer kv.mu.Unlock()
	}
	var rows *sql.Rows
	var err error
	if end == "" {
		rows, err = kv.DB.Query(kv.sql("SELECT k, v FROM /*TPRE*/rows WHERE k >= ? ORDER BY k "), start)
	} else {
		rows, err = kv.DB.Query(kv.sql("SELECT k, v FROM /*TPRE*/rows WHERE k >= ? AND k < ? ORDER BY k "), start, end)
	}
	if err != nil {
		log.Printf("unexpected query error: %v", err)
		return &iter{err: err}
	}

	it := &iter{
		kv:         kv,
		rows:       rows,
		closeCheck: leak.NewChecker(),
	}
	return it
}
Ejemplo n.º 3
0
func (s *Storage) Find(key string) index.Iterator {
	it := &iter{
		s:          s,
		low:        key,
		op:         ">=",
		closeCheck: leak.NewChecker(),
	}
	return it
}
Ejemplo n.º 4
0
func (kv *KeyValue) Find(start, end string) sorted.Iterator {
	if kv.Serial {
		kv.mu.Lock()
		defer kv.mu.Unlock()
	}
	var rows *sql.Rows
	var err error
	if end == "" {
		rows, err = kv.DB.Query(kv.sql("SELECT k, v FROM rows WHERE k >= ? ORDER BY k "), start)
	} else {
		rows, err = kv.DB.Query(kv.sql("SELECT k, v FROM rows WHERE k >= ? AND k < ? ORDER BY k "), start, end)
	}
	if err != nil {
		log.Printf("unexpected query error: %v", err)
		return &iter{err: err}
	}

	it := &iter{
		kv:         kv,
		rows:       rows,
		closeCheck: leak.NewChecker(),
	}
	return it
}