Skip to content

Commit

Permalink
[config] Add log to object UUID cassandra cache manager
Browse files Browse the repository at this point in the history
Add debugging logs to the cassandra object UUID cache for tracking issue.
That log are only available if the server log level is set at least to
debug and if some resource types we want to debug are defined in the
option flag 'DEFAULT.debug_object_cache_types'.

Change-Id: Iacd10017c236cc0595bc525ef7b1e3f3c8c756d6
Partial-Bug: #1768475
  • Loading branch information
Édouard Thuleau committed Jul 21, 2018
1 parent f94d57d commit 57faba1
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 68 deletions.
5 changes: 5 additions & 0 deletions src/config/api-server/vnc_cfg_api_server/utils.py
Expand Up @@ -86,6 +86,7 @@ def parse_args(args_str):
'kombu_ssl_ca_certs': '',
'object_cache_entries': '10000', # max number of objects cached for read
'object_cache_exclude_types': '', # csv of object types to *not* cache
'debug_object_cache_types': '', # csv of object types to debug cache
'db_engine': 'cassandra',
'max_request_size': 1024000,
'fabric_ansible_dir': '/opt/contrail/fabric_ansible_playbooks',
Expand Down Expand Up @@ -293,6 +294,10 @@ def parse_args(args_str):
help="Maximum number of objects cached for read, default 10000")
parser.add_argument("--object_cache_exclude_types",
help="Comma separated values of object types to not cache")
parser.add_argument(
"--debug_object_cache_types",
help="Comma separated values of object types to debug trace between "
"the cache and the DB")
parser.add_argument("--db_engine",
help="Database engine to use, default cassandra")
parser.add_argument("--max_request_size", type=int,
Expand Down
29 changes: 16 additions & 13 deletions src/config/api-server/vnc_cfg_api_server/vnc_cfg_api_server.py
Expand Up @@ -161,6 +161,8 @@
'method': 'POST', 'method_name': 'obj_chmod_http_post'},
{'uri': '/aaa-mode', 'link_name': 'aaa-mode',
'method': 'PUT', 'method_name': 'aaa_mode_http_put'},
{'uri': '/obj-cache', 'link_name': 'obj-cache',
'method': 'GET', 'method_name': 'dump_cache'},
{'uri': '/obj-cache', 'link_name': 'obj-cache',
'method': 'POST', 'method_name': 'dump_cache'},
{'uri': '/execute-job', 'link_name': 'execute-job',
Expand Down Expand Up @@ -1208,7 +1210,8 @@ def obj_view(self, resource_type, obj_dict):
r_class = self.get_resource_class(resource_type)
obj_links = r_class.obj_links & set(obj_dict.keys())
obj_uuids = [ref['uuid'] for link in obj_links for ref in list(obj_dict[link])]
obj_dicts = self._db_conn._object_db.object_raw_read(obj_uuids, ["perms2"])
obj_dicts = self._db_conn._object_db.object_raw_read(
r_class.object_type, obj_uuids, ["perms2"])
uuid_to_obj_dict = dict((o['uuid'], o) for o in obj_dicts)

for link_field in obj_links:
Expand Down Expand Up @@ -2447,18 +2450,14 @@ def obj_chown_http_post(self):
#end obj_chown_http_post

def dump_cache(self):
try:
request = json.loads((get_request().body.buf))
except Exception as e:
request = {}
val = {}
if 'uuid' in request:
obj_uuid = request['uuid']
val = self._db_conn._cassandra_db._obj_cache_mgr.dump_cache(obj_uuid=obj_uuid)
else:
count = request.get('count', 10)
val = self._db_conn._cassandra_db._obj_cache_mgr.dump_cache(count=count)
return val
self._post_common(None, {})

req_dict = get_request().json or {}
obj_uuids = req_dict.get('uuids', [])
count = req_dict.get('count', 10)

return self._db_conn._object_db._obj_cache_mgr.dump_cache(
obj_uuids=obj_uuids, count=count)

# chmod for an object
def obj_chmod_http_post(self):
Expand Down Expand Up @@ -3154,6 +3153,9 @@ def _db_connect(self, reset_config):
obj_cache_exclude_types = \
[t.replace('-', '_').strip() for t in
self._args.object_cache_exclude_types.split(',')]
debug_obj_cache_types = \
[t.replace('-', '_').strip() for t in
self._args.debug_object_cache_types.split(',')]

db_engine = self._args.db_engine
self._db_engine = db_engine
Expand All @@ -3176,6 +3178,7 @@ def _db_connect(self, reset_config):
kombu_ssl_ca_certs=self._args.kombu_ssl_ca_certs,
obj_cache_entries=obj_cache_entries,
obj_cache_exclude_types=obj_cache_exclude_types,
debug_obj_cache_types=debug_obj_cache_types,
cassandra_use_ssl=self._args.cassandra_use_ssl,
cassandra_ca_certs=self._args.cassandra_ca_certs)

Expand Down
16 changes: 10 additions & 6 deletions src/config/api-server/vnc_cfg_api_server/vnc_db.py
Expand Up @@ -81,9 +81,10 @@ def get_db_info(cls):
# end get_db_info

def __init__(self, db_client_mgr, cass_srv_list, reset_config, db_prefix,
cassandra_credential, walk, obj_cache_entries,
obj_cache_exclude_types, log_response_time=None,
ssl_enabled=False, ca_certs=None, pool_size=20):
cassandra_credential, walk, obj_cache_entries,
obj_cache_exclude_types, debug_obj_cache_types,
log_response_time=None, ssl_enabled=False, ca_certs=None,
pool_size=20):
self._db_client_mgr = db_client_mgr
keyspaces = self._UUID_KEYSPACE.copy()
keyspaces[self._USERAGENT_KEYSPACE_NAME] = {
Expand All @@ -94,6 +95,7 @@ def __init__(self, db_client_mgr, cass_srv_list, reset_config, db_prefix,
credential=cassandra_credential, walk=walk,
obj_cache_entries=obj_cache_entries,
obj_cache_exclude_types=obj_cache_exclude_types,
debug_obj_cache_types=debug_obj_cache_types,
log_response_time=log_response_time, ssl_enabled=ssl_enabled,
ca_certs=ca_certs)
# end __init__
Expand Down Expand Up @@ -746,8 +748,9 @@ def __init__(self, api_svr_mgr, db_srv_list, rabbit_servers, rabbit_port,
rabbit_user, rabbit_password, rabbit_vhost, rabbit_ha_mode,
reset_config=False, zk_server_ip=None, db_prefix='',
db_credential=None, obj_cache_entries=0,
obj_cache_exclude_types=None, db_engine='cassandra',
cassandra_use_ssl=False, cassandra_ca_certs=None, **kwargs):
obj_cache_exclude_types=None, debug_obj_cache_types=None,
db_engine='cassandra', cassandra_use_ssl=False,
cassandra_ca_certs=None, **kwargs):
self._db_engine = db_engine
self._api_svr_mgr = api_svr_mgr
self._sandesh = api_svr_mgr._sandesh
Expand Down Expand Up @@ -797,7 +800,8 @@ def db_client_init():
self._object_db = VncServerCassandraClient(
self, db_srv_list, reset_config, db_prefix,
db_credential, walk, obj_cache_entries,
obj_cache_exclude_types, self.log_cassandra_response_time,
obj_cache_exclude_types, debug_obj_cache_types,
self.log_cassandra_response_time,
ssl_enabled=cassandra_use_ssl, ca_certs=cassandra_ca_certs)

self._zk_db.master_election("/api-server-election", db_client_init)
Expand Down

0 comments on commit 57faba1

Please sign in to comment.