Chris Browne cbbrowne at lists.slony.info
Fri Apr 20 13:51:11 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/tests/testlogship
In directory main.slony.info:/tmp/cvs-serv31857/tests/testlogship

Added Files:
      Tag: REL_1_2_STABLE
	README gen_weak_user.sh generate_dml.sh init_add_tables.ik 
	init_cluster.ik init_create_set.ik init_data.sql 
	init_schema.sql init_subscribe_set.ik schema.diff settings.ik 
Log Message:
Add a log shipping regression test.  It is actually not adequate to test
things properly; I start here by adding it in in a form that "seems to
function" before tweaking it further.


--- NEW FILE: settings.ik ---
NUMCLUSTERS=${NUMCLUSTERS:-"1"}
NUMNODES=${NUMNODES:-"3"}
ORIGINNODE=1
WORKERS=${WORKERS:-"1"}
ARCHIVE2=true   # Node #2 needs to run log archiving
LOGSHIP3=true   # Node #3 receives data via log shipping
--- NEW FILE: init_cluster.ik ---
init cluster (id=1, comment = 'Regress test node');
echo 'update functions on node 1 after initializing it';
update functions (id=1);

--- NEW FILE: gen_weak_user.sh ---
weakuser=$1;

for i in 1 2 3 4 5; do
   echo "grant select on table public.table${i} to ${weakuser};"
   echo "grant select on table public.table${i}_id_seq to ${weakuser};"
done
--- NEW FILE: generate_dml.sh ---
. support_funcs.sh

init_dml()
{
  echo "init_dml()"
}

begin()
{
  echo "begin()"
}

rollback()
{
  echo "rollback()"
}

commit()
{
  echo "commit()"
}

generate_initdata()
{
  numrows=$(random_number 50 1000)
  i=0;
  trippoint=`expr $numrows / 20`
  j=0;
  percent=0
  status "generating ${numrows} transactions of random data"
  percent=`expr $j \* 5`
  status "$percent %"
  GENDATA="$mktmp/generate.data"
  echo "" > ${GENDATA}
  while : ; do
    txtalen=$(random_number 1 100)
    txta=$(random_string ${txtalen})
    txta=`echo ${txta} | sed -e "s/\\\\\\\/\\\\\\\\\\\\\\/g" -e "s/'/''/g"`
    txtblen=$(random_number 1 100)
    txtb=$(random_string ${txtblen})
    txtb=`echo ${txtb} | sed -e "s/\\\\\\\/\\\\\\\\\\\\\\/g" -e "s/'/''/g"`
    ra=$(random_number 1 9)
    rb=$(random_number 1 9)
    rc=$(random_number 1 9)
    echo "INSERT INTO table1(data) VALUES ('${txta}');" >> $GENDATA
    echo "INSERT INTO table2(table1_id,data) SELECT id, '${txtb}' FROM table1 WHERE data='${txta}';" >> $GENDATA
    echo "INSERT INTO table3(table2_id) SELECT id FROM table2 WHERE data ='${txtb}';" >> $GENDATA
    echo "INSERT INTO table5(numcol,realcol,ptcol,pathcol,polycol,circcol,ipcol,maccol,bitcol) values ('${ra}${rb}.${rc}','${ra}.${rb}${rc}','(${ra},${rb})','((${ra},${ra}),(${rb},${rb}),(${rc},${rc}),(${ra},${rc}))','((${ra},${rb}),(${rc},${ra}),(${rb},${rc}),(${rc},${rb}))','<(${ra},${rb}),${rc}>','192.168.${ra}.${rb}${rc}','08:00:2d:0${ra}:0${rb}:0${rc}',X'${ra}${rb}${rc}');" >> $GENDATA
    if [ ${i} -ge ${numrows} ]; then
      break;
    else
      i=$((${i} +1))
      working=`expr $i % $trippoint`
      if [ $working -eq 0 ]; then
        j=`expr $j + 1`
        percent=`expr $j \* 5`
        status "$percent %"
      fi 
    fi
  done
  status "done"
}

do_initdata()
{
  originnode=${ORIGINNODE:-"1"}
  eval db=\$DB${originnode}
  eval host=\$HOST${originnode}
  eval user=\$USER${originnode}
  eval port=\$PORT${originnode}
  generate_initdata
  launch_poll
  status "loading data"
  $pgbindir/psql -h $host -p $port -d $db -U $user < $mktmp/generate.data 1> $mktmp/initdata.log 2> $mktmp/initdata.log
  if [ $? -ne 0 ]; then
    warn 3 "do_initdata failed, see $mktmp/initdata.log for details"
  fi 
  status "data load complete - nodes are seeded reasonably"

  status "purge archive log files up to present in order to eliminate those that cannot be used"
  for file in `/usr/bin/find ${mktmp}/archive_logs_2 -name "slony1_log_*.sql" -type f`; do
    status "purge ${file}"
    rm ${file}
  done
  sleep 5
  status "pull log shipping dump" 
  PGHOST=${HOST2} PGPORT=${PORT2} PGUSER=${USER2} ${SLTOOLDIR}/slony1_dump.sh ${DB2} ${CLUSTER1} > ${mktmp}/logship_dump.sql
  status "load log shipping dump into node #3"
  ${PGBINDIR3}/psql -h ${HOST3} -p ${PORT3} -U ${USER3} -d ${DB3} -f ${mktmp}/logship_dump.sql
  
  status "generate more data to test log shipping"
  generate_initdata
  launch_poll
  status "loading data"
  $pgbindir/psql -h $host -p $port -d $db -U $user < $mktmp/generate.data 1> $mktmp/moredata.log 2> $mktmp/moredata.log
  if [ $? -ne 0 ]; then
    warn 3 "loading data failed, see $mktmp/moredata.log for details"
  fi 
  wait_for_catchup
  status "second data load complete - now load files into log shipped node"
  for logfile in `/usr/bin/find ${mktmp}/archive_logs_2 -name "slony1_log_*.sql" -type f | sort`; do
    $pgbindir/psql -h ${HOST3} -p ${PORT3} -d ${DB3} -U ${USER3} -f ${logfile} >> $mktmp/logshipping_output.log 2>> $mktmp/logshipping_errors.log
    status "load file ${logfile} - ${?}"
  done
  status "done"
}

