feat(spanner): define IsolationLevel enum for Spanner transactions by prathmeshcc · Pull Request #15853 · googleapis/google-cloud-cpp
This commit improves the API design by integrating `IsolationLevel` directly into `Transaction::ReadWriteOptions`. Previously, `IsolationLevel` was passed as a separate argument to some `Transaction` constructors, even though it is semantically relevant only to read-write transactions. This could lead to ambiguity or misuse. By making `IsolationLevel` a member of `ReadWriteOptions`, the API more accurately reflects the underlying Spanner transaction semantics, enforcing that isolation levels are configured solely within the context of read-write transactions. This enhances type safety and improves the clarity of the client library's API. This change addresses reviewer feedback regarding the logical grouping of `IsolationLevel` within the `ReadWriteOptions` message.#
This commit refines the API design by integrating `IsolationLevel` directly into `Transaction::ReadWriteOptions`. Previously, `IsolationLevel` was passed as a separate argument to some `Transaction` constructors, even though it is semantically relevant only to read-write transactions. This could lead to ambiguity or misuse. These changes address reviewer feedback, enforcing that isolation levels are configured solely within the context of read-write transactions. This enhances type safe and improves the clarity of the client library's API. Key changes include: - Removing the `IsolationLevel` parameter from `Transaction` constructors, as it is now configured via `ReadWriteOptions`. - Enhancing `Transaction::ReadWriteOptions` with a `WithIsolationLevel` method, allowing for a fluent configuration of the desired isolation level (e.g., `kSerializable`, `kRepeatableRead`). - Updating internal transaction handling logic to correctly propagate the selected isolation level from `ReadWriteOptions` to the Spanner backend.
Changed "Note:" to "@note" in the Doxygen documentation for `Transaction::IsolationLevel` to use the correct Doxygen tag. This improves consistency and ensures proper rendering of the documentation.
This change modifies the `MakeOpts` function in `transaction.cc` to ensure that an explicitly provided `Transaction::IsolationLevel::kUnspecified` value is honored, rather than falling back to a client-level default. Previously, if `kUnspecified` was passed to `WithIsolationLevel()`, it would be treated as if no isolation level was specified, potentially leading to an unexpected fallback. This update ensures that if a user explicitly requests `kUnspecified`, the `TransactionOptions` proto will reflect `ISOLATION_LEVEL_UNSPECIFIED`. The `ReadWriteOptions` class in `transaction.h` was updated to use `absl::optional<IsolationLevel>` to correctly represent the presence or absence of an explicitly se isolation level. A new test case `IsolationLevelNotSpecified` was added to `transaction_test.cc` to verify this behavior, ensuring that when no isolation level is explicitly set, the default `ISOLATION_LEVEL_UNSPECIFIED` is used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters