-
Notifications
You must be signed in to change notification settings - Fork 174
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
PLAT-9401: Support working with sphinx indexes which are distributed over several machines (split index) #7828
Conversation
…distributed over several machines (split index)
Hi @yossipapi, |
… Naos-14.8.0-PLAT-9401
…function by index generator
… Naos-14.8.0-PLAT-9401
{ | ||
if (!self::$sphinxCache || self::$connIndex === self::$cachedConnIndex) | ||
if (!self::$sphinxCache || isset(self::$connIndexes[$indexName]) === isset(self::$cachedConnIndexes[$indexName])) |
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.
Did you mean checking if both are set (or both false) , or comparing the names ?
KalturaLog::debug("Setting sphinx sticky session for key [" . self::$stickySessionKey . "] to sphinx index [" . self::$connIndex . "]"); | ||
self::$sphinxCache->set(self::$stickySessionKey, self::$connIndex, $stickySessionExpiry); | ||
self::$cachedConnIndex = self::$connIndex; | ||
KalturaLog::debug("Setting sphinx sticky session for key [" . self::$stickySessionKey . "] to sphinx index [" . print_r(self::$connIndexes, true) . "]"); |
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.
Better use single quote since no process is done inside the string,
KalturaLog::debug("Got sphinx sticky session for key [" . self::$stickySessionKey . "] to sphinx index [" . $preferredIndex . "]"); | ||
if ($preferredIndex === false) | ||
KalturaLog::debug("Got sphinx sticky session for key [" . self::$stickySessionKey . "] to sphinx index [" . print_r($preferredIndex, true) . "]"); | ||
if ($preferredIndex === false || !isset($preferredIndex[$indexName])) |
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.
Coding standard use {}
} | ||
|
||
protected static function getSphinxConnIndexFromCache() | ||
protected static function getSphinxConnIndexFromCache($indexName = null) |
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.
Function name implies on get , but it changes the state by updating - self::$cachedConnIndexes.
Rename function of break to 2 sub functions - getSphinxConnIndexFromCache and Update
@@ -233,35 +233,40 @@ protected static function getStickySessionKey() | |||
/** | |||
* @return KalturaPDO | |||
*/ | |||
public static function getSphinxConnection($read = true) | |||
public static function getSphinxConnection($read = true, $indexName = null) |
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.
Why not set default indexName to 'default_index'?
$object->setIndexName($indexName); | ||
|
||
$splitIndexFieldName = null; | ||
if(isset($objectAttribtues["splitIndexFieldName"])) |
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.
{}
|
||
$splitIndexFieldName = null; | ||
if(isset($objectAttribtues["splitIndexFieldName"])) | ||
$splitIndexFieldName = $indexName . "." . $objectAttribtues["splitIndexFieldName"]; |
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.
Better use const for splitIndexFieldName
*/ | ||
public function getEntry() | ||
{ | ||
if ($this->getObjectType() == MetadataObjectType::ENTRY) |
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 function returns the index name to use | ||
*/ | ||
public function getSphinxIndexName(); |
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 function can be implemented once instead of 13 times in an abstract class that all relevant classes will inherit from , and it will inherit baseObject.
function getSphinxIndexName()
{
$IndexClass = $this->getIndexObjectName();
return kSphinxSearchManager::getSphinxIndexName($IndexClass::getObjectIndexName());
}
|
||
foreach ($sphinxTablesData as $sphinxTableData) | ||
{ | ||
if($sphinxTableData['Type'] == "rt") |
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.
{}
KalturaLog::debug("Setting sphinx sticky session for key [" . self::$stickySessionKey . "] to sphinx index [" . self::$connIndex . "]"); | ||
self::$sphinxCache->set(self::$stickySessionKey, self::$connIndex, $stickySessionExpiry); | ||
self::$cachedConnIndex = self::$connIndex; | ||
KalturaLog::debug("Setting sphinx sticky session for key [" . self::$stickySessionKey . "] to sphinx index [" . print_r(self::$connIndexes, true) . "]"); |
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.
Use single ' since no processing
{ | ||
$sphinxDS = isset(self::$config['sphinx_datasources']['datasources']) ? self::$config['sphinx_datasources']['datasources'] : array(self::DB_CONFIG_SPHINX); | ||
if($indexName && isset(self::$config['sphinx_datasources_'.$indexName]) && isset(self::$config['sphinx_datasources_'.$indexName]['datasources'])) |
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.
No need to check - isset(self::$config['sphinx_datasources_'.$indexName]), isset will return false to $config['sphinx_datasources_'.$indexName]['datasources'] even if self::$config['sphinx_datasources_'.$indexName] no exist.
{ | ||
$sphinxDS = isset(self::$config['sphinx_datasources']['datasources']) ? self::$config['sphinx_datasources']['datasources'] : array(self::DB_CONFIG_SPHINX); | ||
if($indexName && isset(self::$config['sphinx_datasources_'.$indexName]) && isset(self::$config['sphinx_datasources_'.$indexName]['datasources'])) | ||
$sphinxDS = self::$config['sphinx_datasources_'.$indexName]['datasources']; |
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($indexName && isset(self::$config['sphinx_datasources_'.$indexName]) && isset(self::$config['sphinx_datasources_'.$indexName]['datasources'])) | ||
$sphinxDS = self::$config['sphinx_datasources_'.$indexName]['datasources']; | ||
else | ||
$sphinxDS = isset(self::$config['sphinx_datasources']['datasources']) ? self::$config['sphinx_datasources']['datasources'] : array(self::DB_CONFIG_SPHINX); |
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 isset(self::$config['sphinx_datasources_'.$indexName]['datasources']) is true, but it has empty value, you will not reach the else.
Better add isset(self::$config['sphinx_datasources_'.$indexName]['datasources']) to the condition above , and if it fails , set array array(self::DB_CONFIG_SPHINX)
{ | ||
throw new Exception('Failed to connect to any Sphinx config'); | ||
} | ||
KalturaLog::debug("Actual sphinx index [". self::$connIndex. "] sphinx index by best lag [" . $preferredIndex. "]"); | ||
KalturaLog::debug("Actual sphinx index [". self::$connIndexes[$indexName]. "] sphinx index by best lag [" . $preferredIndex. "]"); |
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.
prefer ' ( no processing )
|
||
$splitIndexFactor = self::getSplitIndexFactor($IndexObjectName); | ||
if(!$splitIndexFactor) | ||
return null; |
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.
{}
alpha/lib/index/BaseIndexObject.php
Outdated
|
||
} | ||
|
||
public static function getSphinxSplitIndexId($originalValue = null, $IndexObjectName) |
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 there a case where $originalValue can be null? or will be called without values? If so why originalValue with default value is not last
@@ -307,6 +308,10 @@ private function getSphinxIdField($fp, IndexableObject $object) { | |||
$this->printToFile($fp, "return '" . $object->indexId . "';",2); | |||
} | |||
|
|||
private function getSphinxSplitIndexFieldName($fp, IndexableObject $object) { |
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.
jump line - {
/** | ||
* @param string splitIndexFieldName | ||
*/ | ||
public function setSplitIndexFieldName($splitIndexFieldName) { |
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 self::SPHINX_INDEX_NAME . '_' . $baseName; | ||
$res = self::SPHINX_INDEX_NAME . '_' . $baseName; | ||
if(isset($splitIndexValue)) |
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.
{}
No description provided.