request_replica_checkpoint.sh #3

  • //
  • p4-sdp/
  • dev_rebrand/
  • Server/
  • Unix/
  • p4/
  • common/
  • bin/
  • request_replica_checkpoint.sh
  • View
  • Commits
  • Open Download .zip Download (3 KB)
#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://workshop.perforce.com/view/p4-sdp/main/LICENSE
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Version ID Block. Relies on +k filetype modifier.
# VersionID='$Id: //p4-sdp/dev_rebrand/Server/Unix/p4/common/bin/request_replica_checkpoint.sh#3 $ $Change: 31617 $'

# This script is intended to be run on a standby replica.  It essentially just
# calls 'p4 admin checkpoint -Z' to request a checkpoint and exits. The actual
# checkpoint is created on the next journal rotation on the master.
declare -i RequestNow=0

export SDP_INSTANCE="${SDP_INSTANCE:-Unset}"
export SDP_INSTANCE="${1:-$SDP_INSTANCE}"
if [[ "$SDP_INSTANCE" == Unset ]]; then 
   echo "Instance parameter not supplied." 
   echo "You must supply the Perforce instance as a parameter to this script." 
   exit 1 
fi

# The '-now' option is currently an undocumented feature, though it may be
# documented in a future release (pending a separate change to normalize command
# line processing to add '-h' and '-man' options across all key scripts).  If
# '-now' is specified, after requesting the checkpoint on the local replica/edge,
# the commit server is then contacted and a 'p4 admin journal' is attempted, thus
# starting the checkpoint process on the local edge immediately
[[ "${2:-}" == "-now" ]] && RequestNow=1

# shellcheck disable=SC1091
source /p4/common/bin/p4_vars "$SDP_INSTANCE"
# shellcheck disable=SC1091
source /p4/common/bin/backup_functions.sh
# shellcheck disable=SC2034
LOGFILE=$LOGS/request_checkpoint.log

######### Start of Script ##########
check_vars
set_vars
rotate_last_run_logs
log "Start $P4SERVER Replica Request Checkpoint"
check_uid
check_dirs

[[ "$P4MASTER_ID" == "$SERVERID" ]] && \
   die "Error: Do not run request_replica_checkpoint.sh on the commit server."

"$P4CBIN"/p4login
request_replica_checkpoint

if [[ "$RequestNow" -eq 1 ]]; then
   log "Requesting journal rotation on the commit server due to '-now'."
   # Use timeout here so we don't hang if there's a firewall block.
   timeout 15s "$P4CBIN"/p4login -p "$P4MASTERPORT" >> "$LOGFILE" 2>&1 ||\
      die "The '-now' option was specified, but could login to commit server with: p4login -p $P4MASTERPORT"
   log "Running: $P4BIN -p $P4MASTERPORT admin journal"
   $P4BIN -p $P4MASTERPORT admin journal >> "$LOGFILE" 2>&1
fi

log "End $P4SERVER Replica Checkpoint"
mail_log_file "$HOSTNAME $P4SERVER replica request checkpoint log."
# Change User Description Committed
#3 31617 C. Thomas Tyler Merged work from dev_c2s (development) stream to sibling dev_rebrand (sparsedev) stream.
#2 31615 C. Thomas Tyler First pass at rebranding changes, including:
* Changes to remove 'swarm.' from Workshop URLS, so swarm.workshop -> workshop.
* Changed URL for Copyright.
* Renamed get_helix_binaries.sh -> get_p4_binaries.sh, with associated directory and doc changes.
* Accounted for rename of HAS -> P4AS.
* Changed HMS references to P4MS.
* Replaced "Helix" and "Helix Core" references.
* Renamed variables to reduce tech debt buildup induced by rebranding.
* Changed default mount points:
/hxdepots[-1,N] -> /p4depots[-1,N]
/hxmetadata[1,2] -> /p4db[-1,2]
/hxlogs -> /p4logs

Also made some changes related to rebranding going out with r25.1.
#1 31591 C. Thomas Tyler Populate stream //p4-sdp/dev_rebrand from //p4-sdp/dev.
//p4-sdp/dev/Server/Unix/p4/common/bin/request_replica_checkpoint.sh
#1 31397 C. Thomas Tyler Populate -b SDP_Classic_to_Streams -s //guest/perforce_software/sdp/...@31368.
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/request_replica_checkpoint.sh
#6 31022 C. Thomas Tyler Removed calls to remove_old_checkpoints_and_journals and remove_old_logs
from request_replica_checkpoint.sh. The removal of old checkpoints/logs
is only to be done upon successful completion of a new checkpoint
operation, and this script only makes the request to start a checkpoint;
it does not verify successful completion.
#5 30652 C. Thomas Tyler Added undoc '-now' option to request_replica_checkpoint.sh to
call 'p4 admin journal' on the commit to trigger an immediate
checkpoint. This option may be documented in a future release
(when command line processing is normalized across the fleet).
#4 30319 C. Thomas Tyler Fixed SDP_INSTANCE value in request_replica_checkpoint.sh
#3 30175 C. Thomas Tyler request_replica_checkpoint.sh can request parallel checkpoints.

Added safety check to avoid running 'p4 admin checkpoint' command
against the commit.

#review-30176
#2 27722 C. Thomas Tyler Refinements to @27712:
* Resolved one out-of-date file (verify_sdp.sh).
* Added missing adoc file for which HTML file had a change (WorkflowEnforcementTriggers.adoc).
* Updated revdate/revnumber in *.adoc files.
* Additional content updates in Server/Unix/p4/common/etc/cron.d/ReadMe.md.
* Bumped version numbers on scripts with Version= def'n.
* Generated HTML, PDF, and doc/gen files:
  - Most HTML and all PDF are generated using Makefiles that call an AsciiDoc utility.
  - HTML for Perl scripts is generated with pod2html.
  - doc/gen/*.man.txt files are generated with .../tools/gen_script_man_pages.sh.

#review-27712
#1 25923 C. Thomas Tyler Added script to request a checkpoint on the next journal rotation,
for use on replicas (e.g. replicas of edge servers).

To Do: Test needed, requires sophisticated topology to test.