Description

In Contrail, each Config API instance populates its own independent cache based on the queries received in the past. This is an optimization that is in place to provide faster API responses and to reduce the number of queries performed by the Config API against the Config Database (Cassandra).

The Contrail Config API refreshes its cache based on the object timestamp. Instead of retrieving the full object from the Config database when an API request comes, the Config API instance fetches an object's latest timestamp from the Config database, and then compares it with the timestamp of the object present in its cache (if any - a hit scenario). If both timestamps match, it means that there is no difference between the cached object on the Config API side and the object stored in the Config database (the source of truth). The Config API then answers the request by using the cached object information.

However, if there is a mismatch between the timestamps, this means that the cached object is no longer valid and that the specific cached object needs to be updated (fetched from the Config database) before answering the API request.

In this article, an example of how to retrieve a specific object from the Config API cache is provided. A Port object in OpenStack corresponds to a Virtual Machine Interface object in Contrail and is used for the purposes of this example.

Solution

Perform the following:

  1. Get the UUID of the object of interest. In this example, we are using a Port object.

(overcloud) [alab stack@undercloud:~]$ openstack port list | grep -i port
| 6787f58d-1435-4c8c-be98-cd5a33f4c2f5 | port_02_2f625732-bb3c-4f11-b09d-ff8ff681e262  | 02:67:87:f5:8d:14 | ip_address='192.168.222.4', subnet_id='7d3f6b19-e385-495c-9c33-25f3986fdc6c'       | ACTIVE |
| 23e15309-ae5b-42a3-87dd-70f3428a2523 | port_02_f415988a-77a0-4ae4-9aa1-8d8f1892795b  | 02:23:e1:53:09:ae | ip_address='192.168.222.4', subnet_id='ec6aee34-6f4f-4be1-9836-f19259620aa1'       | DOWN   |
| be5caa34-24f6-407c-8b56-e3a19293ec0d | port_01_8a6d8df9-cf12-4a63-939c-087bdbe176ff  | 02:be:5c:aa:34:24 | ip_address='192.168.222.3', subnet_id='1d865db2-72de-4319-84dd-c7515354ceee'       | DOWN   |
  1. Access the Config API container to run the following query and to retrieve the specified object:

(config-api)[root@overcloudamg-cc-1 /]$ curl -u $KEYSTONE_AUTH_ADMIN_USER:$KEYSTONE_AUTH_ADMIN_PASSWORD localhost:8095/obj-cache -H "Content-Type: application/json; charset=UTF-8" -d '{"uuids":["6787f58d-1435-4c8c-be98-cd5a33f4c2f5"]}'| python -mjson.tool

{
    "1": {
        "id_perms_ts": 1623298318712568,
        "obj_dict": {
            "display_name": "port_02_2f625732-bb3c-4f11-b09d-ff8ff681e262",
            "fq_name": [
                "default-domain",
                "admin",
                "port_02_2f625732-bb3c-4f11-b09d-ff8ff681e262"
            ],
            "id_perms": {
                "created": "2021-06-10T04:11:17.048480",
                "creator": null,
                "description": "",
                "enable": true,
                "last_modified": "2021-06-10T04:11:58.712531",
                "permissions": {
                    "group": "admin",
                    "group_access": 7,
                    "other_access": 7,
                    "owner": "admin",
                    "owner_access": 7
                },
                "user_visible": true,
                "uuid": {
                    "uuid_lslong": 13733952850968756981,
                    "uuid_mslong": 7460201294040747148
                }
            },
            "instance_ip_back_refs": [
                {
                    "attr": null,
                    "to": [
                        "eedcfcfb-491c-4787-aff4-75c476db0f06"
                    ],
                    "uuid": "eedcfcfb-491c-4787-aff4-75c476db0f06"
                }
            ],
            "parent_type": "project",
            "parent_uuid": "9967dcb8-d49b-44c1-9538-9200465c37bb",
            "perms2": {
                "global_access": 0,
                "owner": "9967dcb8d49b44c195389200465c37bb",
                "owner_access": 7,
                "share": []
            },
            "port_security_enabled": true,
            "routing_instance_refs": [
                {
                    "attr": {
                        "direction": "both",
                        "dst_mac": null,
                        "ipv6_service_chain_address": null,
                        "mpls_label": null,
                        "protocol": null,
                        "service_chain_address": null,
                        "src_mac": null,
                        "vlan_tag": null
                    },
                    "to": [
                        "default-domain",
                        "admin",
                        "test_net_01-2f625732-bb3c-4f11-b09d-ff8ff681e262",
                        "test_net_01-2f625732-bb3c-4f11-b09d-ff8ff681e262"
                    ],
                    "uuid": "d2f82544-7064-4b3f-bdc1-07b571bdc948"
                }
            ],
            "security_group_refs": [
                {
                    "attr": null,
                    "to": [
                        "default-domain",
                        "admin",
                        "default"
                    ],
                    "uuid": "d3a0f0a9-cd3a-4adc-82d1-738fd41ae3ad"
                }
            ],
            "uuid": "6787f58d-1435-4c8c-be98-cd5a33f4c2f5",
            "virtual_machine_interface_bindings": {
                "key_value_pair": [
                    {
                        "key": "host_id",
                        "value": "overcloudamg-compdpdk24hw1-3.alab.example.com"
                    },
                    {
                        "key": "vnic_type",
                        "value": "normal"
                    },
                    {
                        "key": "vif_details",
                        "value": "{\"vhostuser_socket\": \"/var/run/vrouter/uvh_vif_tap6787f58d-14\", \"vhostuser_vrouter_plug\": true, \"vhostuser_mode\": \"server\"}"
                    },
                    {
                        "key": "vif_type",
                        "value": "vhostuser"
                    }
                ]
            },
            "virtual_machine_interface_device_owner": "compute:A_LAB_AZ5",
            "virtual_machine_interface_mac_addresses": {
                "mac_address": [
                    "02:67:87:f5:8d:14"
                ]
            },
            "virtual_machine_refs": [
                {
                    "attr": null,
                    "to": [
                        "e409e886-3aa8-4154-a9ff-c1e63edf4f65"
                    ],
                    "uuid": "e409e886-3aa8-4154-a9ff-c1e63edf4f65"
                }
            ],
            "virtual_network_refs": [
                {
                    "attr": null,
                    "to": [
                        "default-domain",
                        "admin",
                        "test_net_01-2f625732-bb3c-4f11-b09d-ff8ff681e262"
                    ],
                    "uuid": "2f625732-bb3c-4f11-b09d-ff8ff681e262"
                }
            ]
        },
        "row_latest_ts": 1623298318713659
    }
}