Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] transactional support #249

Open
wants to merge 58 commits into
base: main
Choose a base branch
from

Conversation

aburmeis
Copy link
Contributor

@aburmeis aburmeis commented Aug 30, 2022

As mentioned in #80 this introduces a platform transaction manager based on Arango stream transactions. Do do so, all queries and the simple repository have to use options including the transaction id. As stream transactions need all collections written on creation, additional ones can be passed as labels from the @Transactional annotation.

The ArangoTransactionManager will handle each transaction as one stream transaction allowing implicit read from undeclared collections. Isolation level will be repeatable read (serialisable is not supported). All write collections have to be declared, either explicit using @Transactional(label = {"Entities", "hasEdge"}) or implicit from the first AQL WITH (will be combined as the stream transaction begin is postponed until the first query is fired). Any defined transaction timeout is used as lock timeout of the stream transaction.

The manager implements Propagation.REQUIRED and Propagation.SUPPORTS only (REQUIRED is the default). Any other will fail due to lack of suspend/resume implementation.

Transaction management is enabled the following way:

@Configuration
@EnableTransactionManagement
@Import(ArangoTransactionManagementConfigurer.class)
class ArangoTransactionSupport {
}

The typical use case would make all public methods of a service transactional read only and the mutating ones declaring the collections:

@Service
@Transactional(readOnly = true)
public class MyService {

    public Entity getById(Long id) {
        ...
    }

    @Transactional(label = {"Entities"})
    public Entity save(Entity modified) {
        ...
    }
}

You can also use programmatic transactions with support from TransactionAttributeTemplate. Either create one using DefaultTransactionAttribute or set labels before calling execute().

@aburmeis
Copy link
Contributor Author

@Zyqsempai this is the contribution we offered earlier this year

@aburmeis aburmeis force-pushed the feature/transactional branch from ce89c66 to 0ab0fa4 Compare August 31, 2022 12:02
@aburmeis
Copy link
Contributor Author

The additional documentation can be found in a gist: spring-data-reference-repositories-transactions.md

@aburmeis
Copy link
Contributor Author

aburmeis commented Sep 1, 2022

@MalteJoe @jakobjoachim its on the way

@rashtao
Copy link
Collaborator

rashtao commented Sep 15, 2022

Thanks for this awesome contribution, I will review it as soon as I will have time.

@rashtao rashtao self-requested a review September 15, 2022 09:32
@rashtao rashtao self-assigned this Sep 15, 2022
Copy link
Collaborator

@rashtao rashtao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aburmeis,
as far as I can see, ArangoTransactionManager assumes that the db and all the collection involved in the transaction already exist when beginning the transaction. Unfortunately, this is not the case with the current implementation. In fact db and collections are currently initialized lazily. They are checked if exist only when the first operation upon them is performed. This behavior should change, as pointed out in #125 and all data definitions like db, collections, indexes, should be checked on startup.

A further complication derives from the fact that we should support SPEL expressions in dbs and collections names, i.e. see

It should be possible checking existence of db and collections in the ArangoTransactionManager, but note that in case you need to create a collection, you should remember to dinamically evaluate the name in case it contains a SPEL expression and consider the related create options (https://github.com/arangodb/spring-data/blob/286b502d78bee5e5d5f551b4c2213238919fe625/src/main/java/com/arangodb/springframework/annotation/Document.java). To do it, you should ideally have the related entity class, see

private ArangoCollection _collection(final Class<?> entityClass, final Object id) {
final ArangoPersistentEntity<?> persistentEntity = converter.getMappingContext()
.getRequiredPersistentEntity(entityClass);
final String name = determineCollectionFromId(id).orElse(persistentEntity.getCollection());
return _collection(name, persistentEntity, persistentEntity.getCollectionOptions());
}

Therefore, instead of using labels strings to specify write collections of the transaction, it would be ideal having a dedicated annotation which would allow specify the entity classes directly (eg. @ArangoTransaction(writeCollections = {Actor.class, Movie.class})).

@aburmeis aburmeis force-pushed the feature/transactional branch from 54c7fbd to 3307750 Compare January 30, 2023 12:04
@cla-bot
Copy link

cla-bot bot commented Jan 30, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@cla-bot
Copy link

cla-bot bot commented Feb 7, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@cla-bot cla-bot bot removed the cla-signed label Feb 7, 2023
@aburmeis aburmeis force-pushed the feature/transactional branch from 8c14e8a to 68c60f7 Compare March 13, 2023 14:48
@cla-bot
Copy link

cla-bot bot commented Mar 13, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

1 similar comment
@cla-bot
Copy link

cla-bot bot commented Mar 14, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@aburmeis aburmeis force-pushed the feature/transactional branch from 2c98ca6 to 541b112 Compare May 4, 2023 09:56
@cla-bot
Copy link

cla-bot bot commented May 4, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@aburmeis aburmeis force-pushed the feature/transactional branch from 541b112 to 499fe1a Compare May 31, 2023 07:04
@cla-bot
Copy link

cla-bot bot commented May 31, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

2 similar comments
@cla-bot
Copy link

cla-bot bot commented May 31, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@cla-bot
Copy link

cla-bot bot commented Aug 23, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@aburmeis aburmeis force-pushed the feature/transactional branch from e75199b to 25b8270 Compare August 23, 2023 07:34
@cla-bot
Copy link

cla-bot bot commented Aug 23, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

1 similar comment
@cla-bot
Copy link

cla-bot bot commented Aug 23, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@aburmeis aburmeis force-pushed the feature/transactional branch from aa938a2 to 0ffeb3c Compare August 23, 2023 10:48
@cla-bot
Copy link

cla-bot bot commented Aug 23, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@aburmeis aburmeis force-pushed the feature/transactional branch from 41ee67a to 23d40a9 Compare December 5, 2024 17:00
Copy link

cla-bot bot commented Dec 5, 2024

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

Copy link

cla-bot bot commented Dec 6, 2024

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

Copy link

cla-bot bot commented Dec 12, 2024

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants