prestogres 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (393) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +20 -0
  4. data/LICENSE +202 -0
  5. data/NOTICE +22 -0
  6. data/README.md +217 -0
  7. data/Rakefile +13 -0
  8. data/VERSION +1 -0
  9. data/bin/prestogres +254 -0
  10. data/config/pcp.conf.sample +28 -0
  11. data/config/pgpool.conf +678 -0
  12. data/config/pool_hba.conf +84 -0
  13. data/config/pool_passwd +0 -0
  14. data/config/postgresql.conf +2 -0
  15. data/ext/.gitignore +6 -0
  16. data/ext/depend +26 -0
  17. data/ext/extconf.rb +4 -0
  18. data/ext/prestogres_config.c +12 -0
  19. data/pgpool2/.gitignore +36 -0
  20. data/pgpool2/AUTHORS +4 -0
  21. data/pgpool2/COPYING +12 -0
  22. data/pgpool2/ChangeLog +1 -0
  23. data/pgpool2/INSTALL +1 -0
  24. data/pgpool2/Makefile.am +159 -0
  25. data/pgpool2/Makefile.in +1187 -0
  26. data/pgpool2/NEWS +4960 -0
  27. data/pgpool2/README +1 -0
  28. data/pgpool2/README.euc_jp +1 -0
  29. data/pgpool2/README.online-recovery +62 -0
  30. data/pgpool2/TODO +103 -0
  31. data/pgpool2/ac_func_accept_argtypes.m4 +85 -0
  32. data/pgpool2/aclocal.m4 +1088 -0
  33. data/pgpool2/c-compiler.m4 +134 -0
  34. data/pgpool2/c-library.m4 +325 -0
  35. data/pgpool2/child.c +2097 -0
  36. data/pgpool2/config.guess +1532 -0
  37. data/pgpool2/config.h.in +332 -0
  38. data/pgpool2/config.sub +1640 -0
  39. data/pgpool2/configure +15752 -0
  40. data/pgpool2/configure.in +392 -0
  41. data/pgpool2/depcomp +522 -0
  42. data/pgpool2/doc/basebackup.sh +17 -0
  43. data/pgpool2/doc/pgpool-de.html +4220 -0
  44. data/pgpool2/doc/pgpool-en.html +5738 -0
  45. data/pgpool2/doc/pgpool-fr.html +4118 -0
  46. data/pgpool2/doc/pgpool-ja.css +198 -0
  47. data/pgpool2/doc/pgpool-ja.html +11279 -0
  48. data/pgpool2/doc/pgpool-zh_cn.html +4445 -0
  49. data/pgpool2/doc/pgpool.css +280 -0
  50. data/pgpool2/doc/pgpool_remote_start +13 -0
  51. data/pgpool2/doc/recovery.conf.sample +117 -0
  52. data/pgpool2/doc/tutorial-en.html +707 -0
  53. data/pgpool2/doc/tutorial-ja.html +422 -0
  54. data/pgpool2/doc/tutorial-memqcache-en.html +325 -0
  55. data/pgpool2/doc/tutorial-memqcache-ja.html +370 -0
  56. data/pgpool2/doc/tutorial-memqcache-zh_cn.html +322 -0
  57. data/pgpool2/doc/tutorial-watchdog-en.html +306 -0
  58. data/pgpool2/doc/tutorial-watchdog-ja.html +343 -0
  59. data/pgpool2/doc/tutorial-watchdog-zh_cn.html +301 -0
  60. data/pgpool2/doc/tutorial-zh_cn.html +537 -0
  61. data/pgpool2/doc/watchdog.png +0 -0
  62. data/pgpool2/doc/wd-en.html +236 -0
  63. data/pgpool2/doc/wd-en.jpg +0 -0
  64. data/pgpool2/doc/wd-ja.html +219 -0
  65. data/pgpool2/doc/wd-ja.jpg +0 -0
  66. data/pgpool2/doc/wd-zh_cn.html +201 -0
  67. data/pgpool2/doc/where_to_send_queries.odg +0 -0
  68. data/pgpool2/doc/where_to_send_queries.pdf +0 -0
  69. data/pgpool2/general.m4 +166 -0
  70. data/pgpool2/getopt_long.c +200 -0
  71. data/pgpool2/getopt_long.h +44 -0
  72. data/pgpool2/install-sh +251 -0
  73. data/pgpool2/ltmain.sh +8406 -0
  74. data/pgpool2/m4/libtool.m4 +7360 -0
  75. data/pgpool2/m4/ltoptions.m4 +368 -0
  76. data/pgpool2/m4/ltsugar.m4 +123 -0
  77. data/pgpool2/m4/ltversion.m4 +23 -0
  78. data/pgpool2/m4/lt~obsolete.m4 +92 -0
  79. data/pgpool2/main.c +2971 -0
  80. data/pgpool2/md5.c +444 -0
  81. data/pgpool2/md5.h +28 -0
  82. data/pgpool2/missing +360 -0
  83. data/pgpool2/mkinstalldirs +40 -0
  84. data/pgpool2/parser/Makefile.am +50 -0
  85. data/pgpool2/parser/Makefile.in +559 -0
  86. data/pgpool2/parser/copyfuncs.c +3310 -0
  87. data/pgpool2/parser/gram.c +39100 -0
  88. data/pgpool2/parser/gram.h +940 -0
  89. data/pgpool2/parser/gram.y +13408 -0
  90. data/pgpool2/parser/gramparse.h +74 -0
  91. data/pgpool2/parser/keywords.c +32 -0
  92. data/pgpool2/parser/keywords.h +39 -0
  93. data/pgpool2/parser/kwlist.h +425 -0
  94. data/pgpool2/parser/kwlookup.c +88 -0
  95. data/pgpool2/parser/list.c +1156 -0
  96. data/pgpool2/parser/makefuncs.c +518 -0
  97. data/pgpool2/parser/makefuncs.h +83 -0
  98. data/pgpool2/parser/memnodes.h +79 -0
  99. data/pgpool2/parser/nodes.c +29 -0
  100. data/pgpool2/parser/nodes.h +609 -0
  101. data/pgpool2/parser/outfuncs.c +5790 -0
  102. data/pgpool2/parser/parsenodes.h +2615 -0
  103. data/pgpool2/parser/parser.c +262 -0
  104. data/pgpool2/parser/parser.h +46 -0
  105. data/pgpool2/parser/pg_class.h +158 -0
  106. data/pgpool2/parser/pg_config_manual.h +273 -0
  107. data/pgpool2/parser/pg_list.h +352 -0
  108. data/pgpool2/parser/pg_trigger.h +147 -0
  109. data/pgpool2/parser/pg_wchar.h +492 -0
  110. data/pgpool2/parser/pool_memory.c +342 -0
  111. data/pgpool2/parser/pool_memory.h +77 -0
  112. data/pgpool2/parser/pool_parser.h +222 -0
  113. data/pgpool2/parser/pool_string.c +121 -0
  114. data/pgpool2/parser/pool_string.h +37 -0
  115. data/pgpool2/parser/primnodes.h +1280 -0
  116. data/pgpool2/parser/scan.c +4094 -0
  117. data/pgpool2/parser/scan.l +1451 -0
  118. data/pgpool2/parser/scanner.h +120 -0
  119. data/pgpool2/parser/scansup.c +221 -0
  120. data/pgpool2/parser/scansup.h +28 -0
  121. data/pgpool2/parser/snprintf.c +1102 -0
  122. data/pgpool2/parser/stringinfo.c +294 -0
  123. data/pgpool2/parser/stringinfo.h +178 -0
  124. data/pgpool2/parser/value.c +78 -0
  125. data/pgpool2/parser/value.h +62 -0
  126. data/pgpool2/parser/wchar.c +2048 -0
  127. data/pgpool2/pcp.conf.sample +28 -0
  128. data/pgpool2/pcp/Makefile.am +40 -0
  129. data/pgpool2/pcp/Makefile.in +771 -0
  130. data/pgpool2/pcp/libpcp_ext.h +250 -0
  131. data/pgpool2/pcp/md5.c +444 -0
  132. data/pgpool2/pcp/md5.h +28 -0
  133. data/pgpool2/pcp/pcp.c +1652 -0
  134. data/pgpool2/pcp/pcp.h +61 -0
  135. data/pgpool2/pcp/pcp_attach_node.c +172 -0
  136. data/pgpool2/pcp/pcp_detach_node.c +185 -0
  137. data/pgpool2/pcp/pcp_error.c +87 -0
  138. data/pgpool2/pcp/pcp_node_count.c +160 -0
  139. data/pgpool2/pcp/pcp_node_info.c +198 -0
  140. data/pgpool2/pcp/pcp_pool_status.c +166 -0
  141. data/pgpool2/pcp/pcp_proc_count.c +166 -0
  142. data/pgpool2/pcp/pcp_proc_info.c +261 -0
  143. data/pgpool2/pcp/pcp_promote_node.c +185 -0
  144. data/pgpool2/pcp/pcp_recovery_node.c +172 -0
  145. data/pgpool2/pcp/pcp_stop_pgpool.c +179 -0
  146. data/pgpool2/pcp/pcp_stream.c +385 -0
  147. data/pgpool2/pcp/pcp_stream.h +52 -0
  148. data/pgpool2/pcp/pcp_systemdb_info.c +194 -0
  149. data/pgpool2/pcp/pcp_watchdog_info.c +211 -0
  150. data/pgpool2/pcp_child.c +1493 -0
  151. data/pgpool2/pg_md5.c +305 -0
  152. data/pgpool2/pgpool.8.in +121 -0
  153. data/pgpool2/pgpool.conf +553 -0
  154. data/pgpool2/pgpool.conf.sample +666 -0
  155. data/pgpool2/pgpool.conf.sample-master-slave +665 -0
  156. data/pgpool2/pgpool.conf.sample-replication +664 -0
  157. data/pgpool2/pgpool.conf.sample-stream +664 -0
  158. data/pgpool2/pgpool.spec +264 -0
  159. data/pgpool2/pgpool_adm/TODO +7 -0
  160. data/pgpool2/pgpool_adm/pgpool_adm--1.0.sql +85 -0
  161. data/pgpool2/pgpool_adm/pgpool_adm.c +558 -0
  162. data/pgpool2/pgpool_adm/pgpool_adm.control +5 -0
  163. data/pgpool2/pgpool_adm/pgpool_adm.h +46 -0
  164. data/pgpool2/pgpool_adm/pgpool_adm.sql.in +85 -0
  165. data/pgpool2/pool.h +655 -0
  166. data/pgpool2/pool_auth.c +1390 -0
  167. data/pgpool2/pool_config.c +5007 -0
  168. data/pgpool2/pool_config.h +284 -0
  169. data/pgpool2/pool_config.l +3281 -0
  170. data/pgpool2/pool_config_md5.c +29 -0
  171. data/pgpool2/pool_connection_pool.c +812 -0
  172. data/pgpool2/pool_error.c +242 -0
  173. data/pgpool2/pool_globals.c +27 -0
  174. data/pgpool2/pool_hba.c +1723 -0
  175. data/pgpool2/pool_hba.conf.sample +67 -0
  176. data/pgpool2/pool_ip.c +567 -0
  177. data/pgpool2/pool_ip.h +65 -0
  178. data/pgpool2/pool_ipc.h +38 -0
  179. data/pgpool2/pool_lobj.c +242 -0
  180. data/pgpool2/pool_lobj.h +32 -0
  181. data/pgpool2/pool_memqcache.c +3818 -0
  182. data/pgpool2/pool_memqcache.h +268 -0
  183. data/pgpool2/pool_params.c +163 -0
  184. data/pgpool2/pool_passwd.c +249 -0
  185. data/pgpool2/pool_passwd.h +41 -0
  186. data/pgpool2/pool_path.c +193 -0
  187. data/pgpool2/pool_path.h +81 -0
  188. data/pgpool2/pool_process_context.c +247 -0
  189. data/pgpool2/pool_process_context.h +62 -0
  190. data/pgpool2/pool_process_query.c +5001 -0
  191. data/pgpool2/pool_process_reporting.c +1671 -0
  192. data/pgpool2/pool_process_reporting.h +44 -0
  193. data/pgpool2/pool_proto2.c +671 -0
  194. data/pgpool2/pool_proto_modules.c +3524 -0
  195. data/pgpool2/pool_proto_modules.h +185 -0
  196. data/pgpool2/pool_query_cache.c +1020 -0
  197. data/pgpool2/pool_query_context.c +1871 -0
  198. data/pgpool2/pool_query_context.h +105 -0
  199. data/pgpool2/pool_relcache.c +284 -0
  200. data/pgpool2/pool_relcache.h +78 -0
  201. data/pgpool2/pool_rewrite_outfuncs.c +9060 -0
  202. data/pgpool2/pool_rewrite_query.c +715 -0
  203. data/pgpool2/pool_rewrite_query.h +192 -0
  204. data/pgpool2/pool_select_walker.c +1150 -0
  205. data/pgpool2/pool_select_walker.h +68 -0
  206. data/pgpool2/pool_sema.c +161 -0
  207. data/pgpool2/pool_session_context.c +952 -0
  208. data/pgpool2/pool_session_context.h +203 -0
  209. data/pgpool2/pool_shmem.c +185 -0
  210. data/pgpool2/pool_signal.c +158 -0
  211. data/pgpool2/pool_signal.h +61 -0
  212. data/pgpool2/pool_ssl.c +339 -0
  213. data/pgpool2/pool_stream.c +962 -0
  214. data/pgpool2/pool_stream.h +61 -0
  215. data/pgpool2/pool_system.c +659 -0
  216. data/pgpool2/pool_timestamp.c +1215 -0
  217. data/pgpool2/pool_timestamp.h +38 -0
  218. data/pgpool2/pool_type.h +171 -0
  219. data/pgpool2/pool_worker_child.c +384 -0
  220. data/pgpool2/ps_status.c +404 -0
  221. data/pgpool2/recovery.c +435 -0
  222. data/pgpool2/redhat/pgpool.conf.sample.patch +52 -0
  223. data/pgpool2/redhat/pgpool.init +201 -0
  224. data/pgpool2/redhat/pgpool.sysconfig +7 -0
  225. data/pgpool2/redhat/rpm_installer/basebackup-replication.sh +53 -0
  226. data/pgpool2/redhat/rpm_installer/basebackup-stream.sh +55 -0
  227. data/pgpool2/redhat/rpm_installer/config_for_script +17 -0
  228. data/pgpool2/redhat/rpm_installer/failover.sh +64 -0
  229. data/pgpool2/redhat/rpm_installer/getsources.sh +141 -0
  230. data/pgpool2/redhat/rpm_installer/install.sh +1363 -0
  231. data/pgpool2/redhat/rpm_installer/pgpool_recovery_pitr +47 -0
  232. data/pgpool2/redhat/rpm_installer/pgpool_remote_start +15 -0
  233. data/pgpool2/redhat/rpm_installer/recovery.conf +4 -0
  234. data/pgpool2/redhat/rpm_installer/uninstall.sh +57 -0
  235. data/pgpool2/sample/dist_def_pgbench.sql +73 -0
  236. data/pgpool2/sample/pgpool.pam +3 -0
  237. data/pgpool2/sample/pgpool_recovery +20 -0
  238. data/pgpool2/sample/pgpool_recovery_pitr +19 -0
  239. data/pgpool2/sample/pgpool_remote_start +13 -0
  240. data/pgpool2/sample/replicate_def_pgbench.sql +18 -0
  241. data/pgpool2/sql/insert_lock.sql +15 -0
  242. data/pgpool2/sql/pgpool-recovery/pgpool-recovery.c +280 -0
  243. data/pgpool2/sql/pgpool-recovery/pgpool-recovery.sql.in +19 -0
  244. data/pgpool2/sql/pgpool-recovery/pgpool_recovery--1.0.sql +24 -0
  245. data/pgpool2/sql/pgpool-recovery/pgpool_recovery.control +5 -0
  246. data/pgpool2/sql/pgpool-recovery/uninstall_pgpool-recovery.sql +3 -0
  247. data/pgpool2/sql/pgpool-regclass/pgpool-regclass.c +206 -0
  248. data/pgpool2/sql/pgpool-regclass/pgpool-regclass.sql.in +4 -0
  249. data/pgpool2/sql/pgpool-regclass/pgpool_regclass--1.0.sql +7 -0
  250. data/pgpool2/sql/pgpool-regclass/pgpool_regclass.control +5 -0
  251. data/pgpool2/sql/pgpool-regclass/uninstall_pgpool-regclass.sql +1 -0
  252. data/pgpool2/sql/system_db.sql +38 -0
  253. data/pgpool2/strlcpy.c +85 -0
  254. data/pgpool2/test/C/test_extended.c +98 -0
  255. data/pgpool2/test/jdbc/.cvsignore +2 -0
  256. data/pgpool2/test/jdbc/AutoCommitTest.java +45 -0
  257. data/pgpool2/test/jdbc/BatchTest.java +55 -0
  258. data/pgpool2/test/jdbc/ColumnTest.java +60 -0
  259. data/pgpool2/test/jdbc/CreateTempTableTest.java +48 -0
  260. data/pgpool2/test/jdbc/InsertTest.java +34 -0
  261. data/pgpool2/test/jdbc/LockTest.java +36 -0
  262. data/pgpool2/test/jdbc/PgpoolTest.java +75 -0
  263. data/pgpool2/test/jdbc/README.euc_jp +73 -0
  264. data/pgpool2/test/jdbc/RunTest.java +83 -0
  265. data/pgpool2/test/jdbc/SelectTest.java +37 -0
  266. data/pgpool2/test/jdbc/UpdateTest.java +32 -0
  267. data/pgpool2/test/jdbc/expected/CreateTempTable +1 -0
  268. data/pgpool2/test/jdbc/expected/autocommit +10 -0
  269. data/pgpool2/test/jdbc/expected/batch +1 -0
  270. data/pgpool2/test/jdbc/expected/column +100 -0
  271. data/pgpool2/test/jdbc/expected/insert +1 -0
  272. data/pgpool2/test/jdbc/expected/lock +100 -0
  273. data/pgpool2/test/jdbc/expected/select +2 -0
  274. data/pgpool2/test/jdbc/expected/update +1 -0
  275. data/pgpool2/test/jdbc/pgpool.properties +7 -0
  276. data/pgpool2/test/jdbc/prepare.sql +54 -0
  277. data/pgpool2/test/jdbc/run.sh +6 -0
  278. data/pgpool2/test/parser/.cvsignore +6 -0
  279. data/pgpool2/test/parser/README +32 -0
  280. data/pgpool2/test/parser/expected/copy.out +17 -0
  281. data/pgpool2/test/parser/expected/create.out +64 -0
  282. data/pgpool2/test/parser/expected/cursor.out +37 -0
  283. data/pgpool2/test/parser/expected/delete.out +10 -0
  284. data/pgpool2/test/parser/expected/drop.out +12 -0
  285. data/pgpool2/test/parser/expected/insert.out +13 -0
  286. data/pgpool2/test/parser/expected/misc.out +28 -0
  287. data/pgpool2/test/parser/expected/prepare.out +4 -0
  288. data/pgpool2/test/parser/expected/privileges.out +31 -0
  289. data/pgpool2/test/parser/expected/scanner.out +30 -0
  290. data/pgpool2/test/parser/expected/select.out +89 -0
  291. data/pgpool2/test/parser/expected/transaction.out +38 -0
  292. data/pgpool2/test/parser/expected/update.out +11 -0
  293. data/pgpool2/test/parser/expected/v84.out +37 -0
  294. data/pgpool2/test/parser/expected/v90.out +25 -0
  295. data/pgpool2/test/parser/expected/var.out +22 -0
  296. data/pgpool2/test/parser/input/alter.sql +2 -0
  297. data/pgpool2/test/parser/input/copy.sql +17 -0
  298. data/pgpool2/test/parser/input/create.sql +64 -0
  299. data/pgpool2/test/parser/input/cursor.sql +37 -0
  300. data/pgpool2/test/parser/input/delete.sql +10 -0
  301. data/pgpool2/test/parser/input/drop.sql +12 -0
  302. data/pgpool2/test/parser/input/insert.sql +13 -0
  303. data/pgpool2/test/parser/input/misc.sql +28 -0
  304. data/pgpool2/test/parser/input/prepare.sql +4 -0
  305. data/pgpool2/test/parser/input/privileges.sql +31 -0
  306. data/pgpool2/test/parser/input/scanner.sql +34 -0
  307. data/pgpool2/test/parser/input/select.sql +89 -0
  308. data/pgpool2/test/parser/input/transaction.sql +38 -0
  309. data/pgpool2/test/parser/input/update.sql +11 -0
  310. data/pgpool2/test/parser/input/v84.sql +37 -0
  311. data/pgpool2/test/parser/input/v90.sql +38 -0
  312. data/pgpool2/test/parser/input/var.sql +22 -0
  313. data/pgpool2/test/parser/main.c +96 -0
  314. data/pgpool2/test/parser/parse_schedule +16 -0
  315. data/pgpool2/test/parser/pool.h +13 -0
  316. data/pgpool2/test/parser/run-test +62 -0
  317. data/pgpool2/test/pdo-test/README.euc_jp +58 -0
  318. data/pgpool2/test/pdo-test/SQLlist/test1.sql +3 -0
  319. data/pgpool2/test/pdo-test/SQLlist/test2.sql +3 -0
  320. data/pgpool2/test/pdo-test/collections.inc +11 -0
  321. data/pgpool2/test/pdo-test/def.inc +7 -0
  322. data/pgpool2/test/pdo-test/log.txt +0 -0
  323. data/pgpool2/test/pdo-test/mod/database.inc +36 -0
  324. data/pgpool2/test/pdo-test/mod/def.inc +0 -0
  325. data/pgpool2/test/pdo-test/mod/errorhandler.inc +27 -0
  326. data/pgpool2/test/pdo-test/pdotest.php +11 -0
  327. data/pgpool2/test/pdo-test/regsql.inc +56 -0
  328. data/pgpool2/test/pgpool_setup +898 -0
  329. data/pgpool2/test/regression/README +39 -0
  330. data/pgpool2/test/regression/clean.sh +21 -0
  331. data/pgpool2/test/regression/libs.sh +16 -0
  332. data/pgpool2/test/regression/regress.sh +166 -0
  333. data/pgpool2/test/regression/tests/001.load_balance/test.sh +128 -0
  334. data/pgpool2/test/regression/tests/002.native_replication/PgTester.java +47 -0
  335. data/pgpool2/test/regression/tests/002.native_replication/create.sql +6 -0
  336. data/pgpool2/test/regression/tests/002.native_replication/test.sh +71 -0
  337. data/pgpool2/test/regression/tests/003.failover/expected.r +6 -0
  338. data/pgpool2/test/regression/tests/003.failover/expected.s +6 -0
  339. data/pgpool2/test/regression/tests/003.failover/test.sh +45 -0
  340. data/pgpool2/test/regression/tests/004.watchdog/master.conf +12 -0
  341. data/pgpool2/test/regression/tests/004.watchdog/standby.conf +19 -0
  342. data/pgpool2/test/regression/tests/004.watchdog/test.sh +52 -0
  343. data/pgpool2/test/regression/tests/050.bug58/test.sh +50 -0
  344. data/pgpool2/test/regression/tests/051.bug60/bug.sql +12 -0
  345. data/pgpool2/test/regression/tests/051.bug60/database-clean.sql +6 -0
  346. data/pgpool2/test/regression/tests/051.bug60/database-setup.sql +28 -0
  347. data/pgpool2/test/regression/tests/051.bug60/test.sh +79 -0
  348. data/pgpool2/test/regression/tests/052.do_query/test.sh +44 -0
  349. data/pgpool2/test/regression/tests/053.insert_lock_hangs/test.sh +81 -0
  350. data/pgpool2/test/regression/tests/054.postgres_fdw/test.sh +67 -0
  351. data/pgpool2/test/regression/tests/055.backend_all_down/test.sh +52 -0
  352. data/pgpool2/test/regression/tests/056.bug63/jdbctest2.java +66 -0
  353. data/pgpool2/test/regression/tests/056.bug63/test.sh +47 -0
  354. data/pgpool2/test/regression/tests/057.bug61/test.sh +40 -0
  355. data/pgpool2/test/regression/tests/058.bug68/jdbctest3.java +45 -0
  356. data/pgpool2/test/regression/tests/058.bug68/test.sh +47 -0
  357. data/pgpool2/test/timestamp/expected/insert.out +16 -0
  358. data/pgpool2/test/timestamp/expected/misc.out +3 -0
  359. data/pgpool2/test/timestamp/expected/update.out +6 -0
  360. data/pgpool2/test/timestamp/input/insert.sql +16 -0
  361. data/pgpool2/test/timestamp/input/misc.sql +3 -0
  362. data/pgpool2/test/timestamp/input/update.sql +6 -0
  363. data/pgpool2/test/timestamp/main.c +129 -0
  364. data/pgpool2/test/timestamp/parse_schedule +3 -0
  365. data/pgpool2/test/timestamp/run-test +69 -0
  366. data/pgpool2/version.h +1 -0
  367. data/pgpool2/watchdog/Makefile.am +17 -0
  368. data/pgpool2/watchdog/Makefile.in +505 -0
  369. data/pgpool2/watchdog/test/stab.c +266 -0
  370. data/pgpool2/watchdog/test/test.c +85 -0
  371. data/pgpool2/watchdog/test/wd_child_t.c +87 -0
  372. data/pgpool2/watchdog/test/wd_lifecheck_t.c +87 -0
  373. data/pgpool2/watchdog/test/wd_packet_t.c +87 -0
  374. data/pgpool2/watchdog/test/wd_ping_t.c +20 -0
  375. data/pgpool2/watchdog/watchdog.c +408 -0
  376. data/pgpool2/watchdog/watchdog.h +209 -0
  377. data/pgpool2/watchdog/wd_child.c +444 -0
  378. data/pgpool2/watchdog/wd_ext.h +123 -0
  379. data/pgpool2/watchdog/wd_heartbeat.c +577 -0
  380. data/pgpool2/watchdog/wd_if.c +216 -0
  381. data/pgpool2/watchdog/wd_init.c +126 -0
  382. data/pgpool2/watchdog/wd_interlock.c +347 -0
  383. data/pgpool2/watchdog/wd_lifecheck.c +512 -0
  384. data/pgpool2/watchdog/wd_list.c +429 -0
  385. data/pgpool2/watchdog/wd_packet.c +1159 -0
  386. data/pgpool2/watchdog/wd_ping.c +330 -0
  387. data/pgpool2/ylwrap +223 -0
  388. data/pgsql/presto_client.py +346 -0
  389. data/pgsql/prestogres.py +156 -0
  390. data/pgsql/setup_functions.sql +21 -0
  391. data/pgsql/setup_language.sql +3 -0
  392. data/prestogres.gemspec +23 -0
  393. metadata +496 -0
