Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-186

MongoDB\Driver\Server of type Secondary routes command to primary

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.4.0
    • Affects Version/s: None
    • Component/s: None
    • None

      --TEST--
      MongoDB\Driver\Server: Manager->getServer() returning correct server
      --SKIPIF--
      <?php require "tests/utils/basic-skipif.inc"?>
      --FILE--
      <?php
      require_once "tests/utils/basic.inc";
      
      $manager = new MongoDB\Driver\Manager(REPLICASET);
      
      
      $doc = array("example" => "document");
      $bulk = new \MongoDB\Driver\BulkWrite();
      $bulk->insert($doc);
      $wresult = $manager->executeBulkWrite(NS, $bulk);
      
      $bulk = new \MongoDB\Driver\BulkWrite();
      $bulk->insert($doc);
      
      /* writes go to the primary */
      $server = $wresult->getServer();
      /* This is the same server */
      $server2 = $server->executeBulkWrite(NS, $bulk)->getServer();
      
      /* Both are the primary, e.g. the same server */
      var_dump($server == $server2);
      
      
      $rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
      /* Fetch a secondary */
      $server3 = $manager->executeQuery(NS, new MongoDB\Driver\Query(array()), $rp)->getServer();
      
      var_dump($server == $server3);
      var_dump($server->getPort(), $server3->getPort());
      
      
      $bulk = new \MongoDB\Driver\BulkWrite();
      $bulk->insert($doc);
      
      $result = $server3->executeBulkWrite(NS, $bulk);
      var_dump($result, $result->getServer()->getPort());
      ?>
      ===DONE===
      <?php exit(0); ?>
      --EXPECTF--
      ===DONE===
      

      The $server3->executeBulkWrite() should fail as it is directed to the secondary. It is however rerouted to the primary and scceeds.

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            bjori Hannes Magnusson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: