Skip to content

Commit

Permalink
Merge pull request Smile-SA#3468 from rbayet/feat-customize-time-befo…
Browse files Browse the repository at this point in the history
…re-index-is-ghost

[Core] Setting to customize time before an index becomes ghost
  • Loading branch information
rbayet authored Dec 10, 2024
2 parents bb8645f + 15292a3 commit 86a57d7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/module-elasticsuite-core/Helper/IndexSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ public function getNumberOfReplicasPerIndex(string $indexIdentifier): int
return (int) $this->getIndicesSettingsConfigParam('number_of_replicas');
}

/**
* Returns the time elapsed (in seconds) since its creation after which a non-live index is to be considered ghost.
*
* @return int
*/
public function getTimeBeforeGhost(): int
{
return (int) $this->getIndicesSettingsConfigParam('ghost_timeout');
}

/**
* Get number the batch indexing size from the configuration.
*
Expand Down
15 changes: 10 additions & 5 deletions src/module-elasticsuite-core/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,30 @@

<group id="indices_settings" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Indices Settings</label>
<field id="alias" translate="label" type="text" sortOrder="57" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="alias" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Indices Alias Name</label>
</field>
<field id="indices_pattern" translate="label" type="text" sortOrder="58" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="indices_pattern" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Indices Name Pattern</label>
</field>
<field id="number_of_shards" translate="label" type="text" sortOrder="59" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="number_of_shards" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Default Number of Shards per Index</label>
<frontend_class>validate-number</frontend_class>
</field>
<field id="number_of_replicas" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="number_of_replicas" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Default Number of Replicas per Index</label>
<frontend_class>validate-number</frontend_class>
</field>
<field id="custom_number_of_shards_and_replicas_per_index" translate="label" sortOrder="61" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="custom_number_of_shards_and_replicas_per_index" translate="label" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Custom settings per Index</label>
<frontend_model>Smile\ElasticsuiteCore\Block\Adminhtml\Form\Field\IndicesSettings\DynamicField</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
</field>
<field id="ghost_timeout" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Time for an index to be considered Ghost (in seconds)</label>
<comment><![CDATA[Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour).]]></comment>
<validate>integer validate-greater-than-zero validate-number-range number-range-3600-172800</validate>
</field>
</group>

</section>
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<number_of_shards>1</number_of_shards>
<number_of_replicas>0</number_of_replicas>
<batch_indexing_size>1000</batch_indexing_size>
<ghost_timeout>172800</ghost_timeout>
</indices_settings>
</smile_elasticsuite_core_base_settings>

Expand Down
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ Autocomplete,Autocomplete
"Custom stemmer","Custom stemmer"
"In the list ""[default]"" indicates the stemmer used by Elasticsuite by default for the language, while ""[recommended]"" indicates the stemmer is the one or one of those recommended for that language by Elasticsearch in its <a href='https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-stemmer-tokenfilter.html#analysis-stemmer-tokenfilter-configure-parms' target='_blank'>online documentation</a>. Those can differ, hence this configuration parameter.","In the list ""[default]"" indicates the stemmer used by Elasticsuite by default for the language, while ""[recommended]"" indicates the stemmer is the one or one of those recommended for that language by Elasticsearch in its <a href='https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-stemmer-tokenfilter.html#analysis-stemmer-tokenfilter-configure-parms' target='_blank'>online documentation</a>. Those can differ, hence this configuration parameter."
"Please select a stemmer for the store","Please select a stemmer for the store"
"Time for an index to be considered Ghost (in seconds)","Time for an index to be considered Ghost (in seconds)"
"Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour).","Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour)."
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ General,Général
"Custom stemmer","Stemmer spécifique"
"In the list ""[default]"" indicates the stemmer used by Elasticsuite by default for the language, while ""[recommended]"" indicates the stemmer is the one or one of those recommended for that language by Elasticsearch in its <a href='https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-stemmer-tokenfilter.html#analysis-stemmer-tokenfilter-configure-parms' target='_blank'>online documentation</a>. Those can differ, hence this configuration parameter.","Dans la liste, ""[default]"" indique le stemmer utilisé par défaut par Elasticsuite pour la langue, tandis que ""[recommended]"" indique que le stemmer est celui ou l'un de deux recommendés pour cette langue par Elasticsearch dans sa <a href='https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-stemmer-tokenfilter.html#analysis-stemmer-tokenfilter-configure-parms' target='_blank'>documentation en ligne</a>. Ceux-ci peuvent différer, d'où l'existence de ce paramètre de configuration."
"Please select a stemmer for the store","Veuillez sélectionner un stemmer pour le magasin"
"Time for an index to be considered Ghost (in seconds)","Temps avant qu'un index soit considéré Fantôme (en secondes)"
"Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour).","Les index Elasticsuite résultant de l'échec d'une ré-indexation complète sont considérés comme fantômes après que cette période de temps (en secondes) s'est écoulée depuis leur création. Vous pouvez réduire cette période de temps pour accélérer la suppression des index fantômes, mais prenez soin d'ajouter une période de sécurité au temps de réindexation maximum de l'index le plus complexe de votre plateforme (généralement un index catalog_product/de recherche produits). Valeur par défaut: 172 800 secondes (2 jours), valeur minimum: 3600 (1 heure)."
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private function isExternal(string $indexName): bool
private function isGhost($indexDate): bool
{
try {
return (new Zend_Date())->sub($indexDate)->getTimestamp() / self::SECONDS_IN_DAY >= self::NUMBER_DAYS_AFTER_INDEX_IS_GHOST;
return (new Zend_Date())->sub($indexDate)->getTimestamp() >= $this->indexSettingsHelper->getTimeBeforeGhost();
} catch (Zend_Date_Exception $e) {
return false;
}
Expand Down

0 comments on commit 86a57d7

Please sign in to comment.