-
Notifications
You must be signed in to change notification settings - Fork 34
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
EZP-30296: Large API subtree delete leads to serious Solr index inconsistencies #150
Changes from all commits
abf63dc
18c9c5e
4a99ddf
5c1f9de
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 |
---|---|---|
|
@@ -45,6 +45,12 @@ | |
*/ | ||
class Handler implements SearchHandlerInterface, Capable | ||
{ | ||
/* Solr's maxBooleanClauses config value is 1024 */ | ||
const SOLR_BULK_REMOVE_LIMIT = 1000; | ||
/* 16b max unsigned integer value due to Solr (JVM) limitations */ | ||
const SOLR_MAX_QUERY_LIMIT = 65535; | ||
const DEFAULT_QUERY_LIMIT = 1000; | ||
|
||
/** | ||
* Content locator gateway. | ||
* | ||
|
@@ -328,7 +334,7 @@ public function commit($flush = false) | |
*/ | ||
protected function deleteAllItemsWithoutAdditionalLocation($locationId) | ||
{ | ||
$query = $this->prepareQuery(); | ||
$query = $this->prepareQuery(self::SOLR_MAX_QUERY_LIMIT); | ||
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. Ok I get why you wanted really high limit now.. I think unfortunately you'll have to change logic to iterate on this if you get back this amount of hits, or you might get total count which will tell you (roguthly*) how many iterations you need to make right? * In the freak case of parallel async processes for some reason adding locations to this tree at the same time. 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.
It was my first idea, but @adamwojs was really against this approach since it might be expensive, performance wise, to perform two same queries, first to count and second to load locations. WDYT @andrerom? 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. But that said, that can be follow also. You definitely improve the logic here as previous limit was 1000... So ignore this for now unless you feel up for it in this PR 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. AS said above, this is already way better then what is there today. So I'm fine with this as is. 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. |
||
$query->filter = new Criterion\LogicalAnd( | ||
[ | ||
$this->allItemsWithinLocation($locationId), | ||
|
@@ -340,9 +346,15 @@ protected function deleteAllItemsWithoutAdditionalLocation($locationId) | |
$this->gateway->searchAllEndpoints($query) | ||
); | ||
|
||
$contentDocumentIds = []; | ||
|
||
foreach ($searchResult->searchHits as $hit) { | ||
$idPrefix = $this->mapper->generateContentDocumentId($hit->valueObject->id); | ||
$this->gateway->deleteByQuery("_root_:{$idPrefix}*"); | ||
$contentDocumentIds[] = $this->mapper->generateContentDocumentId($hit->valueObject->id) . '*'; | ||
} | ||
|
||
foreach (\array_chunk(\array_unique($contentDocumentIds), self::SOLR_BULK_REMOVE_LIMIT) as $ids) { | ||
$query = '_root_:(' . implode(' OR ', $ids) . ')'; | ||
$this->gateway->deleteByQuery($query); | ||
} | ||
} | ||
|
||
|
@@ -351,7 +363,7 @@ protected function deleteAllItemsWithoutAdditionalLocation($locationId) | |
*/ | ||
protected function updateAllElementsWithAdditionalLocation($locationId) | ||
{ | ||
$query = $this->prepareQuery(); | ||
$query = $this->prepareQuery(self::SOLR_MAX_QUERY_LIMIT); | ||
$query->filter = new Criterion\LogicalAnd( | ||
[ | ||
$this->allItemsWithinLocation($locationId), | ||
|
@@ -380,14 +392,16 @@ protected function updateAllElementsWithAdditionalLocation($locationId) | |
/** | ||
* Prepare standard query for delete purpose. | ||
* | ||
* @param int $limit | ||
* | ||
* @return Query | ||
*/ | ||
protected function prepareQuery() | ||
protected function prepareQuery($limit = self::DEFAULT_QUERY_LIMIT) | ||
{ | ||
return new Query( | ||
[ | ||
'query' => new Criterion\MatchAll(), | ||
'limit' => 1000, | ||
'limit' => $limit, | ||
'offset' => 0, | ||
] | ||
); | ||
|
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 ok with this, so +1 once PR is green ;)
TODO: Drop this line on merge up.