kgusakov commented on a change in pull request #111: URL: https://github.com/apache/ignite-3/pull/111#discussion_r622312384
########## File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/watch/WatchAggregator.java ########## @@ -0,0 +1,243 @@ +/* + * 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.metastorage.watch; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.BiConsumer; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.metastorage.common.Key; +import org.apache.ignite.metastorage.common.WatchEvent; +import org.apache.ignite.metastorage.common.WatchListener; +import org.jetbrains.annotations.NotNull; + +/** + * Needed to aggregate multiple watches to one aggregated watch. + * This approach needed to provide the following additional guarantees to watching mechanism: + * - watch events will be processed sequentially + * - watch events will be resolved in the order of watch registration + */ +public class WatchAggregator { + /** + * Watches' map must be synchronized because of changes from WatchListener in separate thread. + */ + private final Map<Long, Watch> watches = Collections.synchronizedMap(new LinkedHashMap<>()); + + /** Simple auto increment id for internal watches. */ + private long idCntr; Review comment: In fact no at the moment - all add(...) calls guarded by one monitor in MetaStorageManager. But @sk0x50 already asked about it + it can be a problem in the future. So, will change to Atomic. -- 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: [email protected]
