#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.6.3).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `#!/bin/sh' line above, then type `sh FILE'.
#
lock_dir=_sh19407
# Made on 2012-09-07 08:31 EDT by <nm@tornado>.
# Source directory was `/home/nm/src/pg'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#     79 -rw------- burnxid/burnxid.control
#   1567 -rw------- burnxid/burnxid.c
#    108 -rw------- burnxid/README
#     83 -rw------- burnxid/burnxid--1.0.sql
#   1205 -rw------- burnxid/test.sh
#    138 -rw------- burnxid/Makefile
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
  echo 'Note: not verifying md5sums.  Consider installing GNU coreutils.'
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    case `$dir/gettext --version 2>&1 | sed 1q` in
      *GNU*) gettext_dir=$dir ;;
    esac
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
     then shar_n= shar_c='
'
     else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
   test ! -f ${st1} && test -f ${f}; then
  shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
   test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
  shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
   test ! -f ${st3} && test -f ${f}; then
  shar_touch='touch -am $3$4$5$6$2 "$8"'

else
  shar_touch=:
  echo
  ${echo} 'WARNING: not restoring timestamps.  Consider getting and'
  ${echo} 'installing GNU `touch'\'', distributed in GNU coreutils...'
  echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir}
then : ; else ${echo} 'lock directory '${lock_dir}' exists'
  exit 1
fi
if mkdir ${lock_dir}
then ${echo} 'x - created lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to create lock directory `'${lock_dir}\''.'
  exit 1
fi
# ============= burnxid/burnxid.control ==============
if test ! -d 'burnxid'; then
  mkdir 'burnxid'
if test $? -eq 0
then ${echo} 'x - created directory `burnxid'\''.'
else ${echo} 'x - failed to create directory `burnxid'\''.'
  exit 1
fi
fi
if test -f 'burnxid/burnxid.control' && test "$first_param" != -c; then
  ${echo} 'x -SKIPPING burnxid/burnxid.control (file already exists)'
else
${echo} 'x - extracting burnxid/burnxid.control (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'burnxid/burnxid.control' &&
default_version = '1.0'
module_pathname = '$libdir/burnxid'
relocatable = true
SHAR_EOF
  (set 20 12 09 07 07 48 18 'burnxid/burnxid.control'; eval "$shar_touch") &&
  chmod 0600 'burnxid/burnxid.control'
if test $? -ne 0
then ${echo} 'restore of burnxid/burnxid.control failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'burnxid/burnxid.control: MD5 check failed'
       ) << SHAR_EOF
cdbf48b27247d71bfffbb202a7df8c16  burnxid/burnxid.control
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'burnxid/burnxid.control'` -ne 79 && \
  ${echo} 'restoration warning:  size of burnxid/burnxid.control is not 79'
  fi
fi
# ============= burnxid/burnxid.c ==============
if test ! -d 'burnxid'; then
  mkdir 'burnxid'
if test $? -eq 0
then ${echo} 'x - created directory `burnxid'\''.'
else ${echo} 'x - failed to create directory `burnxid'\''.'
  exit 1
fi
fi
if test -f 'burnxid/burnxid.c' && test "$first_param" != -c; then
  ${echo} 'x -SKIPPING burnxid/burnxid.c (file already exists)'
