-
Notifications
You must be signed in to change notification settings - Fork 737
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
Version option deprecation fix and replacements #1803
Conversation
I'm still reading the changelog for 7.x and I'm not sure anymore what to do: https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#breaking_70_api_changes It clearly states:
There's also:
Maybe @damienalexandre could help us with these changes in the api? |
src/AbstractUpdateAction.php
Outdated
* | ||
* @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html | ||
*/ | ||
public function setSequenceNumber($number) |
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.
public function setSequenceNumber($number) | |
public function setSequenceNumber(int $number) |
src/AbstractUpdateAction.php
Outdated
* | ||
* @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html | ||
*/ | ||
public function setPrimaryTerm($term) |
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.
public function setPrimaryTerm($term) | |
public function setPrimaryTerm(int $term) |
src/AbstractUpdateAction.php
Outdated
} | ||
|
||
/** | ||
* Sets the prmary term of a document for use with optimistic concurrency control. |
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.
* Sets the prmary term of a document for use with optimistic concurrency control. | |
* Sets the primary term of a document for use with optimistic concurrency control. |
src/AbstractUpdateAction.php
Outdated
* | ||
* @return int|string Document version | ||
*/ | ||
public function getPrimaryTerm() |
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.
public function getPrimaryTerm() | |
public function getPrimaryTerm(): int |
src/AbstractUpdateAction.php
Outdated
/** | ||
* @return bool | ||
*/ | ||
public function hasPrimaryTerm() |
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.
public function hasPrimaryTerm() | |
public function hasPrimaryTerm(): bool |
src/AbstractUpdateAction.php
Outdated
/** | ||
* @return bool | ||
*/ | ||
public function hasSequenceNumber() |
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.
public function hasSequenceNumber() | |
public function hasSequenceNumber(): bool |
src/AbstractUpdateAction.php
Outdated
* | ||
* @return int|string Document version | ||
*/ | ||
public function getSequenceNumber() |
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.
public function getSequenceNumber() | |
public function getSequenceNumber(): int |
if (isset($responseData['_version'])) { | ||
$data->setVersion($responseData['_version']); |
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 this should be removed finally. As it's still documented as returned.
'version', | ||
'version_type', |
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.
Seems the right fix as this not documented anymore: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/docs-update.html
if (isset($data['_version'])) { | ||
$doc->setVersion($data['_version']); |
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 this should be removed finally. As it's still documented as returned.
@@ -272,10 +275,7 @@ public function getDocument($id, array $options = []): Document | |||
$data = []; | |||
} | |||
|
|||
$document = new Document($id, $data, $this->getName()); | |||
$document->setVersion($result['_version']); |
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 this should be removed finally. As it's still documented as returned.
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'll put back setVersion, just remove it for a document update
src/Index.php
Outdated
$document->setVersion($result['_version']); | ||
|
||
return $document; | ||
return new Document($id, $data, $this->getName()); |
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.
We can probably add the seq_no
and primary_term
to document too as it's documented as returned: https://www.elastic.co/guide/en/elasticsearch/reference/7.9/docs-get.html#docs-get-api-response-body
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 was debating doing that since the param for the document update is different, I think it needs to be separated between what we get back and what is sent for a document update
src/Client.php
Outdated
'if_primary_term', | ||
'if_seq_no', |
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.
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.
Many type-hints changes not in scope of this PR.
That would break the backward compatibility.
src/AbstractUpdateAction.php
Outdated
@@ -59,72 +59,105 @@ public function setIndex($index): self | |||
* | |||
* @return string Index name | |||
*/ | |||
public function getIndex() | |||
public function getIndex(): string |
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.
BC break here, so should probably not be changed
src/AbstractUpdateAction.php
Outdated
*/ | ||
public function hasVersionType() | ||
public function setVersion(int $version): self |
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.
BC break too.
src/AbstractUpdateAction.php
Outdated
public function hasVersionType() | ||
public function setVersion(int $version): self | ||
{ | ||
return $this->setParam('_version', $version); |
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.
return $this->setParam('_version', $version); | |
return $this->setParam('version', $version); |
I reverted the type hints outside of the scope |
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.
Is any of this going to be a breaking change for some of the users?
* @param int $version Document version | ||
* @return $this | ||
*/ | ||
public function setVersionParams(array $responseData): self |
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.
Do we still need this method or could we remove it?
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.
its still used to set the document version on GET
if (isset($bulkResponseData['_version'])) { | ||
$data->setVersion($bulkResponseData['_version']); | ||
} | ||
$data->setVersionParams($bulkResponseData); |
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.
Now I see where we need this. Is there a better way to do 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.
I'm not sure there's a better way, I was trying to avoid to copy/paste code
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 think copy/paste in this case is fine, adding another public method just for avoiding calling each setter doesn't bring so much value.
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.
LGTM.
@deguif Could you also give a 👍 or check if your concerns were addressed?
@ruflin I'm not really confident with the impacts it can have but else I'm 👍 |
@deguif That leaves a lot of room for interpretation 😆 The good news is, that this is master. I'll move forward with it. |
As mentioned in #2049, the version/version_type has been removed in 7.x as concurrency control. These options were still always added in the `addDocument` method which causes an issue when adding a document from one index to another. This PR removes those options, and sorts the other options alphabetically cfr #1803.
As stated in #1796
version
andversion_type
if_seq_no
andif_primary_term