{"record":{"id":"98018d1ecfab0220","repo":"vitessio/vitess","slug":"failed-to-lock-s-if-you-really-want-to-delete-th","errorCode":null,"errorMessage":"failed to lock %s; if you really want to delete this keyspace, re-run with Force=true: %w","messagePattern":"failed to lock (.+?); if you really want to delete this keyspace, re-run with Force=true: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":1146,"sourceCode":"}\n\n// DeleteKeyspace is part of the vtctlservicepb.VtctldServer interface.\nfunc (s *VtctldServer) DeleteKeyspace(ctx context.Context, req *vtctldatapb.DeleteKeyspaceRequest) (resp *vtctldatapb.DeleteKeyspaceResponse, err error) {\n\tspan, ctx := trace.NewSpan(ctx, \"VtctldServer.DeleteKeyspace\")\n\tdefer span.Finish()\n\n\tdefer panicHandler(&err)\n\n\tspan.Annotate(\"keyspace\", req.Keyspace)\n\tspan.Annotate(\"recursive\", req.Recursive)\n\tspan.Annotate(\"force\", req.Force)\n\n\tlctx, unlock, lerr := s.ts.LockKeyspace(ctx, req.Keyspace, \"DeleteKeyspace\")\n\tswitch {\n\tcase lerr == nil:\n\t\tctx = lctx\n\tcase !req.Force:\n\t\terr = fmt.Errorf(\"failed to lock %s; if you really want to delete this keyspace, re-run with Force=true: %w\", req.Keyspace, lerr)\n\t\treturn nil, err\n\tdefault:\n\t\tlog.Warn(fmt.Sprintf(\"%s: failed to lock keyspace %s for deletion, but force=true, proceeding anyway ...\", lerr, req.Keyspace))\n\t}\n\n\tif unlock != nil {\n\t\tdefer func() {\n\t\t\t// Attempting to unlock a keyspace we successfully deleted results\n\t\t\t// in ts.unlockKeyspace returning an error, which can make the\n\t\t\t// overall RPC _seem_ like it failed.\n\t\t\t//\n\t\t\t// So, we do this extra checking to allow for specifically this\n\t\t\t// scenario to result in \"success.\"\n\t\t\torigErr := err\n\t\t\tunlock(&err)\n\t\t\tif origErr == nil && topo.IsErrType(err, topo.NoNode) {\n\t\t\t\terr = nil\n\t\t\t}","sourceCodeStart":1128,"sourceCodeEnd":1164,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L1128-L1164","documentation":"DeleteKeyspace acquires a keyspace lock to serialize against other workflows. If locking fails and Force is false, the delete is refused with this message telling the operator to re-run with Force=true. With Force=true, the lock failure is only logged and deletion proceeds unsafely.","triggerScenarios":"Calling DeleteKeyspace while another workflow holds the keyspace lock (e.g. a running Reshard, MoveTables, or another vtctld operation), or the lock cannot be taken due to topo errors, when Force is not set.","commonSituations":"Deleting a keyspace while a migration is in flight; a stale lock from a crashed workflow; concurrent operator actions in a shared cluster.","solutions":["Wait for the holding workflow to finish, then retry DeleteKeyspace without Force","Find and clean up stale locks (check topo lock paths / workflow status) if no workflow is actually running","Re-run with Force=true only when certain no workflow is active, accepting the risk of concurrent modification"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"ks, err := client.GetKeyspace(ctx, name)\nif err != nil {\n    return fmt.Errorf(\"keyspace state unknown: %w\", err)\n}\n// confirm no active workflows (Reshard/MoveTables) before deleting","typeGuard":null,"tryCatchPattern":"_, err := client.DeleteKeyspace(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"failed to lock\") {\n    // find lock holder or wait; only use Force after verifying no workflow\n}","preventionTips":["Check for in-flight Reshard/MoveTables workflows before deleting","Never blindly pass Force=true in automation","Clear stale locks from crashed workflows before retrying","Serialize keyspace deletions through a single operator/CI job"],"tags":["vitess","keyspace","locking","concurrency"],"backgroundTag":"keyspace-lock-held","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}