22#include " meta/sai_serialize.h"
33#include " meta/saiattributelist.h"
44
5+ sai_status_t internal_api_wait_for_response (
6+ _In_ sai_common_api_t api)
7+ {
8+ SWSS_LOG_ENTER ();
9+
10+ if (!g_syncMode)
11+ {
12+ /*
13+ * By default sync mode is disabled and all create/set/remove are
14+ * considered success operations.
15+ */
16+
17+ return SAI_STATUS_SUCCESS;
18+ }
19+
20+ SWSS_LOG_INFO (" waiting for response %d" , api);
21+
22+ swss::Select s;
23+
24+ s.addSelectable (g_redisGetConsumer.get ());
25+
26+ while (true )
27+ {
28+ SWSS_LOG_INFO (" wait for %d api response" , api);
29+
30+ swss::Selectable *sel;
31+
32+ // get timeout and selector is used for all quad api's
33+ int result = s.select (&sel, GET_RESPONSE_TIMEOUT);
34+
35+ if (result == swss::Select::OBJECT)
36+ {
37+ swss::KeyOpFieldsValuesTuple kco;
38+
39+ g_redisGetConsumer->pop (kco);
40+
41+ const std::string &op = kfvOp (kco);
42+ const std::string &opkey = kfvKey (kco);
43+
44+ SWSS_LOG_INFO (" response: op = %s, key = %s" , opkey.c_str (), op.c_str ());
45+
46+ if (op != " getresponse" ) // ignore non response messages
47+ {
48+ continue ;
49+ }
50+
51+ sai_status_t status;
52+ sai_deserialize_status (opkey, status);
53+
54+ if (g_record)
55+ {
56+ const std::string &str_status = kfvKey (kco);
57+ const std::vector<swss::FieldValueTuple> &values = kfvFieldsValues (kco);
58+
59+ // first serialized is status
60+ recordLine (" G|" + str_status + " |" + joinFieldValues (values));
61+ }
62+
63+ SWSS_LOG_DEBUG (" generic %d api status: %d" , api, status);
64+
65+ return status;
66+ }
67+
68+ SWSS_LOG_ERROR (" generic %d api failed due to SELECT operation result: %s" , api, getSelectResultAsString (result).c_str ());
69+ break ;
70+ }
71+
72+ if (g_record)
73+ {
74+ recordLine (" G|SAI_STATUS_FAILURE" );
75+ }
76+
77+ SWSS_LOG_ERROR (" generic %d api failed to get response" , api);
78+
79+ return SAI_STATUS_FAILURE;
80+ }
81+
582sai_status_t internal_redis_generic_set (
683 _In_ sai_object_type_t object_type,
784 _In_ const std::string &serialized_object_id,
@@ -28,7 +105,7 @@ sai_status_t internal_redis_generic_set(
28105
29106 g_asicState->set (key, entry, " set" );
30107
31- return SAI_STATUS_SUCCESS ;
108+ return internal_api_wait_for_response (SAI_COMMON_API_SET) ;
32109}
33110
34111sai_status_t internal_redis_bulk_generic_set (
@@ -110,7 +187,7 @@ sai_status_t internal_redis_bulk_generic_set(
110187 g_asicState->set (key, entries, " bulkset" );
111188 }
112189
113- return SAI_STATUS_SUCCESS ;
190+ return internal_api_wait_for_response (SAI_COMMON_API_CREATE) ;
114191}
115192
116193
0 commit comments