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

Allow 0 as a valid external version #6149

Closed
wants to merge 2 commits into from

Conversation

bleskes
Copy link
Contributor

@bleskes bleskes commented May 13, 2014

Until now all version types have officially required the version to be a positive long number. Despite of this has being documented, ES versions <=1.0 did not enforce it when using the external version type. As a result people have succesfully indexed documents with 0 as a version. In 1.1. we introduced validation checks on incoming version values and causing indexing request to fail if the version was set to 0. While this is strictly speaking OK, we effectively have a situation where data already indexed does not match the version invariant.

To be lenient and adhere to spirit of our data backward compatibility policy, we have decided to allow 0 as a valid external version type. This is somewhat complicated as 0 is also the internal value of MATCH_ANY, which indicates requests should succeed regardles off the current doc version. To keep things simple, this commit changes the internal value of MATCH_ANY to -3 for all version types.

Since we're doing this in a minor release (and because versions are stored in the transaction log), the default internal version type still accepts 0 as a MATCH_ANY value. This is not a problem for other version types as MATCH_ANY doesn't make sense in that context.

Closes #5662

Until now all version types have officially required the version to be a positive long number. Despite of this has being documented, ES versions <=1.0 did not enforce it when using the `external` version type. As a result people have succesfully indexed documents with 0 as a version. In 1.1. we introduced validation checks on incoming version values and causing indexing request to fail if the version was set to 0. While this is strictly speaking OK, we effectively have a situation where data already indexed does not match the version invariant.

To be lenient and adhere to spirit of our data backward compatibility policy, we have decided to allow 0 as a valid external version type. This is somewhat complicated as 0 is also the internal value of `MATCH_ANY`, which indicates requests should succeed regardles off the current doc version. To keep things simple, this commit changes the internal value of `MATCH_ANY` to `-3` for all version types.

Since we're doing this in a minor release (and because versions are stored in the transaction log), the default `internal` version type still accepts 0 as a `MATCH_ANY` value. This is not a problem for other version types as `MATCH_ANY` doesn't make sense in that context.

Closes elastic#5662
@bleskes bleskes added the review label May 13, 2014
} else {
out.writeVLong(version);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it use writeLong instead to be more future-proof (like UpdateRequest and IndexRequest do) eg. if we need a new special negative value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I started the re-write with get requests which used vLong (which is correct here). You are right, in retrospect it's but to move to long... Will change.

@jpountz
Copy link
Contributor

jpountz commented May 14, 2014

I left a question about whether we should keep using VLong here but other than that this looks good to me.

@bleskes
Copy link
Contributor Author

bleskes commented May 14, 2014

@jpountz I pushed an update. Your comment made me think some more about the writeLong version and it opened a can of worms...

@jpountz
Copy link
Contributor

jpountz commented May 15, 2014

LGTM

@s1monw
Copy link
Contributor

s1monw commented May 15, 2014

this goes also into master no?

@s1monw s1monw removed the review label May 15, 2014
@bleskes
Copy link
Contributor Author

bleskes commented May 15, 2014

@s1monw yes. forgot a label. Adding.

@bleskes bleskes added the v2.0.0 label May 15, 2014
@imotov
Copy link
Contributor

imotov commented May 15, 2014

LGTM, but I think it might be cleaner to have another PR the will go only into master and will stop accepting 0 as MATCH_ANY there. Thoughts?

@bleskes
Copy link
Contributor Author

bleskes commented May 16, 2014

Thanks all for reviewing. I just pushed it master (9f10547) and 1.x (dbcf2b1). I'll make another PR in a second to remove the BW code from master.

@bleskes bleskes closed this May 18, 2014
bleskes added a commit that referenced this pull request May 18, 2014
These calls were introduced in pr #6149 as a backward compatibility layer for the previous value of `Versions.MATCH_ANY`. This is not needed as the translog never contains these values. On top of that, the calls are not effective as the stream the translog used is effectively not versioned (versioining is done on an item by item basis)
bleskes added a commit that referenced this pull request May 18, 2014
These calls were introduced in pr #6149 as a backward compatibility layer for the previous value of `Versions.MATCH_ANY`. This is not needed as the translog never contains these values. On top of that, the calls are not effective as the stream the translog used is effectively not versioned (versioining is done on an item by item basis)
bleskes added a commit to bleskes/elasticsearch that referenced this pull request Mar 23, 2015
bleskes added a commit that referenced this pull request Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexing a document fails when setting version=0 & version_type=external
5 participants