/** * Retrieve all records larger than the id * * @param array $servers<SphinxLogServer> * @param int $gap * @param int $limit * @param array $handledEntries * @param PropelPDO $con the connection to use * @return SphinxLog */ public static function retrieveByLastId(array $servers, $gap = 0, $limit = 1000, array $handledEntries = null, PropelPDO $con = null) { $criteria = new Criteria(); $criterions = null; if (count($servers)) { $criterions = $criteria->getNewCriterion(SphinxLogPeer::ID, null, Criteria::ISNULL); } foreach ($servers as $server) { $dc = $server->getDc(); $crit = $criteria->getNewCriterion(SphinxLogPeer::ID, $server->getLastLogId() - $gap, Criteria::GREATER_THAN); $crit->addAnd($criteria->getNewCriterion(SphinxLogPeer::DC, $dc)); if (!is_null($handledEntries)) { $crit->addAnd($criteria->getNewCriterion(SphinxLogPeer::ID, $handledEntries[$dc], Criteria::NOT_IN)); } $criterions->addOr($crit); } if ($criterions) { $criteria->addAnd($criterions); } $disabledPartnerIds = kConf::get('disable_sphinx_indexing_partners', 'local', array()); if ($disabledPartnerIds) { $criteria->add(SphinxLogPeer::PARTNER_ID, $disabledPartnerIds, Criteria::NOT_IN); } $criteria->addAscendingOrderByColumn(SphinxLogPeer::ID); $criteria->setLimit($limit); return SphinxLogPeer::doSelect($criteria, $con); }
/** * Retrieve all records larger than the id * * @param array $servers<SphinxLogServer> * @param int $limit * @param PropelPDO $con the connection to use * @return SphinxLog */ public static function retrieveByLastId(array $servers, $limit = 1000, PropelPDO $con = null) { $criteria = new Criteria(); $criterions = null; if (count($servers)) { $criterions = $criteria->getNewCriterion(SphinxLogPeer::ID, null, Criteria::ISNULL); } foreach ($servers as $server) { $crit = $criteria->getNewCriterion(SphinxLogPeer::ID, $server->getLastLogId(), Criteria::GREATER_THAN); $crit->addAnd($criteria->getNewCriterion(SphinxLogPeer::DC, $server->getDc())); $criterions->addOr($crit); } if ($criterions) { $criteria->addAnd($criterions); } $criteria->addAscendingOrderByColumn(SphinxLogPeer::ID); $criteria->setLimit($limit); return SphinxLogPeer::doSelect($criteria, $con); }
if (isset($lastLogs[$dc])) { $serverLastLog = $lastLogs[$dc]; if ($serverLastLog->getLastLogId() >= $sphinxLog->getId()) { KalturaLog::debug('Last log id [' . $serverLastLog->getLastLogId() . "] dc [{$dc}] is larger than id [" . $sphinxLog->getId() . "]"); continue; } } else { $serverLastLog = new SphinxLogServer(); $serverLastLog->setServer($sphinxServer); $serverLastLog->setDc($dc); $lastLogs[$dc] = $serverLastLog; } try { $sql = $sphinxLog->getSql(); $affected = $sphinxCon->exec($sql); if (!$affected) { $errorInfo = $sphinxCon->errorInfo(); // if(!preg_match('/^duplicate id/', $errorInfo[2])) // die("No affected records [" . $sphinxCon->errorCode() . "]\n" . print_r($sphinxCon->errorInfo(), true)); } $serverLastLog->setLastLogId($sphinxLog->getId()); $serverLastLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG)); } catch (Exception $e) { KalturaLog::err($e->getMessage()); } } unset($sphinxCon); SphinxLogPeer::clearInstancePool(); $sphinxLogs = SphinxLogPeer::retrieveByLastId($lastLogs); } KalturaLog::log('Done');
/** * Selects a collection of SphinxLogServer objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of SphinxLogServer objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } SphinxLogServerPeer::addSelectColumns($criteria); $startcol2 = SphinxLogServerPeer::NUM_COLUMNS - SphinxLogServerPeer::NUM_LAZY_LOAD_COLUMNS; SphinxLogPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (SphinxLogPeer::NUM_COLUMNS - SphinxLogPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(SphinxLogServerPeer::LAST_LOG_ID, SphinxLogPeer::ID, $join_behavior); $stmt = SphinxLogServerPeer::doSelectStmt($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = SphinxLogServerPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = SphinxLogServerPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = SphinxLogServerPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); SphinxLogServerPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined SphinxLog rows $key2 = SphinxLogPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = SphinxLogPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = SphinxLogPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); SphinxLogPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (SphinxLogServer) to the collection in $obj2 (SphinxLog) $obj2->addSphinxLogServer($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
try { if ($skipExecutedUpdates && $executedServerId == $serverLastLog->getId()) { KalturaLog::log("Sphinx server is initiated and the command already ran synchronously on this machine. Skipping"); } else { $sql = $sphinxLog->getSql(); $affected = $sphinxCon->exec($sql); if (!$affected) { $errorInfo = $sphinxCon->errorInfo(); } } // If the record is an historical record, don't take back the last log id if ($serverLastLog->getLastLogId() < $sphinxLogId) { $serverLastLog->setLastLogId($sphinxLogId); // Clear $handledRecords from before last - gap. foreach ($serverLastLogs as $serverLastLog) { $dc = $serverLastLog->getDc(); $threshold = $serverLastLog->getLastLogId() - $gap; $handledRecords[$dc] = array_filter($handledRecords[$dc], array(new OldLogRecordsFilter($threshold), 'filter')); } } } catch (Exception $e) { KalturaLog::err($e->getMessage()); } } foreach ($lastLogs as $serverLastLog) { $serverLastLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG)); } unset($sphinxCon); SphinxLogPeer::clearInstancePool(); } KalturaLog::log('Done');
public static function cleanMemory() { SphinxLogPeer::clearInstancePool(); // SphinxLogServerPeer::clearInstancePool(); }
/** * 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 = SphinxLogPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setExecutedServerId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setObjectType($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setObjectId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setEntryId($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setPartnerId($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setDc($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setSql($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setCreatedAt($arr[$keys[8]]); } }
/** * Get the associated SphinxLog object * * @param PropelPDO Optional Connection object. * @return SphinxLog The associated SphinxLog object. * @throws PropelException */ public function getSphinxLog(PropelPDO $con = null) { if ($this->aSphinxLog === null && $this->last_log_id !== null) { $this->aSphinxLog = SphinxLogPeer::retrieveByPk($this->last_log_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aSphinxLog->addSphinxLogServers($this); */ } return $this->aSphinxLog; }
/** * 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(SphinxLogPeer::DATABASE_NAME); $criteria->add(SphinxLogPeer::ID, $pks, Criteria::IN); $objs = SphinxLogPeer::doSelect($criteria, $con); } return $objs; }