-
Notifications
You must be signed in to change notification settings - Fork 990
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
fix(transaction): Add special barrier for blocking tx #2512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,8 +162,7 @@ class Transaction { | |
KEYLOCK_ACQUIRED = 1 << 3, // Whether its key locks are acquired | ||
SUSPENDED_Q = 1 << 4, // Whether is suspended (by WatchInShard()) | ||
AWAKED_Q = 1 << 5, // Whether it was awakened (by NotifySuspended()) | ||
EXPIRED_Q = 1 << 6, // Whether it timed out and should be dropped | ||
UNLOCK_MULTI = 1 << 7, // Whether this shard executed UnlockMultiShardCb | ||
UNLOCK_MULTI = 1 << 6, // Whether this shard executed UnlockMultiShardCb | ||
}; | ||
|
||
public: | ||
|
@@ -412,8 +411,7 @@ class Transaction { | |
enum CoordinatorState : uint8_t { | ||
COORD_SCHED = 1, | ||
COORD_CONCLUDING = 1 << 1, // Whether its the last hop of a transaction | ||
COORD_BLOCKED = 1 << 2, | ||
COORD_CANCELLED = 1 << 3, | ||
COORD_CANCELLED = 1 << 2, | ||
}; | ||
|
||
// Auxiliary structure used during initialization | ||
|
@@ -443,6 +441,25 @@ class Transaction { | |
EventCount ec_{}; | ||
}; | ||
|
||
// "Single claim - single modification" barrier. Multiple threads might try to claim it, only one | ||
// will succeed and will be allowed to modify the guarded object until it closes the barrier. | ||
// A closed barrier can't be claimed again or re-used in any way. | ||
class BatonBarrierrier { | ||
public: | ||
bool IsClaimed() const; // Return if barrier is claimed, only for peeking | ||
bool TryClaim(); // Return if the barrier was claimed successfully | ||
void Close(); // Close barrier after it was claimed | ||
|
||
// Wait for barrier until time_point, or indefinitely if time_point::max() was passed. | ||
// After Wait returns, the barrier is guaranteed to be closed, including expiration. | ||
std::cv_status Wait(time_point); | ||
|
||
private: | ||
std::atomic_bool claimed_{false}; | ||
std::atomic_bool closed_{false}; | ||
EventCount ec_{}; | ||
}; | ||
|
||
private: | ||
// Init basic fields and reset re-usable. | ||
void InitBase(DbIndex dbid, CmdArgList args); | ||
|
@@ -484,6 +501,7 @@ class Transaction { | |
// Optimized version of RunInShard for single shard uncontended cases. | ||
RunnableResult RunQuickie(EngineShard* shard); | ||
|
||
// Set ARMED flags, start run barrier and submit poll tasks. Doesn't wait for the run barrier | ||
void ExecuteAsync(); | ||
|
||
// Adds itself to watched queue in the shard. Must run in that shard thread. | ||
|
@@ -592,8 +610,8 @@ class Transaction { | |
ShardId unique_shard_id_{kInvalidSid}; // Set if unique_shard_cnt_ = 1 | ||
UniqueSlotChecker unique_slot_checker_; | ||
|
||
std::atomic_uint32_t wakeup_requested_{0}; // incremented when blocking transaction gets notified | ||
EventCount blocking_ec_; // to wait for wakeup_requested > 0 (or cancelled) | ||
// Barrier for waking blocking transactions that ensures exclusivity of waking operation. | ||
BatonBarrierrier blocking_barrier_{}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something is wrong here. Also maybe "baton_barrier_" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Baton barrier doesn't indicate where its used, it like calling an atomic variable just
|
||
|
||
// Transaction coordinator state, written and read by coordinator thread. | ||
uint8_t coordinator_state_ = 0; | ||
|
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.
why relaxed?
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 am trying to understand why relaxed is enough here. Do not see any obvious reasons why not and it makes me nervous. Usually, it should not be like this.
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.
Will think about it