public static function build_slonik_paths($db_doc, $replica_set, $slony_paths_file) { dbsteward::notice("Building slonik STORE PATHs for replica set ID " . $replica_set['id'] . " output file " . $slony_paths_file); $timestamp = date('r'); $slony_paths_fp = fopen($slony_paths_file, 'a'); if ($slony_paths_fp === FALSE) { throw new exception("failed to open slony paths output file " . $slony_paths_file); } $slony_paths_ofs = new output_file_segmenter($slony_paths_file, 1, $slony_paths_fp, $slony_paths_file); $slony_paths_ofs->set_comment_line_prefix("#"); // keep slonik file comment lines consistent // don't write the fixed file header file name. slony preamble must start with the CLUSTER NAME directive $slony_paths_ofs->disable_fixed_file_header(); $slony_paths_ofs->write("# " . $slony_paths_file . "\n"); $slony_paths_ofs->write("# DBSteward slony paths generated " . $timestamp . "\n"); $slony_paths_ofs->write("# Replica Set: " . $replica_set['id'] . "\n\n"); if (!isset($db_doc->database->slony->slonyNode)) { $slony_paths_ofs->write("DBSTEWARD: NO SLONY NODES DEFINED\n"); return FALSE; } $node_ids = pgsql8::get_slony_replica_set_node_ids($replica_set); for ($i = 0; $i < count($node_ids); $i++) { $node_i = $node_ids[$i]; for ($j = 0; $j < count($node_ids); $j++) { $node_j = $node_ids[$j]; // if we are not talking about the same node for both server and client // write the path if ($node_i != $node_j) { $slony_paths_ofs->write("STORE PATH (SERVER = " . $node_j . ", CLIENT = " . $node_i . ", CONNINFO = '" . "dbname=" . pgsql8::get_slony_replica_set_node_attribute($db_doc, $replica_set, $node_j, 'dbName') . " host=" . pgsql8::get_slony_replica_set_node_attribute($db_doc, $replica_set, $node_j, 'dbHost') . " user="******" password="******"');\n"); } } } $slony_paths_ofs->write("\n"); }