Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
liuh-80 committed Jul 19, 2023
1 parent 6579847 commit 226fc31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 8 additions & 0 deletions sonic_data_client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,18 @@ func TestNonDbClientGetError(t *testing.T) {
}
}

/*
Helper method for receive data from ZmqConsumerStateTable
consumer: Receive data from consumer
return:
true: data received
false: not receive any data after retry
*/
func ReceiveFromZmq(consumer swsscommon.ZmqConsumerStateTable) (bool) {
receivedData := swsscommon.NewKeyOpFieldsValuesQueue()
retry := 0;
for {
// sender's ZMQ may disconnect, wait and retry for reconnect
time.Sleep(time.Duration(1000) * time.Millisecond)
consumer.Pops(receivedData)
if receivedData.Size() == 0 {
Expand Down
19 changes: 10 additions & 9 deletions sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const DASH_TABLE_PREFIX string = "DASH_"
const SWSS_TIMEOUT uint = 0
const MAX_RETRY_COUNT uint = 5
const RETYRY_DELAY_MILLISECOND uint = 100
const RETYRY_DELAY_FACTOR uint = 2
const CHECK_POINT_PATH string = "/etc/sonic"

const (
Expand Down Expand Up @@ -177,7 +178,7 @@ func RetryHelper(zmqClient swsscommon.ZmqClient, action ActionNeedRetry) {
time.Sleep(retry_delay)

zmqClient.Connect()
retry_delay *= time.Duration(2)
retry_delay *= time.Duration(RETYRY_DELAY_FACTOR)
retry++
continue
}
Expand All @@ -200,20 +201,20 @@ func (c *MixedDbClient) DbSetTable(table string, key string, values map[string]s

pt := c.GetTable(table)
RetryHelper(
c.zmqClient,
func () error {
return ProducerStateTableSetWrapper(pt, key, vec)
})
c.zmqClient,
func () error {
return ProducerStateTableSetWrapper(pt, key, vec)
})
return nil
}

func (c *MixedDbClient) DbDelTable(table string, key string) error {
pt := c.GetTable(table)
RetryHelper(
c.zmqClient,
func () error {
return ProducerStateTableDeleteWrapper(pt, key)
})
c.zmqClient,
func () error {
return ProducerStateTableDeleteWrapper(pt, key)
})

return nil
}
Expand Down

0 comments on commit 226fc31

Please sign in to comment.