ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] anton-vinogradov commented on a change in pull request #5656: IGNITE-10663 Read Repair
Date Mon, 17 Jun 2019 10:52:03 GMT
anton-vinogradov commented on a change in pull request #5656: IGNITE-10663 Read Repair
URL: https://github.com/apache/ignite/pull/5656#discussion_r294241168
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/consistency/AbstractCacheConsistencyTest.java
 ##########
 @@ -0,0 +1,336 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.ignite.internal.processors.cache.consistency;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Consumer;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteEvents;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.events.CacheConsistencyViolationEvent;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager;
+import org.apache.ignite.internal.processors.dr.GridDrType;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Before;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION;
+
+/**
+ *
+ */
+public abstract class AbstractCacheConsistencyTest extends GridCommonAbstractTest {
+    /** Events. */
+    private static ConcurrentLinkedDeque<CacheConsistencyViolationEvent> evtDeq = new
ConcurrentLinkedDeque<>();
+
+    /** Key. */
+    protected static int iterableKey;
+
+    /** Is client flag. */
+    protected boolean client;
+
+    /** Backups count. */
+    protected Integer backupsCount() {
+        return 3;
+    }
+
+    /** Cache mode. */
+    protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** Atomicy mode. */
+    protected CacheAtomicityMode atomicyMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        Ignite ignite = startGrids(7); // Server nodes.
+
+        grid(0).getOrCreateCache(cacheConfiguration());
+
+        client = true;
+
+        startGrid(G.allGrids().size() + 1); // Client node 1.
+        startGrid(G.allGrids().size() + 1); // Client node 2.
+
+        final IgniteEvents evts = ignite.events();
+
+        evts.remoteListen(null,
+            (IgnitePredicate<Event>)e -> {
+                assert e instanceof CacheConsistencyViolationEvent;
+
+                evtDeq.add((CacheConsistencyViolationEvent)e);
+
+                return true;
+            },
+            EVT_CONSISTENCY_VIOLATION);
+
+        awaitPartitionMapExchange();
+    }
+
+    /**
+     *
+     */
+    @Before
+    public void before() {
+        evtDeq.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        log.info("Checked " + iterableKey + " keys");
+
+        stopAllGrids();
+    }
+
+    /**
+     *
+     */
+    protected CacheConfiguration<Integer, Integer> cacheConfiguration() {
+        CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
+
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+        cfg.setCacheMode(cacheMode());
+        cfg.setAtomicityMode(atomicyMode());
+        cfg.setBackups(backupsCount());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws
Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setClientMode(client);
+
+        return cfg;
+    }
+
+    /**
+     *
+     */
+    protected static void checkEvent(ReadRepairData data) {
+        Map<Object, Object> fixed = new HashMap<>();
+
+        while (!evtDeq.isEmpty()) {
 
 Review comment:
   forEach is not causes removes AFAIK.
   Code like 
   
           evtDeq.forEach(e -> {
               CacheConsistencyViolationEvent evt = evtDeq.remove();
   
               fixed.putAll(evt.getFixedEntries()); // Optimistic and read commited transactions
produce per key fixes.
           });
   
   looks odd to me, since it used external map API inside the forEach.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message