-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22329: Transactional support in direct client, MINOR
Adds runtime options to the direct client. If you create a trainee as Trainee(persistence='always', runtime={'transactional': True}) then every operation will append a log entry to the .caml file. This is faster per operation, and all of the data continues to be recorded on disk, but the resulting files will be larger than always-persist mode without the transactional option.
- Loading branch information
Showing
8 changed files
with
289 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .trainee import DirectTrainee, TraineeDirectRuntimeOptions | ||
|
||
__all__ = [ | ||
"DirectTrainee", | ||
"TraineeDirectRuntimeOptions" | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Mapping | ||
import typing as t | ||
from uuid import UUID | ||
|
||
from typing_extensions import NotRequired, ReadOnly | ||
|
||
from ...client.schemas.trainee import Trainee, TraineeDict, TraineeRuntimeOptions | ||
from ...client.typing import Persistence | ||
|
||
|
||
class DirectTraineeDict(TraineeDict): | ||
""" | ||
Direct-client-specific trainee state. | ||
.. versionadded:: 32.1 | ||
""" | ||
|
||
transactional: bool | ||
|
||
|
||
class DirectTrainee(Trainee): | ||
""" | ||
Direct-client-specific internal representation of a trainee. | ||
.. versionadded:: 32.1 | ||
""" | ||
|
||
attribute_map = dict(Trainee.attribute_map, transactional='transactional') | ||
|
||
def __init__( | ||
self, | ||
id: str | UUID, | ||
name: t.Optional[str] = None, | ||
*, | ||
metadata: t.Optional[Mapping] = None, | ||
persistence: Persistence = 'allow', | ||
project_id: t.Optional[str | UUID] = None, | ||
transactional: bool = False | ||
): | ||
"""Initialize the Trainee instance.""" | ||
super().__init__(id, name, metadata=metadata, persistence=persistence, project_id=project_id) | ||
self._transactional = transactional | ||
|
||
@property | ||
def transactional(self) -> bool: | ||
""" | ||
Whether this trainee is in transactional mode. | ||
Returns | ||
------- | ||
bool | ||
true if this trainee is running in transactional mode | ||
""" | ||
return self._transactional | ||
|
||
|
||
class TraineeDirectRuntimeOptions(TraineeRuntimeOptions): | ||
""" | ||
Runtime options specific to the direct client. | ||
.. versionadded:: 32.1 | ||
""" | ||
|
||
transactional: ReadOnly[NotRequired[bool | None]] | ||
"""Use transactional mode when `persistence='always'.""" |
This file contains 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
Oops, something went wrong.