<commit_before>#!/bin/bash

PARSED=$(getopt --options v --longoptions connstring:,retries:,datadir: --name "$0" -- "$@" 2> /dev/null)
eval set -- "$PARSED"

RETRIES=2

while [[ $# -gt 0 ]]; do
    case $1 in
        --datadir )
            DATA_DIR=$2
            shift
            ;;
        --connstring )
            CONNSTR=$2
            shift
            ;;
        --retries )
            RETRIES=$2
            shift
            ;;
        * )
            ;;
    esac
    shift
done

[[ -z $DATA_DIR || -z $CONNSTR || ! $RETRIES =~ ^[1-9]$ ]] && exit 1

function receivexlog() {
    pg_receivexlog --directory="${XLOG_FAST}" --dbname="${CONNSTR}" &
    receivexlog_pid=$!

    # run pg_receivexlog until postgres will not start streaming
    while ! ps ax | grep -qE '[w]al receiver process\s+streaming'; do
        # exit if pg_receivexlog is not running
        kill -0 $receivexlog_pid && sleep 1 || exit
    done

    kill $receivexlog_pid
}

ATTEMPT=0
while [[ $((ATTEMPT++)) -le $RETRIES ]]; do
    rm -fr "${DATA_DIR}"
    pg_basebackup --pgdata="${DATA_DIR}" --xlog-method=stream --dbname="${CONNSTR}"
    EXITCODE=$?
    if [[ $EXITCODE == 0 ]]; then
        XLOG_FAST=$(dirname $DATA_DIR)/xlog_fast
        rm -fr $XLOG_FAST
        mv ${DATA_DIR}/pg_xlog $XLOG_FAST
        rm -fr $XLOG_FAST/archive_status
        mkdir ${DATA_DIR}/pg_xlog

        receivexlog &
        break
    elif [[ $ATTEMPT -le $RETRIES ]]; then
        sleep $((ATTEMPT*10))
    fi
done
exit $EXITCODE<commit_msg>Remove xlog segments created by pg_receivexlog. (#165)<commit_after>#!/bin/bash

PARSED=$(getopt --options v --longoptions connstring:,retries:,datadir: --name "$0" -- "$@" 2> /dev/null)
eval set -- "$PARSED"

RETRIES=2

while [[ $# -gt 0 ]]; do
    case $1 in
        --datadir )
            DATA_DIR=$2
            shift
            ;;
        --connstring )
            CONNSTR=$2
            shift
            ;;
        --retries )
            RETRIES=$2
            shift
            ;;
        * )
            ;;
    esac
    shift
done

[[ -z $DATA_DIR || -z $CONNSTR || ! $RETRIES =~ ^[1-9]$ ]] && exit 1

function receivexlog() {
    pg_receivexlog --directory="${XLOG_FAST}" --dbname="${CONNSTR}" &
    receivexlog_pid=$!

    # run pg_receivexlog until postgres will not start streaming
    while ! ps ax | grep -qE '[w]al receiver process\s+streaming'; do
        # exit if pg_receivexlog is not running
        kill -0 $receivexlog_pid && sleep 1 || exit
    done

    kill $receivexlog_pid && sleep 1
    rm -f ${XLOG_FAST}/*
}

ATTEMPT=0
while [[ $((ATTEMPT++)) -le $RETRIES ]]; do
    rm -fr "${DATA_DIR}"
    pg_basebackup --pgdata="${DATA_DIR}" --xlog-method=stream --dbname="${CONNSTR}"
    EXITCODE=$?
    if [[ $EXITCODE == 0 ]]; then
        XLOG_FAST=$(dirname $DATA_DIR)/xlog_fast
        rm -fr $XLOG_FAST
        mv ${DATA_DIR}/pg_xlog $XLOG_FAST
        rm -fr $XLOG_FAST/archive_status
        mkdir ${DATA_DIR}/pg_xlog

        receivexlog &
        break
    elif [[ $ATTEMPT -le $RETRIES ]]; then
        sleep $((ATTEMPT*10))
    fi
done
exit $EXITCODE
{'fraction_non_alphanumeric': 0.1513094083414161, 'fraction_numerical': 0.012285806660200453, 'mean_word_length': 1.9807321772639692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607305', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1079, 'n_words': 256}