You are here

protected function Apache_Solr_Service_Balancer::_selectWriteService in Apache Solr Search 5

Iterate through available write services and select the first with a ping that satisfies configured timeout restrictions (or the default)

Return value

Apache_Solr_Service

Throws

Exception If there are no write services that meet requirements

8 calls to Apache_Solr_Service_Balancer::_selectWriteService()
Apache_Solr_Service_Balancer::add in SolrPhpClient/Apache/Solr/Service/Balancer.php
Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
Apache_Solr_Service_Balancer::addDocument in SolrPhpClient/Apache/Solr/Service/Balancer.php
Add a Solr Document to the index
Apache_Solr_Service_Balancer::addDocuments in SolrPhpClient/Apache/Solr/Service/Balancer.php
Add an array of Solr Documents to the index all at once
Apache_Solr_Service_Balancer::commit in SolrPhpClient/Apache/Solr/Service/Balancer.php
Send a commit command. Will be synchronous unless both wait parameters are set to false.
Apache_Solr_Service_Balancer::delete in SolrPhpClient/Apache/Solr/Service/Balancer.php
Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document

... See full list

File

SolrPhpClient/Apache/Solr/Service/Balancer.php, line 326

Class

Apache_Solr_Service_Balancer
Reference Implementation for using multiple Solr services in a distribution. Functionality includes: routing of read / write operations failover (on selection) for multiple read servers

Code

protected function _selectWriteService($forceSelect = false) {
  if ($this->_useBackoff) {
    return $this
      ->_selectWriteServiceSafe($forceSelect);
  }
  if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) {
    if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect) {

      // we probably had a communication error, ping the current read service, remove it if it times out
      if ($this->_writeableServices[$this->_currentWriteService]
        ->ping($this->_writePingTimeout) === false) {
        $this
          ->removeWriteService($this->_currentWriteService);
      }
    }
    if (count($this->_writeableServices)) {

      // select one of the read services at random
      $ids = array_keys($this->_writeableServices);
      $id = $ids[rand(0, count($ids) - 1)];
      $service = $this->_writeableServices[$id];
      if (is_array($service)) {

        //convert the array definition to a client object
        $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
        $this->_writeableServices[$id] = $service;
      }
      $this->_currentWriteService = $id;
    }
    else {
      throw new Exception('No write services were available');
    }
  }
  return $this->_writeableServices[$this->_currentWriteService];
}