Skip to content

Commit 1f98af8

Browse files
lipxuFengPan-Frank
authored andcommitted
[FRR] bgpcfgd Wait for mgmtd initial config load (#24655)
Why I did it Work item tracking Microsoft ADO (number only): 34848755 How I did it Wait for mgmtd initial config load to avoid "Lock already taken on DS" error How to verify it 2025 Dec 2 00:56:56.302357 bjw-can-7060-1 NOTICE bgp#bgpcfgd: Checking mgmtd datastore readiness... 2025 Dec 2 00:56:56.390985 bjw-can-7060-1 NOTICE bgp#bgpcfgd: mgmtd datastores are ready (attempt 1) Signed-off-by: Feng Pan <fenpan@microsoft.com>
1 parent f05104e commit 1f98af8

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/sonic-bgpcfgd/bgpcfgd/main.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import signal
3+
import subprocess
34
import sys
45
import syslog
56
import threading
7+
import time
68
import traceback
79

810
from swsscommon.swsscommon import ConfigDBConnector
@@ -11,7 +13,7 @@
1113

1214
from .config import ConfigMgr
1315
from .directory import Directory
14-
from .log import log_notice, log_crit
16+
from .log import log_notice, log_crit, log_warn
1517
from .managers_advertise_rt import AdvertiseRouteMgr
1618
from .managers_aggregate_address import AggregateAddressMgr, BGP_AGGREGATE_ADDRESS_TABLE_NAME
1719
from .managers_allow_list import BGPAllowListMgr
@@ -43,6 +45,23 @@ def do_work():
4345
thr.start()
4446
frr = FRR(["bgpd", "zebra", "staticd"])
4547
frr.wait_for_daemons(seconds=20)
48+
49+
# Wait for mgmtd initial config load to avoid "Lock already taken on DS" error
50+
log_notice("Checking mgmtd datastore readiness...")
51+
for attempt in range(10): # Max ~5 seconds
52+
try:
53+
out = subprocess.check_output(['vtysh', '-c', 'show mgmt datastore all'],
54+
stderr=subprocess.DEVNULL, timeout=2, text=True)
55+
# Check if any datastore is locked (FRR topotest approach)
56+
locked_lines = [line for line in out.splitlines() if 'Locked:' in line and 'True' in line]
57+
if not locked_lines:
58+
log_notice("mgmtd datastores are ready (attempt %d)" % (attempt + 1))
59+
break
60+
else:
61+
log_warn("mgmtd datastores still locked (attempt %d): %s" % (attempt + 1, ', '.join(locked_lines)))
62+
except Exception as e:
63+
log_warn("mgmtd check failed (attempt %d): %s" % (attempt + 1, str(e)))
64+
time.sleep(0.5)
4665
#
4766
common_objs = {
4867
'directory': Directory(),
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From ac505e5f4528f6ce85673e518d1df0c7c10a6ac1 Mon Sep 17 00:00:00 2001
2+
From: Donald Sharp <sharpd@nvidia.com>
3+
Date: Fri, 11 Jul 2025 19:19:15 -0400
4+
Subject: [PATCH] mgmt: Note that a DS is locked or not in output
5+
6+
Modify the `show mgmt datastore ..` command to note
7+
if the data store is locked and by which session-id.
8+
9+
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
10+
---
11+
mgmtd/mgmt_ds.c | 6 ++++++
12+
1 file changed, 6 insertions(+)
13+
14+
diff --git a/mgmtd/mgmt_ds.c b/mgmtd/mgmt_ds.c
15+
index 91592df22f..a0e6c83393 100644
16+
--- a/mgmtd/mgmt_ds.c
17+
+++ b/mgmtd/mgmt_ds.c
18+
@@ -514,15 +514,21 @@ void mgmt_ds_dump_tree(struct vty *vty, struct mgmt_ds_ctx *ds_ctx,
19+
20+
void mgmt_ds_status_write_one(struct vty *vty, struct mgmt_ds_ctx *ds_ctx)
21+
{
22+
+ uint64_t session_id;
23+
+ bool locked;
24+
+
25+
if (!ds_ctx) {
26+
vty_out(vty, " >>>>> Datastore Not Initialized!\n");
27+
return;
28+
}
29+
30+
+ locked = mgmt_ds_is_locked(ds_ctx, &session_id);
31+
vty_out(vty, " DS: %s\n", mgmt_ds_id2name(ds_ctx->ds_id));
32+
vty_out(vty, " DS-Hndl: \t\t\t%p\n", ds_ctx);
33+
vty_out(vty, " Config: \t\t\t%s\n",
34+
ds_ctx->config_ds ? "True" : "False");
35+
+ vty_out(vty, " Locked: \t\t\t%s Session-ID: %Lu\n", locked ? "True" : "False",
36+
+ locked ? session_id : 0);
37+
}
38+
39+
void mgmt_ds_status_write(struct vty *vty)
40+
--
41+
2.34.1
42+

src/sonic-frr/patch/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@
5656
0094-zebra-fix-yang-data-for-mcast-group.patch
5757
0095-bgpd-Crash-due-to-usage-of-freed-up-evpn_overlay-att.patch
5858
0096-bgpd-Notify-all-incoming-outgoing-on-peer-group-noti.patch
59+
0097-mgmt-Note-that-a-DS-is-locked-or-not-in-output.patch

0 commit comments

Comments
 (0)