From a4aa095cc7da088d80f094ad5f1250e48592500e Mon Sep 17 00:00:00 2001
From: Georgy Moshkin <gmoshkin@picodata.io>
Date: Wed, 7 Feb 2024 14:02:03 +0300
Subject: [PATCH] fix: vshard used to break box.cfg.listen value

---
 src/rpc/sharding.rs | 7 ++++---
 src/vshard.rs       | 8 ++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/rpc/sharding.rs b/src/rpc/sharding.rs
index 3192adff64..e09e451f7d 100644
--- a/src/rpc/sharding.rs
+++ b/src/rpc/sharding.rs
@@ -22,11 +22,12 @@ crate::define_rpc_request! {
         node.wait_index(req.applied, req.timeout)?;
         node.status().check_term(req.term)?;
 
-        let cfg = node.storage.properties.target_vshard_config()?;
-        crate::tlog!(Debug, "vshard config: {cfg:?}");
-
         let lua = ::tarantool::lua_state();
 
+        let mut cfg = node.storage.properties.target_vshard_config()?;
+        cfg.listen = Some(lua.eval("return box.info.listen")?);
+        crate::tlog!(Debug, "vshard config: {cfg:?}");
+
         if !req.do_reconfigure {
             if let Some(tlua::True) = lua.eval("return pico._vshard_is_configured")? {
                 return Ok(Response {});
diff --git a/src/vshard.rs b/src/vshard.rs
index eb8d7801b0..68a952137b 100644
--- a/src/vshard.rs
+++ b/src/vshard.rs
@@ -14,6 +14,13 @@ use std::collections::HashMap;
 pub struct VshardConfig {
     sharding: HashMap<String, ReplicasetSpec>,
     discovery_mode: DiscoveryMode,
+
+    /// This field is not stored in the global storage, instead
+    /// it is set right before the config is passed into vshard.*.cfg,
+    /// otherwise vshard will override it with an incorrect value.
+    #[serde(skip_serializing_if="Option::is_none")]
+    #[serde(default)]
+    pub listen: Option<String>,
 }
 
 #[rustfmt::skip]
@@ -110,6 +117,7 @@ impl VshardConfig {
         }
 
         Self {
+            listen: None,
             sharding,
             discovery_mode: DiscoveryMode::On,
         }
-- 
GitLab