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

Change populateFromLog to load shredded index config from db config file #8676

Merged
merged 2 commits into from Jul 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions plugins/search/providers/sphinx_search/scripts/populateFromLog.php
Expand Up @@ -59,6 +59,12 @@ function filter($i) {
DbManager::setConfig($dbConf);
DbManager::initialize();

$splitIndexSettings = null;
if(isset($dbConf['sphinx_split_index']) && $dbConf['sphinx_split_index']['enabled'] == true)
{
$splitIndexSettings = $dbConf['sphinx_split_index'];
}

$limit = 1000; // The number of sphinxLog records we want to query
$gap = 500; // The gap from 'getLastLogId' we want to query

Expand All @@ -67,8 +73,10 @@ function filter($i) {
$serverLastLogs = SphinxLogServerPeer::retrieveByServer($sphinxServer, $sphinxReadConn);
$lastLogs = array();
$handledRecords = array();
$sphinxRtTables = getSphinxRtTables($sphinxCon);

foreach($serverLastLogs as $serverLastLog) {
foreach($serverLastLogs as $serverLastLog)
{
$lastLogs[$serverLastLog->getDc()] = $serverLastLog;
$handledRecords[$serverLastLog->getDc()] = array();
}
Expand All @@ -88,7 +96,6 @@ function filter($i) {
try
{
$sphinxCon = DbManager::createSphinxConnection($sphinxServer,$sphinxPort);
$sphinxRtTables = getSphinxRtTables($sphinxCon);
KalturaLog::log("sphinxServer [$sphinxServer], running rt index names [" . implode(",", $sphinxRtTables) . "]");
}
catch(Exception $e)
Expand All @@ -105,7 +112,11 @@ function filter($i) {
$executedServerId = $sphinxLog->getExecutedServerId();
$sphinxLogId = $sphinxLog->getId();
$sphinxLogIndexName = $sphinxLog->getIndexName();

if($isSharded && preg_match('~[0-9]~', $sphinxLogIndexName) == 0 && $splitIndexSettings && isset($splitIndexSettings[$sphinxLog->getObjectType()]))
{
$splitFactor = $splitIndexSettings[$sphinxLog->getObjectType()];
$sphinxLogIndexName = $sphinxLogIndexName . "_" . ($sphinxLog->getPartnerId()/$splitFactor)%$splitFactor;
}

if($isSharded && $sphinxLogIndexName && !in_array($sphinxLogIndexName, $sphinxRtTables))
{
Expand Down Expand Up @@ -139,10 +150,9 @@ function filter($i) {
else
{
$sql = $sphinxLog->getSql();
if($isSharded && $sphinxLog->getObjectType() == "entry")
if($isSharded)
{
$shardedIndexName = $sphinxLog->getIndexName() ? $sphinxLog->getIndexName() : "kaltura_entry_" . ($sphinxLog->getPartnerId()/10)%10;
$sql = str_replace("kaltura_entry", $shardedIndexName, $sql);
$sql = preg_replace('/replace into (kaltura_.*?) /', "replace into $sphinxLogIndexName ", $sql);
}

// sql update commands are created only via an external script for updating entries plays count
Expand Down