ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] Jokser commented on a change in pull request #5765: IGNITE-10078 Node failure during concurrent partition updates may cause partition desync between primary and backup.
Date Tue, 14 May 2019 13:17:58 GMT
Jokser commented on a change in pull request #5765: IGNITE-10078 Node failure during concurrent
partition updates may cause partition desync between primary and backup.
URL: https://github.com/apache/ignite/pull/5765#discussion_r283725596
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/PartitionAtomicUpdateCounterImpl.java
 ##########
 @@ -0,0 +1,160 @@
+/*
+ * 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;
+
+import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.GridEmptyIterator;
+import org.apache.ignite.internal.util.GridLongList;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Partition update counter for non-tx scenarios without support for tracking missed updates.
+ * TODO FIXME https://issues.apache.org/jira/browse/IGNITE-11797
+ */
+public class PartitionAtomicUpdateCounterImpl implements PartitionUpdateCounter {
+    /** Counter of applied updates in partition. */
+    private final AtomicLong cntr = new AtomicLong();
+
+    /**
+     * Initial counter points to last sequential update after WAL recovery.
+     */
+    private long initCntr;
+
+    /** {@inheritDoc} */
+    @Override public void init(long initUpdCntr, @Nullable byte[] cntrUpdData) {
+        cntr.set(initUpdCntr);
+
+        initCntr = initUpdCntr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long initial() {
+        return initCntr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long get() {
+        return cntr.get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long next() {
+        return cntr.incrementAndGet();
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("StatementWithEmptyBody")
+    @Override public void update(long val) throws IgniteCheckedException {
+        long cur;
+
+        while(val > (cur = cntr.get()) && !cntr.compareAndSet(cur, val));
+    }
+
+    /**
+     * Updates counter by delta from start position.
+     *
+     * @param start Start.
+     * @param delta Delta.
+     */
+    @Override public boolean update(long start, long delta) {
+        return false; // Prevent RollbackRecord in mixed tx-atomic mode.
+    }
+
+    /**
+     * Updates initial counter on recovery. Not thread-safe.
+     *
+     * @param start Start.
+     * @param delta Delta.
+     */
+    @Override public void updateInitial(long start, long delta) {
+        try {
+            update(start + delta);
+        }
+        catch (IgniteCheckedException e) {
+            // Ignore.
+        }
+
+        initCntr = get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridLongList finalizeUpdateCounters() {
+        return new GridLongList(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long reserve(long delta) {
+        return next(delta);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long next(long delta) {
+        return cntr.getAndAdd(delta);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean sequential() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public @Nullable byte[] getBytes() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public synchronized void reset() {
 
 Review comment:
   It's not clear why some methods accessing initCntr are synchronized, some are not. Could
you please unify access or provide comment why synchronized is enough only for reset and empty
methods?

----------------------------------------------------------------
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