DEV Community

Query Filter
Query Filter

Posted on

parallel2

process_one_record() {
    line="$1"
    i="$2"            # the record index
    t="$3"            # total count
    log="worker_${i}.log"

    SREC_DUMP="/tmp/srec_${i}.txt"
    OREC_DUMP="/tmp/orec_${i}.txt"

    rm -f "$SREC_DUMP" "$OREC_DUMP"

    key=$(echo "$line" | cut -d "$DELIM" -f "$INT_KEY_COL")
    okey=$(echo "$line" | cut -d "$DELIM" -f "$ORDERID_COL")

    if [[ "$VERSION_KEY_COL" != " " ]]; then
        vkey=$(echo "$line" | cut -d "$DELIM" -f "$VERSION_KEY_COL")
    else
        vkey=""
    fi

    # Write this Sybase line to dump file
    echo "$line" > "$SREC_DUMP"

    {
        echo "[ $i out of $t ] Extracting based on keys: $key, $okey, $vkey"
        echo "Comparing $SREC_DUMP ↔ $OREC_DUMP starting from col $AFTER_IDENT_COL"

        ${SCR_DIR}/dumpFromOracle.sh "$TABLE_NAME" "$key" "$okey" "$OREC_DUMP" "$vkey" "$ROOT" "$region" "$env"
        rc=$?

        if [[ "$rc" -ne 0 ]]; then
            echo "ERROR: dumpFromOracle failed for rec $i (key=$key)" >&2
            exit 1
        fi

        case "$TABLE_NAME" in
            "CacheSelOrder")
                compareCacheSelOrder "$SREC_DUMP" "$OREC_DUMP" "$AFTER_IDENT_COL"
                ;;
            "ExecutionUndInstmtGap")
                compareExecDetailUndInstmtGap "$SREC_DUMP" "$OREC_DUMP" "$AFTER_IDENT_COL"
                ;;
            "CacheLastConfirmedOrder"|"CacheGblOrder"|"ZMenu")
                compareSpecial "$SREC_DUMP" "$OREC_DUMP" "$AFTER_IDENT_COL"
                ;;
            *)
                compare "$SREC_DUMP" "$OREC_DUMP" "$AFTER_IDENT_COL"
                ;;
        esac

    } > "$log" 2>&1
}
export -f process_one_record



MAXJOBS=8
i=0
t=$(wc -l < "$MASTER")

while IFS= read -r line; do
    ((i++))

    # respect your original range skipping:
    if (( i < LOW_RANGE )); then
        continue
    fi
    if (( i > UPPER_RANGE )); then
        break
    fi

    process_one_record "$line" "$i" "$t" &

    # Throttle to max 8 running jobs
    while (( $(jobs -r | wc -l) >= MAXJOBS )); do
        sleep 0.1
    done

done < "$MASTER"

wait   # wait for all workers

Enter fullscreen mode Exit fullscreen mode

Top comments (0)