Skip to content

Commit 5658194

Browse files
Creating missed intermediate partitions
Just only to restore in case of disaster
1 parent 0748a57 commit 5658194

File tree

1 file changed

+67
-43
lines changed

1 file changed

+67
-43
lines changed

pg_partitioner.sh

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,37 @@ function createMasterTable {
7575

7676
}
7777

78+
# Internal use
79+
# $1 = Part name
80+
# $2 = Min level for the partition
81+
# $3 = Max level for the partition
82+
# $4 = Inherits table
83+
function createPartition {
84+
85+
PART_NAME=$1
86+
MIN_LEVEL=$2
87+
MAX_LEVEL=$3
88+
INHERITS_TABLE=$4
89+
90+
$psql -d $_arg_database_name -t -c "CREATE TABLE alf_node_properties_$PART_NAME
91+
(CHECK (node_id > $MIN_LEVEL AND node_id <= $MAX_LEVEL))
92+
INHERITS ($INHERITS_TABLE);"
93+
$psql -d $_arg_database_name -t -c "ALTER TABLE alf_node_properties_$PART_NAME ADD PRIMARY KEY (node_id, qname_id, list_index, locale_id);"
94+
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_n_$PART_NAME ON alf_node_properties_$PART_NAME (node_id);"
95+
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_qn_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id);"
96+
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_loc_$PART_NAME ON alf_node_properties_$PART_NAME (locale_id);"
97+
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_s_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, string_value, node_id);"
98+
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_l_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, long_value, node_id);"
99+
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_b_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, boolean_value, node_id);"
100+
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_f_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, float_value, node_id);"
101+
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_d_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, double_value, node_id);"
102+
103+
$psql -d $_arg_database_name -t -c "GRANT ALL PRIVILEGES ON TABLE alf_node_properties_$PART_NAME TO alfresco"
104+
105+
echo "Partition alf_node_properties_$PART_NAME created"
106+
107+
}
108+
78109
function createPartitions {
79110

80111
initNumberOfNodes
@@ -84,28 +115,15 @@ function createPartitions {
84115
for i in `seq 1 $PARTITIONS`;
85116
do
86117

87-
PART_NAME=$i
88-
MIN_LEVEL=$((($i - 1) * $_arg_nodes_per_partition))
89-
MAX_LEVEL=$(($MIN_LEVEL + $_arg_nodes_per_partition))
118+
PART_NAME=$i
119+
MIN_LEVEL=$((($i - 1) * $_arg_nodes_per_partition))
120+
MAX_LEVEL=$(($MIN_LEVEL + $_arg_nodes_per_partition))
121+
122+
createPartition $PART_NAME $MIN_LEVEL $MAX_LEVEL "alf_node_properties_intermediate"
90123

91-
$psql -d $_arg_database_name -t -c "CREATE TABLE alf_node_properties_$PART_NAME
92-
(CHECK (node_id > $MIN_LEVEL AND node_id <= $MAX_LEVEL))
93-
INHERITS (alf_node_properties_intermediate);"
94-
$psql -d $_arg_database_name -t -c "ALTER TABLE alf_node_properties_$PART_NAME ADD PRIMARY KEY (node_id, qname_id, list_index, locale_id);"
95-
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_n_$PART_NAME ON alf_node_properties_$PART_NAME (node_id);"
96-
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_qn_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id);"
97-
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_loc_$PART_NAME ON alf_node_properties_$PART_NAME (locale_id);"
98-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_s_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, string_value, node_id);"
99-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_l_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, long_value, node_id);"
100-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_b_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, boolean_value, node_id);"
101-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_f_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, float_value, node_id);"
102-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_d_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, double_value, node_id);"
103-
104-
echo "Partition alf_node_properties_$PART_NAME created"
105-
106124
done
107125

108-
echo "$PARTITIONS has been created!"
126+
echo "$PARTITIONS have been created!"
109127
echo "Creating partitions done!"
110128
}
111129

