-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mergeability column to support automatic merges
This adds a new Mergeability column for marking if/when tablets are eligible to me merged by the system based on a threshold. The column stores a duration that is relative to the time the Manager uses, Steady time. There are 3 possible states for the value: 1) -1 : This means a tablet will never automatically merge 2) 0 : Tablet is eligible now to automatically merge 3) positive duration: eligible to merge after the given duration relative to the current system Steady time. Ie. the tablet can be merged if SteadyTime is later than the given duration. This change only adds the new column itself and populates it. The default is to never merge automatically for all cases except for when the system automatically splits tablets. In that case the newly split tablets are marked as being eligible to merge immediately. Future updates will add API enhancements to allow setting/viewing the mergeability setting as well as to enable automatic merging by the system that is based on this new column value. When automatic merging is enabled, if a user wants to make a tablet elgible to be merged in the future they would do so by adding a period of time to the current SteadyTime. For example, to make a tablet eligible to be merged 3 days from now the user would read the current SteadyTime value (represented as a duration), add 3 days to that and then store that new duration in the column. When the current steady time passes that duration the tablet would be eligible to be merged. See #5014 for more details
- Loading branch information
Showing
29 changed files
with
360 additions
and
43 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
core/src/main/java/org/apache/accumulo/core/client/admin/TabletMergeability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.ofNanos(0)); | ||
|
||
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 Duration getDelay() { | ||
return delay; | ||
} | ||
|
||
@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=ALWAYS"; | ||
} else if (isNever()) { | ||
return "TabletMergeability=NOW"; | ||
} | ||
return "TabletMergeability=AFTER:" + delay.toNanos(); | ||
} | ||
|
||
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); | ||
} | ||
|
||
public static TabletMergeability after(Duration delay) { | ||
Preconditions.checkArgument(delay.toNanos() > 0, "Duration of delay must be greater than 0."); | ||
return new TabletMergeability(delay); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
core/src/main/java/org/apache/accumulo/core/metadata/TabletMergeabilityUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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; | ||
|
||
import java.time.Duration; | ||
|
||
import org.apache.accumulo.core.client.admin.TabletMergeability; | ||
import org.apache.accumulo.core.data.Value; | ||
import org.apache.accumulo.core.util.time.SteadyTime; | ||
|
||
public class TabletMergeabilityUtil { | ||
|
||
public static Value toValue(TabletMergeability tabletMergeability) { | ||
return new Value(Long.toString(tabletMergeability.getDelay().toNanos())); | ||
} | ||
|
||
public static TabletMergeability fromValue(Value value) { | ||
return TabletMergeability.from(Duration.ofNanos(Long.parseLong(value.toString()))); | ||
} | ||
|
||
public boolean isMergeable(TabletMergeability mergeability, SteadyTime currentTime) { | ||
if (mergeability.isNever()) { | ||
return false; | ||
} | ||
return currentTime.getDuration().compareTo(mergeability.getDelay()) >= 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.