-
Notifications
You must be signed in to change notification settings - Fork 37
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
Allow directly executing CRUD operations with transaction managers #1755
Allow directly executing CRUD operations with transaction managers #1755
Conversation
import java.util.Optional; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
public abstract class TransactionDecorationDistributedTransactionManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted transaction decoration related logic from AbstractDistributedTransactionManager
to TransactionDecorationDistributedTransactionManager
.
import java.util.Optional; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
public abstract class TransactionDecorationTwoPhaseCommitTransactionManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted transaction decoration related logic from AbstractTwoPhaseCommitTransactionManager
to TransactionDecorationTwoPhaseCommitTransactionManager
.
public interface DistributedTransactionManager | ||
extends TransactionManagerCrudOperable, AutoCloseable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made DistributedTransactionManager
extends TransactionManagerCrudOperable
.
public interface TwoPhaseCommitTransactionManager | ||
extends TransactionManagerCrudOperable, AutoCloseable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also made TwoPhaseCommitTransactionManager
extend TransactionManagerCrudOperable
.
* always used in transactional CRUD operations, so {@link Consistency} specified for CRUD | ||
* operations is ignored. | ||
*/ | ||
public interface CrudOperable<E extends TransactionException> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce CrudOperable
that's an abstraction for executing CRUD operations.
import java.util.Optional; | ||
|
||
/** An interface for transactional CRUD operations for transaction managers. */ | ||
public interface TransactionManagerCrudOperable extends CrudOperable<TransactionException> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TransactionManagerCrudOperable
is an abstraction for transaction managers to execute CRUD operations.
bf10799
to
d6f9cca
Compare
*/ | ||
public interface TransactionCrudOperable { | ||
/** An interface for transactional CRUD operations for transactions. */ | ||
public interface TransactionCrudOperable extends CrudOperable<CrudException> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be just a naming issue. IIUC, CrudException
inherits from TransactionException
, and TransactionCrudOperable
inherits from CrudOperable
. Their inheritance directions seem reversed from the perspective of class names. It's a bit confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Thanks.
Actually, this naming strongly depends on backward compatibility. TransactionCrudOperable
is an existing name, so we can't rename it to preserve backward compatibility.
The requirements here are as follows:
- Add CRUD operation methods to the transaction manager interfaces (
DistributedTransactionManager
andTwoPhaseCommitTransactionManager
). - Access the CRUD operation methods through the same abstraction for the transaction manager interfaces and the transaction interfaces (
DistributedTransaction
andTwoPhaseCommitTransaction
). - The exceptions thrown by the CRUD operation methods differ slightly between the transaction manager interfaces and the transaction interfaces.
Considering these requirements, we finally decided on the current naming. But do you have any better ideas for the naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing the background.
What we can change is only the name of CrudOperable
newly added in this PR. It seems to be only inherited by TransactionManagerCrudOperable
and TransactionCrudOperable
. How about renaming it to TransactionCrudOperableBase
or something so that the inheritance relationships will be as follows?
TransactionCrudOperableBase
TransactionCrudOperable
TransactionManagerCrudOperable
TransactionException
CrudException
Current
CrudOperable
TransactionCrudOperable
TransactionManagerCrudOperable
TransactionException
CrudException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, TransactionManagerCrudOperable
is also newly added in this PR, so we can rename it as well.
The naming XXXBase
sounds more appropriate for abstract classes to me, so I'm not sure it's suitable for interfaces. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I think TransactionManagerCrudOperable
is alined with TransactionCrudOperable
, so it can be left as is. Regarding XxxxBase
, indeed it's less common. I'm also not sure if we should avoid it. Another option is TransactionalCrudOperable
based on the comment An interface for transactional CRUD operations
? It might be a bit confusing, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, TransactionalCrudOperable
is a possible idea. But, as you mentioned, it might still be confusing between TransactionalCrudOperable
and TransactionCrudOperable
.
If we consider CrudOperable
vs. TransactionalCrudOperable
, I prefer CrudOperable
. But that's just my preference. If you have any other better ideas, strong opinions, or strong reasons, please let me know. Thanks.
try { | ||
transaction.rollback(); | ||
} catch (RollbackException e) { | ||
throw new CrudException(e.getMessage(), e, e.getTransactionId().orElse(null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uncommitted transaction will be rolled back, so just warning message or something is enough here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Let me add a warning message here. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 64417d1. Thanks.
static class StateManagedTransaction extends DecoratedTwoPhaseCommitTransaction { | ||
|
||
private enum Status { | ||
ACTIVE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] This is a bit off topic. But PREPARED
and VALIDATED
may seem active as well. So, EXECUTING
or CRUD
or something might be less confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. Let's discuss this in a separate PR. Thanks.
0b1c67c
to
64417d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides this comment, LGTM, thank you.
implements TwoPhaseCommitTransactionManager { | ||
|
||
private static final Logger logger = | ||
LoggerFactory.getLogger(AbstractDistributedTransactionManager.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LoggerFactory.getLogger(AbstractDistributedTransactionManager.class); | |
LoggerFactory.getLogger(AbstractTwoPhaseCommitTransactionManager.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed in 194e18d. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
Description
This PR allows directly executing CRUD operations with transaction managers.
Related issues and/or PRs
N/A
Changes made
get()
,scan()
,put()
,insert()
,upsert()
,update()
,delete()
, andmutate()
) toDistributedTransactionManager
andTwoPhaseCommitTransactionManager
CrudOperable
, and madeTransactionCrudOperable
a subclass ofCrudOperable
TransactionManagerCrudOperable
as a subclass ofCrudOperable
DistributedTransactionManager
andTwoPhaseCommitTransactionManager
extendTransactionManagerCrudOperable
Checklist
Additional notes (optional)
N/A
Release notes
Allowed directly executing CRUD operations with transaction managers.