@@ -119,43 +137,49 @@ function addPartition {
119137
MAX_LEVEL=$(($MIN_LEVEL + $_arg_nodes_per_partition))
120138
PCT_FILLED=$(($COUNT_NODES * 100 / $MAX_LEVEL))
121139

140+
# Check if every intermediate partition has been created
141+
for i in `seq 1 $PARTITIONS`;
142+
do
143+
144+
PART_NAME=$i
145+
MIN_LEVEL=$((($i - 1) * $_arg_nodes_per_partition))
146+
MAX_LEVEL=$(($MIN_LEVEL + $_arg_nodes_per_partition))
147+
148+
# Check if partition exists
149+
OUTPUT=$($psql -d $_arg_database_name -t -c "SELECT EXISTS (
150+
SELECT 1
151+
FROM information_schema.tables
152+
WHERE table_name = 'alf_node_properties_$PART_NAME'
153+
);")
154+
155+
if [[ "$OUTPUT" == " f" ]]; then
156+
createPartition $PART_NAME $MIN_LEVEL $MAX_LEVEL "alf_node_properties"
157+
echo "Partition alf_node_properties_$PART_NAME created"
158+
triggerInsertRows
159+
echo "Adding gap partition done!"
160+
fi
161+
162+
done
163+
122164
# 50 % storage from last partition is full
123165
if [[ $PCT_FILLED > 50 ]]; then
124166

125-
126167
PARTITIONS=$(($PARTITIONS + 1))
127168
MIN_LEVEL=$((($PARTITIONS - 1) * $_arg_nodes_per_partition))
128169
MAX_LEVEL=$(($MIN_LEVEL + $_arg_nodes_per_partition))
129170
PART_NAME=$PARTITIONS
130171

131172
# Check if partition exists
132173
OUTPUT=$($psql -d $_arg_database_name -t -c "SELECT EXISTS (
133-
SELECT 1
134-
FROM information_schema.tables
135-
WHERE table_name = 'alf_node_properties_$PART_NAME'
136-
);")
137-
138-
if [[ "$OUTPUT" == " f" ]]; then
139-
140-
$psql -d $_arg_database_name -t -c "CREATE TABLE alf_node_properties_$PART_NAME
141-
(CHECK (node_id > $MIN_LEVEL AND node_id <= $MAX_LEVEL))
142-
INHERITS (alf_node_properties);"
143-
$psql -d $_arg_database_name -t -c "ALTER TABLE alf_node_properties_$PART_NAME ADD PRIMARY KEY (node_id, qname_id, list_index, locale_id);"
144-
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_n_$PART_NAME ON alf_node_properties_$PART_NAME (node_id);"
145-
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_qn_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id);"
146-
$psql -d $_arg_database_name -t -c "CREATE INDEX fk_alf_nprop_loc_$PART_NAME ON alf_node_properties_$PART_NAME (locale_id);"
147-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_s_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, string_value, node_id);"
148-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_l_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, long_value, node_id);"
149-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_b_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, boolean_value, node_id);"
150-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_f_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, float_value, node_id);"
151-
$psql -d $_arg_database_name -t -c "CREATE INDEX idx_alf_nprop_d_$PART_NAME ON alf_node_properties_$PART_NAME (qname_id, double_value, node_id);"
152-
153-
$psql -d $_arg_database_name -t -c "GRANT ALL PRIVILEGES ON TABLE alf_node_properties_$PART_NAME TO alfresco"
174+
SELECT 1
175+
FROM information_schema.tables
176+
WHERE table_name = 'alf_node_properties_$PART_NAME'
177+
);")
154178

155-
echo "Partition alf_node_properties_$PART_NAME created"
179+
if [[ "$OUTPUT" == " f" ]]; then
156180

181+
createPartition $PART_NAME $MIN_LEVEL $MAX_LEVEL "alf_node_properties"
157182
triggerInsertRows
158-
159183
echo "Adding new partition done!"
160184

161185
else

0 commit comments

Comments
 (0)