Requesting exclusive locks is beneficial if you observe high write
contention, which means you notice that multiple transactions are
concurrently trying to read and write to the same data, resulting in a
large number of aborts. This problem occurs when two transactions
initially acquire shared locks and then both try to upgrade to exclusive
locks at the same time. In this situation both transactions are waiting
for the other to give up their lock, resulting in a deadlocked situation.
Spanner is able to detect this occurring and force one of the
transactions to abort. However, this is a slow and expensive operation
and results in lower performance. In this case it makes sense to acquire
exclusive locks at the start of the transaction because then when
multiple transactions try to act on the same data, they automatically get
serialized. Each transaction waits its turn to acquire the lock and
avoids getting into deadlock situations.
Because the exclusive lock hint is just a hint, it should not be
considered equivalent to a mutex. In other words, you should not use
Spanner exclusive locks as a mutual exclusion mechanism for the execution
of code outside of Spanner.
Note: Request exclusive locks judiciously because they block others
from reading that data for the entire transaction, rather than just when
the writes are being performed. Unless you observe high write contention,
you should use the default of shared read locks so you don't prematurely
block other clients from reading the data that you're writing to.
Shared
Acquire shared locks.
By default when you perform a read as part of a read-write transaction,
Spanner acquires shared read locks, which allows other reads to still
access the data until your transaction is ready to commit. When your
transaction is committing and writes are being applied, the transaction
attempts to upgrade to an exclusive lock for any data you are writing.
For more information about locks, see Lock
modes.
Unspecified
Default value.
LOCK_HINT_UNSPECIFIED is equivalent to LOCK_HINT_SHARED.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis document provides reference information for the \u003ccode\u003eReadRequest.Types.LockHint\u003c/code\u003e enum within the Google Cloud Spanner v1 API, specifically for the .NET environment.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the documentation is for \u003ccode\u003e5.0.0-beta05\u003c/code\u003e, with a number of previous versions available, down to \u003ccode\u003e3.5.0\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eReadRequest.Types.LockHint\u003c/code\u003e enum offers three options for managing locks during a read transaction: \u003ccode\u003eExclusive\u003c/code\u003e, \u003ccode\u003eShared\u003c/code\u003e, and \u003ccode\u003eUnspecified\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eExclusive\u003c/code\u003e lock hints are useful for avoiding deadlocks in scenarios with high write contention, but should be used carefully as they can block other reads.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eShared\u003c/code\u003e locks, which is the default, allow concurrent reads until the transaction is committed and attempts to upgrade the lock to an exclusive one.\u003c/p\u003e\n"]]],[],null,["# Google Cloud Spanner v1 API - Enum ReadRequest.Types.LockHint (5.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [5.1.0 (latest)](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [5.0.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/5.0.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.6.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.6.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.5.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.5.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.4.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.3.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.3.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.2.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.2.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.1.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.1.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [4.0.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.0.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.15.1](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.15.1/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.14.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.14.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.13.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.13.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.12.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.12.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.11.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.11.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.10.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.10.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.9.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.9.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.8.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.7.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.6.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint)\n- [3.5.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.5.0/Google.Cloud.Spanner.V1.ReadRequest.Types.LockHint) \n\n public enum ReadRequest.Types.LockHint\n\nReference documentation and code samples for the Google Cloud Spanner v1 API enum ReadRequest.Types.LockHint.\n\nA lock hint mechanism for reads done within a transaction.\n\nNamespace\n---------\n\n[Google.Cloud.Spanner.V1](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.Spanner.V1.dll"]]