diff options
| author | Alexandre Marques <c137.marques@gmail.com> | 2025-03-14 10:22:12 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-03-18 11:25:36 +0000 |
| commit | 331aef4bcf3ad9bbeea25b3463219f46d46bd4a6 (patch) | |
| tree | 73aca6570eb8b43ada602b8cfb2179b051294ccf /scripts | |
| parent | 944551b0c9dff0d8ef1c93f99044383d402a33a1 (diff) | |
| download | poky-331aef4bcf3ad9bbeea25b3463219f46d46bd4a6.tar.gz | |
scripts: Add clean-hashserver-database script
Auxiliary script to clean the hashserver database based on the files
available in the sstate directory.
It makes used of the new "hashclient gc-mark-stream" command to mark all sstate
relevant hashes as "alive" and removes everything else from the
database.
Usage example:
```
./scripts/clean-hashserver-database \
--sstate-dir ~/build/sstate-cache \
--hashclient ./bitbake/bin/bitabke-hashclient \
--hashserver-address "ws://localhost:8688/ws" \
--mark "alive" \
--threshold-age 60 \
--clean-db
```
(From OE-Core rev: f6737c762ac11f7653a64fac58428428c4222d0f)
Signed-off-by: Alexander Marques <c137.marques@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/clean-hashserver-database | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/clean-hashserver-database b/scripts/clean-hashserver-database new file mode 100755 index 0000000000..9fa162c981 --- /dev/null +++ b/scripts/clean-hashserver-database | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | set -euo pipefail | ||
| 3 | |||
| 4 | SSTATE_DIR="" | ||
| 5 | BB_HASHCLIENT="" | ||
| 6 | BB_HASHSERVER="" | ||
| 7 | |||
| 8 | ALIVE_DB_MARK="alive" | ||
| 9 | CLEAN_DB="false" | ||
| 10 | THRESHOLD_AGE="3600" | ||
| 11 | |||
| 12 | function help() { | ||
| 13 | cat <<HELP_TEXT | ||
| 14 | Usage: $0 --sstate-dir path --hashclient path --hashserver-address address \ | ||
| 15 | [--mark value] [--clean-db] [--threshold-age seconds] | ||
| 16 | |||
| 17 | Auxiliary script remove unused or no longer relevant entries from the hashequivalence database, based | ||
| 18 | on the files available on the sstate directory. | ||
| 19 | |||
| 20 | -h | --help) Show this help message and exit | ||
| 21 | -a | --hashserver-adress) bitbake-hashserver address | ||
| 22 | -c | --hashclient) Path to bitbake-hashclient | ||
| 23 | -m | --mark) Marker string to mark database entries | ||
| 24 | -s | --sstate-dir) Path to the sstate dir | ||
| 25 | -t | --threshold-age) Remove unused entries older than SECONDS old (default: 3600) | ||
| 26 | --clean-db) Remove all unmarked and unused entries from the database | ||
| 27 | HELP_TEXT | ||
| 28 | } | ||
| 29 | |||
| 30 | function argument_parser() { | ||
| 31 | while [ $# -gt 0 ]; do | ||
| 32 | case "$1" in | ||
| 33 | -h | --help) help; exit 0 ;; | ||
| 34 | -a | --hashserver-address) BB_HASHSERVER="$2"; shift ;; | ||
| 35 | -c | --hashclient) BB_HASHCLIENT="$2"; shift ;; | ||
| 36 | -m | --mark) ALIVE_DB_MARK="$2"; shift ;; | ||
| 37 | -s | --sstate-dir) SSTATE_DIR="$2"; shift ;; | ||
| 38 | -t | --threshold-age) THRESHOLD_AGE="$2"; shift ;; | ||
| 39 | --clean-db) CLEAN_DB="true";; | ||
| 40 | *) | ||
| 41 | echo "Argument '$1' is not supported" >&2 | ||
| 42 | help >&2 | ||
| 43 | exit 1 | ||
| 44 | ;; | ||
| 45 | esac | ||
| 46 | shift | ||
| 47 | done | ||
| 48 | |||
| 49 | function validate_mandatory_argument() { | ||
| 50 | local var_value="$1" | ||
| 51 | local error_message="$2" | ||
| 52 | |||
| 53 | if [ -z "$var_value" ]; then | ||
| 54 | echo "$error_message" | ||
| 55 | help >&2 | ||
| 56 | exit 1 | ||
| 57 | fi | ||
| 58 | } | ||
| 59 | |||
| 60 | validate_mandatory_argument "$SSTATE_DIR" "Please provide the path to the sstate dir." | ||
| 61 | validate_mandatory_argument "$BB_HASHCLIENT" "Please provide the path to bitbake-hashclient." | ||
| 62 | validate_mandatory_argument "$BB_HASHSERVER" "Please provide the address of bitbake-hashserver." | ||
| 63 | } | ||
| 64 | |||
| 65 | # -- main code -- | ||
| 66 | argument_parser $@ | ||
| 67 | |||
| 68 | # Mark all db sstate hashes | ||
| 69 | find "$SSTATE_DIR" -name "*.tar.zst" | \ | ||
| 70 | sed 's/.*:\([^_]*\)_.*/unihash \1/' | \ | ||
| 71 | $BB_HASHCLIENT --address "$BB_HASHSERVER" gc-mark-stream "$ALIVE_DB_MARK" | ||
| 72 | |||
| 73 | # Remove unmarked and unused entries | ||
| 74 | if [ "$CLEAN_DB" = "true" ]; then | ||
| 75 | $BB_HASHCLIENT --address "$BB_HASHSERVER" gc-sweep "$ALIVE_DB_MARK" | ||
| 76 | $BB_HASHCLIENT --address "$BB_HASHSERVER" clean-unused "$THRESHOLD_AGE" | ||
| 77 | fi | ||