else
${echo} 'x - extracting burnxid/burnxid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'burnxid/burnxid.c' &&
#include "postgres.h"
X
#include "access/clog.h"
#include "access/subtrans.h"
#include "access/transam.h"
#include "fmgr.h"
#include "storage/lock.h"
X
PG_MODULE_MAGIC;
X
X
/* CLOG private defs */
#define CLOG_XACTS_PER_BYTE 4
#define CLOG_XACTS_PER_PAGE (BLCKSZ * CLOG_XACTS_PER_BYTE)
X
#define TransactionIdToPgIndex(xid) ((xid) % (TransactionId) CLOG_XACTS_PER_PAGE)
X
X
/* SUBTRANS private defs */
#define SUBTRANS_XACTS_PER_PAGE (BLCKSZ / sizeof(TransactionId))
X
#define TransactionIdToEntry(xid) ((xid) % (TransactionId) SUBTRANS_XACTS_PER_PAGE)
X
X
extern Datum set_next_xid(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(set_next_xid);
X
Datum
set_next_xid(PG_FUNCTION_ARGS)
{
X    TransactionId n = DatumGetTransactionId(PG_GETARG_DATUM(0));
X
X	LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
X
X	/* sanity-check values */
X	if (!TransactionIdIsNormal(n))
X		elog(ERROR, "not a normal xid");
X	if (!TransactionIdFollows(n, ShmemVariableCache->nextXid))
X		elog(ERROR, "target is not in the future");
X	if (TransactionIdFollowsOrEquals(n, ShmemVariableCache->xidWarnLimit))
X		elog(ERROR, "target is far enough in the future to elicit warnings");
X
X	/*
X	 * These functions expect to witness a continuous sequence of xids, so
X	 * they only take action for the first xid of each SLRU page.  We may be
X	 * jumping into the middle of a page, so back up to the first xid of that
X	 * page for purposes of calling these.
X	 */
X	ExtendCLOG(n - TransactionIdToPgIndex(n));
X	ExtendSUBTRANS(n - TransactionIdToEntry(n));
X
X	ShmemVariableCache->nextXid = n;
X
X	LWLockRelease(XidGenLock);
X
X	PG_RETURN_VOID();
}
SHAR_EOF
  (set 20 12 09 07 07 57 35 'burnxid/burnxid.c'; eval "$shar_touch") &&
  chmod 0600 'burnxid/burnxid.c'
if test $? -ne 0
then ${echo} 'restore of burnxid/burnxid.c failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'burnxid/burnxid.c: MD5 check failed'
       ) << SHAR_EOF
7bb18b01fd7d2cd6e9edba615990dc3c  burnxid/burnxid.c
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'burnxid/burnxid.c'` -ne 1567 && \
  ${echo} 'restoration warning:  size of burnxid/burnxid.c is not 1567'
  fi
fi
# ============= burnxid/README ==============
if test -f 'burnxid/README' && test "$first_param" != -c; then
  ${echo} 'x -SKIPPING burnxid/README (file already exists)'
else
${echo} 'x - extracting burnxid/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'burnxid/README' &&
Install the pgbench program.  Run "make install" to install this module, then
"sh test.sh" to run the test.
SHAR_EOF
  (set 20 12 09 07 08 23 09 'burnxid/README'; eval "$shar_touch") &&
  chmod 0600 'burnxid/README'
if test $? -ne 0
then ${echo} 'restore of burnxid/README failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'burnxid/README: MD5 check failed'
       ) << SHAR_EOF
83d8e1066fd9c00bded41e49f0ae7fc3  burnxid/README
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'burnxid/README'` -ne 108 && \
  ${echo} 'restoration warning:  size of burnxid/README is not 108'
  fi
fi
# ============= burnxid/burnxid--1.0.sql ==============
if test -f 'burnxid/burnxid--1.0.sql' && test "$first_param" != -c; then
  ${echo} 'x -SKIPPING burnxid/burnxid--1.0.sql (file already exists)'
else
${echo} 'x - extracting burnxid/burnxid--1.0.sql (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'burnxid/burnxid--1.0.sql' &&
CREATE FUNCTION set_next_xid(xid)
X	RETURNS void
X	AS 'MODULE_PATHNAME'
X	LANGUAGE c;
SHAR_EOF
  (set 20 12 09 07 07 55 01 'burnxid/burnxid--1.0.sql'; eval "$shar_touch") &&
  chmod 0600 'burnxid/burnxid--1.0.sql'
if test $? -ne 0
then ${echo} 'restore of burnxid/burnxid--1.0.sql failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'burnxid/burnxid--1.0.sql: MD5 check failed'
       ) << SHAR_EOF
