/**
  * Retrieve the server object of the current data center
  *
  * @param      string $server server name
  * @param      PropelPDO $con the connection to use
  * @return     SphinxLogServer
  */
 public static function retrieveByLocalServer($server, PropelPDO $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(SphinxLogServerPeer::SERVER, $server);
     $criteria->add(SphinxLogServerPeer::DC, kDataCenterMgr::getCurrentDcId());
     return SphinxLogServerPeer::doSelectOne($criteria, $con);
 }
Exemple #2
0
$sphinxServer = null;
require_once $configFile;
define('ROOT_DIR', realpath(dirname(__FILE__) . '/../../../'));
require_once ROOT_DIR . '/infra/bootstrap_base.php';
require_once ROOT_DIR . '/infra/KAutoloader.php';
require_once ROOT_DIR . '/alpha/config/kConf.php';
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*"));
KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/sphinx/classMap.cache');
KAutoloader::register();
error_reporting(E_ALL);
KalturaLog::setLogger(new KalturaStdoutLogger());
$dbConf = kConf::getDB();
DbManager::setConfig($dbConf);
DbManager::initialize();
$serverLastLogs = SphinxLogServerPeer::retrieveByServer($sphinxServer);
$lastLogs = array();
foreach ($serverLastLogs as $serverLastLog) {
    $lastLogs[$serverLastLog->getDc()] = $serverLastLog;
}
$sphinxLogs = SphinxLogPeer::retrieveByLastId($lastLogs);
while (true) {
    while (!count($sphinxLogs)) {
        sleep(1);
        $sphinxLogs = SphinxLogPeer::retrieveByLastId($lastLogs);
    }
    $sphinxCon = null;
    try {
        $sphinxCon = DbManager::createSphinxConnection($sphinxServer);
    } catch (Exception $e) {
        KalturaLog::err($e->getMessage());
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(SphinxLogServerPeer::DATABASE_NAME);
         $criteria->add(SphinxLogServerPeer::ID, $pks, Criteria::IN);
         $objs = SphinxLogServerPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     KalturaLog::debug($sql);
     $sphinxConnection = null;
     $sphinxConnectionId = null;
     if (kConf::hasParam('exec_sphinx') && kConf::get('exec_sphinx')) {
         $sphinxConnection = DbManager::getSphinxConnection(false);
         $sphinxServer = SphinxLogServerPeer::retrieveByLocalServer($sphinxConnection->getHostName());
         if ($sphinxServer) {
             $sphinxConnectionId = $sphinxServer->getId();
         }
     }
     $sphinxLog = new SphinxLog();
     $sphinxLog->setExecutedServerId($sphinxConnectionId);
     $sphinxLog->setObjectId($object->getId());
     $sphinxLog->setObjectType(get_class($object));
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!$sphinxConnection) {
         return true;
     }
     $sphinxConnection = DbManager::getSphinxConnection(false);
     $ret = $sphinxConnection->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $sphinxConnection->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }
Exemple #5
0
}
$pid = $systemSettings['LOG_DIR'] . '/populate.pid';
if (file_exists($pid)) {
    KalturaLog::err("Scheduler already running - pid[" . file_get_contents($pid) . "]");
    exit(1);
}
file_put_contents($pid, getmypid());
$dbConf = kConf::getDB();
DbManager::setConfig($dbConf);
DbManager::initialize();
$limit = 1000;
// The number of sphinxLog records we want to query
$gap = 500;
// The gap from 'getLastLogId' we want to query
$sphinxReadConn = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG_READ);
$serverLastLogs = SphinxLogServerPeer::retrieveByServer($sphinxServer, $sphinxReadConn);
$lastLogs = array();
$handledRecords = array();
foreach ($serverLastLogs as $serverLastLog) {
    $lastLogs[$serverLastLog->getDc()] = $serverLastLog;
    $handledRecords[$serverLastLog->getDc()] = array();
}
while (true) {
    $sphinxLogs = SphinxLogPeer::retrieveByLastId($lastLogs, $gap, $limit, $handledRecords, $sphinxReadConn);
    while (!count($sphinxLogs)) {
        $skipExecutedUpdates = true;
        sleep(1);
        $sphinxLogs = SphinxLogPeer::retrieveByLastId($lastLogs, $gap, $limit, $handledRecords, $sphinxReadConn);
    }
    $sphinxCon = null;
    try {
 private function retrieveSphinxConnectionId()
 {
     $sphinxConnectionId = null;
     if (kConf::hasParam('exec_sphinx') && kConf::get('exec_sphinx')) {
         $sphinxConnection = DbManager::getSphinxConnection(false);
         $sphinxServerCacheStore = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_SPHINX_EXECUTED_SERVER);
         if ($sphinxServerCacheStore) {
             $sphinxConnectionId = $sphinxServerCacheStore->get(self::CACHE_PREFIX . $sphinxConnection->getHostName());
             if ($sphinxConnectionId) {
                 return $sphinxConnectionId;
             }
         }
         $sphinxServer = SphinxLogServerPeer::retrieveByLocalServer($sphinxConnection->getHostName());
         if ($sphinxServer) {
             $sphinxConnectionId = $sphinxServer->getId();
             if ($sphinxServerCacheStore) {
                 $sphinxServerCacheStore->set(self::CACHE_PREFIX . $sphinxConnection->getHostName(), $sphinxConnectionId);
             }
         }
     }
     return $sphinxConnectionId;
 }
Exemple #7
0
 /**
  * Returns the number of related SphinxLogServer objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related SphinxLogServer objects.
  * @throws     PropelException
  */
 public function countSphinxLogServers(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(SphinxLogPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collSphinxLogServers === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(SphinxLogServerPeer::LAST_LOG_ID, $this->id);
             $count = SphinxLogServerPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(SphinxLogServerPeer::LAST_LOG_ID, $this->id);
             if (!isset($this->lastSphinxLogServerCriteria) || !$this->lastSphinxLogServerCriteria->equals($criteria)) {
                 $count = SphinxLogServerPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collSphinxLogServers);
             }
         } else {
             $count = count($this->collSphinxLogServers);
         }
     }
     return $count;
 }
 /**
  * Retrieve all records of the server
  *
  * @param      string $server server name
  * @param      PropelPDO $con the connection to use
  * @return     array<SphinxLogServer>
  */
 public static function retrieveByServer($server, PropelPDO $con = null)
 {
     $criteria = new Criteria();
     $criteria->add(SphinxLogServerPeer::SERVER, $server);
     return SphinxLogServerPeer::doSelect($criteria, $con);
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SphinxLogServerPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setServer($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDc($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setLastLogId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setCreatedAt($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setUpdatedAt($arr[$keys[5]]);
     }
 }
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(SphinxLogServerPeer::DATABASE_NAME);
     $criteria->add(SphinxLogServerPeer::ID, $this->id);
     if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(SphinxLogServerPeer::UPDATED_AT)) {
         $theModifiedColumn = null;
         foreach ($this->modifiedColumns as $modifiedColumn) {
             if ($modifiedColumn != SphinxLogServerPeer::UPDATED_AT) {
                 $theModifiedColumn = $modifiedColumn;
             }
         }
         $atomicColumns = SphinxLogServerPeer::getAtomicColumns();
         if (in_array($theModifiedColumn, $atomicColumns)) {
             $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
         }
     }
     return $criteria;
 }