Search in sources :

Example 11 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapter method createTransactionChain.

@Override
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
    AtomicReference<DOMTransactionChain> legacyChain = new AtomicReference<>();
    org.opendaylight.mdsal.common.api.TransactionChainListener delegateListener = new org.opendaylight.mdsal.common.api.TransactionChainListener() {

        @SuppressWarnings("rawtypes")
        @Override
        public void onTransactionChainFailed(final org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain, final org.opendaylight.mdsal.common.api.AsyncTransaction<?, ?> transaction, final Throwable cause) {
            listener.onTransactionChainFailed(legacyChain.get(), (AsyncTransaction) () -> transaction.getIdentifier(), cause instanceof Exception ? SUBMIT_EX_MAPPER.apply((Exception) cause) : cause);
        }

        @Override
        public void onTransactionChainSuccessful(org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain) {
            listener.onTransactionChainSuccessful(legacyChain.get());
        }
    };
    final org.opendaylight.mdsal.dom.api.DOMTransactionChain delegateChain = delegate().createTransactionChain(delegateListener);
    legacyChain.set(new DOMTransactionChain() {

        @Override
        public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
            return new DOMDataReadOnlyTransactionAdapter(delegateChain.newReadOnlyTransaction());
        }

        @Override
        public DOMDataReadWriteTransaction newReadWriteTransaction() {
            return new DOMDataTransactionAdapter(delegateChain.newReadWriteTransaction());
        }

        @Override
        public DOMDataWriteTransaction newWriteOnlyTransaction() {
            return new DOMDataTransactionAdapter(delegateChain.newWriteOnlyTransaction());
        }

        @Override
        public void close() {
            delegateChain.close();
        }
    });
    return legacyChain.get();
}
Also used : DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) AtomicReference(java.util.concurrent.atomic.AtomicReference) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DataStoreUnavailableException(org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 12 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class AbstractInMemoryBrokerWriteTransactionBenchmark method write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark.

@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark() throws Exception {
    for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
        DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
        writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
        writeTx.submit().get();
    }
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 13 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class AbstractInMemoryBrokerWriteTransactionBenchmark method write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark.

@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark() throws Exception {
    for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
        DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
        writeTx.put(LogicalDatastoreType.OPERATIONAL, OUTER_LIST_100K_PATHS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
        writeTx.submit().get();
    }
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 14 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class DOMTransactionChainTest method allocateAndDelete.

private static DOMDataReadWriteTransaction allocateAndDelete(final DOMTransactionChain txChain) throws InterruptedException, ExecutionException {
    DOMDataReadWriteTransaction tx = txChain.newReadWriteTransaction();
    /**
     * We test existence of /test in third transaction container should
     * still be visible from first one (which is still uncommmited).
     */
    assertTestContainerExists(tx);
    /**
     * We delete node in third transaction
     */
    tx.delete(LogicalDatastoreType.OPERATIONAL, TestModel.TEST_PATH);
    return tx;
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)

Example 15 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class DOMBrokerPerformanceTest method measureOneTransactionTopContainer.

private void measureOneTransactionTopContainer() throws Exception {
    final DOMDataReadWriteTransaction writeTx = measure("Txs:1 Allocate", () -> domBroker.newReadWriteTransaction());
    measure("Txs:1 Write", (Callable<Void>) () -> {
        writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
        writeTx.put(OPERATIONAL, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
        return null;
    });
    measure("Txs:1 Reads:1", (Callable<Void>) () -> {
        // Reads /test in writeTx
        ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
        assertTrue(writeTxContainer.get().isPresent());
        return null;
    });
    measure("Txs:1 Reads:1", (Callable<Void>) () -> {
        // Reads /test in writeTx
        ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
        assertTrue(writeTxContainer.get().isPresent());
        return null;
    });
    measure("Txs:1 Submit, Finish", (Callable<Void>) () -> {
        measure("Txs:1 Submit", (Callable<ListenableFuture<?>>) () -> writeTx.submit()).get();
        return null;
    });
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)24 Test (org.junit.Test)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 Optional (com.google.common.base.Optional)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)4 TransactionChainListener (org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener)3 DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)3 DOMDataReadTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction)3 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)3 ForwardingDOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 InOrder (org.mockito.InOrder)2 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)2 DOMDataBroker (org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)2