From 42e32566f6fd1e3fe65ff79ccff1f4d82011b96d Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 28 Jul 2021 09:41:09 +0300 Subject: [PATCH] production_snitch_base: Fallback for empty DC or rack strings Lubos Kosco points out that on Microsoft Azure, for example, it is possible for the "zone metadata" (which we use as rack information) can be empty as shown in: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service?tabs=windows#instance-metadata Therefore, protect against empty DC or rack strings in `production_snitch_base` to keep the behavior consistent across different snitches. --- locator/production_snitch_base.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/locator/production_snitch_base.cc b/locator/production_snitch_base.cc index 625798c506..e3b8d81a21 100644 --- a/locator/production_snitch_base.cc +++ b/locator/production_snitch_base.cc @@ -123,11 +123,21 @@ sstring production_snitch_base::get_endpoint_info(inet_address endpoint, gms::ap } void production_snitch_base::set_my_dc(const sstring& new_dc) { - _my_dc = new_dc; + if (!new_dc.empty()) { + _my_dc = new_dc; + } else { + _my_dc = default_dc; + logger().warn("{} snitch attempted to set DC to an empty string, falling back to {}.", get_name(), default_dc); + } } void production_snitch_base::set_my_rack(const sstring& new_rack) { - _my_rack = new_rack; + if (!new_rack.empty()) { + _my_rack = new_rack; + } else { + _my_rack = default_rack; + logger().warn("{} snitch attempted to set rack to an empty string, falling back to {}.", get_name(), default_rack); + } } void production_snitch_base::set_prefer_local(bool prefer_local) {