Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vtadmin] vtexplain lock #7724

Merged
merged 3 commits into from
Mar 23, 2021
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