-
Notifications
You must be signed in to change notification settings - Fork 165
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
Sync client shall not block user writes #5844
Changes from all commits
e9322ee
9e7e4f6
313ed46
5429e85
7c62329
54b35d1
6ef9f0e
793517e
433d591
aa74107
d5843dc
c44c806
3d15242
168ef37
07856ba
36ef668
97c5417
b3584c8
5640dcb
475b669
cea8594
1e68dd3
6091910
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 |
---|---|---|
|
@@ -1518,6 +1518,17 @@ void DB::close_internal(std::unique_lock<InterprocessMutex> lock, bool allow_ope | |
} | ||
} | ||
|
||
bool DB::other_writers_waiting_for_lock() const | ||
{ | ||
SharedInfo* info = m_file_map.get_addr(); | ||
|
||
uint32_t next_ticket = info->next_ticket.load(std::memory_order_relaxed); | ||
uint32_t next_served = info->next_served.load(std::memory_order_relaxed); | ||
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. it's safe for us to read these in any order because we hold the write lock? is that correct? 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. Yes, at least the way we use it. But I can think of a scenario where a thread starts writing (i.e, acquires the lock) and checks if other threads are waiting for the lock while at the same time another thread closes the transaction causing 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. For future reference: the above scenario cannot happen. The only thread which can close the transaction is the one holding the lock. |
||
// When holding the write lock, next_ticket = next_served + 1, hence, if the diference between 'next_ticket' and | ||
// 'next_served' is greater than 1, there is at least one thread waiting to acquire the write lock. | ||
return next_ticket > next_served + 1; | ||
} | ||
|
||
class DB::AsyncCommitHelper { | ||
public: | ||
AsyncCommitHelper(DB* db) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,8 @@ class EventLoopDispatcher<void(Args...)> { | |
} | ||
}; | ||
|
||
} // namespace util | ||
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. just curious why we needed to do this? 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. It was a problem on Windows due to the compiler. event_loop_dispatcher.hpp defined things in realm::util namespace, which results in _impl::EnableIfSpanCompatible being realm::util::_impl::EnableIfSpanCompatible if that header is included. But the code relies on realm::_impl::EnableIfSpanCompatible existing. It is a "fix" that Thomas suggested. |
||
|
||
namespace _impl::ForEventLoopDispatcher { | ||
template <typename Sig> | ||
struct ExtractSignatureImpl { | ||
|
@@ -106,6 +108,8 @@ template <typename T> | |
using ExtractSignature = typename ExtractSignatureImpl<T>::signature; | ||
} // namespace _impl::ForEventLoopDispatcher | ||
|
||
namespace util { | ||
|
||
// Deduction guide for function pointers. | ||
template <typename... Args> | ||
EventLoopDispatcher(void (*)(Args...)) -> EventLoopDispatcher<void(Args...)>; | ||
|
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.
what happened 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.
Not sure. But there is no change.