-
Notifications
You must be signed in to change notification settings - Fork 1
/
myrocks_import.sh
executable file
·310 lines (262 loc) · 9.42 KB
/
myrocks_import.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
# Simple script that copies myrocks from a source 5.7 branch into
# a destination branch. There is no git-foo magic done to preserve history.
# Probes source submodule and adds them to the destination.
# Destination must be a clean, clear 8.x branch with no submodules or remnants
# from a previous run.
#
# Should be run from a parent directory that contains both percona-server-5.7
# and percona-server-8.0 children sitting on the branches to pull from and push
# to.
set -e
set -v
START_PWD=${PWD}
SRC_DIR=${START_PWD}/percona-server-5.7
DST_DIR=${START_PWD}/percona-server
if [ ! -e "$SRC_DIR" ]; then
echo "Error : Missing SRC_DIR $SRC_DIR"
exit 1;
fi
if [ ! -e "$DST_DIR" ]; then
echo "Error : Missing DST_DIR $DST_DIR"
exit 1;
fi
CP_DIRS="storage/rocksdb
mysql-test/suite/rocksdb
mysql-test/suite/rocksdb.rpl
mysql-test/suite/rocksdb.stress
mysql-test/suite/rocksdb.sys_vars"
CP_FILES="cmake/check_stdcxx11.cmake
cmake/prepend_append_cflags_if_supported.cmake
mysql-test/include/have_rocksdb.inc
storage/rocksdb/.clang-format"
RM_DIRS="storage/rocksdb/rocksdb
storage/rocksdb/third_party"
cd ${DST_DIR}
for cur_dir in $CP_DIRS; do
mkdir -p ${DST_DIR}/${cur_dir}
cp -r ${SRC_DIR}/${cur_dir}/* ${DST_DIR}/${cur_dir}
find ${DST_DIR}/${cur_dir} -name ".git*" -type f -print | xargs /bin/rm -f
for rm_dir in $RM_DIRS; do
rm -rf ${rm_dir}
done
git add ${DST_DIR}/${cur_dir}
done
for cur_file in $CP_FILES; do
cp -r ${SRC_DIR}/${cur_file} ${DST_DIR}/${cur_file}
git add ${DST_DIR}/${cur_file}
done
cd ${SRC_DIR}
ROCKSDB_SUBMODULE_COMMIT=`git submodule status storage/rocksdb/rocksdb`
ROCKSDB_SUBMODULE_COMMIT=${ROCKSDB_SUBMODULE_COMMIT:1:40}
if [ -z "${ROCKSDB_SUBMODULE_COMMIT}" ]; then
echo "Error : unable to obtain rocksdb submodule commit pointer"
exit 1
fi
LZ4_SUBMODULE_COMMIT=`git submodule status storage/rocksdb/third_party/lz4`
LZ4_SUBMODULE_COMMIT=${LZ4_SUBMODULE_COMMIT:1:40}
if [ -z "${LZ4_SUBMODULE_COMMIT}" ]; then
echo "Error : unable to obtain lz4 submodule commit pointer"
exit 1
fi
ZSTD_SUBMODULE_COMMIT=`git submodule status storage/rocksdb/third_party/zstd`
ZSTD_SUBMODULE_COMMIT=${ZSTD_SUBMODULE_COMMIT:1:40}
if [ -z "${ZSTD_SUBMODULE_COMMIT}" ]; then
echo "Error : unable to obtain zstd submodule commit pointer"
exit 1
fi
# add the submodule commit pointers
cd ${DST_DIR}/storage/rocksdb
if [ -e rocksdb ]; then
echo "Error : rocksdb submodule directory still exists!!!"
exit 1
else
git submodule add -f https://github.com/facebook/rocksdb.git
fi
mkdir third_party
cd third_party
if [ -e lz4 ]; then
echo "Error : lz4 submodule directory still exists!!!"
exit 1
else
git submodule add -f https://github.com/lz4/lz4.git
fi
if [ -e zstd ]; then
echo "Error : zstd submodule directory still exists!!!"
exit 1
else
git submodule add -f https://github.com/facebook/zstd.git
fi
cd -
git submodule init
git submodule update
cd rocksdb
git checkout ${ROCKSDB_SUBMODULE_COMMIT}
cd -
cd third_party/lz4
git checkout ${LZ4_SUBMODULE_COMMIT}
cd -
cd third_party/zstd
git checkout ${ZSTD_SUBMODULE_COMMIT}
cd -
cd ${DST_DIR}
git add storage/rocksdb/rocksdb
git add storage/rocksdb/third_party
git commit -m "5.7 import of MyRocks"
cd ${START_PWD}
exit 0
#
# upstream_repo
# a repo that contains the commits to be merged and can be 'git clone'ed
# upstream_branch
# branch name to merge from the upstream repo
# dst_repo
# local destination repo/directory where to merge into
# dst_branch
# local branch to make proposal on
#
# Pulls/merges upstream commits into local percona server repo
# Results in a new branch named merge_${upstream_branch}_to_${dst_branch} that
# contains the contents of the original dst_branch plus the merged upstream
# changes.
#
# If there are conflicts, the merge_${upstream_branch}_to_${dst_branch} branch
# will be left in an uncommitted state for manual resolution.
#
# Since this script assumes only certain specific directories within the repo
# are rocksdb/myrocks, repo changes must be monitored closely so the script can
# be updated to include any new/renamed source
usage() {
echo "$@"
echo "Usage:"
echo " $0 upstream_repo upstream_commit dst_repo dst_branch"
}
NOTES=""
CLEAN_EXIT="There were errors!!!"
addnote() {
echo $@
NOTES="${NOTES}\n$@"
}
printnotes() {
echo -e "\n\n*************** NOTES *******************"
echo -e ${CLEAN_EXIT}
echo -e ${NOTES}
}
trap printnotes exit
UPSTREAM_REPO=$1
UPSTREAM_BRANCH=$2
DST_REPO=$3
DST_BRANCH=$4
WORKSPACE=${PWD}
if [ -z "${UPSTREAM_REPO}" ]; then
usage "Error : No upstream_repo specified"
exit 1
fi
if [ -z "${UPSTREAM_BRANCH}" ]; then
usage "Error : No upstream_commit specified"
exit 1
fi
if [ -z "${DST_REPO}" ]; then
usage "Error : No dst_repo specified"
exit 1
fi
if [ -z "${DST_BRANCH}" ]; then
usage "Error : No dst_branch specified"
exit 1
fi
# first clone the upstream to a local repo
UPSTREAM_CLONE=upstream-clone
UPSTREAM_WORKING=upstream-working
git clone --branch ${UPSTREAM_BRANCH} ${UPSTREAM_REPO} ${UPSTREAM_CLONE}
# we need to harvest the rocksdb commit pointer for later to manipulate it
# correctly in the final merge branch because the git filter-branch doesn't work
# with submodules.
cd ${UPSTREAM_CLONE}
git remote remove origin
ROCKSDB_SUBMODULE_COMMIT=`git submodule status rocksdb`
ROCKSDB_SUBMODULE_COMMIT=${ROCKSDB_SUBMODULE_COMMIT:1:40}
if [ -z "${ROCKSDB_SUBMODULE_COMMIT}" ]; then
echo "Error : unable to obtain rocksdb submodule commit pointer"
exit 1
fi
cd ..
# lets note the submodule commit id for ease of manually finishing the process
# in case of an early exit
addnote "ROCKSDB_SUBMODULE_COMMIT is ${ROCKSDB_SUBMODULE_COMMIT}"
# set up an empty staging repo
STAGING=staging
rm -rf ${STAGING}
mkdir ${STAGING}
cd ${STAGING}
git init
cd ..
# this loop is the real meat of the process, it strips all of the non myrocks
# files and directories out, restructures the files and directories, then pulls
# the result into a staging repo that contains only the myrocks files in the
# structure that we want.
SRC_DIRS=( "storage/rocksdb" "mysql-test/suite/rocksdb" "mysql-test/suite/rocksdb_rpl" "mysql-test/suite/rocksdb_stress" "mysql-test/suite/rocksdb_sys_vars" )
DST_DIRS=( "storage/rocksdb" "mysql-test/suite/rocksdb" "mysql-test/suite/rocksdb.rpl" "mysql-test/suite/rocksdb.stress" "mysql-test/suite/rocksdb.sys_vars" )
array_size=$(( ${#SRC_DIRS[@]} ))
array_top=$(( ${array_size}-1 ))
for i in `seq 0 ${array_top}`; do
BRANCH=${DST_DIRS[$i]} # use the internal location as the branch name
SRC_DIR=${SRC_DIRS[$i]}
DST_DIR=${DST_DIRS[$i]}
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR}"
# if directory doesn't exist in the upstream-lone, skip it as it might not
# have existed in that version
if [ ! -e "${UPSTREAM_CLONE}/${SRC_DIR}" ]; then
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} : ${UPSTREAM_CLONE}/${SRC_DIR} WAS NOT FOUND!!! SKIPPING"
continue
fi
git clone --branch ${UPSTREAM_BRANCH} ${UPSTREAM_CLONE} ${UPSTREAM_WORKING}
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 2"
cd ${UPSTREAM_WORKING}
git checkout -b ${BRANCH} ${UPSTREAM_BRANCH}
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 3"
git filter-branch -f --subdirectory-filter ${SRC_DIR} -- --all
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 4"
DST_DIR=${DST_DIR} git filter-branch -f --prune-empty --tree-filter 'if [ ! -e ${DST_DIR} ]; then mkdir -p ${DST_DIR}; git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files ${DST_DIR}; fi'
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 5"
cd ../${STAGING}
git remote add upstream ../${UPSTREAM_WORKING}
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 6"
git pull --no-edit upstream ${BRANCH}
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 7"
git remote remove upstream
cd ..
rm -rf ${UPSTREAM_WORKING}
addnote "Processing merge of ${SRC_DIR} to ${DST_DIR} 8"
done
#need to grab mysqldump.c
#git filter-branch -f --subdirectory-filter client -- --all
#DST_DIR=client git filter-branch -f --prune-empty --tree-filter 'if [ ! -e ${DST_DIR} ]; then mkdir -p ${DST_DIR}; git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files ${DST_DIR}; find ${DST_DIR} -type f -not -name mysqldump.c -delete; fi'
# at this point, we could stop the automated process and do the rest manually
# but I let the script continue to illustrate what should be done
# pull the staging repo into the destination branch
cd ${DST_REPO}
addnote "Results will be in branch merge_${UPSTREAM_BRANCH}_to_${DST_BRANCH}"
git checkout -b merge_${UPSTREAM_BRANCH}_to_${DST_BRANCH} ${DST_BRANCH}
git remote add staging ../staging
# if there are conflicts, this should halt the script for manual intervention
git pull --no-edit staging master
git remote remove staging
# add the submodule commit pointer if there is no submodule,
# else just update it
cd storage/rocksdb
if [ ! -e rocksdb ]; then
git submodule add -f https://github.com/facebook/rocksdb.git
fi
git submodule init
git submodule update
cd rocksdb
git checkout ${ROCKSDB_SUBMODULE_COMMIT}
cd ../../..
git add -A
git commit -m "Update of storage/myrocks/rocksdb submodule commit pointer to ${ROCKSDB_SUBMODULE_COMMIT}"
cd ..
CLEAN_EXIT="Completed successfully!!!"
# leave it behind for not for troubleshooting
#rm -rf ${STAGING}
#rm -rf ${UPSTREAM_CLONE}
#rm -rf ${UPSTREAM_WORKING}