a4e8de556fa7d4c133578f8329292b11  burnxid/burnxid--1.0.sql
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'burnxid/burnxid--1.0.sql'` -ne 83 && \
  ${echo} 'restoration warning:  size of burnxid/burnxid--1.0.sql is not 83'
  fi
fi
# ============= burnxid/test.sh ==============
if test -f 'burnxid/test.sh' && test "$first_param" != -c; then
  ${echo} 'x -SKIPPING burnxid/test.sh (file already exists)'
else
${echo} 'x - extracting burnxid/test.sh (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'burnxid/test.sh' &&
#! /bin/sh
X
PGPORT=1
PGDATABASE=burnxid_test
PGDATA=burnxid_datadir
export PGPORT PGDATABASE PGDATA
unset PGHOST
unset PGUSER
X
rm -r $PGDATA
initdb
cat >$PGDATA/postgresql.conf <<EOF
# Manage our own vacuuming and checkpoints
autovacuum = off
autovacuum_freeze_max_age = 2000000000
checkpoint_timeout = '1h'
X
logging_collector = on
fsync = off
listen_addresses = ''
log_min_messages = debug1
max_connections = 40
shared_buffers = 128MB
wal_buffers = 16MB
EOF
X
trap 'exit 1' 1 2 15
trap 'pg_ctl -w stop' 0
pg_ctl -w start
createdb
pgbench -i -s 3
psql -c "
CREATE FUNCTION set_next_xid(xid)
X	RETURNS void
X	AS 'burnxid'
X	LANGUAGE c;
"
X
# Let vacuumdb connect to template0
psql -Xc 'UPDATE pg_database SET datallowconn = true'
X
dovac() {
X	vacuumdb -F -a
X	vacuumdb -F -a
}
X
dovac
while :; do
X	# Rapidly traverse the xid space
X	psql -Xc "select set_next_xid('1431655765')" # 2^32 * 1/3
X	dovac
X	psql -Xc "select set_next_xid('2863311530')" # 2^32 * 2/3
X	dovac
X	psql -Xc "select set_next_xid('4294966296')" # 2^32 - 1000
X	dovac
X
X	# Cross the epoch boundary via natural xid consumption.
X	psql -Xc CHECKPOINT
X	pg_controldata | grep XID
X	pgbench -n -c 2 -t 1000
X	psql -Xc CHECKPOINT
X	pg_controldata | grep XID
done
SHAR_EOF
  (set 20 12 09 07 08 22 31 'burnxid/test.sh'; eval "$shar_touch") &&
  chmod 0600 'burnxid/test.sh'
if test $? -ne 0
then ${echo} 'restore of burnxid/test.sh failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'burnxid/test.sh: MD5 check failed'
       ) << SHAR_EOF
5c0bed339ea743d54eb3fb4bc4651a9f  burnxid/test.sh
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'burnxid/test.sh'` -ne 1205 && \
  ${echo} 'restoration warning:  size of burnxid/test.sh is not 1205'
  fi
fi
# ============= burnxid/Makefile ==============
if test -f 'burnxid/Makefile' && test "$first_param" != -c; then
  ${echo} 'x -SKIPPING burnxid/Makefile (file already exists)'
else
${echo} 'x - extracting burnxid/Makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'burnxid/Makefile' &&
EXTENSION = burnxid
MODULES = burnxid
DATA = burnxid--1.0.sql
X
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
SHAR_EOF
  (set 20 12 09 07 07 53 56 'burnxid/Makefile'; eval "$shar_touch") &&
  chmod 0600 'burnxid/Makefile'
if test $? -ne 0
then ${echo} 'restore of burnxid/Makefile failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'burnxid/Makefile: MD5 check failed'
       ) << SHAR_EOF
fb5d217e6482a044a074127a44cbf591  burnxid/Makefile
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'burnxid/Makefile'` -ne 138 && \
  ${echo} 'restoration warning:  size of burnxid/Makefile is not 138'
  fi
fi
if rm -fr ${lock_dir}
then ${echo} 'x - removed lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to remove lock directory `'${lock_dir}\''.'
  exit 1
fi
exit 0
