diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
index 4181353f1fd..76a58cffa56 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.catalog;
import java.io.IOException;
+import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,6 +33,7 @@ import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
@@ -160,6 +162,26 @@ public class MetaEditor {
}
}
+ /**
+ * Execute the passed mutations
against .META.
table.
+ * @param ct CatalogTracker on whose back we will ride the edit.
+ * @param mutations Puts and Deletes to execute on .META.
+ * @throws IOException
+ */
+ static void mutateMetaTable(final CatalogTracker ct, final List mutations)
+ throws IOException {
+ HTable t = MetaReader.getMetaHTable(ct);
+ try {
+ t.batch(mutations);
+ } catch (InterruptedException e) {
+ InterruptedIOException ie = new InterruptedIOException(e.getMessage());
+ ie.initCause(e);
+ throw ie;
+ } finally {
+ t.close();
+ }
+ }
+
/**
* Adds a META row for the specified new region.
* @param regionInfo region information
@@ -350,6 +372,36 @@ public class MetaEditor {
LOG.info("Deleted from META, regions: " + regionsInfo);
}
+ /**
+ * Adds and Removes the specified regions from .META.
+ * @param catalogTracker
+ * @param regionsToRemove list of regions to be deleted from META
+ * @param regionsToAdd list of regions to be added to META
+ * @throws IOException
+ */
+ public static void mutateRegions(CatalogTracker catalogTracker,
+ final List regionsToRemove, final List regionsToAdd)
+ throws IOException {
+ List mutation = new ArrayList();
+ if (regionsToRemove != null) {
+ for (HRegionInfo hri: regionsToRemove) {
+ mutation.add(new Delete(hri.getRegionName()));
+ }
+ }
+ if (regionsToAdd != null) {
+ for (HRegionInfo hri: regionsToAdd) {
+ mutation.add(makePutFromRegionInfo(hri));
+ }
+ }
+ mutateMetaTable(catalogTracker, mutation);
+ if (regionsToRemove != null && regionsToRemove.size() > 0) {
+ LOG.debug("Deleted from META, regions: " + regionsToRemove);
+ }
+ if (regionsToAdd != null && regionsToAdd.size() > 0) {
+ LOG.debug("Add to META, regions: " + regionsToAdd);
+ }
+ }
+
/**
* Deletes daughters references in offlined split parent.
* @param catalogTracker