cshannon commented on code in PR #5284: URL: https://github.com/apache/accumulo/pull/5284#discussion_r1937337383
########## core/src/main/java/org/apache/accumulo/core/client/admin/TabletMergeabilityInfo.java: ########## @@ -0,0 +1,112 @@ +/* + * 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 + * + * https://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.accumulo.core.client.admin; + +import java.time.Duration; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Supplier; + +import org.apache.accumulo.core.clientImpl.TabletMergeabilityUtil; + +import com.google.common.base.Preconditions; + +/** + * @since 4.0.0 + */ +public class TabletMergeabilityInfo { + + private final TabletMergeability tabletMergeability; + private final Optional<Duration> insertionTime; + private final Supplier<Duration> currentTime; + + public TabletMergeabilityInfo(TabletMergeability tabletMergeability, + Optional<Duration> insertionTime, Supplier<Duration> currentTime) { + this.tabletMergeability = Objects.requireNonNull(tabletMergeability); + this.insertionTime = Objects.requireNonNull(insertionTime); + this.currentTime = Objects.requireNonNull(currentTime); + // This makes sure that insertionTime is set if TabletMergeability has a delay, and is empty + // if TabletMergeability is NEVER + Preconditions.checkArgument(tabletMergeability.isNever() == insertionTime.isEmpty(), + "insertionTime must not be empty if and only if TabletMergeability delay is >= 0"); + } + + /** + * @return the TabletMergeability + */ + public TabletMergeability getTabletMergeability() { + return tabletMergeability; + } + + /** + * Returns the time of the Manager when the TabletMergeability was set on the tablet. This will be + * empty if TabletMergeability is set to never + * + * @return the insertion time is set or else empty + */ + public Optional<Duration> getInsertionTime() { + return insertionTime; + } + + /** + * Returns the current time of the Manager + * + * @return the current time + */ + public Duration getCurrentTime() { + return currentTime.get(); + } Review Comment: Yep that makes sense now, the confusion for me was I was thinking getTabletInformation() was going to load all the tablets first before returning, so the memoized current time would not be loaded until after that. But that method returns a stream and is backed by a scanner so your scenario is quite possible where there are updates during the scan that could end up causing that. I think it makes sense to work the example into the comment. -- 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]
