@@ -393,22 +393,28 @@ func QueueLastProcessedKey(key roachpb.RKey, queue string) roachpb.Key {
393393}
394394
395395// LockTableSingleKey creates a key under which all single-key locks for the
396- // given key can be found. Note that there can be multiple locks for the given
397- // key, but those are distinguished using the "version" which is not in scope
398- // of the keys package.
396+ // given key can be found. buf is used as scratch-space to avoid allocations
397+ // -- its contents will be overwritten and not appended to.
398+ // Note that there can be multiple locks for the given key, but those are
399+ // distinguished using the "version" which is not in scope of the keys
400+ // package.
399401// For a scan [start, end) the corresponding lock table scan is
400402// [LTSK(start), LTSK(end)).
401- func LockTableSingleKey (key roachpb.Key ) roachpb.Key {
403+ func LockTableSingleKey (key roachpb.Key , buf []byte ) (roachpb.Key , []byte ) {
404+ // The +3 accounts for the bytesMarker and terminator.
405+ keyLen := len (LocalRangeLockTablePrefix ) + len (LockTableSingleKeyInfix ) + len (key ) + 3
406+ if cap (buf ) < keyLen {
407+ buf = make ([]byte , 0 , keyLen )
408+ } else {
409+ buf = buf [:0 ]
410+ }
402411 // Don't unwrap any local prefix on key using Addr(key). This allow for
403412 // doubly-local lock table keys. For example, local range descriptor keys can
404413 // be locked during split and merge transactions.
405- // The +3 account for the bytesMarker and terminator.
406- buf := make (roachpb.Key , 0 ,
407- len (LocalRangeLockTablePrefix )+ len (LockTableSingleKeyInfix )+ len (key )+ 3 )
408414 buf = append (buf , LocalRangeLockTablePrefix ... )
409415 buf = append (buf , LockTableSingleKeyInfix ... )
410416 buf = encoding .EncodeBytesAscending (buf , key )
411- return buf
417+ return buf , buf
412418}
413419
414420// DecodeLockTableSingleKey decodes the single-key lock table key to return the key
@@ -448,6 +454,12 @@ func IsLocal(k roachpb.Key) bool {
448454 return bytes .HasPrefix (k , localPrefix )
449455}
450456
457+ // IsLocalStoreKey performs a cheap check that returns true iff the parameter
458+ // is a local store key.
459+ func IsLocalStoreKey (k roachpb.Key ) bool {
460+ return bytes .HasPrefix (k , localStorePrefix )
461+ }
462+
451463// Addr returns the address for the key, used to lookup the range containing the
452464// key. In the normal case, this is simply the key's value. However, for local
453465// keys, such as transaction records, the address is the inner encoded key, with
0 commit comments