Skip to content
Snippets Groups Projects
Commit b2fee44f authored by roadscape's avatar roadscape
Browse files

fix sync status check - sync last 1hr only after init complete

parent 7f5dda22
No related branches found
No related tags found
No related merge requests found
...@@ -120,6 +120,12 @@ class Sync: ...@@ -120,6 +120,12 @@ class Sync:
lbound = Blocks.head_num() + 1 lbound = Blocks.head_num() + 1
ubound = steemd.last_irreversible() ubound = steemd.last_irreversible()
if is_initial_sync:
# if initial sync, do not touch last hours-worth of blocks.
# 1hr is threshold for healthy/complete sync, so this is a
# cheap way to avoid "sync complete" signal until posts_cache
# is fully populated, etc.
ubound = ubound - 1200
if ubound <= lbound: if ubound <= lbound:
return return
......
...@@ -9,7 +9,8 @@ if [[ ! $? -eq 0 ]]; then ...@@ -9,7 +9,8 @@ if [[ ! $? -eq 0 ]]; then
kill -9 $RUN_SV_PID kill -9 $RUN_SV_PID
fi fi
# NOTE: this API endpoint returns head age in seconds, and a 200 code if it's less than 3600 # NOTE: this API endpoint returns head age in seconds, and a 200 code if it's
# less than 3600; otherwise, a 500, signaling that initial sync is not complete.
HTTP_CODE=`curl -I -s -o /dev/null -w "%{http_code}" http://127.0.0.1/head_age` HTTP_CODE=`curl -I -s -o /dev/null -w "%{http_code}" http://127.0.0.1/head_age`
# if we get a 200 then hive is synced, start syncing operation # if we get a 200 then hive is synced, start syncing operation
...@@ -17,15 +18,18 @@ if [[ ${HTTP_CODE} -eq 200 ]]; then ...@@ -17,15 +18,18 @@ if [[ ${HTTP_CODE} -eq 200 ]]; then
kill -SIGINT $HIVESYNC_PID kill -SIGINT $HIVESYNC_PID
echo hivemindsync: waiting for hive to exit cleanly echo hivemindsync: waiting for hive to exit cleanly
while [ -e /proc/$HIVESYNC_PID ]; do sleep 0.1; done while [ -e /proc/$HIVESYNC_PID ]; do sleep 0.1; done
echo hivemindsync: stopping postgres service echo hivemindsync: stopping postgres service
service postgresql stop service postgresql stop
echo hivemindsync: starting a new state file upload operation, compressing directory... echo hivemindsync: starting a new state file upload operation, compressing directory...
cd /var/lib/postgresql/9.5 cd /var/lib/postgresql/9.5
tar cf hivemind.tar.bz2 --use-compress-prog=pbzip2 -C /var/lib/postgresql/9.5 main tar cf hivemind.tar.bz2 --use-compress-prog=pbzip2 -C /var/lib/postgresql/9.5 main
if [[ ! $? -eq 0 ]]; then if [[ ! $? -eq 0 ]]; then
echo NOTIFYALERT! hivemindsync was unable to compress shared memory file, check the logs. echo NOTIFYALERT! hivemindsync was unable to compress state file, check the logs.
exit 1 exit 1
fi fi
FILE_NAME=hivemind-$SCHEMA_HASH-`date '+%Y%m%d-%H%M%S'`.tar.bz2 FILE_NAME=hivemind-$SCHEMA_HASH-`date '+%Y%m%d-%H%M%S'`.tar.bz2
echo hivemindsync: uploading $FILE_NAME to s3://$S3_BUCKET echo hivemindsync: uploading $FILE_NAME to s3://$S3_BUCKET
aws s3 cp hivemind.tar.bz2 s3://$S3_BUCKET/$FILE_NAME aws s3 cp hivemind.tar.bz2 s3://$S3_BUCKET/$FILE_NAME
...@@ -33,12 +37,14 @@ if [[ ${HTTP_CODE} -eq 200 ]]; then ...@@ -33,12 +37,14 @@ if [[ ${HTTP_CODE} -eq 200 ]]; then
echo NOTIFYALERT! hivemindsync was unable to upload $FILE_NAME to s3://$S3_BUCKET echo NOTIFYALERT! hivemindsync was unable to upload $FILE_NAME to s3://$S3_BUCKET
exit 1 exit 1
fi fi
echo hivemindsync: replacing current version of hivemind-$SCHEMA_HASH-latest.tar.bz2 with $FILE_NAME echo hivemindsync: replacing current version of hivemind-$SCHEMA_HASH-latest.tar.bz2 with $FILE_NAME
aws s3 cp s3://$S3_BUCKET/$FILE_NAME s3://$S3_BUCKET/hivemind-$SCHEMA_HASH-latest.tar.bz2 aws s3 cp s3://$S3_BUCKET/$FILE_NAME s3://$S3_BUCKET/hivemind-$SCHEMA_HASH-latest.tar.bz2
if [[ ! $? -eq 0 ]]; then if [[ ! $? -eq 0 ]]; then
echo NOTIFYALERT! hivemindsync was unable to overwrite the current statefile with $FILE_NAME echo NOTIFYALERT! hivemindsync was unable to overwrite the current statefile with $FILE_NAME
exit 1 exit 1
fi fi
# kill the container starting the process again # kill the container starting the process again
RUN_SV_PID=`pgrep -f /etc/service/hivesync` RUN_SV_PID=`pgrep -f /etc/service/hivesync`
kill -9 $RUN_SV_PID kill -9 $RUN_SV_PID
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment