private final Map<PathArgument, RouteEntry> routeEntries = new HashMap<>();
private final YangInstanceIdentifier locRibTarget;
- private final DOMTransactionChain chain;
+ private final NodeIdentifierWithPredicates tableKey;
+ private DOMTransactionChain chain;
private final ExportPolicyPeerTracker exportPolicyPeerTracker;
private final NodeIdentifier attributesIdentifier;
private final Long ourAs;
private final RIBSupport ribSupport;
private final TablesKey localTablesKey;
- private final ListenerRegistration<LocRibWriter> reg;
+ private final YangInstanceIdentifier target;
+ private final DOMDataTreeChangeService service;
+ private ListenerRegistration<LocRibWriter> reg;
private final PathSelectionMode pathSelectionMode;
private final LongAdder totalPathsCounter = new LongAdder();
private final LongAdder totalPrefixesCounter = new LongAdder();
final ExportPolicyPeerTracker exportPolicyPeerTracker, final TablesKey tablesKey,
final PathSelectionMode pathSelectionMode) {
this.chain = Preconditions.checkNotNull(chain);
+ this.target = Preconditions.checkNotNull(target);
final NodeIdentifierWithPredicates tableKey = RibSupportUtils.toYangTablesKey(tablesKey);
this.localTablesKey = tablesKey;
+ this.tableKey = tableKey;
this.locRibTarget = YangInstanceIdentifier.create(target.node(LocRib.QNAME).node(Tables.QNAME).node(tableKey).getPathArguments());
this.ourAs = Preconditions.checkNotNull(ourAs);
+ this.service = Preconditions.checkNotNull(service);
this.ribSupport = registry.getRIBSupportContext(tablesKey).getRibSupport();
this.attributesIdentifier = this.ribSupport.routeAttributesIdentifier();
this.exportPolicyPeerTracker = exportPolicyPeerTracker;
this.pathSelectionMode = pathSelectionMode;
+ init();
+ }
+
+ private synchronized void init() {
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Routes.QNAME), this.ribSupport.emptyRoutes());
- tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Attributes.QNAME).node(ATTRIBUTES_UPTODATE_TRUE.getNodeType()), ATTRIBUTES_UPTODATE_TRUE);
+ tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Attributes.QNAME)
+ .node(ATTRIBUTES_UPTODATE_TRUE.getNodeType()), ATTRIBUTES_UPTODATE_TRUE);
tx.submit();
- final YangInstanceIdentifier tableId = target.node(Peer.QNAME).node(Peer.QNAME).node(EffectiveRibIn.QNAME).node(Tables.QNAME).node(tableKey);
+ final YangInstanceIdentifier tableId = this.target.node(Peer.QNAME).node(Peer.QNAME).node(EffectiveRibIn.QNAME)
+ .node(Tables.QNAME).node(this.tableKey);
final DOMDataTreeIdentifier wildcard = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tableId);
- this.reg = service.registerDataTreeChangeListener(wildcard, this);
+ this.reg = this.service.registerDataTreeChangeListener(wildcard, this);
}
public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry, @Nonnull final TablesKey tablesKey,
pathSelectionStrategy);
}
+ /**
+ * Re-initialize this LocRibWriter with new transaction chain.
+ *
+ * @param newChain new transaction chain
+ */
+ synchronized void restart(@Nonnull final DOMTransactionChain newChain) {
+ Preconditions.checkNotNull(newChain);
+ close();
+ this.chain = newChain;
+ init();
+ }
+
@Override
public void close() {
this.reg.close();
- // FIXME: wait for the chain to close? unfortunately RIBImpl is the listener, so that may require some work
+ this.reg = null;
this.chain.close();
}
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
private final BgpDeployer.WriteConfiguration configurationWriter;
private ClusterSingletonServiceRegistration registration;
private final DOMDataBrokerExtension service;
- private final List<LocRibWriter> locRibs = new ArrayList<>();
+ private final Map<TransactionChain, LocRibWriter> txChainToLocRibWriter = new HashMap<>();
private final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies;
private final ImportPolicyPeerTracker importPolicyPeerTracker;
private final RIBImplRuntimeMXBeanImpl renderStats;
} catch (final TransactionCommitFailedException e1) {
LOG.error("Failed to initiate LocRIB for key {}", key, e1);
}
+ createLocRibWriter(key);
+ }
+ private synchronized void createLocRibWriter(final TablesKey key) {
+ LOG.debug("Creating LocRIB writer for key {}", key);
+ final DOMTransactionChain txChain = createPeerChain(this);
PathSelectionMode pathSelectionStrategy = this.bestPathSelectionStrategies.get(key);
if (pathSelectionStrategy == null) {
pathSelectionStrategy = BasePathSelectionModeFactory.createBestPathSelectionStrategy();
}
- final LocRibWriter locRibWriter = LocRibWriter.create(this.ribContextRegistry, key, createPeerChain(this),
+ final LocRibWriter locRibWriter = LocRibWriter.create(this.ribContextRegistry, key, txChain,
getYangRibId(), this.localAs, getService(), this.exportPolicyPeerTrackerMap.get(key), pathSelectionStrategy);
registerTotalPathCounter(key, locRibWriter);
registerTotalPrefixesCounter(key, locRibWriter);
- this.locRibs.add(locRibWriter);
+ this.txChainToLocRibWriter.put(txChain, locRibWriter);
}
@Override
}
@Override
- public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+ public synchronized void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction, final Throwable cause) {
LOG.error("Broken chain in RIB {} transaction {}", getInstanceIdentifier(), transaction != null ? transaction.getIdentifier() : null, cause);
+ if (this.txChainToLocRibWriter.containsKey(chain)) {
+ final LocRibWriter locRibWriter = this.txChainToLocRibWriter.remove(chain);
+ final DOMTransactionChain newChain = createPeerChain(this);
+ locRibWriter.restart(newChain);
+ this.txChainToLocRibWriter.put(newChain, locRibWriter);
+ }
}
@Override
}
@Override
- public ListenableFuture<Void> closeServiceInstance() {
- LOG.info("Close RIB Singleton Service {}", getIdentifier());
- this.locRibs.forEach(LocRibWriter::close);
- this.locRibs.clear();
+ public synchronized ListenableFuture<Void> closeServiceInstance() {
+ LOG.info("RIB {} closing instance", this.ribId.getValue());
+ this.txChainToLocRibWriter.values().forEach(LocRibWriter::close);
+ this.txChainToLocRibWriter.clear();
final DOMDataWriteTransaction t = this.domChain.newWriteOnlyTransaction();
t.delete(LogicalDatastoreType.OPERATIONAL, getYangRibId());