115 lines
2.9 KiB
Bash
115 lines
2.9 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
|
|
TMPDIR="${TMPDIR:-/tmp}"
|
||
|
|
mkdir -p "${TMPDIR}"
|
||
|
|
|
||
|
|
# shellcheck source=/dev/null
|
||
|
|
source "${ROOT_DIR}/scripts/graph_client_helpers.sh"
|
||
|
|
graph_helpers_init "${ROOT_DIR}"
|
||
|
|
|
||
|
|
AMDUATD_BIN="${ROOT_DIR}/build/amduatd"
|
||
|
|
ASL_BIN="${ROOT_DIR}/vendor/amduat/build/amduat-asl"
|
||
|
|
if [[ ! -x "${AMDUATD_BIN}" || ! -x "${ASL_BIN}" ]]; then
|
||
|
|
echo "missing binaries; build amduatd and amduat-asl first" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
iters="${AMDUATD_INDEX_STRESS_ITERS:-20}"
|
||
|
|
case "${iters}" in
|
||
|
|
''|*[!0-9]*)
|
||
|
|
echo "invalid AMDUATD_INDEX_STRESS_ITERS: ${iters}" >&2
|
||
|
|
exit 2
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
if [[ "${iters}" -le 0 ]]; then
|
||
|
|
echo "AMDUATD_INDEX_STRESS_ITERS must be > 0" >&2
|
||
|
|
exit 2
|
||
|
|
fi
|
||
|
|
|
||
|
|
run_one() {
|
||
|
|
local i="$1"
|
||
|
|
local tmp_root root sock space_id log_file pid ready_rc
|
||
|
|
|
||
|
|
tmp_root="$(mktemp -d -p "${TMPDIR}" amduatd-graph-index-stress-XXXXXX)"
|
||
|
|
root="${tmp_root}/root"
|
||
|
|
sock="${tmp_root}/amduatd.sock"
|
||
|
|
space_id="graphindex${i}"
|
||
|
|
log_file="${tmp_root}/amduatd.log"
|
||
|
|
pid=""
|
||
|
|
|
||
|
|
cleanup_one() {
|
||
|
|
if [[ -n "${pid}" ]]; then
|
||
|
|
kill "${pid}" >/dev/null 2>&1 || true
|
||
|
|
wait "${pid}" >/dev/null 2>&1 || true
|
||
|
|
fi
|
||
|
|
rm -rf "${tmp_root}"
|
||
|
|
}
|
||
|
|
trap cleanup_one RETURN
|
||
|
|
|
||
|
|
mkdir -p "${root}"
|
||
|
|
"${ASL_BIN}" index init --root "${root}" >/dev/null
|
||
|
|
|
||
|
|
"${AMDUATD_BIN}" --root "${root}" --sock "${sock}" --store-backend index --space "${space_id}" \
|
||
|
|
>"${log_file}" 2>&1 &
|
||
|
|
pid=$!
|
||
|
|
|
||
|
|
ready_rc=0
|
||
|
|
graph_wait_for_ready "${sock}" "${pid}" "${log_file}" || ready_rc=$?
|
||
|
|
if [[ ${ready_rc} -eq 77 ]]; then
|
||
|
|
return 77
|
||
|
|
fi
|
||
|
|
if [[ ${ready_rc} -ne 0 ]]; then
|
||
|
|
echo "iteration ${i}: daemon not ready" >&2
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
node_a="$(
|
||
|
|
graph_http_post "${sock}" "/v2/graph/nodes" '{"name":"idx-a"}' \
|
||
|
|
--header "Content-Type: application/json" \
|
||
|
|
--header "X-Amduat-Space: ${space_id}"
|
||
|
|
)"
|
||
|
|
echo "${node_a}" | grep -q '"name":"idx-a"' || {
|
||
|
|
echo "iteration ${i}: first node create failed: ${node_a}" >&2
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
|
||
|
|
node_b="$(
|
||
|
|
graph_http_post "${sock}" "/v2/graph/nodes" '{"name":"idx-b"}' \
|
||
|
|
--header "Content-Type: application/json" \
|
||
|
|
--header "X-Amduat-Space: ${space_id}"
|
||
|
|
)"
|
||
|
|
echo "${node_b}" | grep -q '"name":"idx-b"' || {
|
||
|
|
echo "iteration ${i}: second node create failed: ${node_b}" >&2
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
|
||
|
|
edge="$(
|
||
|
|
graph_http_post "${sock}" "/v2/graph/edges" \
|
||
|
|
'{"subject":"idx-a","predicate":"ms.within_domain","object":"idx-b"}' \
|
||
|
|
--header "Content-Type: application/json" \
|
||
|
|
--header "X-Amduat-Space: ${space_id}"
|
||
|
|
)"
|
||
|
|
echo "${edge}" | grep -q '"edge_ref":"' || {
|
||
|
|
echo "iteration ${i}: edge create failed: ${edge}" >&2
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "iteration ${i}/${iters}: ok"
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
for i in $(seq 1 "${iters}"); do
|
||
|
|
rc=0
|
||
|
|
run_one "${i}" || rc=$?
|
||
|
|
if [[ ${rc} -eq 77 ]]; then
|
||
|
|
exit 77
|
||
|
|
fi
|
||
|
|
if [[ ${rc} -ne 0 ]]; then
|
||
|
|
exit "${rc}"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
echo "ok: index append stress passed (${iters} iterations)"
|