Esempio n. 1
0
func getTables(conn PoolConnection) (tables []*schema.Table, err error) {
	var cursor eproto.DbCursor
	keyStart := buildTablesKey()
	keyEnd := append(buildTablesKey(), '|')
	cursor, err = conn.Iterate(nil, keyStart, keyEnd, 0)
	if err != nil {
		return nil, err
	}
	var tablesName [][]byte
	for ; cursor.Valid(); cursor.Next() {
		tablesName = append(tablesName, cursor.Value())
	}
	if err = cursor.Error(); err != nil {
		return nil, err
	}
	if len(tablesName) == 0 {
		return nil, nil
	}
	var tablesBytes [][]byte
	tablesBytes, err = conn.Gets(nil, tablesName)
	if err != nil {
		return nil, err
	}
	tables = make([]*schema.Table, len(tablesBytes))
	for _, tableBytes := range tablesBytes {
		table := new(schema.Table)
		err = json.Unmarshal(tableBytes, table)
		if err != nil {
			return nil, err
		}
		tables = append(tables, table)
	}

	return tables, err
}
Esempio n. 2
0
func (qe *QueryEngine) fetchIterate(logStats *sqlQueryStats, conn PoolConnection,
	start, end []byte, limit int, ignoreKey, ignoreValue bool) (keys [][]byte, values [][]byte) {
	var err error
	if conn == nil {
		waitingForConnectionStart := time.Now()
		conn, err = qe.connPool.SafeGet()
		logStats.WaitingForConnection += time.Now().Sub(waitingForConnectionStart)
		if err != nil {
			panic(NewTabletErrorDB(FATAL, err))
		} else {
			defer conn.Recycle()
		}
	}
	var cursor eproto.DbCursor
	if cursor, err = conn.Iterate(nil, start, end, limit); err != nil {
		panic(NewTabletErrorDB(FAIL, err))
	}
	for ; cursor.Valid(); cursor.Next() {
		if !ignoreKey {
			keys = append(keys, cursor.Key())
		}
		if !ignoreValue {
			values = append(values, cursor.Value())
		}
	}
	if cursor.Error() != nil {
		panic(NewTabletErrorDB(FAIL, err))
	}
	return keys, values
}