cshannon commented on code in PR #5187: URL: https://github.com/apache/accumulo/pull/5187#discussion_r1910404398
########## core/src/main/java/org/apache/accumulo/core/client/admin/TabletMergeability.java: ########## @@ -0,0 +1,90 @@ +/* + * 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.io.Serializable; +import java.time.Duration; +import java.util.Objects; + +import com.google.common.base.Preconditions; + +public class TabletMergeability implements Serializable { + private static final long serialVersionUID = 1L; + + public static final TabletMergeability NEVER = new TabletMergeability(Duration.ofNanos(-1)); + public static final TabletMergeability NOW = new TabletMergeability(Duration.ZERO); + + private final Duration delay; + + private TabletMergeability(Duration delay) { + this.delay = Objects.requireNonNull(delay); + } + + public boolean isNever() { + return this.delay.isNegative(); + } + + public boolean isNow() { + return this.delay.isZero(); + } + + public boolean isFuture() { + return delay.toNanos() > 0; + } + + public Duration getDelay() { + return delay; Review Comment: I didn't end up making this change yet because it would make things a bit tricky for things like json serialization. It would make the serialization harder because the json code would now have to duplicate business logic and know to translate NEVER to -1 and NOW to 0 for the delay. [This](https://github.com/apache/accumulo/pull/5187/files#diff-d0c46782a2fa101a9e218b4e37c26a18c066e0745128fb351b08b4e8f1480483R84) is the spot I am talking about. That code would have to make sure to not call getDelay() unless it was positive and we would introduce multiple locations in the code that need to be updated if we wanted to change the meaning of -1 and 0. They are different packages so we can't make it package scope for the private delay either. All that being said, I think this is doable and not a bad idea but if we do this I think it probably makes sense to completely decouple the serialization as well if the intent is to be more flexible in the future and no other code should really know what -1 and 0 mean outside of the internals of TabletMergeability. This would mean only allowing publicly accessible methods that create a TabletMergeability to set a delay of > 0 and requiring the use of TabletMergeability.now() or TabletMergeability.never() for all other cases so [this](https://github.com/apache/accumulo/pull/5187/files#diff-b7655aae54212259b0644ce511c60e22e39b1f9122701f427a176587477921b3R141) method would go away. For serialization, I think the json format in TabletMergeabilityMetadata would need to be changed to something like the following: ```java private static class GSonData { boolean never; boolean now; Long delay; Long steadyTime; } ``` and we would just have to set steadyTime and delay to null values if either never or now was true. @keith-turner - thoughts? -- 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]
