Skip to content

Commit

Permalink
Merge branch 'master' into dev-logrotate-config
Browse files Browse the repository at this point in the history
  • Loading branch information
fastiuk authored Aug 11, 2024
2 parents 441f58b + e37bfea commit 746ee08
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
displayName: "Install gcovr 5.2 (for --exclude-throw-branches support)"
- script: |
set -ex
sudo pip install Pympler==0.8
sudo pip install Pympler==0.8 pytest
sudo apt-get install -y redis-server
sudo sed -i 's/notify-keyspace-events ""/notify-keyspace-events AKE/' /etc/redis/redis.conf
sudo sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf
Expand Down
6 changes: 6 additions & 0 deletions common/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace swss {
#define CHASSIS_STATE_DB 13
#define APPL_STATE_DB 14
#define EVENT_DB 19
#define BMP_STATE_DB 20

/***** APPLICATION DATABASE *****/

Expand Down Expand Up @@ -323,6 +324,7 @@ namespace swss {
#define CFG_BGP_MONITORS_TABLE_NAME "BGP_MONITORS"
#define CFG_BGP_PEER_RANGE_TABLE_NAME "BGP_PEER_RANGE"
#define CFG_BGP_DEVICE_GLOBAL_TABLE_NAME "BGP_DEVICE_GLOBAL"
#define CFG_BMP_TABLE_NAME "BMP"

#define CFG_SWITCH_HASH_TABLE_NAME "SWITCH_HASH"
#define CFG_DEVICE_METADATA_TABLE_NAME "DEVICE_METADATA"
Expand Down Expand Up @@ -574,6 +576,10 @@ namespace swss {
#define EVENT_STATS_TABLE_NAME "EVENT_STATS"
#define EVENT_ALARM_STATS_TABLE_NAME "ALARM_STATS"

/***** BMP STATE DATABASE *****/
#define BMP_STATE_BGP_NEIGHBOR_TABLE "BGP_NEIGHBOR_TABLE"
#define BMP_STATE_BGP_RIB_IN_TABLE "BGP_RIB_IN_TABLE"
#define BMP_STATE_BGP_RIB_OUT_TABLE "BGP_RIB_OUT_TABLE"

#ifdef __cplusplus
}
Expand Down
39 changes: 25 additions & 14 deletions pyext/swsscommon.i
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include "zmqclient.h"
#include "zmqconsumerstatetable.h"
#include "zmqproducerstatetable.h"
#include <memory>
#include <functional>
%}

%include <std_string.i>
Expand Down Expand Up @@ -156,31 +158,36 @@
SWIG_Python_AppendOutput($result, temp);
}

