-
Notifications
You must be signed in to change notification settings - Fork 41
Refactor transaction decoration mechanism #2585
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
Conversation
0ca09e8 to
0fd37fa
Compare
| public abstract class ActiveTransactionManagedDistributedTransactionManager | ||
| extends TransactionDecorationDistributedTransactionManager | ||
| implements DistributedTransactionExpirationHandlerSettable { | ||
| public class ActiveTransactionManagedDistributedTransactionManager |
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.
Refactored this from using inheritance to using composition (decorator pattern).
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.
There is now StateManagedDistributedTransactionManager that can have Status.ACTIVE. So, this class prefix "Active" seems to related to the state and a bit confusing to me. I think this class provides the capability to resume and join a transaction, so how about renaming to something like ResumableDistributedTransactionManager?
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, that makes sense. However, we already have the property scalar.db.active_transaction_management.expiration_time_millis for configuring the expiration time of active transaction management:
scalardb/core/src/main/java/com/scalar/db/config/DatabaseConfig.java
Lines 51 to 52 in 0fd37fa
| public static final String ACTIVE_TRANSACTION_MANAGEMENT_EXPIRATION_TIME_MILLIS = | |
| PREFIX + "active_transaction_management.expiration_time_millis"; |
So I think it's better to keep the class name as is for consistency. Thanks.
| public abstract class ActiveTransactionManagedTwoPhaseCommitTransactionManager | ||
| extends TransactionDecorationTwoPhaseCommitTransactionManager | ||
| implements TwoPhaseCommitTransactionExpirationHandlerSettable { | ||
| public class ActiveTransactionManagedTwoPhaseCommitTransactionManager |
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.
Ditto. Refactored this from using inheritance to using composition (decorator pattern).
| public abstract class TransactionDecorationDistributedTransactionManager | ||
| extends AbstractDistributedTransactionManager | ||
| implements DistributedTransactionDecoratorAddable { | ||
| public class StateManagedDistributedTransactionManager |
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.
Ditto. Refactored this from using inheritance to using composition (decorator pattern).
| public abstract class TransactionDecorationTwoPhaseCommitTransactionManager | ||
| extends AbstractTwoPhaseCommitTransactionManager | ||
| implements TwoPhaseCommitTransactionDecoratorAddable { | ||
| public class StateManagedTwoPhaseCommitTransactionManager |
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.
Ditto. Refactored this from using inheritance to using composition (decorator pattern).
| @Override | ||
| public DistributedTransactionManager createDistributedTransactionManager(DatabaseConfig config) { | ||
| return new ConsensusCommitManager(config); | ||
| return new ActiveTransactionManagedDistributedTransactionManager( |
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.
Wrapped the Consensus Commit transaction manager instance using decorator pattern.
| public TwoPhaseCommitTransactionManager createTwoPhaseCommitTransactionManager( | ||
| DatabaseConfig config) { | ||
| return new TwoPhaseConsensusCommitManager(config); | ||
| return new ActiveTransactionManagedTwoPhaseCommitTransactionManager( |
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.
Ditto.
| @Override | ||
| public DistributedTransactionManager createDistributedTransactionManager(DatabaseConfig config) { | ||
| return new JdbcTransactionManager(config); | ||
| return new ActiveTransactionManagedDistributedTransactionManager( |
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.
Wrapped the JDBC transaction manager instance using decorator pattern.
| throw new CrudException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } | ||
| String txId = UUID.randomUUID().toString(); | ||
| DistributedTransaction transaction = begin(txId); |
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.
| DistributedTransaction transaction = begin(txId); | |
| DistributedTransaction transaction = begin(); |
[minor] A bit simpler?
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 41b597a. Thanks!
| throw new CrudException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } | ||
| String txId = UUID.randomUUID().toString(); | ||
| TwoPhaseCommitTransaction transaction = begin(txId); |
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.
Same as above
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 41b597a. Thanks!
| public abstract class ActiveTransactionManagedDistributedTransactionManager | ||
| extends TransactionDecorationDistributedTransactionManager | ||
| implements DistributedTransactionExpirationHandlerSettable { | ||
| public class ActiveTransactionManagedDistributedTransactionManager |
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.
There is now StateManagedDistributedTransactionManager that can have Status.ACTIVE. So, this class prefix "Active" seems to related to the state and a bit confusing to me. I think this class provides the capability to resume and join a transaction, so how about renaming to something like ResumableDistributedTransactionManager?
komamitsu
left a comment
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! 👍
Torch3333
left a comment
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!
feeblefakie
left a comment
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!
Can you elaborate the reason for the refactoring?
The old way got too complicated?
I'm just wondering.
Yes. In this case, using inheritance makes the classes stateful, which complicates things. Using composition (the decorator pattern) makes future refactoring easier. Thanks! |
Description
This PR refactors the transaction decoration mechanism.
Related issues and/or PRs
N/A
Changes made
DistributedTransactionDecorator,DistributedTransactionDecoratorAddable,TwoPhaseCommitTransactionDecorator, andTwoPhaseCommitTransactionDecoratorAddable.Checklist
Additional notes (optional)
N/A
Release notes
N/A