func (s *SessionManager) NewSession(ctx context.Context, conn *mysql.Conn) error {
	var err error
	s.mu.Lock()
	defer s.mu.Unlock()
	s.sessions[conn.ConnectionID], err = s.builder(ctx, conn, s.addr)
	if err != nil {
		return err
	}
	logger := s.sessions[conn.ConnectionID].GetLogger()
	if logger == nil {
		log := logrus.StandardLogger()
		logger = logrus.NewEntry(log)
	}
	s.sessions[conn.ConnectionID].SetLogger(
		logger.WithField(sqle.ConnectionIdLogField, conn.ConnectionID).
			WithField(sqle.ConnectTimeLogKey, time.Now()),
	)
	return err
}
NewSession creates a Session for the given connection and saves it to the session pool.
package server
import (
	"context"
	"sync"
	"time"
	"github.com/dolthub/vitess/go/mysql"
	"github.com/opentracing/opentracing-go"
	"github.com/sirupsen/logrus"
	sqle "github.com/dolthub/go-mysql-server"
	"github.com/dolthub/go-mysql-server/sql"
)
type SessionBuilder func(ctx context.Context, conn *mysql.Conn, addr string) (sql.Session, error)
type DoneFunc func()
func DefaultSessionBuilder(ctx context.Context, c *mysql.Conn, addr string) (sql.Session, error) {
	client := sql.Client{Address: c.RemoteAddr().String(), User: c.User, Capabilities: c.Capabilities}
	return sql.NewBaseSessionWithClientServer(addr, client, c.ConnectionID), nil
}
type SessionManager struct {
	addr        string
	tracer      opentracing.Tracer
	hasDBFunc   func(name string) bool
	memory      *sql.MemoryManager
	processlist sql.ProcessList
	mu          *sync.Mutex
	builder     SessionBuilder
	sessions    map[uint32]sql.Session
	pid         uint64
}
func NewSessionManager(
	builder SessionBuilder,
	tracer opentracing.Tracer,
	hasDBFunc func(name string) bool,
	memory *sql.MemoryManager,
	processlist sql.ProcessList,
	addr string,
) *SessionManager {
	return &SessionManager{
		addr:        addr,
		tracer:      tracer,
		hasDBFunc:   hasDBFunc,
		memory:      memory,
		processlist: processlist,
		mu:          new(sync.Mutex),
		builder:     builder,
		sessions:    make(map[uint32]sql.Session),
	}
}
func (s *SessionManager) nextPid() uint64 {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.pid++
	return s.pid
}