/[rserv]/bin/MasterInit
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /bin/MasterInit

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Tue Aug 5 09:20:08 2003 UTC (20 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: debian
Changes since 1.1: +7 -5 lines
change paths to support Debian

1 dpavlin 1.2 #!/usr/bin/perl
2 dpavlin 1.1 # MasterInit
3     # Vadim Mikheev, (c) 2000, PostgreSQL Inc.
4    
5     eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
6     & eval 'exec perl -S $0 $argv:q'
7     if 0;
8    
9     use Pg;
10     use Getopt::Long;
11    
12     $| = 1;
13    
14     $result = GetOptions("debug!", "verbose!", "help",
15     "host=s", "user=s", "password=s");
16    
17     my $debug = $opt_debug || 0;
18     my $verbose = $opt_verbose || 0;
19    
20     if (defined($opt_help) || (scalar(@ARGV) < 1)) {
21     print "Usage: $0 --host=name --user=name --password=string masterdb\n";
22     exit ((scalar(@ARGV) < 1)? 1:0);
23     }
24    
25 dpavlin 1.2 my $module_filename = '$libdir/rserv';
26    
27 dpavlin 1.1 my $master = $ARGV[0] || "master";
28    
29     my $minfo = "dbname=$master";
30     $minfo = "$minfo host=$opt_host" if (defined($opt_host));
31     $minfo = "$minfo user=$opt_user" if (defined($opt_user));
32     $minfo = "$minfo password=$opt_password" if (defined($opt_password));
33    
34     sub RollbackAndQuit {
35     $conn = shift @_;
36    
37     print STDERR "Error in query: ", $conn->errorMessage;
38     $conn->exec("ROLLBACK");
39     exit (-1);
40     }
41    
42     my $conn = Pg::connectdb($minfo);
43     if ($conn->status != PGRES_CONNECTION_OK) {
44     print STDERR "Failed opening $minfo\n";
45     exit 1;
46     }
47    
48     my $result = $conn->exec("BEGIN");
49     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
50    
51     $result = $conn->exec("set transaction isolation level serializable");
52     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
53    
54     # List of slave servers
55     $result = $conn->exec("create table _RSERV_SERVERS_" .
56     " (server serial, host text, post int4, dbase text)");
57     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
58    
59     # List of replicated tables
60     $result = $conn->exec("create table _RSERV_TABLES_" .
61     " (tname name, cname name, reloid oid, key int4)");
62     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
63    
64     # Bookkeeping log for row replication
65     $result = $conn->exec("create table _RSERV_LOG_" .
66     " (reloid oid, logid int4, logtime timestamp, deleted int4, key text)");
67     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
68    
69     # This is to speedup lookup of deleted tuples
70     $result = $conn->exec("create index _RSERV_LOG_INDX_DLT_ID_ on _RSERV_LOG_ (deleted, logid)");
71     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
72    
73     # This is to speedup cleanup
74     $result = $conn->exec("create index _RSERV_LOG_INDX_TM_ID_ on _RSERV_LOG_ (logtime, logid)");
75     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
76    
77     # This is to speedup trigger and lookup of updated tuples
78     $result = $conn->exec("create index _RSERV_LOG_INDX_REL_KEY_ on _RSERV_LOG_ (reloid, key)");
79     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
80    
81     # Sync point for each slave server
82     $result = $conn->exec("create table _RSERV_SYNC_" .
83     " (server int4, syncid int4, synctime timestamp" .
84     ", status int4, minid int4, maxid int4, active text)");
85     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
86    
87     $result = $conn->exec("create index _RSERV_SYNC_INDX_SRV_ID_ on _RSERV_SYNC_ (server, syncid)");
88     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
89    
90     # Sync point reference numbers
91     $result = $conn->exec("create sequence _rserv_sync_seq_");
92     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
93    
94 dpavlin 1.2 $result = $conn->exec("CREATE FUNCTION _rserv_log_() RETURNS trigger" .
95     " AS '$module_filename' LANGUAGE 'c'");
96 dpavlin 1.1 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
97    
98     $result = $conn->exec("CREATE FUNCTION _rserv_sync_(int4) RETURNS int4" .
99 dpavlin 1.2 " AS '$module_filename' LANGUAGE 'c'");
100 dpavlin 1.1 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
101    
102     $result = $conn->exec("CREATE FUNCTION _rserv_debug_(int4) RETURNS int4" .
103 dpavlin 1.2 " AS '$module_filename' LANGUAGE 'c'");
104 dpavlin 1.1 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
105    
106     $result = $conn->exec("COMMIT");
107     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
108    
109     exit (0);

  ViewVC Help
Powered by ViewVC 1.1.26