data/pgpool2/pcp/md5.h ADDED
@@ -0,0 +1,28 @@
1
+ /*-------------------------------------------------------------------------
2
+ *
3
+ * md5.h
4
+ * Interface to md5.c
5
+ *
6
+ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
+ * Portions Copyright (c) 1994, Regents of the University of California
8
+ *
9
+ * $Header$
10
+ *
11
+ *-------------------------------------------------------------------------
12
+ */
13
+
14
+ /*
15
+ * This file is imported from PostgreSQL 8.1.3.
16
+ * Modified by Taiki Yamaguchi <yamaguchi@sraoss.co.jp>
17
+ */
18
+
19
+ #ifndef MD5_H
20
+ #define MD5_H
21
+
22
+ #define MAX_USER_NAME_LEN 128
23
+ #define MD5_PASSWD_LEN 32
24
+
25
+ extern int pool_md5_hash(const void *buff, size_t len, char *hexsum);
26
+ extern int pool_md5_encrypt(const char *passwd, const char *salt, size_t salt_len, char *buf);
27
+
28
+ #endif
data/pgpool2/pcp/pcp.c ADDED
@@ -0,0 +1,1652 @@
1
+ /*
2
+ * $Header$
3
+ *
4
+ * Handles PCP connection, and protocol communication with pgpool-II
5
+ * These are client APIs. Server program should use APIs in pcp_stream.c
6
+ *
7
+ *
8
+ * pgpool: a language independent connection pool server for PostgreSQL
9
+ * written by Tatsuo Ishii
10
+ *
11
+ * Copyright (c) 2003-2013 PgPool Global Development Group
12
+ *
13
+ * Permission to use, copy, modify, and distribute this software and
14
+ * its documentation for any purpose and without fee is hereby
15
+ * granted, provided that the above copyright notice appear in all
16
+ * copies and that both that copyright notice and this permission
17
+ * notice appear in supporting documentation, and that the name of the
18
+ * author not be used in advertising or publicity pertaining to
19
+ * distribution of the software without specific, written prior
20
+ * permission. The author makes no representations about the
21
+ * suitability of this software for any purpose. It is provided "as
22
+ * is" without express or implied warranty.
23
+ *
24
+ */
25
+
26
+ #include <stdio.h>
27
+ #include <string.h>
28
+ #include <stdlib.h>
29
+ #include <sys/types.h>
30
+ #include <sys/socket.h>
31
+ #include <sys/time.h>
32
+ #include <sys/un.h>
33
+ #include <netinet/in.h>
34
+ #include <netinet/tcp.h>
35
+ #include <netdb.h>
36
+ #include <unistd.h>
37
+
38
+ #include "pool.h"
39
+ #include "pcp.h"
40
+ #include "pcp_stream.h"
41
+ #include "pool_process_reporting.h"
42
+ #include "md5.h"
43
+
44
+
45
+ struct timeval pcp_timeout;
46
+
47
+ static PCP_CONNECTION *pc;
48
+ #ifdef DEBUG
49
+ static int debug = 1;
50
+ #else
51
+ static int debug = 0;
52
+ #endif
53
+ static int pcp_authorize(char *username, char *password);
54
+
55
+ static int _pcp_detach_node(int nid, bool gracefully);
56
+ static int _pcp_promote_node(int nid, bool gracefully);
57
+
58
+ /* --------------------------------
59
+ * pcp_connect - open connection to pgpool using given arguments
60
+ *
61
+ * return 0 on success, -1 otherwise
62
+ * --------------------------------
63
+ */
64
+ int
65
+ pcp_connect(char *hostname, int port, char *username, char *password)
66
+ {
67
+ struct sockaddr_in addr;
68
+ struct sockaddr_un unix_addr;
69
+ struct hostent *hp;
70
+ int fd;
71
+ int on = 1;
72
+ int len;
73
+
74
+ if (pc != NULL)
75
+ {
76
+ if (debug) fprintf(stderr, "DEBUG: connection to backend \"%s\" already exists\n", hostname);
77
+ return 0;
78
+ }
79
+
80
+ if (hostname == NULL || *hostname == '\0' || *hostname == '/')
81
+ {
82
+ char *path;
83
+
84
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
85
+
86
+ if (fd < 0)
87
+ {
88
+ if (debug) fprintf(stderr, "DEBUG: could not create socket\n");
89
+ errorcode = SOCKERR;
90
+ return -1;
91
+ }
92
+
93
+ memset(&unix_addr, 0, sizeof(unix_addr));
94
+ unix_addr.sun_family = AF_UNIX;
95
+
96
+ if (hostname == NULL || *hostname == '\0')
97
+ {
98
+ path = UNIX_DOMAIN_PATH;
99
+ }
100
+ else
101
+ {
102
+ path = hostname;
103
+ }
104
+
105
+ snprintf(unix_addr.sun_path, sizeof(unix_addr.sun_path), "%s/.s.PGSQL.%d",
106
+ path, port);
107
+
108
+ if (connect(fd, (struct sockaddr *) &unix_addr, sizeof(unix_addr)) < 0)
109
+ {
110
+ if (debug) fprintf(stderr, "DEBUG: could not connect to \"%s\"\n", unix_addr.sun_path);
111
+ close(fd);
112
+ errorcode = CONNERR;
113
+ return -1;
114
+ }
115
+ }
116
+ else
117
+ {
118
+ fd = socket(AF_INET, SOCK_STREAM, 0);
119
+ if (fd < 0)
120
+ {
121
+ if (debug) fprintf(stderr, "DEBUG: could not create socket\n");
122
+ errorcode = SOCKERR;
123
+ return -1;
124
+ }
125
+
126
+ if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
127
+ (char *) &on, sizeof(on)) < 0)
128
+ {
129
+ if (debug) fprintf(stderr, "DEBUG: could not set socket option\n");
130
+ close(fd);
131
+ errorcode = SOCKERR;
132
+ return -1;
133
+ }
134
+
135
+ memset((char *) &addr, 0, sizeof(addr));
136
+ addr.sin_family = AF_INET;
137
+ hp = gethostbyname(hostname);
138
+ if ((hp == NULL) || (hp->h_addrtype != AF_INET))
139
+ {
140
+ if (debug) fprintf(stderr, "DEBUG: could not retrieve hostname\n");
141
+ close(fd);
142
+ errorcode = HOSTERR;
143
+ return -1;
144
+ }
145
+ memmove((char *) &(addr.sin_addr),
146
+ (char *) hp->h_addr,
147
+ hp->h_length);
148
+ addr.sin_port = htons(port);
149
+
150
+ len = sizeof(struct sockaddr_in);
151
+ if (connect(fd, (struct sockaddr *) &addr, len) < 0)
152
+ {
153
+ if (debug) fprintf(stderr, "DEBUG: could not connect to \"%s\"\n", hostname);
154
+ close(fd);
155
+ errorcode = CONNERR;
156
+ return -1;
157
+ }
158
+ }
159
+
160
+ pc = pcp_open(fd);
161
+ if (pc == NULL)
162
+ {
163
+ if (debug) fprintf(stderr, "DEBUG: could not allocate buffer space\n");
164
+ close(fd);
165
+ return -1;
166
+ }
167
+
168
+ if (pcp_authorize(username, password) < 0)
169
+ {
170
+ pcp_close(pc);
171
+ pc = NULL;
172
+ return -1;
173
+ }
174
+
175
+ return 0;
176
+ }
177
+
178
+ /* --------------------------------
179
+ * pcp_authorize - authenticate with pgpool using username and password
180
+ *
181
+ * return 0 on success, -1 otherwise
182
+ * --------------------------------
183
+ */
184
+ static int
185
+ pcp_authorize(char *username, char *password)
186
+ {
187
+ char tos;
188
+ char *buf = NULL;
189
+ int wsize;
190
+ int rsize;
191
+ char salt[4];
192
+ char encrypt_buf[(MD5_PASSWD_LEN+1)*2];
193
+ char md5[MD5_PASSWD_LEN+1];
194
+
195
+ /* request salt */
196
+ pcp_write(pc, "M", 1);
197
+ wsize = htonl(sizeof(int));
198
+ pcp_write(pc, &wsize, sizeof(int));
199
+ if (pcp_flush(pc) < 0)
200
+ {
201
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
202
+ return -1;
203
+ }
204
+
205
+ if (pcp_read(pc, &tos, 1))
206
+ return -1;
207
+ if (pcp_read(pc, &rsize, sizeof(int)))
208
+ return -1;
209
+ rsize = ntohl(rsize);
210
+ buf = (char *)malloc(rsize);
211
+ if (buf == NULL)
212
+ {
213
+ errorcode = NOMEMERR;
214
+ return -1;
215
+ }
216
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
217
+ return -1;
218
+ memcpy(salt, buf, 4);
219
+ free(buf);
220
+
221
+ /* encrypt password */
222
+ pool_md5_hash(password, strlen(password), md5);
223
+ md5[MD5_PASSWD_LEN] = '\0';
224
+
225
+ pool_md5_encrypt(md5, username, strlen(username),
226
+ encrypt_buf + MD5_PASSWD_LEN + 1);
227
+ encrypt_buf[(MD5_PASSWD_LEN+1)*2-1] = '\0';
228
+
229
+ pool_md5_encrypt(encrypt_buf+MD5_PASSWD_LEN+1, salt, 4,
230
+ encrypt_buf);
231
+ encrypt_buf[MD5_PASSWD_LEN] = '\0';
232
+
233
+ pcp_write(pc, "R", 1);
234
+ wsize = htonl((strlen(username)+1 + strlen(encrypt_buf)+1) + sizeof(int));
235
+ pcp_write(pc, &wsize, sizeof(int));
236
+ pcp_write(pc, username, strlen(username)+1);
237
+ pcp_write(pc, encrypt_buf, strlen(encrypt_buf)+1);
238
+ if (pcp_flush(pc) < 0)
239
+ {
240
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
241
+ return -1;
242
+ }
243
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"R\", len=%d\n", ntohl(wsize));
244
+
245
+ if (pcp_read(pc, &tos, 1))
246
+ return -1;
247
+ if (pcp_read(pc, &rsize, sizeof(int)))
248
+ return -1;
249
+ rsize = ntohl(rsize);
250
+ buf = (char *)malloc(rsize);
251
+ if (buf == NULL)
252
+ {
253
+ errorcode = NOMEMERR;
254
+ return -1;
255
+ }
256
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
257
+ return -1;
258
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
259
+
260
+ if (tos == 'e')
261
+ {
262
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
263
+ errorcode = BACKENDERR;
264
+ }
265
+ else if (tos == 'r')
266
+ {
267
+ if (strcmp(buf, "AuthenticationOK") == 0)
268
+ {
269
+ free(buf);
270
+ return 0;
271
+ }
272
+
273
+ if (debug) fprintf(stderr, "DEBUG: authentication failed. reason=%s\n", buf);
274
+ errorcode = AUTHERR;
275
+ }
276
+ free(buf);
277
+
278
+ return -1;
279
+ }
280
+
281
+ /* --------------------------------
282
+ * pcp_disconnect - close connection to pgpool
283
+ * --------------------------------
284
+ */
285
+ void
286
+ pcp_disconnect(void)
287
+ {
288
+ int wsize;
289
+
290
+ if (pc == NULL)
291
+ {
292
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
293
+ return;
294
+ }
295
+
296
+ pcp_write(pc, "X", 1);
297
+ wsize = htonl(sizeof(int));
298
+ pcp_write(pc, &wsize, sizeof(int));
299
+ if (pcp_flush(pc) < 0)
300
+ {
301
+ /* backend had closed connection already */
302
+ }
303
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"X\", len=%d\n", (int) sizeof(int));
304
+
305
+ pcp_close(pc);
306
+ pc = NULL;
307
+ }
308
+
309
+ /* --------------------------------
310
+ * pcp_terminate_pgpool - send terminate packet
311
+ *
312
+ * return 0 on success, -1 otherwise
313
+ * --------------------------------
314
+ */
315
+ int
316
+ pcp_terminate_pgpool(char mode)
317
+ {
318
+ int wsize;
319
+
320
+ if (pc == NULL)
321
+ {
322
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
323
+ errorcode = NOCONNERR;
324
+ return -1;
325
+ }
326
+
327
+ pcp_write(pc, "T", 1);
328
+ wsize = htonl(sizeof(int) + sizeof(char));
329
+ pcp_write(pc, &wsize, sizeof(int));
330
+ pcp_write(pc, &mode, sizeof(char));
331
+ if (pcp_flush(pc) < 0)
332
+ {
333
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
334
+ return -1;
335
+ }
336
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"T\", len=%d\n", ntohl(wsize));
337
+
338
+ return 0;
339
+ }
340
+
341
+ /* --------------------------------
342
+ * pcp_node_count - get number of nodes currently connected to pgpool
343
+ *
344
+ * return array of node IDs on success, -1 otherwise
345
+ * --------------------------------
346
+ */
347
+ int
348
+ pcp_node_count(void)
349
+ {
350
+ char tos;
351
+ char *buf = NULL;
352
+ int wsize;
353
+ int rsize;
354
+ char *index = NULL;
355
+
356
+ if (pc == NULL)
357
+ {
358
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
359
+ errorcode = NOCONNERR;
360
+ return -1;
361
+ }
362
+
363
+ pcp_write(pc, "L", 1);
364
+ wsize = htonl(sizeof(int));
365
+ pcp_write(pc, &wsize, sizeof(int));
366
+ if (pcp_flush(pc) < 0)
367
+ {
368
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
369
+ return -1;
370
+ }
371
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"L\", len=%d\n", ntohl(wsize));
372
+
373
+ if (pcp_read(pc, &tos, 1))
374
+ return -1;
375
+ if (pcp_read(pc, &rsize, sizeof(int)))
376
+ return -1;
377
+ rsize = ntohl(rsize);
378
+ buf = (char *)malloc(rsize);
379
+ if (buf == NULL)
380
+ {
381
+ errorcode = NOMEMERR;
382
+ return -1;
383
+ }
384
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
385
+ {
386
+ free(buf);
387
+ return -1;
388
+ }
389
+
390
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
391
+
392
+ if (tos == 'e')
393
+ {
394
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
395
+ errorcode = BACKENDERR;
396
+ }
397
+ else if (tos == 'l')
398
+ {
399
+ if (strcmp(buf, "CommandComplete") == 0)
400
+ {
401
+ index = (char *) memchr(buf, '\0', rsize) + 1;
402
+ if (index != NULL)
403
+ {
404
+ int ret = atoi(index);
405
+ free(buf);
406
+ return ret;
407
+ }
408
+ }
409
+ }
410
+
411
+ free(buf);
412
+
413
+ return -1;
414
+ }
415
+
416
+ /* --------------------------------
417
+ * pcp_node_info - get information of node pointed by given argument
418
+ *
419
+ * return structure of node information on success, -1 otherwise
420
+ * --------------------------------
421
+ */
422
+ BackendInfo *
423
+ pcp_node_info(int nid)
424
+ {
425
+ int wsize;
426
+ char node_id[16];
427
+ char tos;
428
+ char *buf = NULL;
429
+ int rsize;
430
+
431
+ if (pc == NULL)
432
+ {
433
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
434
+ errorcode = NOCONNERR;
435
+ return NULL;
436
+ }
437
+
438
+ snprintf(node_id, sizeof(node_id), "%d", nid);
439
+
440
+ pcp_write(pc, "I", 1);
441
+ wsize = htonl(strlen(node_id)+1 + sizeof(int));
442
+ pcp_write(pc, &wsize, sizeof(int));
443
+ pcp_write(pc, node_id, strlen(node_id)+1);
444
+ if (pcp_flush(pc) < 0)
445
+ {
446
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
447
+ return NULL;
448
+ }
449
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"I\", len=%d\n", ntohl(wsize));
450
+
451
+ if (pcp_read(pc, &tos, 1))
452
+ return NULL;
453
+ if (pcp_read(pc, &rsize, sizeof(int)))
454
+ return NULL;
455
+ rsize = ntohl(rsize);
456
+ buf = (char *)malloc(rsize);
457
+ if (buf == NULL)
458
+ {
459
+ errorcode = NOMEMERR;
460
+ return NULL;
461
+ }
462
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
463
+ {
464
+ free(buf);
465
+ return NULL;
466
+ }
467
+
468
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
469
+
470
+ if (tos == 'e')
471
+ {
472
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
473
+ errorcode = BACKENDERR;
474
+ free(buf);
475
+ return NULL;
476
+ }
477
+ else if (tos == 'i')
478
+ {
479
+ if (strcmp(buf, "CommandComplete") == 0)
480
+ {
481
+ char *index = NULL;
482
+ BackendInfo* backend_info = NULL;
483
+
484
+ backend_info = (BackendInfo *)malloc(sizeof(BackendInfo));
485
+ if (backend_info == NULL)
486
+ {
487
+ errorcode = NOMEMERR;
488
+ free(buf);
489
+ return NULL;
490
+ }
491
+
492
+ index = (char *) memchr(buf, '\0', rsize) + 1;
493
+ if (index != NULL)
494
+ strcpy(backend_info->backend_hostname, index);
495
+
496
+ index = (char *) memchr(index, '\0', rsize) + 1;
497
+ if (index != NULL)
498
+ backend_info->backend_port = atoi(index);
499
+
500
+ index = (char *) memchr(index, '\0', rsize) + 1;
501
+ if (index != NULL)
502
+ backend_info->backend_status = atoi(index);
503
+
504
+ index = (char *) memchr(index, '\0', rsize) + 1;
505
+ if (index != NULL)
506
+ backend_info->backend_weight = atof(index);
507
+
508
+ free(buf);
509
+ return backend_info;
510
+ }
511
+ }
512
+
513
+ free(buf);
514
+ return NULL;
515
+ }
516
+
517
+ /* --------------------------------
518
+ * pcp_node_count - get number of nodes currently connected to pgpool
519
+ *
520
+ * return array of pids on success, NULL otherwise
521
+ * --------------------------------
522
+ */
523
+ int *
524
+ pcp_process_count(int *pnum)
525
+ {
526
+ char tos;
527
+ char *buf = NULL;
528
+ int wsize;
529
+ int rsize;
530
+
531
+ if (pc == NULL)
532
+ {
533
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
534
+ errorcode = NOCONNERR;
535
+ return NULL;
536
+ }
537
+
538
+ pcp_write(pc, "N", 1);
539
+ wsize = htonl(sizeof(int));
540
+ pcp_write(pc, &wsize, sizeof(int));
541
+ if (pcp_flush(pc) < 0)
542
+ {
543
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
544
+ return NULL;
545
+ }
546
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"N\", len=%d\n", ntohl(wsize));
547
+
548
+ if (pcp_read(pc, &tos, 1))
549
+ return NULL;
550
+ if (pcp_read(pc, &rsize, sizeof(int)))
551
+ return NULL;
552
+ rsize = ntohl(rsize);
553
+ buf = (char *)malloc(rsize);
554
+ if (buf == NULL)
555
+ {
556
+ errorcode = NOMEMERR;
557
+ return NULL;
558
+ }
559
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
560
+ {
561
+ free(buf);
562
+ return NULL;
563
+ }
564
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
565
+
566
+ if (tos == 'e')
567
+ {
568
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
569
+ free(buf);
570
+ errorcode = BACKENDERR;
571
+ return NULL;
572
+ }
573
+ else if (tos == 'n')
574
+ {
575
+ if (strcmp(buf, "CommandComplete") == 0)
576
+ {
577
+ int process_count;
578
+ int *process_list = NULL;
579
+ char *index = NULL;
580
+ int i;
581
+
582
+ index = (char *) memchr(buf, '\0', rsize) + 1;
583
+ process_count = atoi(index);
584
+
585
+ process_list = (int *)malloc(sizeof(int) * process_count);
586
+ if (process_list == NULL)
587
+ {
588
+ free(buf);
589
+ errorcode = NOMEMERR;
590
+ return NULL;
591
+ }
592
+
593
+ for (i = 0; i < process_count; i++)
594
+ {
595
+ index = (char *) memchr(index, '\0', rsize) + 1;
596
+ process_list[i] = atoi(index);
597
+ }
598
+
599
+ *pnum = process_count;
600
+ free(buf);
601
+ return process_list;
602
+ }
603
+ }
604
+
605
+ free(buf);
606
+ return NULL;
607
+ }
608
+
609
+ /* --------------------------------
610
+ * pcp_process_info - get information of node pointed by given argument
611
+ *
612
+ * return structure of process information on success, -1 otherwise
613
+ * --------------------------------
614
+ */
615
+ ProcessInfo *
616
+ pcp_process_info(int pid, int *array_size)
617
+ {
618
+ int wsize;
619
+ char process_id[16];
620
+ char tos;
621
+ char *buf = NULL;
622
+ int rsize;
623
+
624
+ ProcessInfo *process_info = NULL;
625
+ ConnectionInfo *conn_info = NULL;
626
+ int ci_size = 0;
627
+ int offset = 0;
628
+
629
+ if (pc == NULL)
630
+ {
631
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
632
+ errorcode = NOCONNERR;
633
+ return NULL;
634
+ }
635
+
636
+ snprintf(process_id, sizeof(process_id), "%d", pid);
637
+
638
+ pcp_write(pc, "P", 1);
639
+ wsize = htonl(strlen(process_id)+1 + sizeof(int));
640
+ pcp_write(pc, &wsize, sizeof(int));
641
+ pcp_write(pc, process_id, strlen(process_id)+1);
642
+ if (pcp_flush(pc) < 0)
643
+ {
644
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
645
+ return NULL;
646
+ }
647
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"P\", len=%d\n", ntohl(wsize));
648
+
649
+ while (1)
650
+ {
651
+ if (pcp_read(pc, &tos, 1))
652
+ return NULL;
653
+ if (pcp_read(pc, &rsize, sizeof(int)))
654
+ return NULL;
655
+ rsize = ntohl(rsize);
656
+ buf = (char *)malloc(rsize);
657
+ if (buf == NULL)
658
+ {
659
+ errorcode = NOMEMERR;
660
+ return NULL;
661
+ }
662
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
663
+ {
664
+ free(buf);
665
+ return NULL;
666
+ }
667
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
668
+
669
+ if (tos == 'e')
670
+ {
671
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
672
+ free(buf);
673
+ errorcode = BACKENDERR;
674
+ return NULL;
675
+ }
676
+ else if (tos == 'p')
677
+ {
678
+ char *index;
679
+
680
+ if (strcmp(buf, "ArraySize") == 0)
681
+ {
682
+ index = (char *) memchr(buf, '\0', rsize) + 1;
683
+ if (index != NULL)
684
+ ci_size = atoi(index);
685
+
686
+ *array_size = ci_size;
687
+
688
+ process_info = (ProcessInfo *)malloc(sizeof(ProcessInfo) * ci_size);
689
+ if (process_info == NULL)
690
+ {
691
+ free(buf);
692
+ errorcode = NOMEMERR;
693
+ return NULL;
694
+ }
695
+
696
+ conn_info = (ConnectionInfo *)malloc(sizeof(ConnectionInfo) * ci_size);
697
+ if (conn_info == NULL)
698
+ {
699
+ free(buf);
700
+ free(process_info);
701
+ errorcode = NOMEMERR;
702
+ return NULL;
703
+ }
704
+
705
+ continue;
706
+ }
707
+ else if (strcmp(buf, "ProcessInfo") == 0)
708
+ {
709
+ process_info[offset].connection_info = &conn_info[offset];
710
+
711
+ index = (char *) memchr(buf, '\0', rsize) + 1;
712
+ if (index != NULL)
713
+ process_info[offset].pid = atoi(index);
714
+
715
+ index = (char *) memchr(index, '\0', rsize) + 1;
716
+ if (index != NULL)
717
+ strcpy(process_info[offset].connection_info->database, index);
718
+
719
+ index = (char *) memchr(index, '\0', rsize) + 1;
720
+ if (index != NULL)
721
+ strcpy(process_info[offset].connection_info->user, index);
722
+
723
+ index = (char *) memchr(index, '\0', rsize) + 1;
724
+ if (index != NULL)
725
+ process_info[offset].start_time = atol(index);
726
+
727
+ index = (char *) memchr(index, '\0', rsize) + 1;
728
+ if (index != NULL)
729
+ process_info[offset].connection_info->create_time = atol(index);
730
+
731
+ index = (char *) memchr(index, '\0', rsize) + 1;
732
+ if (index != NULL)
733
+ process_info[offset].connection_info->major = atoi(index);
734
+
735
+ index = (char *) memchr(index, '\0', rsize) + 1;
736
+ if (index != NULL)
737
+ process_info[offset].connection_info->minor = atoi(index);
738
+
739
+ index = (char *) memchr(index, '\0', rsize) + 1;
740
+ if (index != NULL)
741
+ process_info[offset].connection_info->counter = atoi(index);
742
+
743
+ index = (char *) memchr(index, '\0', rsize) + 1;
744
+ if (index != NULL)
745
+ process_info[offset].connection_info->backend_id = atoi(index);
746
+
747
+ index = (char *) memchr(index, '\0', rsize) + 1;
748
+ if (index != NULL)
749
+ process_info[offset].connection_info->pid = atoi(index);
750
+
751
+ index = (char *) memchr(index, '\0', rsize) + 1;
752
+ if (index != NULL)
753
+ process_info[offset].connection_info->connected = atoi(index);
754
+
755
+ offset++;
756
+ }
757
+ else if (strcmp(buf, "CommandComplete") == 0)
758
+ {
759
+ free(buf);
760
+ return process_info;
761
+ }
762
+ else
763
+ {
764
+ /* never reached */
765
+ }
766
+ }
767
+ }
768
+
769
+ free(buf);
770
+ return NULL;
771
+ }
772
+
773
+ /* --------------------------------
774
+ * pcp_systemdb_info - get information of system DB
775
+ *
776
+ * return structure of system DB information on success, -1 otherwise
777
+ * --------------------------------
778
+ */
779
+ SystemDBInfo *
780
+ pcp_systemdb_info(void)
781
+ {
782
+ char tos;
783
+ char *buf = NULL;
784
+ int wsize;
785
+ int rsize;
786
+ SystemDBInfo *systemdb_info = NULL;
787
+ int offset = 0;
788
+
789
+ if (pc == NULL)
790
+ {
791
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
792
+ errorcode = NOCONNERR;
793
+ return NULL;
794
+ }
795
+
796
+ pcp_write(pc, "S", 1);
797
+ wsize = htonl(sizeof(int));
798
+ pcp_write(pc, &wsize, sizeof(int));
799
+ if (pcp_flush(pc) < 0)
800
+ {
801
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
802
+ return NULL;
803
+ }
804
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"S\", len=%d\n", ntohl(wsize));
805
+
806
+ while (1) {
807
+ if (pcp_read(pc, &tos, 1))
808
+ return NULL;
809
+ if (pcp_read(pc, &rsize, sizeof(int)))
810
+ return NULL;
811
+ rsize = ntohl(rsize);
812
+ buf = (char *)malloc(rsize);
813
+ if (buf == NULL)
814
+ {
815
+ errorcode = NOMEMERR;
816
+ return NULL;
817
+ }
818
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
819
+ {
820
+ free(buf);
821
+ return NULL;
822
+ }
823
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
824
+
825
+ if (tos == 'e')
826
+ {
827
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
828
+ free(buf);
829
+ errorcode = BACKENDERR;
830
+ return NULL;
831
+ }
832
+ else if (tos == 's')
833
+ {
834
+ char *index;
835
+
836
+ if (strcmp(buf, "SystemDBInfo") == 0)
837
+ {
838
+ systemdb_info = (SystemDBInfo *)malloc(sizeof(SystemDBInfo));
839
+ if (systemdb_info == NULL)
840
+ {
841
+ free(buf);
842
+ errorcode = NOMEMERR;
843
+ return NULL;
844
+ }
845
+
846
+ index = (char *) memchr(buf, '\0', rsize) + 1;
847
+ if (index != NULL)
848
+ systemdb_info->hostname = strdup(index);
849
+ if (systemdb_info->hostname == NULL)
850
+ {
851
+ free(buf);
852
+ free_systemdb_info(systemdb_info);
853
+ errorcode = NOMEMERR;
854
+ return NULL;
855
+ }
856
+
857
+ index = (char *) memchr(index, '\0', rsize) + 1;
858
+ if (index != NULL)
859
+ systemdb_info->port = atoi(index);
860
+
861
+ index = (char *) memchr(index, '\0', rsize) + 1;
862
+ if (index != NULL)
863
+ systemdb_info->user = strdup(index);
864
+ if (systemdb_info->user == NULL)
865
+ {
866
+ free(buf);
867
+ free_systemdb_info(systemdb_info);
868
+ errorcode = NOMEMERR;
869
+ return NULL;
870
+ }
871
+
872
+ index = (char *) memchr(index, '\0', rsize) + 1;
873
+ if (index != NULL)
874
+ systemdb_info->password = strdup(index);
875
+ if (systemdb_info->password == NULL)
876
+ {
877
+ free(buf);
878
+ free_systemdb_info(systemdb_info);
879
+ errorcode = NOMEMERR;
880
+ return NULL;
881
+ }
882
+
883
+ index = (char *) memchr(index, '\0', rsize) + 1;
884
+ if (index != NULL)
885
+ systemdb_info->schema_name = strdup(index);
886
+ if (systemdb_info->schema_name == NULL)
887
+ {
888
+ free(buf);
889
+ free_systemdb_info(systemdb_info);
890
+ errorcode = NOMEMERR;
891
+ return NULL;
892
+ }
893
+
894
+ index = (char *) memchr(index, '\0', rsize) + 1;
895
+ if (index != NULL)
896
+ systemdb_info->database_name = strdup(index);
897
+ if (systemdb_info->database_name == NULL)
898
+ {
899
+ free(buf);
900
+ free_systemdb_info(systemdb_info);
901
+ errorcode = NOMEMERR;
902
+ return NULL;
903
+ }
904
+
905
+ index = (char *) memchr(index, '\0', rsize) + 1;
906
+ if (index != NULL)
907
+ systemdb_info->dist_def_num = atoi(index);
908
+
909
+ index = (char *) memchr(index, '\0', rsize) + 1;
910
+ if (index != NULL)
911
+ systemdb_info->system_db_status = atoi(index);
912
+
913
+ if (systemdb_info->dist_def_num > 0)
914
+ {
915
+ systemdb_info->dist_def_slot = NULL;
916
+ systemdb_info->dist_def_slot = (DistDefInfo *)malloc(sizeof(DistDefInfo) * systemdb_info->dist_def_num);
917
+ if (systemdb_info->dist_def_slot == NULL)
918
+ {
919
+ free(buf);
920
+ free_systemdb_info(systemdb_info);
921
+ errorcode = NOMEMERR;
922
+ return NULL;
923
+ }
924
+ }
925
+ }
926
+ else if (strcmp(buf, "DistDefInfo") == 0)
927
+ {
928
+ DistDefInfo *dist_def_info = NULL;
929
+ int i;
930
+
931
+ dist_def_info = (DistDefInfo *)malloc(sizeof(DistDefInfo));
932
+ if (dist_def_info == NULL)
933
+ {
934
+ free(buf);
935
+ free_systemdb_info(systemdb_info);
936
+ errorcode = NOMEMERR;
937
+ return NULL;
938
+ }
939
+
940
+ index = (char *) memchr(buf, '\0', rsize) + 1;
941
+ if (index != NULL)
942
+ dist_def_info->dbname = strdup(index);
943
+ if (dist_def_info->dbname == NULL)
944
+ {
945
+ free(buf);
946
+ free_systemdb_info(systemdb_info);
947
+ errorcode = NOMEMERR;
948
+ return NULL;
949
+ }
950
+
951
+ index = (char *) memchr(index, '\0', rsize) + 1;
952
+ if (index != NULL)
953
+ dist_def_info->schema_name = strdup(index);
954
+ if (dist_def_info->schema_name == NULL)
955
+ {
956
+ free(buf);
957
+ free_systemdb_info(systemdb_info);
958
+ errorcode = NOMEMERR;
959
+ return NULL;
960
+ }
961
+
962
+ index = (char *) memchr(index, '\0', rsize) + 1;
963
+ if (index != NULL)
964
+ dist_def_info->table_name = strdup(index);
965
+ if (dist_def_info->table_name == NULL)
966
+ {
967
+ free(buf);
968
+ free_systemdb_info(systemdb_info);
969
+ errorcode = NOMEMERR;
970
+ return NULL;
971
+ }
972
+
973
+ index = (char *) memchr(index, '\0', rsize) + 1;
974
+ if (index != NULL)
975
+ dist_def_info->dist_key_col_name = strdup(index);
976
+ if (dist_def_info->dist_key_col_name == NULL)
977
+ {
978
+ free(buf);
979
+ free_systemdb_info(systemdb_info);
980
+ errorcode = NOMEMERR;
981
+ return NULL;
982
+ }
983
+
984
+ index = (char *) memchr(index, '\0', rsize) + 1;
985
+ if (index != NULL)
986
+ dist_def_info->col_num = atoi(index);
987
+
988
+ dist_def_info->col_list = NULL;
989
+ dist_def_info->col_list = (char **)malloc(sizeof(char *) * dist_def_info->col_num);
990
+ if (dist_def_info->col_list == NULL)
991
+ {
992
+ free(buf);
993
+ free_systemdb_info(systemdb_info);
994
+ errorcode = NOMEMERR;
995
+ return NULL;
996
+ }
997
+ for (i = 0; i < dist_def_info->col_num; i++)
998
+ {
999
+ index = (char *) memchr(index, '\0', rsize) + 1;
1000
+ if (index != NULL)
1001
+ dist_def_info->col_list[i] = strdup(index);
1002
+ if (dist_def_info->col_list[i] == NULL)
1003
+ {
1004
+ free(buf);
1005
+ free_systemdb_info(systemdb_info);
1006
+ errorcode = NOMEMERR;
1007
+ return NULL;
1008
+ }
1009
+ }
1010
+
1011
+ dist_def_info->type_list = NULL;
1012
+ dist_def_info->type_list = (char **)malloc(sizeof(char *) * dist_def_info->col_num);
1013
+ if (dist_def_info->type_list == NULL)
1014
+ {
1015
+ free(buf);
1016
+ free_systemdb_info(systemdb_info);
1017
+ errorcode = NOMEMERR;
1018
+ return NULL;
1019
+ }
1020
+ for (i = 0; i < dist_def_info->col_num; i++)
1021
+ {
1022
+ index = (char *) memchr(index, '\0', rsize) + 1;
1023
+ if (index != NULL)
1024
+ dist_def_info->type_list[i] = strdup(index);
1025
+ if (dist_def_info->type_list[i] == NULL)
1026
+ {
1027
+ free(buf);
1028
+ free_systemdb_info(systemdb_info);
1029
+ errorcode = NOMEMERR;
1030
+ return NULL;
1031
+ }
1032
+ }
1033
+
1034
+ index = (char *) memchr(index, '\0', rsize) + 1;
1035
+ if (index != NULL)
1036
+ dist_def_info->dist_def_func = strdup(index);
1037
+ if (dist_def_info->dist_def_func == NULL)
1038
+ {
1039
+ free(buf);
1040
+ free_systemdb_info(systemdb_info);
1041
+ errorcode = NOMEMERR;
1042
+ return NULL;
1043
+ }
1044
+
1045
+ memcpy(&systemdb_info->dist_def_slot[offset++], dist_def_info, sizeof(DistDefInfo));
1046
+ }
1047
+ else if (strcmp(buf, "CommandComplete") == 0)
1048
+ {
1049
+ free(buf);
1050
+ return systemdb_info;
1051
+ }
1052
+ else
1053
+ {
1054
+ /* never reached */
1055
+ }
1056
+ }
1057
+ }
1058
+
1059
+ free(buf);
1060
+ return NULL;
1061
+ }
1062
+
1063
+ void
1064
+ free_systemdb_info(SystemDBInfo * si)
1065
+ {
1066
+ int i, j;
1067
+
1068
+ free(si->hostname);
1069
+ free(si->user);
1070
+ free(si->password);
1071
+ free(si->schema_name);
1072
+ free(si->database_name);
1073
+
1074
+ if (si->dist_def_slot != NULL)
1075
+ {
1076
+ for (i = 0; i < si->dist_def_num; i++)
1077
+ {
1078
+ DistDefInfo *di = &si->dist_def_slot[i];
1079
+ free(di->dbname);
1080
+ free(di->schema_name);
1081
+ free(di->table_name);
1082
+ free(di->dist_def_func);
1083
+ for (j = 0; j < di->col_num; j++)
1084
+ {
1085
+ free(di->col_list[j]);
1086
+ free(di->type_list[j]);
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ free(si);
1092
+ }
1093
+
1094
+ /* --------------------------------
1095
+ * pcp_detach_node - detach a node given by the argument from pgpool's control
1096
+ *
1097
+ * return 0 on success, -1 otherwise
1098
+ * --------------------------------
1099
+ */
1100
+ int
1101
+ pcp_detach_node(int nid)
1102
+ {
1103
+ return _pcp_detach_node(nid, FALSE);
1104
+ }
1105
+
1106
+ /* --------------------------------
1107
+
1108
+ * and detach a node given by the argument from pgpool's control
1109
+ *
1110
+ * return 0 on success, -1 otherwise
1111
+ * --------------------------------
1112
+ */
1113
+ int
1114
+ pcp_detach_node_gracefully(int nid)
1115
+ {
1116
+ return _pcp_detach_node(nid, TRUE);
1117
+ }
1118
+
1119
+ static int _pcp_detach_node(int nid, bool gracefully)
1120
+ {
1121
+ int wsize;
1122
+ char node_id[16];
1123
+ char tos;
1124
+ char *buf = NULL;
1125
+ int rsize;
1126
+ char *sendchar;
1127
+
1128
+ if (pc == NULL)
1129
+ {
1130
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
1131
+ errorcode = NOCONNERR;
1132
+ return -1;
1133
+ }
1134
+
1135
+ snprintf(node_id, sizeof(node_id), "%d", nid);
1136
+
1137
+ if (gracefully)
1138
+ sendchar = "d";
1139
+ else
1140
+ sendchar = "D";
1141
+
1142
+ pcp_write(pc, sendchar, 1);
1143
+ wsize = htonl(strlen(node_id)+1 + sizeof(int));
1144
+ pcp_write(pc, &wsize, sizeof(int));
1145
+ pcp_write(pc, node_id, strlen(node_id)+1);
1146
+ if (pcp_flush(pc) < 0)
1147
+ {
1148
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
1149
+ return -1;
1150
+ }
1151
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize));
1152
+
1153
+ if (pcp_read(pc, &tos, 1))
1154
+ return -1;
1155
+ if (pcp_read(pc, &rsize, sizeof(int)))
1156
+ return -1;
1157
+ rsize = ntohl(rsize);
1158
+ buf = (char *)malloc(rsize);
1159
+ if (buf == NULL)
1160
+ {
1161
+ errorcode = NOMEMERR;
1162
+ return -1;
1163
+ }
1164
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
1165
+ {
1166
+ free(buf);
1167
+ return -1;
1168
+ }
1169
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
1170
+
1171
+ if (tos == 'e')
1172
+ {
1173
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
1174
+ errorcode = BACKENDERR;
1175
+ }
1176
+ else if (tos == 'd')
1177
+ {
1178
+ /* strcmp() for success message, or fail */
1179
+ if(strcmp(buf, "CommandComplete") == 0)
1180
+ {
1181
+ free(buf);
1182
+ return 0;
1183
+ }
1184
+ }
1185
+
1186
+ free(buf);
1187
+ return -1;
1188
+ }
1189
+
1190
+
1191
+ /* --------------------------------
1192
+ * pcp_attach_node - attach a node given by the argument from pgpool's control
1193
+ *
1194
+ * return 0 on success, -1 otherwise
1195
+ * --------------------------------
1196
+ */
1197
+ int
1198
+ pcp_attach_node(int nid)
1199
+ {
1200
+ int wsize;
1201
+ char node_id[16];
1202
+ char tos;
1203
+ char *buf = NULL;
1204
+ int rsize;
1205
+
1206
+ if (pc == NULL)
1207
+ {
1208
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
1209
+ errorcode = NOCONNERR;
1210
+ return -1;
1211
+ }
1212
+
1213
+ snprintf(node_id, sizeof(node_id), "%d", nid);
1214
+
1215
+ pcp_write(pc, "C", 1);
1216
+ wsize = htonl(strlen(node_id)+1 + sizeof(int));
1217
+ pcp_write(pc, &wsize, sizeof(int));
1218
+ pcp_write(pc, node_id, strlen(node_id)+1);
1219
+ if (pcp_flush(pc) < 0)
1220
+ {
1221
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
1222
+ return -1;
1223
+ }
1224
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize));
1225
+
1226
+ if (pcp_read(pc, &tos, 1))
1227
+ return -1;
1228
+ if (pcp_read(pc, &rsize, sizeof(int)))
1229
+ return -1;
1230
+ rsize = ntohl(rsize);
1231
+ buf = (char *)malloc(rsize);
1232
+ if (buf == NULL)
1233
+ {
1234
+ errorcode = NOMEMERR;
1235
+ return -1;
1236
+ }
1237
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
1238
+ {
1239
+ free(buf);
1240
+ return -1;
1241
+ }
1242
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
1243
+
1244
+ if (tos == 'e')
1245
+ {
1246
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
1247
+ errorcode = BACKENDERR;
1248
+ }
1249
+ else if (tos == 'c')
1250
+ {
1251
+ /* strcmp() for success message, or fail */
1252
+ if(strcmp(buf, "CommandComplete") == 0)
1253
+ {
1254
+ free(buf);
1255
+ return 0;
1256
+ }
1257
+ }
1258
+
1259
+ free(buf);
1260
+ return -1;
1261
+ }
1262
+
1263
+ /* --------------------------------
1264
+ * pcp_pool_status - return setup parameters and status
1265
+ *
1266
+ * returns and array of POOL_REPORT_CONFIG, NULL otherwise
1267
+ * --------------------------------
1268
+ */
1269
+ POOL_REPORT_CONFIG*
1270
+ pcp_pool_status(int *array_size)
1271
+ {
1272
+ char tos;
1273
+ char *buf = NULL;
1274
+ int wsize;
1275
+ int rsize;
1276
+ POOL_REPORT_CONFIG *status = NULL;
1277
+ int ci_size = 0;
1278
+ int offset = 0;
1279
+
1280
+ if (pc == NULL)
1281
+ {
1282
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
1283
+ errorcode = NOCONNERR;
1284
+ return NULL;
1285
+ }
1286
+
1287
+ pcp_write(pc, "B", 1);
1288
+ wsize = htonl(sizeof(int));
1289
+ pcp_write(pc, &wsize, sizeof(int));
1290
+ if (pcp_flush(pc) < 0)
1291
+ {
1292
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
1293
+ return NULL;
1294
+ }
1295
+ if (debug) fprintf(stderr, "DEBUG pcp_pool_status: send: tos=\"B\", len=%d\n", ntohl(wsize));
1296
+
1297
+ while (1) {
1298
+ if (pcp_read(pc, &tos, 1))
1299
+ return NULL;
1300
+ if (pcp_read(pc, &rsize, sizeof(int)))
1301
+ return NULL;
1302
+ rsize = ntohl(rsize);
1303
+ buf = (char *)malloc(rsize);
1304
+ if (buf == NULL)
1305
+ {
1306
+ errorcode = NOMEMERR;
1307
+ return NULL;
1308
+ }
1309
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
1310
+ {
1311
+ free(buf);
1312
+ return NULL;
1313
+ }
1314
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
1315
+
1316
+ if (tos == 'e')
1317
+ {
1318
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
1319
+ free(buf);
1320
+ errorcode = BACKENDERR;
1321
+ return NULL;
1322
+ }
1323
+ else if (tos == 'b')
1324
+ {
1325
+ char *index;
1326
+
1327
+ if (strcmp(buf, "ArraySize") == 0)
1328
+ {
1329
+ index = (char *) memchr(buf, '\0', rsize) + 1;
1330
+ ci_size = ntohl(*((int *)index));
1331
+
1332
+ *array_size = ci_size;
1333
+
1334
+ status = (POOL_REPORT_CONFIG *) malloc(ci_size * sizeof(POOL_REPORT_CONFIG));
1335
+
1336
+ continue;
1337
+ }
1338
+ else if (strcmp(buf, "ProcessConfig") == 0)
1339
+ {
1340
+ index = (char *) memchr(buf, '\0', rsize) + 1;
1341
+ if (index != NULL)
1342
+ strcpy(status[offset].name, index);
1343
+
1344
+ index = (char *) memchr(index, '\0', rsize) + 1;
1345
+ if (index != NULL)
1346
+ strcpy(status[offset].value, index);
1347
+
1348
+ index = (char *) memchr(index, '\0', rsize) + 1;
1349
+ if (index != NULL)
1350
+ strcpy(status[offset].desc, index);
1351
+
1352
+ offset++;
1353
+ }
1354
+ else if (strcmp(buf, "CommandComplete") == 0)
1355
+ {
1356
+ free(buf);
1357
+ return status;
1358
+ }
1359
+ else
1360
+ {
1361
+ /* never reached */
1362
+ }
1363
+ }
1364
+ }
1365
+
1366
+ free(buf);
1367
+ return NULL;
1368
+ }
1369
+
1370
+ void
1371
+ pcp_set_timeout(long sec)
1372
+ {
1373
+ /* disable timeout (wait forever!) (2008/02/08 yamaguti) */
1374
+ sec = 0;
1375
+ pcp_timeout.tv_sec = sec;
1376
+ }
1377
+
1378
+
1379
+ int
1380
+ pcp_recovery_node(int nid)
1381
+ {
1382
+ int wsize;
1383
+ char node_id[16];
1384
+ char tos;
1385
+ char *buf = NULL;
1386
+ int rsize;
1387
+
1388
+ if (pc == NULL)
1389
+ {
1390
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
1391
+ errorcode = NOCONNERR;
1392
+ return -1;
1393
+ }
1394
+
1395
+ snprintf(node_id, sizeof(node_id), "%d", nid);
1396
+
1397
+ pcp_write(pc, "O", 1);
1398
+ wsize = htonl(strlen(node_id)+1 + sizeof(int));
1399
+ pcp_write(pc, &wsize, sizeof(int));
1400
+ pcp_write(pc, node_id, strlen(node_id)+1);
1401
+ if (pcp_flush(pc) < 0)
1402
+ {
1403
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
1404
+ return -1;
1405
+ }
1406
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"D\", len=%d\n", ntohl(wsize));
1407
+
1408
+ if (pcp_read(pc, &tos, 1))
1409
+ return -1;
1410
+ if (pcp_read(pc, &rsize, sizeof(int)))
1411
+ return -1;
1412
+ rsize = ntohl(rsize);
1413
+ buf = (char *)malloc(rsize);
1414
+ if (buf == NULL)
1415
+ {
1416
+ errorcode = NOMEMERR;
1417
+ return -1;
1418
+ }
1419
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
1420
+ {
1421
+ free(buf);
1422
+ return -1;
1423
+ }
1424
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
1425
+
1426
+ if (tos == 'e')
1427
+ {
1428
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
1429
+ errorcode = BACKENDERR;
1430
+ }
1431
+ else if (tos == 'c')
1432
+ {
1433
+ /* strcmp() for success message, or fail */
1434
+ if(strcmp(buf, "CommandComplete") == 0)
1435
+ {
1436
+ free(buf);
1437
+ return 0;
1438
+ }
1439
+ }
1440
+
1441
+ free(buf);
1442
+ return -1;
1443
+ }
1444
+
1445
+ void
1446
+ pcp_enable_debug(void)
1447
+ {
1448
+ debug = 1;
1449
+ }
1450
+
1451
+ void
1452
+ pcp_disable_debug(void)
1453
+ {
1454
+ debug = 0;
1455
+ }
1456
+
1457
+ /* --------------------------------
1458
+ * pcp_promote_node - promote a node given by the argument as new pgpool's master
1459
+ *
1460
+ * return 0 on success, -1 otherwise
1461
+ * --------------------------------
1462
+ */
1463
+ int
1464
+ pcp_promote_node(int nid)
1465
+ {
1466
+ return _pcp_promote_node(nid, FALSE);
1467
+ }
1468
+
1469
+ /* --------------------------------
1470
+
1471
+ * and promote a node given by the argument as new pgpool's master
1472
+ *
1473
+ * return 0 on success, -1 otherwise
1474
+ * --------------------------------
1475
+ */
1476
+ int
1477
+ pcp_promote_node_gracefully(int nid)
1478
+ {
1479
+ return _pcp_promote_node(nid, TRUE);
1480
+ }
1481
+
1482
+ static int _pcp_promote_node(int nid, bool gracefully)
1483
+ {
1484
+ int wsize;
1485
+ char node_id[16];
1486
+ char tos;
1487
+ char *buf = NULL;
1488
+ int rsize;
1489
+ char *sendchar;
1490
+
1491
+ if (pc == NULL)
1492
+ {
1493
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
1494
+ errorcode = NOCONNERR;
1495
+ return -1;
1496
+ }
1497
+
1498
+ snprintf(node_id, sizeof(node_id), "%d", nid);
1499
+
1500
+ if (gracefully)
1501
+ sendchar = "j";
1502
+ else
1503
+ sendchar = "J";
1504
+
1505
+ pcp_write(pc, sendchar, 1);
1506
+ wsize = htonl(strlen(node_id)+1 + sizeof(int));
1507
+ pcp_write(pc, &wsize, sizeof(int));
1508
+ pcp_write(pc, node_id, strlen(node_id)+1);
1509
+ if (pcp_flush(pc) < 0)
1510
+ {
1511
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
1512
+ return -1;
1513
+ }
1514
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"E\", len=%d\n", ntohl(wsize));
1515
+
1516
+ if (pcp_read(pc, &tos, 1))
1517
+ return -1;
1518
+ if (pcp_read(pc, &rsize, sizeof(int)))
1519
+ return -1;
1520
+ rsize = ntohl(rsize);
1521
+ buf = (char *)malloc(rsize);
1522
+ if (buf == NULL)
1523
+ {
1524
+ errorcode = NOMEMERR;
1525
+ return -1;
1526
+ }
1527
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
1528
+ {
1529
+ free(buf);
1530
+ return -1;
1531
+ }
1532
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
1533
+
1534
+ if (tos == 'e')
1535
+ {
1536
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
1537
+ errorcode = BACKENDERR;
1538
+ }
1539
+ else if (tos == 'd')
1540
+ {
1541
+ /* strcmp() for success message, or fail */
1542
+ if(strcmp(buf, "CommandComplete") == 0)
1543
+ {
1544
+ free(buf);
1545
+ return 0;
1546
+ }
1547
+ }
1548
+
1549
+ free(buf);
1550
+ return -1;
1551
+ }
1552
+
1553
+ /* --------------------------------
1554
+ * pcp_watchdog_info - get information of watchdog
1555
+ *
1556
+ * return structure of watchdog information on success, -1 otherwise
1557
+ * --------------------------------
1558
+ */
1559
+ WdInfo *
1560
+ pcp_watchdog_info(int nid)
1561
+ {
1562
+ int wsize;
1563
+ char wd_index[16];
1564
+ char tos;
1565
+ char *buf = NULL;
1566
+ int rsize;
1567
+
1568
+ if (pc == NULL)
1569
+ {
1570
+ if (debug) fprintf(stderr, "DEBUG: connection does not exist\n");
1571
+ errorcode = NOCONNERR;
1572
+ return NULL;
1573
+ }
1574
+
1575
+ snprintf(wd_index, sizeof(wd_index), "%d", nid);
1576
+
1577
+ pcp_write(pc, "W", 1);
1578
+ wsize = htonl(strlen(wd_index)+1 + sizeof(int));
1579
+ pcp_write(pc, &wsize, sizeof(int));
1580
+ pcp_write(pc, wd_index, strlen(wd_index)+1);
1581
+ if (pcp_flush(pc) < 0)
1582
+ {
1583
+ if (debug) fprintf(stderr, "DEBUG: could not send data to backend\n");
1584
+ return NULL;
1585
+ }
1586
+ if (debug) fprintf(stderr, "DEBUG: send: tos=\"W\", len=%d\n", ntohl(wsize));
1587
+
1588
+ if (pcp_read(pc, &tos, 1))
1589
+ return NULL;
1590
+ if (pcp_read(pc, &rsize, sizeof(int)))
1591
+ return NULL;
1592
+ rsize = ntohl(rsize);
1593
+ buf = (char *)malloc(rsize);
1594
+ if (buf == NULL)
1595
+ {
1596
+ errorcode = NOMEMERR;
1597
+ return NULL;
1598
+ }
1599
+ if (pcp_read(pc, buf, rsize - sizeof(int)))
1600
+ {
1601
+ free(buf);
1602
+ return NULL;
1603
+ }
1604
+
1605
+ if (debug) fprintf(stderr, "DEBUG: recv: tos=\"%c\", len=%d, data=%s\n", tos, rsize, buf);
1606
+
1607
+ if (tos == 'e')
1608
+ {
1609
+ if (debug) fprintf(stderr, "DEBUG: command failed. reason=%s\n", buf);
1610
+ errorcode = BACKENDERR;
1611
+ free(buf);
1612
+ return NULL;
1613
+ }
1614
+ else if (tos == 'w')
1615
+ {
1616
+ if (strcmp(buf, "CommandComplete") == 0)
1617
+ {
1618
+ char *index = NULL;
1619
+ WdInfo* watchdog_info = NULL;
1620
+
1621
+ watchdog_info = (WdInfo *)malloc(sizeof(WdInfo));
1622
+ if (watchdog_info == NULL)
1623
+ {
1624
+ errorcode = NOMEMERR;
1625
+ free(buf);
1626
+ return NULL;
1627
+ }
1628
+
1629
+ index = (char *) memchr(buf, '\0', rsize) + 1;
1630
+ if (index != NULL)
1631
+ strcpy(watchdog_info->hostname, index);
1632
+
1633
+ index = (char *) memchr(index, '\0', rsize) + 1;
1634
+ if (index != NULL)
1635
+ watchdog_info->pgpool_port = atoi(index);
1636
+
1637
+ index = (char *) memchr(index, '\0', rsize) + 1;
1638
+ if (index != NULL)
1639
+ watchdog_info->wd_port = atoi(index);
1640
+
1641
+ index = (char *) memchr(index, '\0', rsize) + 1;
1642
+ if (index != NULL)
1643
+ watchdog_info->status = atof(index);
1644
+
1645
+ free(buf);
1646
+ return watchdog_info;
1647
+ }
1648
+ }
1649
+
1650
+ free(buf);
1651
+ return NULL;
1652
+ }