-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mergeability column to support automatic merges #5187
Changes from 4 commits
346f936
10830fe
408a941
ca60fe5
78c8e3e
0e7fc81
bf951c4
97aa2a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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() { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to ignore this suggestion. Was thinking this name went better w/ the getDelay() method.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think isDelayed() is probably better and will rename it. I kept going back and forth with trying to decide on the correct names and I think this may change anyways. I've been wondering if instead of Right now the name is TabletMereability but as @ctubbsii had pointed out in a previous conversation, the current goal for this is really tablet automatic mergeability so we can use it to determine if we can run an automatic merge on a tablet range just like we do automatic splits. However, there has been some talk of making it more generic to mergeabilty in general (Even regular user triggered merges) which may also impact how we name things but not sure we will or need to. Either way, I expect in future PRs as this evolves the naming is going to be tweaked a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keith-turner - The more I think about it, the more I'm not sure I like using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah NOW is kinda tricky. I like ALWAYS. Maybe could have two states instead of three by making delay be >=0 instead of >0. Then its just NEVER or DELAYED. NEVER is the one that is nice to specifically designate intention. From an encoding standpoint that would be a boolean and a long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting idea, I think that makes sense to allow a delay of >= 0 because it fits in nicely as part of the regular delay logic but NEVER is the edge case as you said. For the json encoding we keep the boolean and long but inside the TabletMergeability class maybe we can just represent "NEVER" with a null delay. I think we should still keep the always() method shortcut I think because it's going to be a commonly used value. |
||||||||||||||||||||||||||
return delay.toNanos() > 0; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public Duration getDelay() { | ||||||||||||||||||||||||||
return delay; | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could do the following to give more flexibility w/ changing how now and never are represented, would need add javadoc if doing so.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 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 method would go away. For serialization, I think the json format in TabletMergeabilityMetadata would need to be changed to something like the following: 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking this one step further you could even just require the delay in TabletMergeability to always be positive and never < 0 and add a couple boolean flags to signal NOW and NEVER and just make the delay null in that case vs using 0 or -1. It probably doesn't matter either way though if we keep using 0 and -1 as it would be hidden internally to the class and not exposed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now its documented on the javadoc what -1,0, and >0 mean, which seems good for now. Its nice to structure the API so that the -1 case does not cause bugs in code calling getDelay AND to make it more flexible to change, but not really sure of the best way to achieve those goals. The javadoc lets someone know hey you need to handle this -1 case, which helps w/ the usage bug case. Making the API more flexible is tricky and as you mentioned this will probably evolve as more of the feature is implemented also, so it would be good to see what is learned from that. If the code is released w/ that javadoc then its behavior is set and it would be ok for the serialization code to be tightly coupled to the behavior in the javadoc. |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||
public boolean equals(Object o) { | ||||||||||||||||||||||||||
if (o == null || getClass() != o.getClass()) { | ||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
TabletMergeability that = (TabletMergeability) o; | ||||||||||||||||||||||||||
return Objects.equals(delay, that.delay); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||
public int hashCode() { | ||||||||||||||||||||||||||
return Objects.hashCode(delay); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||
public String toString() { | ||||||||||||||||||||||||||
if (isNow()) { | ||||||||||||||||||||||||||
return "TabletMergeability=NOW"; | ||||||||||||||||||||||||||
} else if (isNever()) { | ||||||||||||||||||||||||||
return "TabletMergeability=NEVER"; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return "TabletMergeability=AFTER:" + delay.toNanos(); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to convert this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, not a bad idea, nanoseconds would be pretty tough to understand in a log. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could convert to ms and include the unit at the end of the string. |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public static TabletMergeability from(Duration delay) { | ||||||||||||||||||||||||||
Preconditions.checkArgument(delay.toNanos() >= -1, | ||||||||||||||||||||||||||
"Duration of delay must be -1, 0, or a positive offset."); | ||||||||||||||||||||||||||
return new TabletMergeability(delay); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method needs javadoc outlining the acceptable input values for duration. Since this is a public API class wondering if the following would be better instead, however those methods would still need javadoc. Could make those constants private if adding these also, thinking the methods give a bit more flexibility to change.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good idea and I may do this as well in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I will add some javadocs and we can tweak them in future PRs if things evolve/change which should be fine as long as we do it before we release 4.0.0 |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public static TabletMergeability after(Duration delay) { | ||||||||||||||||||||||||||
Preconditions.checkArgument(delay.toNanos() > 0, "Duration of delay must be greater than 0."); | ||||||||||||||||||||||||||
return new TabletMergeability(delay); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* 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.metadata.schema; | ||
|
||
import static org.apache.accumulo.core.util.LazySingletons.GSON; | ||
|
||
import java.io.Serializable; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.accumulo.core.client.admin.TabletMergeability; | ||
import org.apache.accumulo.core.data.Value; | ||
import org.apache.accumulo.core.util.time.SteadyTime; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
public class TabletMergeabilityMetadata implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public static final TabletMergeabilityMetadata NEVER = | ||
new TabletMergeabilityMetadata(TabletMergeability.NEVER); | ||
public static final TabletMergeabilityMetadata NOW = | ||
new TabletMergeabilityMetadata(TabletMergeability.NOW); | ||
|
||
private final TabletMergeability tabletMergeability; | ||
private final SteadyTime steadyTime; | ||
|
||
private TabletMergeabilityMetadata(TabletMergeability tabletMergeability, SteadyTime steadyTime) { | ||
this.tabletMergeability = Objects.requireNonNull(tabletMergeability); | ||
this.steadyTime = steadyTime; | ||
Preconditions.checkArgument(tabletMergeability.isFuture() == (steadyTime != null), | ||
"SteadyTime must be set if and only if TabletMergeability delay is greater than 0."); | ||
} | ||
|
||
private TabletMergeabilityMetadata(TabletMergeability tabletMergeability) { | ||
this(tabletMergeability, null); | ||
} | ||
|
||
public TabletMergeability getTabletMergeability() { | ||
return tabletMergeability; | ||
} | ||
|
||
public Optional<SteadyTime> getSteadyTime() { | ||
return Optional.ofNullable(steadyTime); | ||
} | ||
|
||
public boolean isMergeable(SteadyTime currentTime) { | ||
if (tabletMergeability.isNever()) { | ||
return false; | ||
} | ||
return currentTime.getDuration().compareTo(totalDelay()) >= 0; | ||
} | ||
|
||
private Duration totalDelay() { | ||
return steadyTime != null ? steadyTime.getDuration().plus(tabletMergeability.getDelay()) | ||
: tabletMergeability.getDelay(); | ||
} | ||
|
||
private static class GSonData { | ||
long delay; | ||
Long steadyTime; | ||
} | ||
|
||
String toJson() { | ||
GSonData jData = new GSonData(); | ||
jData.delay = tabletMergeability.getDelay().toNanos(); | ||
jData.steadyTime = steadyTime != null ? steadyTime.getNanos() : null; | ||
return GSON.get().toJson(jData); | ||
} | ||
|
||
static TabletMergeabilityMetadata fromJson(String json) { | ||
GSonData jData = GSON.get().fromJson(json, GSonData.class); | ||
TabletMergeability tabletMergeability = TabletMergeability.from(Duration.ofNanos(jData.delay)); | ||
SteadyTime steadyTime = | ||
jData.steadyTime != null ? SteadyTime.from(jData.steadyTime, TimeUnit.NANOSECONDS) : null; | ||
return new TabletMergeabilityMetadata(tabletMergeability, steadyTime); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
TabletMergeabilityMetadata that = (TabletMergeabilityMetadata) o; | ||
return Objects.equals(tabletMergeability, that.tabletMergeability) | ||
&& Objects.equals(steadyTime, that.steadyTime); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(tabletMergeability, steadyTime); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TabletMergeabilityMetadata{" + tabletMergeability + ", " + steadyTime + '}'; | ||
} | ||
|
||
public static TabletMergeabilityMetadata after(Duration delay, SteadyTime currentTime) { | ||
return from(TabletMergeability.after(delay), currentTime); | ||
} | ||
|
||
public static TabletMergeabilityMetadata from(TabletMergeability tm, SteadyTime currentTime) { | ||
return new TabletMergeabilityMetadata(tm, currentTime); | ||
} | ||
|
||
public static Value toValue(TabletMergeabilityMetadata tmm) { | ||
return new Value(tmm.toJson()); | ||
} | ||
|
||
public static TabletMergeabilityMetadata fromValue(Value value) { | ||
return TabletMergeabilityMetadata.fromJson(value.toString()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need
@since
tags in javadoc since this class is in a public API package.