-
Notifications
You must be signed in to change notification settings - Fork 276
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
fixes #1705 by locking node while Assigning rel #1706
Changes from 6 commits
e060bc2
772525b
d885f66
c3f6a8f
4191932
a958dab
ea53581
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 |
---|---|---|
|
@@ -28,6 +28,10 @@ def read_transaction(**config, &block) | |
|
||
alias transaction write_transaction | ||
|
||
def lock_node(node) | ||
node.as(:n).query.remove('n._AGLOCK_').exec if tx&.open? || explicit_session&.open? | ||
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. why the condition? No harm would happen if the condition is not met. |
||
end | ||
|
||
private | ||
|
||
def send_transaction(method, **config, &block) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,30 @@ def self.count | |
expect(from_node.reload.to_classes).to be_empty | ||
end | ||
|
||
context 'concurrent update' do | ||
before do | ||
allow_any_instance_of(ActiveGraph::Node::Query::QueryProxy).to receive(:replace_with).and_wrap_original do |original, *args| | ||
$concurrency_queue << 'ready' | ||
Thread.stop | ||
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. I think the right thing would be to stop at |
||
original.call(*args) | ||
end | ||
end | ||
after { $concurrency_queue = nil } | ||
let!(:from_node) { FromClass.create(name: 'foo') } | ||
let!(:to_node) { ToClass.create(name: 'bar') } | ||
|
||
it 'does not create duplicate has_one relationship' do | ||
count = 100 | ||
$concurrency_queue = Thread::Queue.new | ||
threads = count.times.map { Thread.new { to_node.update(from_class: from_node) } } | ||
sleep(0.1) until $concurrency_queue.size == count | ||
$concurrency_queue.clear | ||
threads.each(&:run) | ||
threads.each(&:join) | ||
expect(ActiveGraph::Base.query("MATCH (node2:`ToClass`)<-[rel1:`HAS_REL`]-(from_class:`FromClass`) return from_class").to_a.size).to eq(1) | ||
end | ||
end | ||
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. I am not thrilled about this spec. |
||
|
||
it 'delets has_one rel from from_node when new relation is created' do | ||
to_node_two = ToClass.new(name: 'bar-2') | ||
Rel2Class.new(from_node: from_node, to_node: to_node, score: 10).save | ||
|
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.
using
-
is faster compared to usingselect
loop and then checking withinclude?
again