github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/concurrency/latch_manager.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package concurrency
    12  
    13  import (
    14  	"context"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
    17  	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanlatch"
    18  	"github.com/cockroachdb/cockroach/pkg/roachpb"
    19  )
    20  
    21  // latchManagerImpl implements the latchManager interface.
    22  type latchManagerImpl struct {
    23  	m spanlatch.Manager
    24  }
    25  
    26  func (m *latchManagerImpl) Acquire(ctx context.Context, req Request) (latchGuard, *Error) {
    27  	lg, err := m.m.Acquire(ctx, req.LatchSpans)
    28  	if err != nil {
    29  		return nil, roachpb.NewError(err)
    30  	}
    31  	return lg, nil
    32  }
    33  
    34  func (m *latchManagerImpl) Release(lg latchGuard) {
    35  	m.m.Release(lg.(*spanlatch.Guard))
    36  }
    37  
    38  func (m *latchManagerImpl) Info() (global, local kvserverpb.LatchManagerInfo) {
    39  	return m.m.Info()
    40  }