Skip to content
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

Merged
merged 18 commits into from
May 19, 2019

Conversation

yossipapi
Copy link
Collaborator

No description provided.

@yossipapi yossipapi changed the base branch from Naos-14.8.0 to Naos-14.13.0 January 29, 2019 10:00
@kaltura-hooks
Copy link

Hi @yossipapi,
Thank you for contributing this pull request!
Please sign the Kaltura CLA so we can review and merge your contribution.
Learn more at http://bit.ly/KalturaContrib

@yossipapi yossipapi changed the base branch from Naos-14.13.0 to Naos-14.14.0 February 17, 2019 13:29
@yossipapi yossipapi changed the base branch from Naos-14.14.0 to Naos-14.18.0 April 7, 2019 10:55
@yossipapi yossipapi changed the base branch from Naos-14.18.0 to Naos-14.19.0 April 28, 2019 12:24
@yossipapi yossipapi changed the base branch from Naos-14.19.0 to Naos-14.20.0 April 29, 2019 10:16
{
if (!self::$sphinxCache || self::$connIndex === self::$cachedConnIndex)
if (!self::$sphinxCache || isset(self::$connIndexes[$indexName]) === isset(self::$cachedConnIndexes[$indexName]))
Copy link
Contributor

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) . "]");
Copy link
Contributor

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]))
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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"]))
Copy link
Contributor

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"];
Copy link
Contributor

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)
Copy link
Contributor

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();
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{}

@yossipapi yossipapi changed the base branch from Naos-14.20.0 to Orion-15.0.0 May 15, 2019 14:02
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) . "]");
Copy link
Contributor

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']))
Copy link
Contributor

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'];
Copy link
Contributor

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);
Copy link
Contributor

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. "]");
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{}


}

public static function getSphinxSplitIndexId($originalValue = null, $IndexObjectName)
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{}

@yossipapi yossipapi merged commit 3310eb0 into Orion-15.0.0 May 19, 2019
@yossipapi yossipapi deleted the Naos-14.8.0-PLAT-9401 branch May 19, 2019 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants