diff --git a/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java b/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java index 4481b12..68966fc 100644 --- a/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java +++ b/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java @@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.io.hfile.Compression; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.Store; @@ -356,6 +357,35 @@ public class MetaUtils { } } + public void setVersionReplicationCompression(final byte [] tableName) + throws IOException { + List metas = getMETARows(tableName); + for (HRegionInfo hri: metas) { + final HRegion m = getMetaRegion(hri); + scanMetaRegion(m, new ScannerListener() { + private boolean inTable = true; + + @SuppressWarnings("synthetic-access") + public boolean processRow(HRegionInfo info) throws IOException { + LOG.debug("Testing " + Bytes.toString(tableName) + " against " + + Bytes.toString(info.getTableDesc().getName())); + if (Bytes.equals(info.getTableDesc().getName(), tableName)) { + this.inTable = false; + HColumnDescriptor fam = info.getTableDesc().getColumnFamilies()[0]; + fam.setMaxVersions(1); + fam.setCompressionType(Compression.Algorithm.LZO); + fam.setScope(1); + updateMETARegionInfo(m, info); + return true; + } + // If we got here and we have not yet encountered the table yet, + // inTable will be false. Otherwise, we've passed out the table. + // Stop the scanner. + return this.inTable; + }}); + } + } + /** * Offline version of the online TableOperation, * org.apache.hadoop.hbase.master.DeleteColumn. @@ -485,4 +515,10 @@ public class MetaUtils { return Bytes.equals(n, HConstants.ROOT_TABLE_NAME) || Bytes.equals(n, HConstants.META_TABLE_NAME); } + + public static void main(String[] args) throws Exception { + MetaUtils utils = new MetaUtils(HBaseConfiguration.create()); + utils.setVersionReplicationCompression(Bytes.toBytes(args[0])); + utils.shutdown(); + } }