Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b7ac62b

Browse files
committed
merge with shardman
2 parents cf8cf1b + b42f863 commit b7ac62b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+12865
-466
lines changed

contrib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ SUBDIRS = \
4949
pg_pathman \
5050
pg_prewarm \
5151
pg_query_state \
52+
pg_shardman \
5253
pg_standby \
5354
pg_stat_statements \
5455
pg_transfer \

contrib/pg_shardman/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.o
2+
*.so
3+
.dir-locals.el
4+
bin/setup.sh
5+
6+
*.pyc
7+
__pycache__

contrib/pg_shardman/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pg_shardman is released under the PostgreSQL License, a liberal Open Source
2+
license, similar to the BSD or MIT licenses.
3+
4+
Copyright (c) 2017, Postgres Professional
5+
Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
6+
Portions Copyright (c) 1994, The Regents of the University of California
7+
8+
Permission to use, copy, modify, and distribute this software and its
9+
documentation for any purpose, without fee, and without a written agreement is
10+
hereby granted, provided that the above copyright notice and this paragraph and
11+
the following two paragraphs appear in all copies.
12+
13+
IN NO EVENT SHALL POSTGRES PROFESSIONAL BE LIABLE TO ANY PARTY FOR DIRECT,
14+
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15+
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF POSTGRES
16+
PROFESSIONAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17+
18+
POSTGRES PROFESSIONAL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20+
PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
21+
POSTGRES PROFESSIONAL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
22+
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

contrib/pg_shardman/Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# the extension name
2+
EXTENSION = pg_shardman
3+
EXTVERSION = 0.0.2
4+
# This file will be executed by CREATE EXTENSION, so let pgxs install it.
5+
DATA = $(EXTENSION)--$(EXTVERSION).sql
6+
7+
REGRESS = shardman_installation
8+
9+
MODULE_big = pg_shardman
10+
OBJS = pg_shardman.o
11+
PGFILEDESC = "pg_shardman - sharding for Postgres"
12+
13+
ifndef USE_PGXS # hmm, user didn't requested to use pgxs
14+
# relative path to this makefile
15+
mkfile_path := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
16+
# relative path to dir with this makefile
17+
mkfile_dir := $(dir $(mkfile_path))
18+
# abs path to dir with this makefile
19+
mkfile_abspath := $(shell cd $(mkfile_dir) && pwd -P)
20+
# parent dir name of directory with makefile
21+
parent_dir_name := $(shell basename $(shell dirname $(mkfile_abspath)))
22+
ifneq ($(parent_dir_name),contrib) # a-ha, but this shardman is not inside 'contrib' dir
23+
USE_PGXS := 1 # so use it anyway, most probably that's what the user wants
24+
endif
25+
endif
26+
# $(info) is introduced in 3.81, and PG doesn't support makes older than 3.80
27+
ifeq ($(MAKE_VERSION),3.80)
28+
$(warning $$USE_PGXS is [${USE_PGXS}] (we use it automatically if not in contrib dir))
29+
else
30+
$(info $$USE_PGXS is [${USE_PGXS}] (we use it automatically if not in contrib dir))
31+
endif
32+
33+
ifdef USE_PGXS # use pgxs
34+
# You can specify path to pg_config in PG_CONFIG var
35+
ifndef PG_CONFIG
36+
PG_CONFIG := pg_config
37+
endif
38+
PG_CONFIG = pg_config
39+
INCLUDEDIR := $(shell $(PG_CONFIG) --includedir)
40+
PG_CPPFLAGS += -I$(INCLUDEDIR) # add server's include directory for libpq-fe.h
41+
SHLIB_LINK += -lpq # add libpq
42+
PGXS := $(shell $(PG_CONFIG) --pgxs)
43+
include $(PGXS)
44+
45+
else # assume the extension is in contrib/ dir of pg distribution
46+
# install pg_pathman and postgres_fdw too
47+
EXTRA_INSTALL = contrib/pg_pathman contrib/postgres_fdw
48+
PG_CPPFLAGS = -I$(libpq_srcdir) # include libpq-fe, defined in Makefile.global.in
49+
SHLIB_LINK = $(libpq) # defined in Makefile.global.in
50+
SHLIB_PREREQS = submake-libpq
51+
subdir = contrib/pg_shardman
52+
top_builddir = ../..
53+
# Add pathman to shared preload libraries when running regression tests
54+
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
55+
include $(top_builddir)/src/Makefile.global
56+
include $(top_srcdir)/contrib/contrib-global.mk
57+
endif
58+
59+
python_tests:
60+
$(MAKE) -C tests/python

