Skip to content

Commit f8d6cd3

Browse files
authored
Merge pull request #10441 from cdrini/solr-next
Solr-next
2 parents 7f605ce + 6f36f6a commit f8d6cd3

File tree

12 files changed

+553
-13
lines changed

12 files changed

+553
-13
lines changed

compose.production.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ services:
2525
environment:
2626
# More memory for production
2727
- SOLR_JAVA_MEM=-Xms10g -Xmx10g
28+
# This might overwrite the above?
29+
- SOLR_HEAP=8g
2830
restart: unless-stopped
2931

3032
solr_haproxy:
@@ -44,7 +46,12 @@ services:
4446

4547
solr_restarter:
4648
profiles: ["ol-solr0"]
47-
build: scripts/solr_restarter
49+
build:
50+
context: scripts/solr_restarter
51+
args:
52+
- APT_MIRROR=${APT_MIRROR:-}
53+
- DOCKER_KEY_URL=${DOCKER_KEY_URL:-}
54+
- DOCKER_REPOSITORY_URL=${DOCKER_REPOSITORY_URL:-}
4855
restart: unless-stopped
4956
environment:
5057
- TEST_URL=http://openlibrary.org/search.json?q=hello&mode=everything&limit=0

scripts/deployment/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ deploy_openlibrary() {
297297
cp -r openlibrary/compose*.yaml openlibrary_new
298298
cp -r openlibrary/docker openlibrary_new
299299
cp -r openlibrary/scripts openlibrary_new
300+
cp -r openlibrary/conf openlibrary_new
300301
tar -czf openlibrary_new.tar.gz openlibrary_new
301302
if ! copy_to_servers "$TMP_DIR/openlibrary_new.tar.gz" "/opt/openlibrary" "openlibrary_new"; then
302303
cleanup "$TMP_DIR"

scripts/solr_builder/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## This image is where we should execute the Jenkins commands
2+
# WARNING: This image is pushed up to openlibrary/solrbuilder _manually_ . Changes
3+
# made to this file WILL NOT be automatically used, you have to manually rebuild/push:
4+
# docker build -t openlibrary/solr-builder:latest .
5+
# docker push openlibrary/solr-builder:latest
26

37
# Jenkins does not automatically build the following image;
48
# If you make changes to this Dockerfile, you will need to run these

scripts/solr_builder/Dockerfile.olpython

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
FROM openlibrary/olbase:latest
2+
ARG PIP_INDEX_URL
3+
ARG HTTPS_PROXY
4+
ARG NO_PROXY
25

36
ENV PYTHONPATH=/openlibrary:/openlibrary/vendor/infogami
47

scripts/solr_builder/Jenkinsfile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pipeline {
22
agent {
3-
dockerfile {
4-
filename 'Dockerfile'
5-
dir 'scripts/solr_builder'
3+
docker {
4+
// filename 'Dockerfile'
5+
image 'openlibrary/solr-builder:latest'
66
// Needed to make docker-in-docker work
77
args '-v /var/run/docker.sock:/var/run/docker.sock'
88
args '-v /var/lib/docker/volumes/jenkins-data:/var/lib/docker/volumes/jenkins-data'
@@ -22,6 +22,9 @@ pipeline {
2222
booleanParam(name: 'INDEX_AUTHORS', defaultValue: true, description: 'If true, reindexes authors into solr')
2323
booleanParam(name: 'INDEX_LISTS', defaultValue: true, description: 'If true, reindexes lists into solr')
2424
string(name: 'MAX_CORES', defaultValue: '18', description: 'Max number of simultaneous cores')
25+
string(name: 'PIP_INDEX_URL', defaultValue: '', description: 'Path to custom PIP index (needed on prod)')
26+
string(name: 'HTTPS_PROXY', defaultValue: '', description: 'Proxy for HTTP requests (needed on prod)')
27+
string(name: 'NO_PROXY', defaultValue: 'archive.org,openlibrary.org,.archive.org,.openlibrary.org', description: 'No proxy for these domains')
2528
}
2629
environment {
2730
// The *host* location of Jenkins directory
@@ -81,6 +84,15 @@ pipeline {
8184
}
8285
stage('Setup dump file') {
8386
stages {
87+
stage('Cleanup ol dump files') {
88+
steps {
89+
dir(env.DUMP_DIR) {
90+
sh "rm \$(ls ol_dump_2* | grep -v ${env.OL_DUMP_FILE}) || true"
91+
sh "rm \$(ls ol_dump_ratings_2* | grep -v ${env.OL_RATINGS_FILE}) || true"
92+
sh "rm \$(ls ol_dump_reading-log_2* | grep -v ${env.OL_READING_LOG_FILE}) || true"
93+
}
94+
}
95+
}
8496
stage('Download dump file') {
8597
steps {
8698
dir(env.DUMP_DIR) {
@@ -163,7 +175,7 @@ pipeline {
163175
steps {
164176
dir(env.HOST_SOLR_BUILDER_DIR) {
165177
sh(label: 'Stop solr if running',
166-
script: 'docker rm -f -v solr_builder-solr-1 || true')
178+
script: 'docker rm -f -v solr_builder-solr-1 solr_builder-solr_prod-1 || true')
167179

168180
sh(label: 'Remove solr volume',
169181
script: 'docker volume rm solr_builder_solr-data || true')
@@ -176,8 +188,13 @@ pipeline {
176188
sh(label: 'Launch solr',
177189
script: 'docker compose up --no-deps -d solr')
178190

191+
// Needed because nexus is unable to pull this from the Dockerfile for
192+
// some reason
193+
sh(label: 'Manually pull openlibrary/olbase:latest image',
194+
script: 'docker pull openlibrary/olbase:latest')
195+
179196
sh(label: 'Build "lite" ol environment',
180-
script: 'docker compose build --pull ol')
197+
script: 'docker compose build ol')
181198

182199
sh(label: 'Build the cython files',
183200
script: 'docker compose run --rm ol ./build-cython.sh')

scripts/solr_builder/compose.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ services:
101101
build:
102102
context: ../..
103103
dockerfile: scripts/solr_builder/Dockerfile.olpython
104+
args:
105+
- PIP_INDEX_URL=${PIP_INDEX_URL:-}
106+
- HTTPS_PROXY=${HTTPS_PROXY:-}
107+
- NO_PROXY=${NO_PROXY:-}
104108
volumes:
105109
# Persistent volume mount for installed git submodules
106110
- ol-vendor:/openlibrary/vendor
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# NOTE: Not fully tested, needs to be run line-by-line for a bit to make sure everything still
4+
# works, especially in our new proxy world!
5+
6+
SOLR_PROD_SERVER="ol-solr0"
7+
SOLR_BUILDER_SERVER="ol-solr1"
8+
9+
# Error if slack token not set
10+
if [ -z "$SLACK_TOKEN" ]; then
11+
echo "SLACK_TOKEN not set"
12+
exit 1
13+
fi
14+
15+
##
16+
# helpers
17+
##
18+
source ./scripts/solr_builder/utils.sh
19+
20+
send_slack_message "#openlibrary-g" "
21+
Beep boop! Heads up moving solr from incubation to its production server. Process should take ~1.5 hours.
22+
Let me know if you notice any issues! (CC @cdrini)
23+
"
24+
25+
echo "1. Switching everything to ol-solr0"
26+
switch_all_web_to_solr $SOLR_PROD_SERVER
27+
test_all_ol_search # Confirm everything is working
28+
if [ $? -ne 0 ]; then
29+
echo "ERROR: $SOLR_PROD_SERVER is not working"
30+
exit 1
31+
fi
32+
33+
# 2. Dump ol-solr1
34+
./scripts/solr_builder/dump-solr.sh $SOLR_BUILDER_SERVER
35+
36+
# 3. Switch everything to ol-solr1
37+
switch_all_web_to_solr $SOLR_BUILDER_SERVER
38+
test_all_ol_search # Confirm everything is working
39+
if [ $? -ne 0 ]; then
40+
echo "ERROR: $SOLR_BUILDER_SERVER is not working"
41+
exit 1
42+
fi
43+
44+
# 4. Backup prod/old solr
45+
./scripts/solr_builder/dump-solr.sh $SOLR_PROD_SERVER
46+
47+
# 5. Load ol-solr1 data on ol-solr0
48+
49+
# Require prompt before continuing
50+
wait_yn "Ready to begin deleting solr?"
51+
52+
./scripts/solr_builder/restore-solr.sh $SOLR_PROD_SERVER $SOLR_BUILDER_SERVER
53+
54+
# 6. Switch everything to ol-solr0
55+
56+
# Confirm on ol-dev1 first
57+
switch_web_to_solr ol-dev1 $SOLR_PROD_SERVER
58+
test_ol_search 'testing.openlibrary.org'
59+
if [ $? -ne 0 ]; then
60+
echo "ERROR: ol-dev1 is not working"
61+
exit 1
62+
fi
63+
64+
# Now let's go full throttle!
65+
switch_all_web_to_solr $SOLR_PROD_SERVER
66+
test_all_ol_search # Confirm everything is working
67+
68+
send_slack_message "#openlibrary-g" "
69+
Ok, solr moved over, and production now connected to it! Note it's catching up on edits done
70+
since the start of this, but should be done soon :+1: Let me know if you notice
71+
anything off! (cc @cdrini @seabelis)
72+
"

scripts/solr_builder/dump-solr.sh

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/bin/bash
2+
3+
set -e
4+
source ./scripts/solr_builder/utils.sh
5+
6+
OL_HOME="ol-home0.us.archive.org"
7+
SOLR_SERVER=$1
8+
SOLR_HOST="$(ol_server $SOLR_SERVER)"
9+
DUMP_FILE="${SOLR_SERVER}_dump.tar.gz"
10+
DUMP_OFFSET_FILE="${SOLR_SERVER}_dump.offset"
11+
12+
if [ "$SOLR_SERVER" == "ol-solr0" ]; then
13+
solr_container="openlibrary-solr-1"
14+
solr_updater_container="openlibrary-solr-updater-1"
15+
offset_file="solr-update.offset"
16+
elif [ "$SOLR_SERVER" == "ol-solr1" ]; then
17+
solr_container="solr_builder-solr_prod-1"
18+
solr_updater_container="openlibrary-solr-next-updater-1"
19+
offset_file="solr-next-update.offset"
20+
else
21+
echo "Invalid SOLR_SERVER: $SOLR_SERVER"
22+
exit 1
23+
fi
24+
25+
# Make sure it has ubuntu xenial and openlibrary/olbase:latest
26+
echo "Pulling down images on $SOLR_SERVER ... "
27+
ssh -t $SOLR_SERVER "
28+
set -e
29+
docker pull ubuntu:xenial
30+
docker pull openlibrary/olbase:latest
31+
"
32+
33+
echo "Check if either solr-dump container is running"
34+
echo -n " solr-dump ... "
35+
solr_dump_running=$(ssh $SOLR_SERVER "docker ps --quiet --filter name=solr-dump")
36+
if [ -n "$solr_dump_running" ]; then
37+
echo "✗ ERROR: $SOLR_SERVER has a solr-dump container running"
38+
exit 1
39+
else
40+
echo ""
41+
fi
42+
echo -n " solr-dump-upload ... "
43+
solr_dump_upload_running=$(ssh $SOLR_SERVER "docker ps --quiet --filter name=solr-dump-upload")
44+
if [ -n "$solr_dump_upload_running" ]; then
45+
echo "✗ ERROR: $SOLR_SERVER has a solr-dump-upload container running"
46+
exit 1
47+
else
48+
echo ""
49+
fi
50+
51+
52+
# Clean up old dumps
53+
echo "Cleaning up old dumps on $SOLR_SERVER ... "
54+
ssh $SOLR_SERVER "
55+
set -e
56+
rm -f /tmp/solr/$DUMP_FILE || true
57+
rm -f /tmp/solr/$DUMP_OFFSET_FILE || true
58+
"
59+
60+
61+
# Check if enough disk space
62+
echo -n "Checking disk space on $SOLR_SERVER ... "
63+
var_solr_size=$(ssh $SOLR_SERVER "
64+
set -e
65+
docker run --rm \
66+
--volumes-from $solr_container \
67+
ubuntu:xenial \
68+
du -s /var/solr | awk '{print \$1}'
69+
")
70+
empty_space=$(ssh $SOLR_SERVER "
71+
set -e
72+
df /tmp | tail -n 1 | awk '{print \$4}'
73+
")
74+
var_solr_size_str=$(numfmt --to=iec --suffix=B $((var_solr_size * 1000)))
75+
empty_space_str=$(numfmt --to=iec --suffix=B $((empty_space * 1000)))
76+
77+
if [ $var_solr_size -gt $empty_space ]; then
78+
echo "✗ ERROR: Not enough space on $SOLR_SERVER"
79+
echo "(/var/solr is $var_solr_size_str, $SOLR_SERVER has $empty_space_str free)"
80+
# exit 1
81+
fi
82+
echo ""
83+
echo "(/var/solr is $var_solr_size_str, $SOLR_SERVER has $empty_space_str free)"
84+
85+
echo "Check if $solr_updater_container is running"
86+
solr_updater_running=$(ssh $OL_HOME "docker ps --quiet --filter name=$solr_updater_container")
87+
88+
# If running, stop it
89+
if [ -n "$solr_updater_running" ]; then
90+
echo -n "Stopping $solr_updater_container ..."
91+
ssh $OL_HOME "
92+
set -e
93+
docker stop $solr_updater_container
94+
" > /dev/null
95+
echo ""
96+
else
97+
echo "$solr_updater_container not running"
98+
fi
99+
100+
# Note the offset
101+
offset=$(ssh $OL_HOME "
102+
set -e
103+
docker run --rm \
104+
--volumes-from $solr_updater_container \
105+
ubuntu:xenial \
106+
cat solr-updater-data/$offset_file
107+
")
108+
echo "solr-updater offset: $offset"
109+
# Save the offset to /tmp/solr/ol_solr_dump_$(date +%Y-%m-%d).offset
110+
ssh $SOLR_SERVER "
111+
set -e
112+
mkdir -p /tmp/solr
113+
echo '$offset' > /tmp/solr/$DUMP_OFFSET_FILE
114+
"
115+
116+
echo "Committing any transient changes into solr before dumping... (takes ~30s)"
117+
time ssh $SOLR_SERVER "
118+
set -e
119+
curl -s 'http://localhost:8984/solr/openlibrary/update?commit=true'
120+
sleep 15 # Just in case
121+
"
122+
123+
echo "Pause solr"
124+
ssh $SOLR_SERVER "docker pause $solr_container"
125+
126+
echo "Beginning dump (took 1h30 minutes 2024-08)"
127+
echo "Dumping solr data to $SOLR_SERVER:/tmp/solr/$DUMP_FILE"
128+
# Run detached so it persists if the ssh connection is lost
129+
time ssh -t $SOLR_SERVER "
130+
set -e
131+
mkdir -p /tmp/solr
132+
docker run --rm -d \
133+
--name solr-dump \
134+
--volumes-from $solr_container \
135+
-v /tmp/solr:/tmp/solr \
136+
ubuntu:xenial \
137+
tar czf /tmp/solr/$DUMP_FILE /var/solr
138+
docker logs -f solr-dump
139+
"
140+
141+
# Unpause solr
142+
ssh $SOLR_SERVER "docker unpause $solr_container"
143+
144+
# Should be ~39G
145+
ssh $SOLR_SERVER "du -sh /tmp/solr/$DUMP_FILE"
146+
147+
# Restart solr_updater_container if it was running
148+
if [ -n "$solr_updater_running" ]; then
149+
echo -n "Starting $solr_updater_container ... "
150+
ssh $OL_HOME "
151+
set -e
152+
docker start $solr_updater_container
153+
" > /dev/null
154+
echo ""
155+
fi
156+
157+
echo "Uploading dump to IA"
158+
time ssh -t $SOLR_SERVER "
159+
set -e
160+
docker run --rm -d \
161+
--name solr-dump-upload \
162+
-v /tmp/solr:/tmp/solr \
163+
-v /opt/olsystem/etc/ia.ini:/olsystem/etc/ia.ini:ro \
164+
openlibrary/olbase:latest \
165+
bash -c '
166+
ia \
167+
--config-file=/olsystem/etc/ia.ini \
168+
upload ol_solr_dump \
169+
--retries 300 \
170+
-H x-archive-keep-old-version:0 \
171+
/tmp/solr/$DUMP_FILE \
172+
/tmp/solr/$DUMP_OFFSET_FILE \
173+
--metadata 'collection:ol_exports' \
174+
--metadata 'year:$(date +%Y)' \
175+
--metadata 'format:Data'
176+
'
177+
docker logs -f solr-dump-upload
178+
"
179+
180+
echo "Dump complete!"

0 commit comments

Comments
 (0)