@@ -75,6 +75,37 @@ function createMasterTable {
75
75
76
76
}
77
77
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
+
78
109
function createPartitions {
79
110
80
111
initNumberOfNodes
@@ -84,28 +115,15 @@ function createPartitions {
84
115
for i in ` seq 1 $PARTITIONS ` ;
85
116
do
86
117
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"
90
123
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
-
106
124
done
107
125
108
- echo " $PARTITIONS has been created!"
126
+ echo " $PARTITIONS have been created!"
109
127
echo " Creating partitions done!"
110
128
}
111
129
@@ -119,43 +137,49 @@ function addPartition {
119
137
MAX_LEVEL=$(( $MIN_LEVEL + $_arg_nodes_per_partition ))
120
138
PCT_FILLED=$(( $COUNT_NODES * 100 / $MAX_LEVEL ))
121
139
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
+
122
164
# 50 % storage from last partition is full
123
165
if [[ $PCT_FILLED > 50 ]]; then
124
166
125
-
126
167
PARTITIONS=$(( $PARTITIONS + 1 ))
127
168
MIN_LEVEL=$(( ($PARTITIONS - 1 ) * $_arg_nodes_per_partition ))
128
169
MAX_LEVEL=$(( $MIN_LEVEL + $_arg_nodes_per_partition ))
129
170
PART_NAME=$PARTITIONS
130
171
131
172
# Check if partition exists
132
173
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
+ );" )
154
178
155
- echo " Partition alf_node_properties_ $PART_NAME created "
179
+ if [[ " $OUTPUT " == " f " ]] ; then
156
180
181
+ createPartition $PART_NAME $MIN_LEVEL $MAX_LEVEL " alf_node_properties"
157
182
triggerInsertRows
158
-
159
183
echo " Adding new partition done!"
160
184
161
185
else
0 commit comments