Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (41 sloc) 1.47 KB
// Copyright 2014 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package batcheval
import (
"context"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/batcheval/result"
"github.com/cockroachdb/cockroach/pkg/storage/engine"
"github.com/cockroachdb/cockroach/pkg/storage/spanset"
)
func init() {
RegisterCommand(roachpb.LeaseInfo, declareKeysLeaseInfo, LeaseInfo)
}
func declareKeysLeaseInfo(
_ *roachpb.RangeDescriptor, header roachpb.Header, req roachpb.Request, spans *spanset.SpanSet,
) {
spans.Add(spanset.SpanReadOnly, roachpb.Span{Key: keys.RangeLeaseKey(header.RangeID)})
}
// LeaseInfo returns information about the lease holder for the range.
func LeaseInfo(
ctx context.Context, batch engine.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error) {
reply := resp.(*roachpb.LeaseInfoResponse)
lease, nextLease := cArgs.EvalCtx.GetLease()
if nextLease != (roachpb.Lease{}) {
// If there's a lease request in progress, speculatively return that future
// lease.
reply.Lease = nextLease
} else {
reply.Lease = lease
}
return result.Result{}, nil
}
You can’t perform that action at this time.