Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ public interface TableDescriptor {
*/
boolean isCompactionEnabled();

/**
* Check if the compaction only remove expired file, skipping merge files flag of the table is
* true. If flag is false then do normal compactions.
* @return true if table compaction only remove expired file, skipping merge files.
*/
boolean shouldSkipMergingCompaction();

/**
* Check if the split enable flag of the table is true. If flag is false then no region split will
* be done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public class TableDescriptorBuilder {
public static final String COMPACTION_ENABLED = "COMPACTION_ENABLED";
private static final Bytes COMPACTION_ENABLED_KEY = new Bytes(Bytes.toBytes(COMPACTION_ENABLED));

/**
* Used by HBase Shell interface to access this metadata attribute which denotes if the table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we planning to expose this via shell as another commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, we can use shell to change the table description with SKIP_MERGING_COMPACTION.
alter 'tableName',CONFIGURATION => {'SKIP_MERGING_COMPACTION' => 'true'}

* compact only remove expired file, skipping merge files.
*/
@InterfaceAudience.Private
public static final String SKIP_MERGING_COMPACTION = "SKIP_MERGING_COMPACTION";
private static final Bytes SKIP_MERGING_COMPACTION_KEY =
new Bytes(Bytes.toBytes(SKIP_MERGING_COMPACTION));

/**
* Used by HBase Shell interface to access this metadata attribute which denotes if the table is
* split enabled.
Expand Down Expand Up @@ -214,6 +223,12 @@ public class TableDescriptorBuilder {
*/
public static final boolean DEFAULT_MERGE_ENABLED = true;

/**
* Constant that denotes whether the table compaction only remove expired file, skipping merging
* file by default
*/
public static final boolean DEFAULT_SKIP_MERGING_COMPACTION = false;

/**
* Constant that denotes the maximum default size of the memstore in bytes after which the
* contents are flushed to the store files.
Expand Down Expand Up @@ -434,6 +449,12 @@ public TableDescriptorBuilder setCompactionEnabled(final boolean isEnable) {
return this;
}

public TableDescriptorBuilder
setSkipMergingCompaction(final boolean shouldSkipMergingCompaction) {
desc.setSkipMergingCompaction(shouldSkipMergingCompaction);
return this;
}

public TableDescriptorBuilder setSplitEnabled(final boolean isEnable) {
desc.setSplitEnabled(isEnable);
return this;
Expand Down Expand Up @@ -795,6 +816,17 @@ public boolean isCompactionEnabled() {
return getOrDefault(COMPACTION_ENABLED_KEY, Boolean::valueOf, DEFAULT_COMPACTION_ENABLED);
}

/**
* Check if the compaction only remove expired file flag of the table is true. If flag is false
* then do normal compactions.
* @return true if table compaction only remove expired file, skipping merge files.
*/
@Override
public boolean shouldSkipMergingCompaction() {
return getOrDefault(SKIP_MERGING_COMPACTION_KEY, Boolean::valueOf,
DEFAULT_SKIP_MERGING_COMPACTION);
}

/**
* Setting the table compaction enable flag.
* @param isEnable True if enable compaction.
Expand All @@ -804,6 +836,17 @@ public ModifyableTableDescriptor setCompactionEnabled(final boolean isEnable) {
return setValue(COMPACTION_ENABLED_KEY, Boolean.toString(isEnable));
}

/**
* Setting the table compaction only remove expired file, skipping merge files flag.
* @param shouldSkipMergingCompaction True if table compaction only remove expired file,
* skipping merge files.
* @return the modifyable TD
*/
public ModifyableTableDescriptor
setSkipMergingCompaction(final boolean shouldSkipMergingCompaction) {
return setValue(SKIP_MERGING_COMPACTION_KEY, Boolean.toString(shouldSkipMergingCompaction));
}

/**
* Check if the split enable flag of the table is true. If flag is false then no split will be
* done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public class HStore
public static final String DEFAULT_BLOCK_STORAGE_POLICY = "NONE";
public static final int DEFAULT_COMPACTCHECKER_INTERVAL_MULTIPLIER = 1000;
public static final int DEFAULT_BLOCKING_STOREFILE_COUNT = 16;
public static final String DELETE_EXPIRED_STOREFILE_KEY = "hbase.store.delete.expired.storefile";
public static final Boolean DEFAULT_DELETE_EXPIRED_STOREFILE = true;

// HBASE-24428 : Update compaction priority for recently split daughter regions
// so as to prioritize their compaction.
Expand Down Expand Up @@ -1453,6 +1455,15 @@ public Optional<CompactionContext> requestCompaction(int priority,
// Before we do compaction, try to get rid of unneeded files to simplify things.
removeUnneededFiles();

if (this.region.getTableDescriptor().shouldSkipMergingCompaction()) {
if (!conf.getBoolean(DELETE_EXPIRED_STOREFILE_KEY, DEFAULT_DELETE_EXPIRED_STOREFILE)) {
LOG.info("Since config 'hbase.store.delete.expired.storefile' is set to false, ignoring "
+ "SKIP_MERGING_COMPACTION set at table level");
} else {
return Optional.empty();
}
}

final CompactionContext compaction = storeEngine.createCompaction();
CompactionRequestImpl request = null;
this.storeEngine.readLock();
Expand Down Expand Up @@ -1555,7 +1566,7 @@ private void addToCompactingFiles(Collection<HStoreFile> filesToAdd) {
}

private void removeUnneededFiles() throws IOException {
if (!conf.getBoolean("hbase.store.delete.expired.storefile", true)) {
if (!conf.getBoolean(DELETE_EXPIRED_STOREFILE_KEY, DEFAULT_DELETE_EXPIRED_STOREFILE)) {
return;
}
if (getColumnFamilyDescriptor().getMinVersions() > 0) {
Expand Down