Search and contents

A Node stopped and started: the trail names who is missing, and completes by itself

This page stops one Node of a three-Node practice site and starts it again, and reads what an order's trail says on the way. You see a trail that is still answered with a Node missing, that names the Node, and that is whole again with no step by hand. You also see the one place where a Node that has come back is still named missing for a while, and where that place is not.

Every value on this page is invented. The order, the lot, the quantity and the words a model writes are made up for this walk-through, or written by a model about made-up data. Nothing here is a real order, and nothing says a real site would read this way.

This is test tooling, not part of the public API. The site script and the stand-ins behind it may change in any release, and the stability policy (public-api-stability.md) does not cover them. The trail and the narrative routes are documented in order-trail-assembly.md and order-narrative-route.md. The test that proves the behaviour in process, with Nodes that can be made slow or made to answer garbage, is tests/test_drill_peer_degradation.py.

What you need

  • A running practice site, with the order blocked. One late order across a site says how it is made and why the order reads in-progress for a few seconds after up returns. The wait_blocked helper below waits for it. Do not start this page before the order reads blocked.
  • A model that answers chat requests, for the narrative in step 5. Nothing else on this page asks one. A narrative is a model call, and the first call after the model has been idle can take many seconds.
  • Nothing else: the helpers use python3, which the site needs already. They do not need jq.

Run the commands from the repository root, in one shell, after this once:

SITE="${KINDRED_PRACTICE_DIR:-$HOME/.kindred-practice-site}"
export KINDRED_PRACTICE_DIR="$SITE"
ORDER=MD-2027-0301
PS=deployment/practice_site.sh
api() { # the asking Node's Management API, with its token
  KINDRED_MANAGEMENT_URL=http://127.0.0.1:18470 \
  KINDRED_MANAGEMENT_TOKEN_FILE="$SITE/asking-node.token" \
    deployment/kindred_management.sh "$@"
}
show() { # print the named fields of a JSON answer
  python3 -c 'import json, sys; d = json.load(sys.stdin); print({k: d.get(k) for k in sys.argv[1:]})' "$@"
}
wait_blocked() { # wait until the MES's record of the order reads blocked
  for _ in $(seq 1 40); do
    status=$(api trail "$ORDER" 2> /dev/null |
      python3 -c 'import json, sys; print(json.load(sys.stdin)["record"]["attributes"]["status"])' 2> /dev/null) || status=""
    [ "$status" = blocked ] && return 0
    sleep 3
  done
  echo "the order never read blocked" >&2
  return 1
}
narrative() { # the order's trail narrative, asked of the MES's own route; one model call
  curl -s -H "Authorization: Bearer $(cat "$SITE/asking-node.token")" \
    "http://127.0.0.1:18480/v1/orders/$ORDER/trail/narrative" |
    python3 -c 'import json, sys; d = json.load(sys.stdin); print({k: d[k] for k in ("complete", "source")})'
}
wait_blocked

Step 1: read the trail with every Node up

api trail "$ORDER" | show complete local_complete not_contributed
{'complete': True, 'local_complete': True, 'not_contributed': []}

complete says every Node the MES asked answered. local_complete says the MES read all of its own entries. not_contributed lists a Node that was asked, or should have been, and gave nothing.

Step 2: stop ERP

$PS stop erp
$PS status

status exits 1 and shows erp as down. Stopping can take several seconds. Production Scheduling and the MES are still up.

Step 3: ask for the trail again

api trail "$ORDER" | show complete local_complete not_contributed
echo "exit ${PIPESTATUS[0]}"
{'complete': False, 'local_complete': True, 'not_contributed': [{'node_type': 'ERP', 'address': '127.0.0.1:18421', 'outcome': 'unreachable', 'reason': 'unreachable at the last rescan'}]}
exit 0

The trail still comes back, says it is incomplete, and names the Node: not_contributed holds exactly one element, ERP, with the outcome unreachable. The MES's own entries are kept, and no entry of ERP's is in the answer. The command exits 0: a trail with a Node missing is an answer, not an error, and it is the reader's job to look at complete.

The reason is always written on the asking side. Nothing ERP says about its own failure is in the answer or in any log. A Node that is slow to answer is named timed_out, and one that answers something that is not an Activity Log page is named malformed, with no text of its answer anywhere. The practice site has no command that makes a Node slow or makes one answer garbage, so those two are shown only by the test.

The material genealogy is the same question about materials, and is named the same way:

api genealogy "$ORDER" | show completeness not_contributed
{'completeness': 'incomplete', 'not_contributed': [{'node_type': 'ERP', 'address': '127.0.0.1:18421', 'outcome': 'unreachable', 'reason': 'unreachable at the last rescan'}]}

Step 4: start ERP and ask once more

$PS start erp
api trail "$ORDER" | show complete not_contributed
{'complete': True, 'not_contributed': []}

start waits until ERP's listener answers, so the next trail already sees it. Nothing is restarted, nothing is rescanned by hand, and the Management API holds no memory of ERP having been down: it looks for its peers anew on every request. That is why this step is complete at once, and it is the reason for the next one.

Step 5: the window in which a Node that has come back is still named missing

