korlov42 commented on code in PR #4256: URL: https://github.com/apache/ignite-3/pull/4256#discussion_r1778603431
########## modules/catalog-compaction/src/main/java/org/apache/ignite/internal/catalog/compaction/CatalogCompactionRunner.java: ########## @@ -211,12 +203,24 @@ public void updateCoordinator(ClusterNode newCoordinator) { triggerCompaction(lowWatermark); } - /** Returns local view of the node on who is currently compaction coordinator. For test purposes only.*/ + /** Returns local view of the node on who is currently compaction coordinator. For test purposes only. */ @TestOnly public @Nullable String coordinator() { return compactionCoordinatorNodeName; } + /** Returns {@link MinimumRequiredTimeCollectorService}. For test purposes only. */ + @TestOnly + public MinimumRequiredTimeCollectorService localMinTimeCollectorService() { + return localMinTimeCollectorService; + } Review Comment: so, you've introduced TestOnly method to expose object that was created outside and passed in constructor of CompactionRunner just one line before in the test... please remove this method ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/MinimumRequiredTimeCollectorServiceImpl.java: ########## @@ -0,0 +1,64 @@ +/* + * 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.table.distributed.raft; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.ignite.internal.replicator.TablePartitionId; + +/** Collects minimum required timestamp for each partition. */ +public class MinimumRequiredTimeCollectorServiceImpl implements MinimumRequiredTimeCollectorService { + private final ConcurrentHashMap<TablePartitionId, Long> partitions = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override + public synchronized void addPartition(TablePartitionId tablePartitionId) { + partitions.put(tablePartitionId, UNDEFINED_MIN_TIME); + } + + /** {@inheritDoc} */ + @Override + public synchronized void recordMinActiveTxTimestamp(TablePartitionId tablePartitionId, long timestamp) { Review Comment: why `synchronized`? I get that to make 2 call to ConcurrentHashMap atomic, but why don't just synchronize a single bucket rather that entire collection (e.g. use `computeIfPresent`) ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/MinimumRequiredTimeCollectorServiceImpl.java: ########## @@ -0,0 +1,64 @@ +/* + * 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.table.distributed.raft; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.ignite.internal.replicator.TablePartitionId; + +/** Collects minimum required timestamp for each partition. */ +public class MinimumRequiredTimeCollectorServiceImpl implements MinimumRequiredTimeCollectorService { + private final ConcurrentHashMap<TablePartitionId, Long> partitions = new ConcurrentHashMap<>(); + + /** {@inheritDoc} */ + @Override + public synchronized void addPartition(TablePartitionId tablePartitionId) { + partitions.put(tablePartitionId, UNDEFINED_MIN_TIME); + } + + /** {@inheritDoc} */ + @Override + public synchronized void recordMinActiveTxTimestamp(TablePartitionId tablePartitionId, long timestamp) { + Long time = partitions.get(tablePartitionId); + if (time == null) { + // Ignore removed partitions. + return; + } + + if (time == UNDEFINED_MIN_TIME || timestamp > time) { + partitions.put(tablePartitionId, timestamp); + } + } + + /** {@inheritDoc} */ + @Override + public synchronized void removePartition(TablePartitionId tablePartitionId) { + partitions.remove(tablePartitionId); + } + + /** {@inheritDoc} */ + @Override + public Map<TablePartitionId, Long> minTimestampPerPartition() { + return Map.copyOf(partitions); + } + + @Override + public void close() { Review Comment: `close()` methods in its current form act more like `reset()`. After close, component must either throw an exception on every invocation or just ignore such invocation. But why do we have it in the first place? `MinimumRequiredTimeCollectorService` is created once per node and will garbage collected as soon as the last reference to the node instance will be lost. Is it a real use case when someone stops the node and keeps it somewhere (i.g. it's not collected by GC)? -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org