/**
  * @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;
 }
예제 #2
0
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     // limit the number of large sphinx SQLs to 1/min per object, since they load the sphinx database
     // and sphinx servers. the upper limit of 'slightly less than 1MB' is because of the max_allowed_packet
     // limit in mysql (by default 1MB). the upper limit is here to prevent the addition of too many category
     // users (for example), that will render the category un-indexable
     if (strlen($sql) > 128 * 1024 && strlen($sql) < 1000000) {
         $lockKey = 'large_sql_lock_' . get_class($object) . '_' . $object->getId();
         $cache = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_SPHINX_STICKY_SESSIONS);
         if ($cache && !$cache->add($lockKey, true, 60)) {
             KalturaLog::log('skipping sql for key ' . $lockKey);
             return;
         }
     }
     KalturaLog::debug($sql);
     $sphinxLog = new SphinxLog();
     $sphinxLog->setExecutedServerId($this->retrieveSphinxConnectionId());
     $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 (!kConf::get('exec_sphinx', 'local', 0)) {
         return true;
     }
     $sphinxConnection = DbManager::getSphinxConnection(false);
     $ret = $sphinxConnection->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $sphinxConnection->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }