/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.md.sal.common.api.data; import org.opendaylight.yangtools.concepts.Path; import org.opendaylight.yangtools.yang.common.RpcResult; /** * Two phase commit handler (cohort) of the two-phase commit protocol of data. * *

* The provider should expose the implementation of DataCommitHandler if it's * functionality depends on any subset of data stored in data repositories, in * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier) * operation. * *

* Operations of two-phase commit handlers should not change data in data store, * this is responsibility of the coordinator (broker or some component of the * broker). * * Commit handlers are responsible for changing the internal state of the * provider to reflect the committed changes in data. * *

Two-phase commit

* *

Commit Request Phase

* *
    *
  1. Consumer edits data by invocation of * DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot) *
  2. Consumer starts a commit by invoking * DataBrokerService.commit(DataStoreIdentifier) *
  3. Broker retrieves a list of all registered * DataCommitHandlers *
  4. For each DataCommitHandler *
      *
    1. Broker invokes a * DataCommitHandler.requestCommit(DataStoreIdentifier) operation. *
    2. DataCommitHandler returns a RpcResult with * CommitTransaction *
    3. If the result was successful, broker adds CommitTransaction * to the list of opened transactions. If not, brokers stops a commit request * phase and starts a rollback phase. *
    *
  5. Broker starts a commit finish phase *
* *

Commit Finish Phase

* *
    *
  1. For each CommitTransaction from Commit Request phase *
      *
    1. Broker broker invokes a * CommitTransaction.finish() *
    2. The provider finishes a commit (applies the change) and returns an * RpcResult. *
    *
  2. * *
* *

Commit Rollback Phase

*
  • For each DataCommitTransaction from Commit Request phase *
      *
    1. Broker * broker invokes a {@link DataCommitTransaction#finish()} *
    2. The provider rollbacks a commit and returns an {@link RpcResult} of * rollback.
    *
  • Broker returns a error result to the consumer. * * @param

    Class representing a path * @param Superclass from which all data objects are derived from. * @deprecated Replaced by {@link AsyncConfigurationCommitHandler} */ @Deprecated public interface DataCommitHandler

    , D> { DataCommitTransaction requestCommit(DataModification modification); public interface DataCommitTransaction

    , D> { DataModification getModification(); /** * * Finishes a commit. * * This callback is invoked by commit coordinator to finish commit action. * * The implementation is required to finish transaction or return unsuccessful * rpc result if something went wrong. * * The provider (commit handler) should apply all changes to its state * which are a result of data change- * * @return */ RpcResult finish() throws IllegalStateException; /** * Rollbacks a commit. * * This callback is invoked by commit coordinator to finish commit action. * * The provider (commit handler) should rollback all changes to its state * which were a result of previous request commit. * * @return * @throws IllegalStateException * If the method is invoked after {@link #finish()} */ RpcResult rollback() throws IllegalStateException; } }