Skip to content
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

No way to resolve the replication conflict of the operation type is 'insert.' #4503

Open
Kasen opened this issue Sep 16, 2019 · 6 comments
Open
Labels
feature A new functionality needs feedback Something is unclear with the issue replication
Milestone

Comments

@Kasen
Copy link

Kasen commented Sep 16, 2019

Tarantool version:
1.10.3-80

OS version:
MacOS 10.14.6

Bug description:
I try to resolve the replication conflict between two tuples with before_replace trigger. Which looks like this:

function(old, new)
    -- the fourth field is a timestamp
    if new and old and box.session.type() == 'applier' and new[4] > old[4] then
        return new
    end
end

If an operation type is 'replace' then this trigger works correct, but if an operation type is 'insert', I receive the error:

 error applying row: {type: 'INSERT', replica_id: 1, lsn: 6, space_id: 512, index_id: 0, tuple: [12477, '1837192990', '0002', 1568389264.6109, 1, 1, 3, '']}

So I don't know how to resolve this conflict. 🤷‍♂

Steps to reproduce:
On master instance:

  1. box.schema.create_space('t')
  2. box.space.t:create_index('primary')

On replica instance:

  1. box.space.t:insert({1})
  2. box.space.t:before_replace(function(old, new) return new end)

On master instance:

  1. box.space.t:insert({1})
@kyukhin kyukhin added bug Something isn't working replication labels Nov 8, 2019
@kyukhin kyukhin added this to the 1.10.5 milestone Nov 8, 2019
@Gerold103
Copy link
Collaborator

That is correct. You can't. The primary key stays the same, and the operation type is still INSERT after your trigger, and the old tuple still exists. So there is no reason why this INSERT should not fail.

@Gerold103
Copy link
Collaborator

But. You can change the new tuple, and it will turn the operation into REPLACE. Try this:

box.space.t:before_replace(function(old, new) return box.tuple.new(new) end)

@Gerold103
Copy link
Collaborator

Sorry, closed accidentally.

@Gerold103 Gerold103 reopened this Nov 24, 2019
@kostja
Copy link
Contributor

kostja commented Nov 25, 2019

Given there is a workaround, this should be turned into a documentation issue.

@kyukhin kyukhin modified the milestones: 1.10.5, 1.10.6 Jan 13, 2020
@Gerold103 Gerold103 added the needs feedback Something is unclear with the issue label Feb 23, 2020
@printercu
Copy link

printercu commented Mar 25, 2020

What if changing INSERT into REPLACE is not acceptable? Ex., I want to skip only duplicate records but still get an error for any other conflicts like this:

    space:before_replace(function(old, new)
        if old and new and utils.tuples_equal(old, new) then
            return old
        end
        return new
    end)

UPD. It appears that this code works as intended, and the problem was in the inserted data.

@kostja
Copy link
Contributor

kostja commented Apr 8, 2020

OK, so what is the issue then? You can return old, new, or an entirely new tuple - the trigger may behave differently depending on data it receives.

For this and many other cases we need to add access to transaction state through Lua API. It's a matter of adding a few Lua bindings, so is more like a feature, not a bug. But given it's pretty safe to add these bindings, I think we can add them to 1.10 as well.

The bindings should provide access not only to the current operation type, but LSN and server id.

@kyukhin kyukhin modified the milestones: 1.10.6, 1.10.7 Apr 20, 2020
@kyukhin kyukhin added feature A new functionality and removed bug Something isn't working labels Apr 23, 2020
@kyukhin kyukhin modified the milestones: 1.10.7, wishlist Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new functionality needs feedback Something is unclear with the issue replication
Projects
None yet
Development

No branches or pull requests

5 participants