Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"strings"
"sync"
"time"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -55,6 +56,9 @@ type API struct {
clusterMap map[string]*cluster.Cluster
serv *grpcserver.Server
router *mux.Router

// See https://github.com/vitessio/vitess/issues/7723 for why this exists.
vtexplainLock sync.Mutex
}

// NewAPI returns a new API, configured to service the given set of clusters,
Expand Down Expand Up @@ -996,10 +1000,22 @@ func (api *API) VTExplain(ctx context.Context, req *vtadminpb.VTExplainRequest)

opts := &vtexplain.Options{ReplicationMode: "ROW"}

lockWaitStart := time.Now()

api.vtexplainLock.Lock()
defer api.vtexplainLock.Unlock()

lockWaitTime := time.Since(lockWaitStart)
log.Infof("vtexplain lock wait time: %s", lockWaitTime)

span.Annotate("vtexplain_lock_wait_time", lockWaitTime.String())

if err := vtexplain.Init(srvVSchema, schema, shardMap, opts); err != nil {
return nil, fmt.Errorf("error initilaizing vtexplain: %w", err)
}

defer vtexplain.Stop()

plans, err := vtexplain.Run(req.Sql)
if err != nil {
return nil, fmt.Errorf("error running vtexplain: %w", err)
Expand Down