4 # Copyright (C) 2015 Ubuntu Kylin
6 # Author: Min Chen <minchen@ubuntukylin.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Library Public License for more details.
19 my_dir=$(dirname "$0")
22 #pgid_list=$single_node/$cluster-$id/pgid_list
23 function get_pgid_list()
25 find $osd_data/current/ -type d -name "*_head"|\
26 sed -n 's/\(.*\)\/current\/\([0-9a-fA-F]\+\.[0-9a-fA-F]\+\)_head/\2 \1/p'|\
27 sort -t ' ' -k 1.1,1h -k 2.1,2 > $pgid_list;
33 echo $hobject_path| sed -n 's/\(.*\)\/\([0-9a-fA-F]\+\.[0-9a-fA-F]\+\)_head\(.*\)/\2/p'
37 function get_infos_seq()
39 local func="get_infos_seq"
41 local keyword=":infos."
42 local infos_key=`get_map_header_key $keyword`
44 if [ "$infos_key"x = ""x ];then
45 echo "$func: keyword not input or infos_key not exists"
48 local prefix=`get_map_header_prefix`
51 infos_seq=`get_header_seq $prefix $key`
52 if [ "$infos_seq"x = ""x ];then
53 echo "$func: infos_seq not exists"
59 function get_pg_epoch()
61 local func="get_pg_epoch"
62 if [ "$1"x = ""x ];then
63 echo "$func: no pgid input"
67 get_pg_epoch_firefly "$1"
68 if [ "$pg_epoch"x != ""x ]; then
69 # echo "Epoch for $1: $pg_epoch (firefly)"
73 get_pg_epoch_hammer "$1"
74 if [ "$pg_epoch"x != ""x ]; then
75 # echo "Epoch for $1: $pg_epoch (hammer)"
79 echo "$func: Couldn't find epoch for $1"
83 function get_pg_epoch_firefly()
85 local func="get_pg_epoch_firefly"
86 if [ "$1"x = ""x ];then
87 echo "$func: no pgid input"
91 local key=$pgid"_epoch"
94 # infos_seq default to 1
96 local infos_seq=`printf "%016d" $infos_seq`
97 local prefix="_USER_"$infos_seq"_USER_"
99 pg_epoch=`get_header_kv $prefix $key int`
102 function get_pg_epoch_hammer()
104 local func="get_pg_epoch_hammer"
105 if [ "$1"x = ""x ];then
106 echo "$func: no pgid input"
110 local hkey_prefix="$(get_map_header_prefix)"
111 local hkey="$(printf '...head.%x.%08X' "$(echo "$pgid"|cut -d'.' -f1)" "$((0x$(echo "$pgid"|cut -d'.' -f2)))")"
113 local infos_seq="$(get_header_seq "$hkey_prefix" "$hkey")"
114 local infos_seq=`printf "%016d" $infos_seq`
115 local prefix="_USER_"$infos_seq"_USER_"
118 pg_epoch=`get_header_kv $prefix $key int`