The sort before tended to be alphabetical, which put test
`8_force_delete_snapshot` after `815_sync_out-of-order_snapshots`, but
`8` should come before `815`.
Before:
```
root@demo:~/sanoid/tests/syncoid# ./run-tests.sh
Running test 1_bookmark_replication_intermediate ... [PASS]
Running test 2_bookmark_replication_no_intermediate ... [PASS]
Running test 3_force_delete ... [PASS]
Running test 4_bookmark_replication_edge_case ... [PASS]
Running test 5_reset_resume_state ... mbuffer: error: outputThread: error writing to <stdout> at offset 0x90000: Broken pipe
mbuffer: warning: error during output to <stdout>: Broken pipe
[PASS]
Running test 6_reset_resume_state2 ... [PASS]
Running test 7_preserve_recordsize ... [PASS]
Running test 815_sync_out-of-order_snapshots ... [PASS]
Running test 8_force_delete_snapshot ... [PASS]
```
After:
```
root@demo:~/sanoid/tests/syncoid# ./run-tests.sh
Running test 1_bookmark_replication_intermediate ... [PASS]
Running test 2_bookmark_replication_no_intermediate ... [PASS]
Running test 3_force_delete ... [PASS]
Running test 4_bookmark_replication_edge_case ... [PASS]
Running test 5_reset_resume_state ... mbuffer: error: outputThread: error writing to <stdout> at offset 0xf0000: Broken pipe
mbuffer: warning: error during output to <stdout>: Broken pipe
[PASS]
Running test 6_reset_resume_state2 ... [PASS]
Running test 7_preserve_recordsize ... [PASS]
Running test 8_force_delete_snapshot ... [PASS]
Running test 815_sync_out-of-order_snapshots ... [PASS]
```
This is a continuation of a previous commit to sort snapshots by
`createtxg` if possible. Now, we have to match the behavior when
selecting an appropriate snapshot based on the transaction group of the
relevant bookmark in `syncdataset()`.
Supersedes: https://github.com/jimsalterjrs/sanoid/pull/667
It is possible for `creation` of a subsequent snapshot to be in the past
compared to the current snapshot due to system clock discrepancies,
which leads to earlier snapshots not being replicated in the initial
syncoid sync.
Also, `syncoid --no-sync-snap` might not pick up the most recently taken
snapshot if the clock moved backwards before taking that snapshot.
Sorting snapshots by the `createtxg` value is reliable and documented
in `man 8 zfsprops` as the proper way to order snapshots, but it was not
available in ZFS versions before 0.7. To maintain backwards
compatibility, the sorting falls back to sorting by the `creation`
property, which was the old behavior.
Fixes: https://github.com/jimsalterjrs/sanoid/issues/815
The `getsnaps` subroutine now retrieves the "createtxg" property of the
snapshot.
This is necessary to support the fix for
https://github.com/jimsalterjrs/sanoid/issues/815 (Syncoid: Data loss
because getoldestsnapshot() might not choose the first snapshot).
* The part that was "a little obnoxious" has been rewritten to extract
the desired properties in a single loop after importing each line into
a hash rather than processing line by line with a state tracking flag.
* The `getsnapsfallback` subroutine had duplicated logic that has been
absorbed into `getsnaps` with a recursion argument to enable the
fallback mode.
If there was an obsolete remote syncoid_hostname_* snapshot that did not
get removed at the correct time, for some reason, like, maybe, network
problems, it would have been cleaned up in pruneoldsyncsnaps just before
this code, and we would get a strange error message saying:
could not find any snapshots to destroy; check snapshot names.
Also, when using --quiet, do not output anything, as failing to remove
an obsolete snapshot is not really a big problem.