Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cshannon committed Dec 13, 2024
1 parent 69f226e commit 15f67ab
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.util.time.SteadyTime;

import com.google.common.base.Preconditions;

public class TabletMergeability {

public static TabletMergeability NEVER = new TabletMergeability(Duration.ofNanos(-1));

public static TabletMergeability NOW = new TabletMergeability(Duration.ofNanos(0));

private final Duration time;

TabletMergeability(Duration time) {
this.time = time;
}

public boolean isNever() {
return this.time.isNegative();
}

public boolean isNow() {
return this.time.isZero();
}

public boolean isMergeable(SteadyTime currentTime) {
if (isNever()) {
return false;
}
return currentTime.getDuration().compareTo(time) >= 0;
}

public static TabletMergeability after(Duration time) {
Preconditions.checkArgument(time.getNano() > 0, "Duration must be greater than 0.");
return new TabletMergeability(time);
}

public static Value toValue(TabletMergeability tabletMergeability) {
return new Value(Long.toString(tabletMergeability.time.toNanos()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.accumulo.core.client.ConditionalWriter;
import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.client.admin.TabletMergeability;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.TableId;
Expand Down Expand Up @@ -392,6 +393,8 @@ interface TabletUpdates<T> {

T putCloned();

T putTabletMergeability(TabletMergeability tabletMergeability);

/**
* By default the server lock is automatically added to mutations unless this method is set to
* false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public static class TabletColumnFamily {
public static final String REQUESTED_QUAL = "requestToHost";
public static final ColumnFQ REQUESTED_COLUMN = new ColumnFQ(NAME, new Text(REQUESTED_QUAL));

public static final String MERGEABILITY_QUAL = "mergeability";
public static final ColumnFQ MERGEABILITY_COLUMN =
new ColumnFQ(NAME, new Text(MERGEABILITY_QUAL));

public static Value encodePrevEndRow(Text per) {
if (per == null) {
return new Value(new byte[] {0});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ public enum ColumnType {
SELECTED,
COMPACTED,
USER_COMPACTION_REQUESTED,
UNSPLITTABLE
UNSPLITTABLE,
MERGEABILITY
}

public static class Location {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOADED;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOCATION;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOGS;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.MERGEABILITY;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.MERGED;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.OPID;
import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.PREV_ROW;
Expand All @@ -48,6 +49,7 @@
import java.util.TreeMap;

import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.client.admin.TabletMergeability;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
Expand Down Expand Up @@ -312,6 +314,13 @@ public TabletMetadataBuilder putCloned() {
return this;
}

@Override
public TabletMetadataBuilder putTabletMergeability(TabletMergeability tabletMergeability) {
fetched.add(MERGEABILITY);
internalBuilder.putTabletMergeability(tabletMergeability);
return this;
}

@Override
public TabletMetadataBuilder automaticallyPutServerLock(boolean b) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;

import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.client.admin.TabletMergeability;
import org.apache.accumulo.core.clientImpl.TabletAvailabilityUtil;
import org.apache.accumulo.core.data.ArrayByteSequence;
import org.apache.accumulo.core.data.ByteSequence;
Expand Down Expand Up @@ -390,6 +391,13 @@ public T automaticallyPutServerLock(boolean b) {
return getThis();
}

@Override
public T putTabletMergeability(TabletMergeability tabletMergeability) {
TabletColumnFamily.MERGEABILITY_COLUMN.put(mutation,
TabletMergeability.toValue(tabletMergeability));
return getThis();
}

public void setCloseAfterMutate(AutoCloseable closeable) {
this.closeAfterMutate = closeable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ScanFileColumnFamily;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SplitColumnFamily;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.SuspendLocationColumn;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.UserCompactionRequestedColumnFamily;
import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
import org.apache.accumulo.core.metadata.schema.filters.TabletMetadataFilter;
Expand Down Expand Up @@ -394,6 +395,9 @@ public Options fetch(ColumnType... colsToFetch) {
case UNSPLITTABLE:
qualifiers.add(SplitColumnFamily.UNSPLITTABLE_COLUMN);
break;
case MERGEABILITY:
qualifiers.add(TabletColumnFamily.MERGEABILITY_COLUMN);
break;
default:
throw new IllegalArgumentException("Unknown col type " + colToFetch);
}
Expand Down

0 comments on commit 15f67ab

Please sign in to comment.