github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqlbase/locking.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 sqlbase
    12  
    13  import (
    14  	"fmt"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    17  )
    18  
    19  // ToScanLockingStrength converts a tree.LockingStrength to its corresponding
    20  // ScanLockingStrength.
    21  func ToScanLockingStrength(s tree.LockingStrength) ScanLockingStrength {
    22  	switch s {
    23  	case tree.ForNone:
    24  		return ScanLockingStrength_FOR_NONE
    25  	case tree.ForKeyShare:
    26  		return ScanLockingStrength_FOR_KEY_SHARE
    27  	case tree.ForShare:
    28  		return ScanLockingStrength_FOR_SHARE
    29  	case tree.ForNoKeyUpdate:
    30  		return ScanLockingStrength_FOR_NO_KEY_UPDATE
    31  	case tree.ForUpdate:
    32  		return ScanLockingStrength_FOR_UPDATE
    33  	default:
    34  		panic(fmt.Sprintf("unknown locking strength %s", s))
    35  	}
    36  }
    37  
    38  // ToScanLockingWaitPolicy converts a tree.LockingWaitPolicy to its
    39  // corresponding ScanLockingWaitPolicy.
    40  func ToScanLockingWaitPolicy(wp tree.LockingWaitPolicy) ScanLockingWaitPolicy {
    41  	switch wp {
    42  	case tree.LockWaitBlock:
    43  		return ScanLockingWaitPolicy_BLOCK
    44  	case tree.LockWaitSkip:
    45  		return ScanLockingWaitPolicy_SKIP
    46  	case tree.LockWaitError:
    47  		return ScanLockingWaitPolicy_ERROR
    48  	default:
    49  		panic(fmt.Sprintf("unknown locking wait policy %s", wp))
    50  	}
    51  }