---
src/osaf/consensus/plugins/etcd3.plugin | 44 ++++++++++++++-----------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/src/osaf/consensus/plugins/etcd3.plugin
b/src/osaf/consensus/plugins/etcd3.plugin
index 6252eedcb..3784fa41d 100644
--- a/src/osaf/consensus/plugins/etcd3.plugin
+++ b/src/osaf/consensus/plugins/etcd3.plugin
@@ -37,26 +37,32 @@ export ETCDCTL_API=3
get() {
readonly key="$1"
- if output=$(etcdctl $etcd_options --dial-timeout $etcd_timeout get
"$directory$key" 2>&1)
- then
- key_=$(echo "$output" | tail -n2 | head -n1)
- value=$(echo "$output" | tail -n1)
- if [ "$key_" = "$directory$key" ]; then
- if [ "$key_" = "$value" ]; then
- # blank value returned
- echo ""
- return 0
+ while true; do
+ if output=$(etcdctl $etcd_options --dial-timeout $etcd_timeout get
"$directory$key" 2>&1)
+ then
+ key_=$(echo "$output" | tail -n2 | head -n1)
+ value=$(echo "$output" | tail -n1)
+ if [ "$key_" = "$directory$key" ]; then
+ if [ "$key_" = "$value" ]; then
+ # blank value returned
+ echo ""
+ return 0
+ else
+ echo "$value"
+ return 0
+ fi
else
- echo "$value"
- return 0
+ # key missing!
+ return 1
fi
- else
- # key missing!
- return 1
+ elif echo $etcd_options | grep -q "endpoints=localhost" &&
+ echo $output | grep -q "Error: context deadline exceeded"; then
+ sleep 1
+ continue
fi
- else
- return 2
- fi
+ break
+ done
+ return 2
}
# set
@@ -136,7 +142,7 @@ create_key() {
return 0
fi
- if output=$(etcdctl $etcd_options --dial-timeout $etcd_timeout get
"$directory$key" | tail -n1)
+ if output=$(get $key)
then
return 1
else
@@ -243,7 +249,7 @@ lock() {
return 0
fi
- current_owner=$(etcdctl $etcd_options --dial-timeout $etcd_timeout get
"$directory$keyname" | tail -n1)
+ current_owner=$(get $keyname)
# see if we already hold the lock
if [ "$current_owner" = "$owner" ]; then
return 0
--
2.17.1
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel