db_cluster_admin.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. This module provides a generic database clustering system. It can be
  15. used as a middle layer between modules and database connectors.
  16. </para>
  17. <para>
  18. Via clustering, database operations can be executed across multiple
  19. servers, based on policies such as parallel write, serial or round
  20. robin write and read.
  21. </para>
  22. <para>
  23. The following database commands are considered to be write operations:
  24. INSERT, DELETE, UPDATE, REPLACE, INSERT-DELAYED, INSERT-UPDATE. The
  25. read operations are done for database commands: QUERY and RAW-QUERY.
  26. </para>
  27. </section>
  28. <section>
  29. <title>Dependencies</title>
  30. <section>
  31. <title>&kamailio; Modules</title>
  32. <para>
  33. The following modules must be loaded before this module:
  34. <itemizedlist>
  35. <listitem>
  36. <para>
  37. <emphasis>db connector</emphasis> - database connectors.
  38. </para>
  39. </listitem>
  40. </itemizedlist>
  41. </para>
  42. </section>
  43. <section>
  44. <title>External Libraries or Applications</title>
  45. <para>
  46. The following libraries or applications must be installed before running
  47. &kamailio; with this module loaded:
  48. <itemizedlist>
  49. <listitem>
  50. <para>
  51. <emphasis>None</emphasis>
  52. </para>
  53. </listitem>
  54. </itemizedlist>
  55. </para>
  56. </section>
  57. </section>
  58. <section>
  59. <title>Parameters</title>
  60. <section id="db_cluster.p.connection">
  61. <title><varname>connection</varname> (str)</title>
  62. <para>
  63. Specify the connection to a real database system. The format is
  64. 'conid=>DBURL' - providing a connection id and the database
  65. URL used by the database driver used.
  66. </para>
  67. <para>
  68. <emphasis>
  69. Default value is NULL.
  70. </emphasis>
  71. </para>
  72. <example>
  73. <title>Set <varname>connection</varname> parameter</title>
  74. <programlisting format="linespecific">
  75. ...
  76. modparam("db_cluster", "connection",
  77. "con1=>mysql://kamailio:kamailiorw@localhost/kamailio1")
  78. modparam("db_cluster", "connection",
  79. "con2=>mysql://kamailio:kamailiorw@localhost/kamailio2")
  80. ...
  81. </programlisting>
  82. </example>
  83. </section>
  84. <section id="db_cluster.p.cluster">
  85. <title><varname>cluster</varname> (str)</title>
  86. <para>
  87. Specify the cluster definition. The format is
  88. 'clsid=>conid1=def1;conid2=def2' - providing a cluster id and the list of
  89. database connections to be used. For each connection you have to provide
  90. a usage definition. The usage definition is a 4-char long string,
  91. specifying priority and command mode for read and write operations to be
  92. performed on that connection.
  93. </para>
  94. <para>
  95. The priority is a digit between 0 and 9, where a higher value means higher priority.
  96. Priority 0 means that the connection is not going to be used in that cluster.
  97. </para>
  98. <para>
  99. Command mode is a character among s, r and p. s is for doing serial
  100. operations (try first and if fails, try next); r is for doing round
  101. robin operations; p - is for doing parallel operations (this is valid
  102. only for write operations).
  103. </para>
  104. <para>
  105. <para>
  106. The first two characters is priority and mode for read, followed by
  107. two characters for priority and mode for write operations. "p" is
  108. only used for write operations.
  109. </para>
  110. <emphasis>
  111. Default value is NULL.
  112. </emphasis>
  113. </para>
  114. <example>
  115. <title>Set <varname>cluster</varname> parameter</title>
  116. <programlisting format="linespecific">
  117. ...
  118. modparam("db_cluster", "cluster", "cls1=>con1=9s8p;con2=9s8p")
  119. ...
  120. </programlisting>
  121. </example>
  122. </section>
  123. <section id="db_cluster.p.inactive_interval">
  124. <title><varname>inactive_interval</varname> (int)</title>
  125. <para>
  126. How long (seconds) a connection is considered inactive after a DB
  127. operations failed on it.
  128. </para>
  129. <para>
  130. <emphasis>
  131. Default value is 300 (5 min).
  132. </emphasis>
  133. </para>
  134. <example>
  135. <title>Set <varname>inactive_interval</varname> parameter</title>
  136. <programlisting format="linespecific">
  137. ...
  138. modparam("db_cluster", "inactive_interval", 180)
  139. ...
  140. </programlisting>
  141. </example>
  142. </section>
  143. <section id="db_cluster.p.max_query_length">
  144. <title><varname>max_query_length</varname> (int)</title>
  145. <para>
  146. How long (seconds) a failed db operation needs to last before
  147. deactivating the connection for inactive_interval seconds. This
  148. prevents disabling of connections that reply fast with error
  149. codes, thus being active (e.g., due to primary key insert errors).
  150. In such cases, the database server is active.
  151. </para>
  152. <para>
  153. <emphasis>
  154. Default value is 0.
  155. </emphasis>
  156. </para>
  157. <example>
  158. <title>Set <varname>max_query_length</varname> parameter</title>
  159. <programlisting format="linespecific">
  160. ...
  161. modparam("db_cluster", "max_query_length", 5)
  162. ...
  163. </programlisting>
  164. </example>
  165. </section>
  166. </section>
  167. <section>
  168. <title>Usage</title>
  169. <para>
  170. Practically, all the modules that want to use a cluster, have to set
  171. their db_url parameter to "cluster://clusterid".
  172. </para>
  173. <para>
  174. Following rules apply when doing DB commands: the connecions with highest
  175. priority are chosen first and the operations are performed according
  176. to the command mode. Note that for same priority, only one command mode
  177. is used (the one from the first connection with that priority found
  178. in the definition of the cluster). If the DB command is not successful,
  179. next set of connections based on priority is selected and the command is
  180. tried again. When the command is successful, no other try is made.
  181. </para>
  182. <para>
  183. For parallel operations, a command is considered successful if it
  184. succeeded on one connection from a group with same priority.
  185. </para>
  186. <para>
  187. Next example shows how to set a cluster with two connections to MySQL
  188. to be used for parallel writing from acc and round-robin reading by
  189. sqlops.
  190. </para>
  191. <example>
  192. <title>Sample of usage</title>
  193. <programlisting format="linespecific">
  194. ...
  195. modparam("db_cluster", "connection",
  196. "c1=&gt;mysql://kamailio:kamailiorw@localhost/kamailio1")
  197. modparam("db_cluster", "connection",
  198. "c2=&gt;mysql://kamailio:kamailiorw@localhost/kamailio2")
  199. modparam("db_cluster", "cluster", "k1=&gt;c1=9r9p;c2=9r9p")
  200. modparam("acc", "db_url", "cluster://k1")
  201. modparam("sqlops", "sqlcon", "ca=&gt;cluster://k1")
  202. ...
  203. </programlisting>
  204. </example>
  205. </section>
  206. </chapter>