Browse Source

Avoid race condition when processing RowEvents

In ovsdbapp adds the ability
to pass a "frozen" object to the RowEventHandler so that if a
transaction is started from the main thread that changes the row,
it won't step on the values that the Event is trying to process.

This patch backports the ovs_idl backend-specific
RowEventHandler which converts the row to a frozen_row.

Change-Id: I87489596e2ff224431f7e83f43a1725172ee0953
Related-Bug: #1896816
(cherry picked from commit ab6d4afd95)
Terry Wilson 8 months ago
committed by Brian Haley
2 changed files with 57 additions and 3 deletions
  1. +54
  2. +3

+ 54
- 0
networking_ovn/ovsdb/ View File

@ -0,0 +1,54 @@
# Copyright 2021 Red Hat, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# We don't technically require ovs 2.10 or ovsdbapp that has these fixes so
# just include them here for stable releases
from ovs.db import custom_index
IndexEntryClass = custom_index.IndexEntryClass
except ImportError:
import collections
from ovs.db import data
def IndexEntryClass(table):
def defaults_uuid_to_row(atom, base):
return atom.value
columns = ['uuid'] + list(table.columns.keys())
cls = collections.namedtuple(, columns)
cls._table = table
cls.__new__.__defaults__ = (None,) + tuple(
for c in table.columns.values())
return cls
from ovsdbapp.backend.ovs_idl import idlutils
frozen_row = idlutils.frozen_row
except AttributeError:
def frozen_row(row):
IndexEntry = row._table.rows.IndexEntry
except AttributeError:
row._table.rows = IndexEntryClass(row._table)
return IndexEntry(
**{col: getattr(row, col)
for col in row._table.columns if hasattr(row, col)})
from ovsdbapp.backend.ovs_idl import event as row_event
from ovsdbapp import event as ovsdb_event
RowEventHandler = row_event.RowEventHandler
except AttributeError:
class RowEventHandler(ovsdb_event.RowEventHandler):
def notify(self, event, row, updates=None):
row = frozen_row(row)
super(RowEventHandler, self).notify(event, row, updates)

+ 3
- 3
networking_ovn/ovsdb/ View File

@ -25,7 +25,6 @@ from import Stream
from ovsdbapp.backend.ovs_idl import connection
from ovsdbapp.backend.ovs_idl import event as row_event
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp import event
from networking_ovn.common import config as ovn_config
from networking_ovn.common import constants as ovn_const
@ -33,6 +32,7 @@ from networking_ovn.common import exceptions
from networking_ovn.common import hash_ring_manager
from networking_ovn.common import utils
from networking_ovn.db import hash_ring as db_hash_ring
from networking_ovn.ovsdb import backports
LOG = log.getLogger(__name__)
@ -351,7 +351,7 @@ class FIPAddDeleteEvent(row_event.RowEvent):
class OvnDbNotifyHandler(event.RowEventHandler):
class OvnDbNotifyHandler(backports.RowEventHandler):
def __init__(self, driver):
super(OvnDbNotifyHandler, self).__init__()
self.driver = driver
@ -368,7 +368,7 @@ class Ml2OvnIdlBase(connection.OvsdbIdl):
class BaseOvnIdl(Ml2OvnIdlBase):
def __init__(self, remote, schema):
self.notify_handler = event.RowEventHandler()
self.notify_handler = backports.RowEventHandler()
super(BaseOvnIdl, self).__init__(remote, schema)