%typemap(in, fragment="SWIG_AsPtr_std_string")
%typemap(in, fragment="SWIG_AsVal_std_string")
const std::vector<std::pair< std::string,std::string >,std::allocator< std::pair< std::string,std::string > > > &
(std::vector< std::pair< std::string,std::string >,std::allocator< std::pair< std::string,std::string > > > temp,
int res) {
res = SWIG_OK;
for (int i = 0; i < PySequence_Length($input); ++i) {
temp.push_back(std::pair< std::string,std::string >());
PyObject *item = PySequence_GetItem($input, i);
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
std::unique_ptr<PyObject, std::function<void(PyObject *)> > item(
PySequence_GetItem($input, i),
[](PyObject *ptr){
Py_DECREF(ptr);
});
if (!PyTuple_Check(item.get()) || PyTuple_Size(item.get()) != 2) {
SWIG_fail;
}
PyObject *key = PyTuple_GetItem(item, 0);
PyObject *value = PyTuple_GetItem(item, 1);
std::string *ptr = (std::string *)0;
PyObject *key = PyTuple_GetItem(item.get(), 0);
PyObject *value = PyTuple_GetItem(item.get(), 1);
std::string str;

if (PyBytes_Check(key)) {
temp.back().first.assign(PyBytes_AsString(key), PyBytes_Size(key));
} else if (SWIG_AsPtr_std_string(key, &ptr)) {
temp.back().first = *ptr;
} else if (SWIG_AsVal_std_string(key, &str) != SWIG_ERROR) {
temp.back().first = str;
} else {
SWIG_fail;
}
if (PyBytes_Check(value)) {
temp.back().second.assign(PyBytes_AsString(value), PyBytes_Size(value));
} else if (SWIG_AsPtr_std_string(value, &ptr)) {
temp.back().second = *ptr;
} else if (SWIG_AsVal_std_string(value, &str) != SWIG_ERROR) {
temp.back().second = str;
} else {
SWIG_fail;
}
Expand All @@ -191,13 +198,17 @@
%typemap(typecheck) const std::vector< std::pair< std::string,std::string >,std::allocator< std::pair< std::string,std::string > > > &{
$1 = 1;
for (int i = 0; i < PySequence_Length($input); ++i) {
PyObject *item = PySequence_GetItem($input, i);
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
std::unique_ptr<PyObject, std::function<void(PyObject *)> > item(
PySequence_GetItem($input, i),
[](PyObject *ptr){
Py_DECREF(ptr);
});
if (!PyTuple_Check(item.get()) || PyTuple_Size(item.get()) != 2) {
$1 = 0;
break;
}
PyObject *key = PyTuple_GetItem(item, 0);
PyObject *value = PyTuple_GetItem(item, 1);
PyObject *key = PyTuple_GetItem(item.get(), 0);
PyObject *value = PyTuple_GetItem(item.get(), 1);
if (!PyBytes_Check(key)
&& !PyUnicode_Check(key)
&& !PyString_Check(key)
Expand Down
4 changes: 2 additions & 2 deletions sonic-db-cli/sonic-db-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ int executeCommands(
try
{
int db_id = SonicDBConfig::getDbId(db_name, netns);
if (useUnixSocket)
auto host = SonicDBConfig::getDbHostname(db_name, netns);
if (useUnixSocket && host != "redis_chassis.server")
{
auto db_socket = SonicDBConfig::getDbSock(db_name, netns);
client = make_shared<DBConnector>(db_id, db_socket, 0);
}
else
{
auto host = SonicDBConfig::getDbHostname(db_name, netns);
auto port = SonicDBConfig::getDbPort(db_name, netns);
client = make_shared<DBConnector>(db_id, host, port, 0);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/test_redis_ut.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import time
import psutil
import pytest
import multiprocessing
from threading import Thread
Expand Down Expand Up @@ -851,3 +852,30 @@ def test_SmartSwitchDBConnector():
assert tbl.get("dputest2")[1][1] == ("dashfield2", "dashvalue2")
assert len(SonicDBConfig.getDbKeys()) == len(global_db_config_json["INCLUDES"])


def test_TableSetBinary():
app_db = swsscommon.DBConnector("APPL_DB", 0, True)
t = swsscommon.Table(app_db, "TABLE")
buff = b""
for i in range(0, 256):
buff += bytes([i])
buff = buff.decode('latin-1')
fvs = swsscommon.FieldValuePairs([("binary", buff)])
t.set("binary", fvs)
(status, fvs) = t.get("binary")
assert status == True
assert fvs[0][1] == buff


def test_TableOpsMemoryLeak():
OP_COUNT = 50000
app_db = swsscommon.DBConnector("APPL_DB", 0, True)
t = swsscommon.Table(app_db, "TABLE")
long_data = "x" * 100
fvs = swsscommon.FieldValuePairs([(long_data, long_data)])
rss = psutil.Process(os.getpid()).memory_info().rss
for _ in range(OP_COUNT):
t.set("long_data", fvs)
t.get("long_data")
assert psutil.Process(os.getpid()).memory_info().rss - rss < OP_COUNT

0 comments on commit 746ee08

Please sign in to comment.