Skip to content

Commit

Permalink
Revert code
Browse files Browse the repository at this point in the history
  • Loading branch information
liuh-80 committed Jul 17, 2023
1 parent a5ee6e9 commit 4186b0b
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ type MixedDbClient struct {
mu sync.RWMutex // Mutex for data protection among routines for DbClient
}

var mixedDbClientMap = map[string]MixedDbClient{}

func getMixedDbClient(zmqAddress string) (MixedDbClient) {
client, ok := mixedDbClientMap[zmqAddress]
if !ok {
client = MixedDbClient {
applDB : swsscommon.NewDBConnector(APPL_DB_NAME, SWSS_TIMEOUT, false),
tableMap : map[string]swsscommon.ProducerStateTable{},
}

// enable ZMQ by zmqAddress parameter
if zmqAddress != "" {
client.zmqClient = swsscommon.NewZmqClient(zmqAddress)
} else {
client.zmqClient = nil
}

mixedDbClientMap[zmqAddress] = client
}

return client
}

func parseJson(str []byte) (interface{}, error) {
var res interface{}
err := json.Unmarshal(str, &res)
Expand Down Expand Up @@ -196,14 +219,14 @@ func (c *MixedDbClient) DbDelTable(table string, key string) error {
}

func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string, zmqAddress string) (Client, error) {
var client MixedDbClient
var err error

// Testing program may ask to use redis local tcp connection
if UseRedisLocalTcpPort {
useRedisTcpClient()
}

var client = getMixedDbClient(zmqAddress)
client.prefix = prefix
client.target = ""
client.origin = origin
Expand All @@ -229,8 +252,6 @@ func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string,
}
client.paths = paths
client.workPath = common_utils.GNMI_WORK_PATH
client.applDB = swsscommon.NewDBConnector(APPL_DB, REDIS_SOCK, SWSS_TIMEOUT)
client.tableMap = map[string]swsscommon.ProducerStateTable{}

return &client, nil
}
Expand Down Expand Up @@ -1129,20 +1150,7 @@ func (c *MixedDbClient) Capabilities() []gnmipb.ModelData {
}

func (c *MixedDbClient) Close() error {
for _, pt := range c.tableMap {
zpt, ok := pt.(swsscommon.ZmqProducerStateTable)
if ok {
swsscommon.DeleteZmqProducerStateTable(zpt)
} else {
swsscommon.DeleteProducerStateTable(pt)
}
}

if c.zmqClient != nil {
swsscommon.DeleteZmqClient(c.zmqClient)
}

swsscommon.DeleteDBConnector(c.applDB)
// Do nothing here, because MixedDbClient will be cache in mixedDbClientMap and reuse
return nil
}

Expand Down

0 comments on commit 4186b0b

Please sign in to comment.