Do not read bridge node multiple times 51/110551/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Mar 2024 17:32:12 +0000 (18:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Mar 2024 17:32:12 +0000 (18:32 +0100)
We have guards against non-existing bridge nodes, but when they succeed
we throw away the data we have read. This can lead to theoretical TOCTOE
errors.

Fix this by only reading the bridge node once.

Change-Id: I5e224b350d3c4f5e05d1366fa8f4282b6834dba8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QosUpdateCommand.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/ovsdb/transact/QueueUpdateCommand.java

index 339506416605c33ea6e71b0ee7637f119fb2050a..bd4ffadbf9d04263a6cbc5dd0767e2dae9ec6e70 100644 (file)
@@ -64,11 +64,12 @@ public class QosUpdateCommand implements TransactCommand {
         for (Entry<InstanceIdentifier<QosEntries>, QosEntries> qosMapEntry: createdOrUpdated.entrySet()) {
             InstanceIdentifier<OvsdbNodeAugmentation> iid =
                     qosMapEntry.getKey().firstIdentifierOf(OvsdbNodeAugmentation.class);
-            if (!state.getBridgeNode(iid).isPresent()) {
+            final var optBridgeNode = state.getBridgeNode(iid);
+            if (optBridgeNode.isEmpty()) {
                 return;
             }
-            OvsdbNodeAugmentation operNode =
-                state.getBridgeNode(iid).orElseThrow().augmentation(OvsdbNodeAugmentation.class);
+
+            OvsdbNodeAugmentation operNode = optBridgeNode.orElseThrow().augmentation(OvsdbNodeAugmentation.class);
 
             QosEntries qosEntry = qosMapEntry.getValue();
             Qos qos = transaction.getTypedRowWrapper(Qos.class);
index 4d40bc02f7c181b38d02596a1a0f9514ddd90de2..5f7218fb10a8bd95d4ad7e7ed9c10b875ee93db5 100644 (file)
@@ -58,10 +58,11 @@ public class QueueUpdateCommand implements TransactCommand {
     private static void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
             final Map<InstanceIdentifier<Queues>, Queues> createdOrUpdated,
             final InstanceIdentifierCodec instanceIdentifierCodec) {
-        for (Entry<InstanceIdentifier<Queues>, Queues> queueMapEntry: createdOrUpdated.entrySet()) {
+        for (Entry<InstanceIdentifier<Queues>, Queues> queueMapEntry : createdOrUpdated.entrySet()) {
             InstanceIdentifier<OvsdbNodeAugmentation> iid =
                     queueMapEntry.getKey().firstIdentifierOf(OvsdbNodeAugmentation.class);
-            if (!state.getBridgeNode(iid).isPresent()) {
+            final var optBridgeNode = state.getBridgeNode(iid);
+            if (optBridgeNode.isEmpty()) {
                 return;
             }
 
@@ -100,23 +101,20 @@ public class QueueUpdateCommand implements TransactCommand {
                 LOG.warn("Incomplete Queue other_config", e);
             }
 
-            OvsdbNodeAugmentation operNode =
-                state.getBridgeNode(iid).orElseThrow().augmentation(OvsdbNodeAugmentation.class);
+            OvsdbNodeAugmentation operNode = optBridgeNode.orElseThrow().augmentation(OvsdbNodeAugmentation.class);
             Uuid operQueueUuid = getQueueEntryUuid(operNode.getQueues(), queueEntry.key());
             if (operQueueUuid == null) {
                 UUID namedUuid = new UUID(SouthboundConstants.QUEUE_NAMED_UUID_PREFIX
                         + TransactUtils.bytesToHexString(queueEntry.getQueueId().getValue().getBytes(UTF_8)));
                 transaction.add(op.insert(queue).withId(namedUuid.toString()));
-                LOG.info("Added queue Uuid : {} for Ovsdb Node : {}",
-                        namedUuid, operNode);
+                LOG.info("Added queue Uuid : {} for Ovsdb Node : {}", namedUuid, operNode);
             } else {
                 UUID uuid = new UUID(operQueueUuid.getValue());
                 Queue extraQueue = transaction.getTypedRowSchema(Queue.class);
                 extraQueue.getUuidColumn().setData(uuid);
                 transaction.add(op.update(queue)
                         .where(extraQueue.getUuidColumn().getSchema().opEqual(uuid)).build());
-                LOG.info("Updated queue entries: {} for Ovsdb Node : {}",
-                        queue, operNode);
+                LOG.info("Updated queue entries: {} for Ovsdb Node : {}", queue, operNode);
             }
         }
     }