A Node that is itself asked for a trail does not look anew. It keeps one list of its peers, found when it started and looked at again on a schedule every 30 seconds, and it asks only a peer its last look found up. The MES serves a narrative of an order's trail from that list. So for up to 30 seconds after a peer starts again, the narrative can still say the trail is incomplete and name the peer.

This is where the window shows. It does not show in step 4, and it is not a property of the trail command: only of a Node's own, long-lived list.

$PS stop erp
sleep 35   # a Node's own scan has found ERP down by now
$PS start erp
for _ in 1 2 3 4 5 6 7 8; do sleep 4; narrative; done
{'complete': False, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': False, 'source': 'model'}
{'complete': False, 'source': 'model'}
{'complete': False, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}
{'complete': True, 'source': 'model'}

Two runs, with the MES's narrative asked about every six seconds (each answer takes a few seconds, so the line count is not a clock). In the first, the first answer, about 4 seconds after start returned, was still incomplete and the second, about 11 seconds, was complete. In the second, the first three answers (4, 11 and 18 seconds) were incomplete and the fourth (24 seconds) was complete. The scan runs every 30 seconds from when the Node started, so where in the 30 seconds the restart falls decides the length of the window, and it is never longer than 30 seconds. The Management API's trail in step 4 was complete at once in both runs.

The narrative says it in a section written by code, and not by the model, whatever the model made of its prompt:

**Incomplete Trail**
This trail does not hold every Node's activity for this order.
- ERP: unreachable

A Node's own ask of a peer (an order's status, a standard cost) looks again once before it gives up, but no more often than every 5 seconds, so it recovers sooner than the list does. That case is shown by the test, not here.

Step 6: a failed ask, by hand

ERP has no route that asks the MES a question, so the practice site's ask-order-status runs ERP's own task in a second process built the way the Node builds it (see One late order across a site for what it is). With the MES stopped it fails in one line, and the line names the reason without naming the order:

$PS stop mes
$PS ask-order-status "$ORDER" > /dev/null
echo "exit $?"
$PS start mes
ask failed: no MES peer is reachable, so there is nobody to ask
exit 1

The asking process looks for the MES when it is built, found it down, and gave up at once. A failed ask leaves an entry in ERP's Activity Log that carries no order id, so it is in no order's trail. The trail asked in the same minute, with the MES stopped, is still answered, because the Management API is its own process:

api trail "$ORDER" | show complete

What this does not show

  • A Node that is up but wrong. A record that differs between Nodes, or one that waits for a person, is Two Nodes that disagree. A stopped Node refuses nothing; it is not there.
  • A certificate that is wrong, expired or replaced. That is A certificate that fails.
  • A slow Node, or one that answers garbage. The site has no command for either. The test pins that they are named timed_out and malformed, and that the whole trail returns inside its deadline.
  • A Node's own ask that finds a peer down before its scan has noticed. It tries three times and then gives up with another error. The asking process of step 6 always scans first, so it never takes that path. The test does.
  • Production Scheduling stopped. What the MES's shift handoff does without the scheduler is in the test only.
  • A schedule revision in the trail. The trail does not carry one.
  • A real appliance, a network or a clock. Every address is on one host.

Limits

  • The Management API cannot show the window. It builds a fresh registry for each request and scans before it asks. Only a Node's own list, through the narrative route, shows it.
  • The window is up to 30 seconds and is a constant in the code, not a setting in a Node's config.
  • A failed ask is in no order's trail. The entry it leaves carries no order id.
  • A peer that is not asked leaves nothing. A trail that skips a peer because the last scan found it down logs no entry for it; a peer that was asked and could not be reached leaves one. The trail names both.
  • The narrative is a model call. Its words are a draft; the incomplete section is the part code writes.

What the test checks

tests/test_drill_peer_degradation.py runs the three Nodes in process, each on a database of its own, and pins what this page says of them:

  • with every Node up the trail is complete and each ask succeeds (test_with_every_node_up_the_trail_is_complete_and_each_ask_succeeds);
  • with ERP stopped the trail is incomplete, names ERP, keeps the MES's entries and returns inside its deadline (test_erp_stopped_the_trail_is_incomplete_names_erp_keeps_mes_and_still_returns), and so does the genealogy (test_erp_stopped_the_genealogy_is_incomplete_and_names_erp);
  • a peer that answers a body that is not an Activity Log page is named malformed and its text is nowhere (test_an_erp_that_answers_a_malformed_body_is_named_malformed_and_its_text_is_nowhere);
  • a started peer stays named until the Node's next scan, and then the trail is complete with no step by hand (test_a_started_peer_stays_named_until_the_next_scan_then_the_trail_is_complete, test_the_nodes_own_scheduled_rescan_completes_the_trail_with_no_step_by_hand);
  • a Node's own ask recovers after its look-again (test_a_started_peer_answers_an_ask_after_the_look_again_with_no_scan_by_hand);
  • the Management API holds nothing between requests, in tests/test_management_correlation.py (test_nothing_is_kept_between_requests).

tests/test_break_it_pages.py runs this page's setup, checks that every script, flag, route and test file the page names exists, that the page says what it does not show, and that it claims nothing the drill does not show. It does not run a block that needs a running site.

Release: v0.11.0