contrib/pg_shardman/bin/common.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -e
3+
4+
script_dir=`dirname "$(readlink -f "$0")"`
5+
source "${script_dir}/setup.sh"
6+
7+
PATH="$PATH:${pgpath}bin/"
8+
function start_nodes()
9+
{
10+
echo "Starting nodes"
11+
for ((i=0; i<${#worker_datadirs[@]}; ++i)); do
12+
datadir="${worker_datadirs[i]}"
13+
port="${worker_ports[i]}"
14+
pg_ctl -o "-p $port" -D $datadir -l $logfile start
15+
done
16+
pg_ctl -o "-p $lord_port" -D $lord_datadir -l $logfile start
17+
}
18+
19+
function stop_nodes()
20+
{
21+
echo "Stopping nodes"
22+
for datadir in $lord_datadir "${worker_datadirs[@]}"; do
23+
pg_ctl -D $datadir stop || true
24+
done
25+
}
26+
27+
function restart_nodes()
28+
{
29+
echo "Restarting nodes"
30+
for ((i=0; i<${#worker_datadirs[@]}; ++i)); do
31+
datadir="${worker_datadirs[i]}"
32+
port="${worker_ports[i]}"
33+
pg_ctl -o "-p $port" -D $datadir -l $logfile restart
34+
done
35+
pg_ctl -o "-p $lord_port" -D $lord_datadir -l $logfile restart
36+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
drop table if exists pgbench_history;
2+
create table pgbench_history (tid int, bid int, aid int, delta int,
3+
mtime timestamp, filler char(22));
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
pgpath=~/postgres/install/vanilla/
2+
pathmanpath=~/postgres/pg_pathman
3+
install_pathman=false
4+
logfile=/tmp/shmn.log
5+
6+
lord_datadir=/tmp/data1
7+
lord_port=5432
8+
9+
# declare -a worker_datadirs=()
10+
# declare -a worker_ports=()
11+
12+
# declare -a worker_datadirs=("${HOME}/postgres/data2")
13+
# declare -a worker_ports=("5433")
14+
15+
# declare -a worker_datadirs=("${HOME}/postgres/data2" "${HOME}/postgres/data3")
16+
# declare -a worker_ports=("5433" "5434")
17+
18+
# declare -a worker_datadirs=("${HOME}/postgres/data2" "${HOME}/postgres/data3" "${HOME}/postgres/data4")
19+
# declare -a worker_ports=("5433" "5434" "5435")
20+
21+
declare -a worker_datadirs=("/tmp/data2" "/tmp/data3" "/tmp/data4" "/tmp/data5")
22+
declare -a worker_ports=("5433" "5434" "5435" "5436")
23+
24+
function run_demo()
25+
{
26+
:
27+
psql -c "drop table if exists t cascade;"
28+
psql -c "CREATE TABLE t(i int);"
29+
30+
psql -c "drop table if exists pt cascade;"
31+
psql -c "CREATE TABLE pt(id INT primary key, payload REAL);"
32+
psql -c "INSERT INTO pt SELECT generate_series(1, 10), random();"
33+
34+
# declarative partitioning
35+
# psql -p 5433 -c "drop table if exists ppt cascade;"
36+
# psql -p 5433 -c "CREATE TABLE ppt(id INT primary key, payload REAL);"
37+
# psql -c "create server node_1 foreign data wrapper postgres_fdw options (port '5433');"
38+
# psql -c "create user mapping for current_user server node_1;"
39+
# psql -c "create foreign table ppt (id int, payload real) server node_1;"
40+
41+
# psql -c "create table ppt_root (id int, payload real) partition by range (id);"
42+
# psql -c "alter table ppt_root attach partition ppt for values from (MINVALUE) TO (MAXVALUE);"
43+
44+
# with joe
45+
# for port in "${worker_ports[@]}" $lord_port; do
46+
# psql -p $port -c "set synchronous_commit to local; drop role if exists joe; create role joe superuser login; grant usage on FOREIGN DATA WRAPPER postgres_fdw to joe;"
47+
# done
48+
# psql -c "select shardman.add_node('port=5433', conn_string => 'user=joe password=12345 dbname=ars port=5433');"
49+
# psql -c "select shardman.add_node('port=5434', conn_string => 'user=joe password=12345 dbname=ars port=5434');"
50+
# psql -c "select shardman.add_node('port=5435', conn_string => 'user=joe password=12345 dbname=ars port=5435');"
51+
# psql -c "select shardman.add_node('port=5436', conn_string => 'user=joe password=12345 dbname=ars port=5436');"
52+
53+
psql -c "select shardman.add_node('port=5433');"
54+
psql -c "select shardman.add_node('port=5434');"
55+
psql -c "select shardman.add_node('port=5435');"
56+
psql -c "select shardman.add_node('port=5436');"
57+
58+
psql -c "select shardman.create_hash_partitions('pt', 'id', 4);"
59+
psql -c "select shardman.set_redundancy('pt', 2);"
60+
61+
# for port in "${worker_ports[@]}"; do
62+
# psql -p $port -f /home/ars/postgres/pg_shardman/bin/pgbench_history.sql
63+
# done
64+
# psql -f devops/pgbench_ddl.sql
65+
# psql -c "select shardman.create_hash_partitions('pgbench_accounts', 'aid', 30, 1);"
66+
# psql -c "select shardman.create_hash_partitions('pgbench_tellers', 'tid', 30, 1);"
67+
# psql -c "select shardman.create_hash_partitions('pgbench_branches', 'bid', 30, 1);"
68+
# pgbench -p 5433 -s 10 -i --no-ddl
69+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
script_dir=`dirname "$(readlink -f "$0")"`
4+
source "${script_dir}/common.sh"
5+
6+
if $install_pathman; then
7+
cd $pathmanpath
8+
USE_PGXS=1 make clean
9+
USE_PGXS=1 make install
10+
fi
11+
12+
cd "${script_dir}/.."
13+
make clean
14+
make install
15+
16+
> $logfile
17+
18+
stop_nodes
19+
pkill -9 postgres || true
20+
for datadir in $lord_datadir "${worker_datadirs[@]}"; do
21+
rm -rf "$datadir"
22+
mkdir -p "$datadir"
23+
initdb -D "$datadir"
24+
done
25+
26+
cat postgresql.conf.common >> ${lord_datadir}/postgresql.conf
27+
cat postgresql.conf.lord >> ${lord_datadir}/postgresql.conf
28+
for worker_datadir in "${worker_datadirs[@]}"; do
29+
cat postgresql.conf.common >> ${worker_datadir}/postgresql.conf
30+
cat postgresql.conf.worker >> ${worker_datadir}/postgresql.conf
31+
done
32+
33+
for datadir in $lord_datadir "${worker_datadirs[@]}"; do
34+
cat pg_hba.conf > ${datadir}/pg_hba.conf
35+
done
36+
37+
start_nodes
38+
for port in $lord_port "${worker_ports[@]}"; do
39+
createdb -p $port `whoami`
40+
echo "creating pg_shardman extension..."
41+
psql -p $port -c "create extension pg_shardman cascade;"
42+
done
43+
44+
restart_nodes
45+
46+
run_demo
47+
48+
# psql
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
script_dir=`dirname "$(readlink -f "$0")"`
4+
source "${script_dir}/common.sh"
5+
6+
cd "${script_dir}/.."
7+
8+
> $logfile
9+
10+
restart_nodes # make sure nodes run
11+
# first workers, then lord
12+
for port in "${worker_ports[@]}" $lord_port; do
13+
psql -p $port -c "set synchronous_commit to local; drop extension if exists pg_shardman cascade;"
14+
done
15+
16+
make clean
17+
make install
18+
19+
restart_nodes
20+
for port in $lord_port "${worker_ports[@]}"; do
21+
psql -p $port -c "set synchronous_commit to local; create extension pg_shardman cascade;"
22+
done
23+
24+
run_demo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
script_dir=`dirname "$(readlink -f "$0")"`
4+
source "${script_dir}/common.sh"
5+
6+
stop_nodes

contrib/pg_shardman/conf.add

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shared_preload_libraries='pg_shardman, pg_pathman'

contrib/pg_shardman/devops/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.retry
2+
inventory_manual/manual
3+
logs/
4+
res/
5+
tester_res.csv*
6+
wal_lag.txt
7+
8+
/postgresql.conf.common
9+
/postgresql.conf.lord
10+
/postgresql.conf.worker
11+
12+
# vagrant stuff
13+
*.log
14+
.vagrant/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Vagrant.configure("2") do |config|
2+
3+
config.vm.define "node1" do |node|
4+
node.vm.box = "ubuntu/xenial64"
5+
node.vm.network "private_network", ip: "10.42.42.10"
6+
end
7+
8+
config.vm.define "node2" do |node|
9+
node.vm.box = "ubuntu/xenial64"
10+
node.vm.network "private_network", ip: "10.42.42.20"
11+
end
12+
13+
config.vm.define "node3" do |node|
14+
node.vm.box = "ubuntu/xenial64"
15+
node.vm.network "private_network", ip: "10.42.42.30"
16+
end
17+
18+
# ssh-copy-id
19+
config.vm.provision "shell" do |s|
20+
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
21+
s.inline = <<-SHELL
22+
echo #{ssh_pub_key} >> /home/ubuntu/.ssh/authorized_keys
23+
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
24+
SHELL
25+
end
26+
27+
end

contrib/pg_shardman/devops/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)