anton-vinogradov commented on a change in pull request #9661: URL: https://github.com/apache/ignite/pull/9661#discussion_r776396247
########## File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridCompoundReadRepairFuture.java ########## @@ -0,0 +1,130 @@ +/* + * 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.distributed.near.consistency; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.apache.ignite.lang.IgniteInClosure; + +/** + * Compound future that represents the result of the external fixes for some keys. + */ +public class GridCompoundReadRepairFuture extends GridFutureAdapter<Void> implements IgniteInClosure<IgniteInternalFuture<Void>> { + /** Initialization flag. */ + private static final int INIT_FLAG = 0x1; + + /** Flags updater. */ + private static final AtomicIntegerFieldUpdater<GridCompoundReadRepairFuture> FLAGS_UPD = + AtomicIntegerFieldUpdater.newUpdater(GridCompoundReadRepairFuture.class, "initFlag"); + + /** Listener calls updater. */ + private static final AtomicIntegerFieldUpdater<GridCompoundReadRepairFuture> LSNR_CALLS_UPD = + AtomicIntegerFieldUpdater.newUpdater(GridCompoundReadRepairFuture.class, "lsnrCalls"); + + /** Initialization flag. Updated via {@link #FLAGS_UPD}. */ + private volatile int initFlag; + + /** Listener calls. */ + private volatile int lsnrCalls; + + /** Count of compounds in the future. */ + private volatile int size; + + /** Keys. */ + private volatile Collection<Object> keys; + + /** Irreparable Keys. */ + private volatile Collection<Object> irreparableKeys; + + /** + * @param fut Future. + */ + public void add(IgniteInternalFuture<Void> fut) { + size++; // All additions are from the same thread. + + fut.listen(this); + } + + /** {@inheritDoc} */ + @Override public void apply(IgniteInternalFuture<Void> fut) { + Throwable e = fut.error(); + + if (e != null) { + if (e instanceof IgniteConsistencyViolationException) { + synchronized (this) { + Collection<?> keys = ((IgniteConsistencyViolationException)e).keys(); + + if (this.keys == null) + this.keys = new GridConcurrentHashSet<>(); + + this.keys.addAll(keys); + + if (e instanceof IgniteIrreparableConsistencyViolationException) { + Collection<?> irreparableKeys = ((IgniteIrreparableConsistencyViolationException)e).irreparableKeys(); + + if (this.irreparableKeys == null) + this.irreparableKeys = new GridConcurrentHashSet<>(); + + this.irreparableKeys.addAll(irreparableKeys); + } + } + } + else + onDone(e); + } + + LSNR_CALLS_UPD.incrementAndGet(this); + + checkComplete(); + } + + /** + * Mark this future as initialized. + */ + public final void markInitialized() { + if (FLAGS_UPD.compareAndSet(this, 0, INIT_FLAG)) Review comment: Simplified! -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
