Changeset 522 for trunk


Ignore:
Timestamp:
08/12/2011 19:39:18 (9 months ago)
Author:
blee
Message:

First pass at optimizing confexport performance

  • Keep state between confexport runs to avoid unnecessary export regeneration
  • In recipe-style exports, include only the relevant recipe metadata

See #140

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/confexport.in

    r515 r522  
    2929# This script prepares an "export" of the confman repository for system 
    3030# processes to be able to pull. It is intended to be prepared regularly 
    31 # by a cron. It may be useful to modify this script to only prepare 
    32 # the export if the repository's most recent commit post-dates the 
    33 # tarball. 
     31# by an automated process like cron. 
    3432 
    3533if [ -r @pkgdatadir@/confmancommon.sh ] ; then 
     
    4139 
    4240# This changes the behavior of some library functions (e.g. URIs, locks) 
    43 CONF_EXPORT="true" 
     41CONF_EXPORT=true 
    4442 
    4543function print_help { 
    46     echo "usage: $0 [-d]" >&4 
     44    echo "usage: $0 [-f] [-d]" >&4 
    4745    echo "Type '$0 -h' to display this help and exit." >&4 
    4846    conf_cleanExit ${1:-0} 
    4947} 
    5048 
    51 while getopts "dh" OPT 2>&4 ; do 
     49FORCE=false 
     50DEBUG=false 
     51 
     52while getopts "fdh" OPT 2>&4 ; do 
    5253    case "$OPT" in 
     54        f)  FORCE=true ;; 
    5355        d)  DEBUG=true ;; 
    5456        h)  print_help 0;; 
     
    6466    exec 1>/dev/null 
    6567fi 
     68 
     69echo "Export operation started" | conf_logger 
    6670 
    6771confexport_lock_system 
     
    8286esac 
    8387 
    84 if [ -z "$temp_conf_export" ] ; then 
     88if [ -z "${temp_conf_export}" ] ; then 
    8589    echo "Could not create tempfile. Exiting." >&2 
    8690    exit 1 
    8791fi 
    8892 
    89 echo "Beginning export operation." | conf_logger 
    90 if ! conf_export $temp_conf_export ; then 
    91     echo "The export failed. Exiting." >&2 
    92     rm -rf $temp_conf_export 
    93     exit 1 
     93if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
     94    WORK_PATH=$(conf_tmp_dir) 
     95    conf_debug "Using temporary export working copy at ${WORK_PATH}" 
    9496else 
    95     # Prepare the new export 
    96     chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} $temp_conf_export 
    97     chmod -R ${CONF_EXPORT_MODE} $temp_conf_export 
    98     # Switch to the new export 
    99     old_conf_export=$(conf_tmp_dir) 
    100     mv ${CONF_EXPORT_FILE} $old_conf_export 
    101     mv $temp_conf_export ${CONF_EXPORT_FILE} 
    102     # Remove the old export 
    103     rm -rf $old_conf_export 
     97    WORK_PATH="${CONF_EXPORT_WORK_PATH}" 
     98    conf_debug "Using persistent export working copy at ${WORK_PATH}" 
    10499fi 
     100 
     101conf_checkout_tree 
     102 
     103export_revision=$(conf_revision) 
     104sys_revision=$(conf_export_sysrev) 
     105 
     106conf_debug "export_revision is ${export_revision}" 
     107conf_debug "sys_revision is ${sys_revision}" 
     108 
     109if [ "${sys_revision}" -gt "${export_revision}" ]; then 
     110    echo "Error: The last export was newer than the current repository.  Exiting without making changes." >&2 
     111    conf_cleanExit 1 
     112elif [ "${sys_revision}" -eq "${export_revision}" ]; then 
     113    if ! ${FORCE}; then 
     114        echo "System is up to date." | conf_logger 
     115        conf_cleanExit 0 
     116    fi 
     117fi 
     118 
     119if ! conf_export "${temp_conf_export}"; then 
     120    echo "Error: The export failed. Exiting." >&2 
     121    rm -rf "${temp_conf_export}" 
     122    conf_cleanExit 1 
     123fi 
     124 
     125# Prepare the new export 
     126chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} "${temp_conf_export}" || exit 1 
     127chmod -R ${CONF_EXPORT_MODE} "${temp_conf_export}" || exit 1 
     128 
     129# Switch to the new export 
     130old_conf_export=$(conf_tmp_dir) 
     131mv "${CONF_EXPORT_FILE}" "${old_conf_export}" || exit 1 
     132mv "${temp_conf_export}" "${CONF_EXPORT_FILE}" 
     133 
     134conf_record_export 
     135 
     136echo "Export operation finished successfully" | conf_logger 
    105137 
    106138confexport_unlock_system "${system_lock}" 
    107139 
    108 echo "Export complete." | conf_logger 
     140# Remove the old export 
     141rm -rf "${old_conf_export}" 
     142 
     143# If CONF_EXPORT_WORK_PATH is not set, we were using a temporary 
     144# directory, so clean it up 
     145if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
     146    rm -rf "${WORK_PATH}" 
     147fi 
    109148 
    110149conf_cleanExit 0 
  • trunk/confmanlib.sh.in

    r519 r522  
    2828 
    2929REPO_ACTION="${REPO_DB}/last_action" 
     30EXPORT_REV_FILE="${REPO_DB}/last_export" 
    3031REPO_SYNC_STATE="${REPO_DB}/state" 
    3132RECIPE_NAME="$(cat "$RECIPE_FILE" 2>/dev/null)" 
     
    402403    local exportpath="$1" 
    403404    local modules 
    404  
    405     if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
    406         WORK_PATH=$(conf_tmp_dir) 
    407     else 
    408         WORK_PATH="${CONF_EXPORT_WORK_PATH}" 
    409     fi 
    410  
    411     conf_checkout_tree 
     405    local module 
     406    local recipefile 
     407    local recipe 
    412408 
    413409    case ${CONF_EXPORT_STYLE} in 
     
    423419        recipe) 
    424420            for recipefile in $(conf_recipe_dir)/*; do 
    425                 modules="meta $(conf_get_recipe $recipefile)" 
    426                 tar -hczf "$exportpath/${recipefile#$(conf_recipe_dir)/}.tgz" -C "${WORK_PATH}" $modules 
     421                recipe=${recipefile#$(conf_recipe_dir)/} 
     422                modules=$(conf_get_recipe ${recipefile}) 
     423                tar -hczf "${exportpath}/${recipe}.tgz" -C "${WORK_PATH}" "${recipefile}" ${modules} 
    427424            done 
    428425            ;; 
     
    433430    esac 
    434431 
    435     if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 
    436         rm -rf ${WORK_PATH} 
    437     fi 
    438      
    439432    return 0 
    440433} 
     
    10231016} 
    10241017 
     1018# Returns the revision of the last export operation on stdout 
     1019function conf_export_sysrev { 
     1020    local export_sysrev 
     1021    local rv 
     1022 
     1023    export_sysrev=0 
     1024    rv=0 
     1025 
     1026    if [ -f "${EXPORT_REV_FILE}" ]; then 
     1027        if ! export_sysrev=$(cat "${EXPORT_REV_FILE}"); then 
     1028            echo "Could not read file: ${EXPORT_REV_FILE}" >&2 
     1029            export_sysrev=0 
     1030            rv=1 
     1031        fi 
     1032    fi 
     1033 
     1034    echo ${export_sysrev} 
     1035    return ${rv} 
     1036} 
     1037 
    10251038# Returns the last action of the repository on stdout 
    10261039function conf_lastact { 
     
    10371050    local revision=`conf_revision` 
    10381051    $SUDO sh -c "echo '${action}:${revision}' > $REPO_ACTION" 
     1052} 
     1053 
     1054# Records the export operation 
     1055function conf_record_export { 
     1056    local revision=$(conf_revision) 
     1057 
     1058    if ! echo "${revision}" > "${EXPORT_REV_FILE}"; then 
     1059            echo "Could not record export to file: ${EXPORT_REV_FILE}" >&2 
     1060            return 1 
     1061    fi 
    10391062} 
    10401063 
Note: See TracChangeset for help on using the changeset viewer.