mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
added some distributed reads doc
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@305864 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7f2c77fd73
commit
ffc053f605
12 changed files with 841 additions and 1 deletions
155
reference/mongo/mongo/gethosts.xml
Normal file
155
reference/mongo/mongo/gethosts.xml
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongo.getHosts" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Mongo::getHosts</refname>
|
||||
<refpurpose>Updates status for all hosts associated with this</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>array</type><methodname>Mongo::getHosts</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
This method can only be used with a connection to a replica set. It returns
|
||||
the status of all of the hosts in the set and updates the connection
|
||||
information (the updating is invisible to the user).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
This is called automatically by the driver every five seconds.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns an array of information about the hosts in the set. Includes each
|
||||
host's hostname, id in the set, health (1 is healthy), the uptime, and how
|
||||
up-to-date the host is compared to the primary. For example, on a
|
||||
three-member replica set running locally, it might look something like:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Array
|
||||
(
|
||||
[ubuntu:27017] => Array
|
||||
(
|
||||
[_id] => 0
|
||||
[name] => ubuntu:27017
|
||||
[health] => 1
|
||||
[state] => 1
|
||||
[stateStr] => PRIMARY
|
||||
[optime] => MongoTimestamp Object
|
||||
(
|
||||
[sec] => 1
|
||||
[inc] => 1291155754
|
||||
)
|
||||
|
||||
[optimeDate] => MongoDate Object
|
||||
(
|
||||
[sec] => 1291155754
|
||||
[usec] => 0
|
||||
)
|
||||
|
||||
[self] => 1
|
||||
)
|
||||
|
||||
[ubuntu:27019] => Array
|
||||
(
|
||||
[_id] => 2
|
||||
[name] => ubuntu:27019
|
||||
[health] => 1
|
||||
[state] => 2
|
||||
[stateStr] => SECONDARY
|
||||
[uptime] => 91928
|
||||
[optime] => MongoTimestamp Object
|
||||
(
|
||||
[sec] => 1
|
||||
[inc] => 1291155754
|
||||
)
|
||||
|
||||
[optimeDate] => MongoDate Object
|
||||
(
|
||||
[sec] => 1291155754
|
||||
[usec] => 0
|
||||
)
|
||||
|
||||
[lastHeartbeat] => MongoDate Object
|
||||
(
|
||||
[sec] => 1291158846
|
||||
[usec] => 0
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[ubuntu:27018] => Array
|
||||
(
|
||||
[_id] => 1
|
||||
[name] => ubuntu:27018
|
||||
[health] => 1
|
||||
[state] => 2
|
||||
[stateStr] => SECONDARY
|
||||
[uptime] => 91944
|
||||
[optime] => MongoTimestamp Object
|
||||
(
|
||||
[sec] => 1
|
||||
[inc] => 1291155754
|
||||
)
|
||||
|
||||
[optimeDate] => MongoDate Object
|
||||
(
|
||||
[sec] => 1291155754
|
||||
[usec] => 0
|
||||
)
|
||||
|
||||
[lastHeartbeat] => MongoDate Object
|
||||
(
|
||||
[sec] => 1291158846
|
||||
[usec] => 0
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
]]>
|
||||
</screen>
|
||||
<para>
|
||||
This returns &null; if the connection is not connected to a replica set or
|
||||
has not been initialized, yet.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
65
reference/mongo/mongo/getslave.xml
Normal file
65
reference/mongo/mongo/getslave.xml
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongo.getslave" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Mongo::getSlave</refname>
|
||||
<refpurpose>Returns the address being used by this for slaveOkay reads</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>string</type><methodname>Mongo::getSlave</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
This finds the address of the slave currently being used for reads. It is a
|
||||
read-only method: it does not change anything about the internal state of the
|
||||
object.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
The address of the slave this connection is using for reads.
|
||||
</para>
|
||||
<para>
|
||||
This returns &null; if this is not connected to a replica set or not yet
|
||||
initialized.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
53
reference/mongo/mongo/getslaveokay.xml
Normal file
53
reference/mongo/mongo/getslaveokay.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongo.getslaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Mongo::getSlaveOkay</refname>
|
||||
<refpurpose>Get slaveOkay setting for this connection</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>boolean</type><methodname>Mongo::getSlaveOkay</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns the value of slaveOkay for this instance.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
67
reference/mongo/mongo/setslaveokay.xml
Normal file
67
reference/mongo/mongo/setslaveokay.xml
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongo.setslaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Mongo::setSlaveOkay</refname>
|
||||
<refpurpose>Change slaveOkay setting for this connection</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>boolean</type><methodname>Mongo::setSlaveOkay</methodname>
|
||||
<methodparam><type>boolean</type><parameter>ok</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
<para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<parameter>ok</parameter>
|
||||
</term>
|
||||
<listitem>
|
||||
<para>
|
||||
If reads should be sent to secondary members of a replica set for all
|
||||
possible queries using this <classname>Mongo</classname> instance.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns the former value of slaveOkay for this instance.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
81
reference/mongo/mongo/switchslave.xml
Normal file
81
reference/mongo/mongo/switchslave.xml
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongo.switchslave" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Mongo::switchSlave</refname>
|
||||
<refpurpose>Choose a new slave for slaveOkay reads</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>string</type><methodname>Mongo::switchSlave</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
This choses a random slave for a connection to read from. It is called
|
||||
automatically by the driver and should not need to be used. It calls
|
||||
<function>Mongo::getHosts</function> (to refresh the status of hosts) and
|
||||
<function>Mongo::getSlave</function> (to get the return value).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
The address of the slave this connection is using for reads. This may be the
|
||||
same as the previous address as addresses are randomly chosen. It may return
|
||||
only one address if only one secondary (or only the primary) is available.
|
||||
</para>
|
||||
<para>
|
||||
For example, if we had a three member replica set with a primary, secondary,
|
||||
and arbiter this method would always return the address of the secondary.
|
||||
If the secondary became unavailable, this method would always return the
|
||||
address of the primary. If the primary also became unavailable, this method
|
||||
would throw an exception, as an arbiter cannot handle reads.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="errors">
|
||||
&reftitle.errors;
|
||||
<para>
|
||||
Throws a <classname>MongoException</classname> (error code 15) if it is
|
||||
called on a non-replica-set connection. It will also throw
|
||||
<classname>MongoException</classname>s if it cannot find anyone (primary or
|
||||
secondary) to read from (error code 16).
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
53
reference/mongo/mongocollection/getslaveokay.xml
Normal file
53
reference/mongo/mongocollection/getslaveokay.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongocollection.getslaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoCollection::getSlaveOkay</refname>
|
||||
<refpurpose>Get slaveOkay setting for this collection</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>boolean</type><methodname>MongoCollection::getSlaveOkay</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns the value of slaveOkay for this instance.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
68
reference/mongo/mongocollection/setslaveokay.xml
Normal file
68
reference/mongo/mongocollection/setslaveokay.xml
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongocollection.setslaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoCollection::setSlaveOkay</refname>
|
||||
<refpurpose>Change slaveOkay setting for this collection</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>boolean</type><methodname>MongoCollection::setSlaveOkay</methodname>
|
||||
<methodparam><type>boolean</type><parameter>ok</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
<para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<parameter>ok</parameter>
|
||||
</term>
|
||||
<listitem>
|
||||
<para>
|
||||
If reads should be sent to secondary members of a replica set for all
|
||||
possible queries using this <classname>MongoCollection</classname>
|
||||
instance.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns the former value of slaveOkay for this instance.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongocursor.slaveOkay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refentry xml:id="mongocursor.slaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoCursor::slaveOkay</refname>
|
||||
<refpurpose>Sets whether this query can be done on a slave</refpurpose>
|
||||
|
|
53
reference/mongo/mongodb/getslaveokay.xml
Normal file
53
reference/mongo/mongodb/getslaveokay.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongodb.getslaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoDB::getSlaveOkay</refname>
|
||||
<refpurpose>Get slaveOkay setting for this database</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>boolean</type><methodname>MongoDB::getSlaveOkay</methodname>
|
||||
<void/>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns the value of slaveOkay for this instance.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
67
reference/mongo/mongodb/setslaveokay.xml
Normal file
67
reference/mongo/mongodb/setslaveokay.xml
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- $Revision$ -->
|
||||
<refentry xml:id="mongodb.setslaveokay" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>MongoDB::setSlaveOkay</refname>
|
||||
<refpurpose>Change slaveOkay setting for this database</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>boolean</type><methodname>MongoDB::setSlaveOkay</methodname>
|
||||
<methodparam><type>boolean</type><parameter>ok</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
|
||||
<para>
|
||||
See <link linkend="mongo.queries">the query section</link> of this manual for
|
||||
information on distributing reads to slaves.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
<para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<parameter>ok</parameter>
|
||||
</term>
|
||||
<listitem>
|
||||
<para>
|
||||
If reads should be sent to secondary members of a replica set for all
|
||||
possible queries using this <classname>MongoDB</classname> instance.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
Returns the former value of slaveOkay for this instance.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||
vim: et tw=78 syn=sgml
|
||||
vi: ts=1 sw=1
|
||||
-->
|
|
@ -3,6 +3,175 @@
|
|||
<section xml:id="mongo.queries" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Querying</title>
|
||||
|
||||
<section>
|
||||
<title>Distributing queries to slaves</title>
|
||||
|
||||
<note>
|
||||
<title>1.1.0+</title>
|
||||
<para>
|
||||
If you are using a
|
||||
<link xlink:href="&url.mongodb.replica;">replica set</link> and version
|
||||
1.1.0 or above of the driver, the driver can automatically route reads to
|
||||
slaves. This behavior does not exist in earlier versions of the driver and
|
||||
<emphasis>cannot</emphasis> be used with "normal" master-slave.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<para>
|
||||
By default, the driver will send all queries to the master. If you set the
|
||||
"slaveOkay" option, the driver will send all queries to a non-primary server,
|
||||
if possible. The "slaveOkay" option can be set at every "level":
|
||||
<link linkend="mongo.setslaveokay">connection</link>,
|
||||
<link linkend="mongodb.setslaveokay">database</link>,
|
||||
<link linkend="mongocollection.setslaveokay">collection</link>, and
|
||||
<link linkend="mongocursor.slaveokay">cursor</link>. Each class inherits the
|
||||
"slaveOkay" setting from the class above it, so if you do:
|
||||
</para>
|
||||
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$db->setSlaveOkay(true);
|
||||
$c = $db->myCollection;
|
||||
|
||||
$cursor = $c->find();
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
||||
<para>
|
||||
then the query will be executed against a slave (the collection inherited
|
||||
"slaveOkay" from the database and the cursor inherited it from the
|
||||
collection).
|
||||
</para>
|
||||
|
||||
<section>
|
||||
<title>How slaves are chosen</title>
|
||||
|
||||
<para>
|
||||
Each instance of <classname>Mongo</classname> gets its own slave, randomly
|
||||
chosen from the readable slaves. This holds, even if you are using
|
||||
persistent connections. So, if we do something like:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// connects to a replica set with members ip0, ip1, and ip2
|
||||
// ip0 is the primary, ip1 and ip2 are secondaries
|
||||
$m1 = new Mongo("mongodb://ip0", array("replicaSet" => true, "persist" => "x"));
|
||||
echo "m1's slave is ".$m1->getSlave()."\n";
|
||||
|
||||
// uses the same connection as $m1
|
||||
$m2 = new Mongo("mongodb://ip0", array("replicaSet" => true, "persist" => "x"));
|
||||
echo "m2's slave is ".$m2->getSlave()."\n";
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
we'd probably end up with something like:
|
||||
</para>
|
||||
<screen>
|
||||
m1's slave is: ip2
|
||||
m2's slave is: ip1
|
||||
</screen>
|
||||
|
||||
<para>
|
||||
If we continued to create new <classname>Mongo</classname>s, we should get a
|
||||
fairly even distribution between ip1 and ip2.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Slaves are chosen on a per-instance basis and do no change (unless something
|
||||
bad happens to your set and they are forced to).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
You can see what the driver thinks is the current status of the set members
|
||||
by running <function>Mongo::getHosts</function>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If no non-primary server is readable, the driver will send
|
||||
reads to the primary (even if "slaveOkay" is set). A server is considered
|
||||
readable if its state is 2 (SECONDARY) and its health is 1. You can check
|
||||
this with <function>Mongo::getHosts</function> (some fields omitted for
|
||||
clarity):
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
Array
|
||||
(
|
||||
[ubuntu:27017] => Array
|
||||
(
|
||||
[_id] => 0
|
||||
[name] => ip0
|
||||
[health] => 1
|
||||
[state] => 1
|
||||
[stateStr] => PRIMARY
|
||||
)
|
||||
|
||||
[ubuntu:27019] => Array
|
||||
(
|
||||
[_id] => 2
|
||||
[name] => ip1
|
||||
[health] => 1
|
||||
[state] => 2
|
||||
[stateStr] => SECONDARY
|
||||
)
|
||||
|
||||
[ubuntu:27018] => Array
|
||||
(
|
||||
[_id] => 1
|
||||
[name] => ip2
|
||||
[health] => 1
|
||||
[state] => 2
|
||||
[stateStr] => SECONDARY
|
||||
)
|
||||
|
||||
)
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The set above has two readable servers, "ip1" and "ip2". If both of
|
||||
these went down or became stale, reads would go to "ip0".
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If you enjoy twiddling knobs that you probably shouldn't mess with, you can
|
||||
force the driver to use a different slave by calling
|
||||
<function>Mongo::switchSlave</function>. This randomly chooses a new slave
|
||||
to use and shouldn't be used unless you know what you're doing.
|
||||
</para>
|
||||
|
||||
</section>
|
||||
<section>
|
||||
<title>Random notes</title>
|
||||
|
||||
<para>
|
||||
Writes are always sent to the primary. Database commands, even read-only
|
||||
commands, are also always sent to the primary.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The health and state of a slave is checked every 5 seconds or when the next
|
||||
operation occurs after 5 seconds. It will also recheck the configuration
|
||||
when the driver has a problem reaching a server. You can manually force the
|
||||
driver to update the status by calling <function>Mongo::getHosts</function>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Note that a non-primary server may be behind the primary in operations, so
|
||||
your application must be okay with getting out-of-date data (or you must use
|
||||
w for all writes).
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Querying by _id</title>
|
||||
<para>
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
<function name='mongo::selectDB' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongo::selectCollection' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongo::listDBs' from='PECL mongo >=1.0.4'/>
|
||||
<function name='mongo::setslaveokay' from='PECL mongo >=1.1.0'/>
|
||||
<function name='mongo::getslaveokay' from='PECL mongo >=1.1.0'/>
|
||||
<function name='mongo::gethosts' from='PECL mongo >=1.1.0'/>
|
||||
<function name='mongo::getslave' from='PECL mongo >=1.1.0'/>
|
||||
<function name='mongo::switchslave' from='PECL mongo >=1.1.0'/>
|
||||
<!-- MongoDB -->
|
||||
<function name='mongodb::__construct' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongodb::__tostring' from='PECL mongo >=0.9.0'/>
|
||||
|
@ -41,6 +46,8 @@
|
|||
<function name='mongodb::forceerror' from='PECL mongo >=0.9.5'/>
|
||||
<function name='mongodb::reseterror' from='PECL mongo >=0.9.5'/>
|
||||
<function name='mongodb::authenticate' from='PECL mongo >=1.0.1'/>
|
||||
<function name='mongodb::setslaveokay' from='PECL mongo >=1.1.0'/>
|
||||
<function name='mongodb::getslaveokay' from='PECL mongo >=1.1.0'/>
|
||||
<!-- MongoCollection -->
|
||||
<function name='mongocollection::__construct' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::__tostring' from='PECL mongo >=0.9.0'/>
|
||||
|
@ -63,6 +70,8 @@
|
|||
<function name='mongocollection::createdbref' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::getdbref' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocollection::group' from='PECL mongo >=0.9.2'/>
|
||||
<function name='mongocollection::setslaveokay' from='PECL mongo >=1.1.0'/>
|
||||
<function name='mongocollection::getslaveokay' from='PECL mongo >=1.1.0'/>
|
||||
<!-- MongoCursor -->
|
||||
<function name='mongocursor::__construct' from='PECL mongo >=0.9.0'/>
|
||||
<function name='mongocursor::hasnext' from='PECL mongo >=0.9.0'/>
|
||||
|
|
Loading…
Reference in a new issue