-
Notifications
You must be signed in to change notification settings - Fork 70
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
Use Node Identifier, Fix ES Duplicates #378
Conversation
This adds the missing implementation for the existing nodeMoveIsHandledCorrectly method. Additionally this also add a new private method to get the node path as stored in ES.
This fixes a weird issue when the node instance from context does not have the right path. See inline comments for details.
Use the node identifier instead of its path to generate the ES document identifier
we want to use that in other places as well to stay DRY
Instead of doing the sha1 dance manually, use static method for that so we can stay DRY
👍 this has been working for us in a big site for the last 5 years successfully. |
As a side-note: we (@cron-eu) will be using this in "5.0" branch for our use-case, so we could provide a PR with the fix even for that low version. An idea to have this included would be to release it as "5.1.0" (and 6.1.0, 7.1.0, 8.1.0) and making a note that a "reindex" is required for that minor update. Don't know if one can expect people to read docs on that for a "simple patch level" release. And I don't think there is a "backwards compatible way" of fixing the bug without reindexing your content. |
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.
By reading the code, good job and nice move. Now we need to take a decision on the major or minor release strategy ;)
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.
Love this, left some comments about more explanation of things.
The release could be minor IMHO, and yes, I at least expect people to read things. 😎
And backporting that to older branches would be great, IMHO! 🚀
@@ -274,6 +274,13 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null): voi | |||
$handleNode = function (NodeInterface $node, Context $context) use ($targetWorkspaceName, $indexer) { | |||
$nodeFromContext = $context->getNodeByIdentifier($node->getIdentifier()); | |||
if ($nodeFromContext instanceof NodeInterface) { | |||
if ($node->getPath() !== $nodeFromContext->getPath()) { | |||
// If the node from context does have a different path, purge the context cache and re-fetch |
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.
A note explaining when/why that could happen would be awesome!
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.
see here my next comment on that topic.
if ($node->getPath() !== $nodeFromContext->getPath()) { | ||
// If the node from context does have a different path, purge the context cache and re-fetch | ||
|
||
// TODO: find a better way to handle 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.
What is wrong with this solution? Would you like to avoid flushing the full cache?
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.
Indeed; I will prefer flushing the cache just for this specific node, but I was not able to figure out a good way to handle that. Do you have an idea here?
And maybe it should be safe(r) to just flush the cache always, regardless of the "node path was changed" condition. What do you think?
TL;DR
I can remember that back then, in 2016 (!) as I have implemented this initially, it took me some time of hair pulling to track down this issue.. I still do not quite understand why the cached data does not cause any issues when the node path was not being changed; maybe the neos context node caching behavior has some flaws, using the node path for invalidation or stuff like that?
Any news on this one ? |
I just had a quick look at the chanegs again and still like it. Nothing new, though. ;) |
Add @kitsunet as reviewer, lot's of ES usage "in his world", so maybe he can check. |
|
||
return sha1($contextPath); | ||
return sha1($nodeIdentifier . $workspaceName); |
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.
Currently, the contextPath contains, site, workspace, dimensions, and nodeIdentifier.
Dimensions should/may be covered, as they are indexed into separate indices. But sites are currently combined in the indices per dimension. Could that be an issue when cloning a site where somehow the nodeIdentfiers are the same?
Why don't we just use the persistent_object_identifier, which is already unique?
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.
If you have two sites with nodes sharing the same identifier, you are doomed, I think. That should never happen, no? Then again, it could happen, so adding the site here might be good.
Using the persistent_object_identifier
OTOH is a no-go IMHO. It should stay an implementation detail internal to the CR and not be used outide it.
@@ -13,7 +13,7 @@ | |||
* source code. | |||
*/ | |||
|
|||
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Domain\Model\TargetContextPath; |
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.
This class should be obsolete now and should be removed.
@remuslazar Any news on this PR ? Should be nice to have it merged |
Dear @remuslazar, thanks for tackling this in the first place! During the core sprint, I reviewed and tested the change and it worked perfectly. We decided though, that we like to release the change as a minor version and so I implemented the feature as an alternative strategy in #394 I already merged that feature. And will close this one in favor of #394 |
@daniellienert great stuff, thanks a lot for your effort! 👍 |
Abstract
This changes the way the Elasticsearch document identifier is being calculated by using the node identifier instead of the node path.
Resolves
Rationale
Using the node path to deduce the identifier in Elasticsearch has some flaws and bad side effects when moving nodes around; in that case, especially when using an async node indexing (e.g. by using the ES Queue Indexer), the indexing process will produce duplicates, basically it will leave the old node around and index a new node (with the correct path) and this will cause race conditions when doing ES queries and also issues when doing e.g. pagination etc.
Breaking
This change will require a "flow:nodeindex", so maybe a minor (or major?) release will the way to go.
Implementation Details
In addition to the logic change this also makes the existing implementation more DRY by removing the duplicated code in the
IndexerDriver
- see 1baf54e.Testing
This also adds an implementation for the existing
NodeIndexerTest::nodeMoveIsHandledCorrectly()
test method.To run the functional tests in e.g. docker, do:
FLOW_CONTEXT="Testing/ElasticVersion6" bin/phpunit --colors --stop-on-failure \ -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml \ Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional
Discussion
I will like to port this change to older versions as well so this will also work in older Neos 4.3 projects..