--- NEW FILE: init_add_tables.ik ---
set add table (id=1, set id=1, origin=1, fully qualified name = 'public.table1', comment='accounts table');
set add table (id=2, set id=1, origin=1, fully qualified name = 'public.table2', key='table2_id_key');

try {
   set add table (id=3, set id=1, origin=1, fully qualified name = 'public.table3', key = 'no_good_candidate_pk', comment='bad table - table 3');
} on error {
   echo 'Tried to replicate table3 with no good candidate PK - rejected';
} on success {
   echo 'Tried to replicate table3 with no good candidate PK - accepted';
   exit 1;
}

set add table (id=4, set id=1, origin=1, fully qualified name = 'public.table4', comment='a table of many types');
--- NEW FILE: init_create_set.ik ---
create set (id=1, origin=1, comment='All test1 tables');


--- NEW FILE: init_data.sql ---
INSERT INTO table1(data) VALUES ('placeholder 1');
INSERT INTO table1(data) VALUES ('placeholder 2');
INSERT INTO table2(table1_id,data) VALUES (1,'placeholder 1');
INSERT INTO table2(table1_id,data) VALUES (2,'placeholder 2');

INSERT INTO table4(numcol,realcol,ptcol,pathcol,polycol,circcol,ipcol,maccol,bitcol) values ('74.0','7.40','(7,4)','((7,7),(4,4),(0,0),(7,0))','((7,4),(0,7),(4,0),(0,4))','<(7,4),0>','192.168.7.40','08:00:2d:07:04:00',X'740');

INSERT INTO table4(numcol,realcol,ptcol,pathcol,polycol,circcol,ipcol,maccol,bitcol) values ('93.1','9.31','(9,3)','((9,9),(3,3),(1,1),(9,1))','((9,3),(1,9),(3,1),(1,3))','<(9,3),1>','192.168.9.31','08:00:2d:09:03:01',X'931');
--- NEW FILE: init_schema.sql ---
CREATE TABLE table1(
  id		SERIAL		PRIMARY KEY, 
  data		TEXT
);

CREATE TABLE table2(
  id		SERIAL		UNIQUE NOT NULL, 
  table1_id	INT4		REFERENCES table1(id) 
					ON UPDATE CASCADE ON DELETE CASCADE, 
  data		TEXT
);

create table table3 (
  id serial NOT NULL,
  id2 integer
);

create unique index no_good_candidate_pk on table3 (id, id2);

create table table4 (
  id serial primary key,
  numcol numeric(12,4), -- 1.23
  realcol real,     -- (1.23)
  ptcol point,      -- (1,2)
  pathcol path,     -- ((1,1),(2,2),(3,3),(4,4))
  polycol polygon,  -- ((1,1),(2,2),(3,3),(4,4))
  circcol circle,   -- <(1,2>,3>
  ipcol inet,       -- "192.168.1.1"
  maccol macaddr,   -- "04:05:06:07:08:09"
  bitcol bit varying(20)  -- X'123' 
);

--- NEW FILE: schema.diff ---
SELECT id,data FROM table1 ORDER BY id
SELECT id,table1_id,data FROM table2 ORDER BY id
SELECT id,numcol,realcol,ptcol,pathcol,polycol,circcol,ipcol,maccol, bitcol from table4 order by id;

--- NEW FILE: README ---
$Id: README,v 1.1.2.1 2007-04-20 20:51:09 cbbrowne Exp $
  
testlogship is a basic test that replication generally functions with
log shipping.  
  
It creates three simple tables as one replication set, and replicates
them from one database to another.
  
The three tables are of the three interesting types:
  
1.  table1 has a formal primary key

2.  table2 lacks a formal primary key, but has a candidate primary key

It tries replicating a third table, which has an invalid candidate
primary key (columns not defined NOT NULL), which should cause it to
be rejected.  That is done in a slonik TRY {} block.

It also creates...

3.  table3 which has columns of all sorts of vaguely esoteric types to
exercise that points, paths, bitmaps, mac addresses, and inet types
replicate properly.

--- NEW FILE: init_subscribe_set.ik ---
subscribe set (id = 1, provider = 1, receiver = 2, forward = no);
echo 'sleep a couple of seconds...';
sleep (seconds = 2);
echo 'done sleeping...';



More information about the Slony1-commit mailing list