You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jm...@apache.org on 2013/02/13 19:54:08 UTC
svn commit: r1445845 -
/hbase/branches/hbase-7290/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
Author: jmhsieh
Date: Wed Feb 13 18:54:07 2013
New Revision: 1445845
URL: http://svn.apache.org/r1445845
Log:
HBASE-7501 Introduce MetaEditor method that both adds and deletes rows in .META. table (Matteo Bertozzi)
Modified:
hbase/branches/hbase-7290/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
Modified: hbase/branches/hbase-7290/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
URL: http://svn.apache.org/viewvc/hbase/branches/hbase-7290/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java?rev=1445845&r1=1445844&r2=1445845&view=diff
==============================================================================
--- hbase/branches/hbase-7290/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java (original)
+++ hbase/branches/hbase-7290/hbase-server/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java Wed Feb 13 18:54:07 2013
@@ -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.NotAllMet
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;
@@ -161,6 +163,26 @@ public class MetaEditor {
}
/**
+ * Execute the passed <code>mutations</code> against <code>.META.</code> 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<Mutation> 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
* @throws IOException if problem connecting or updating meta
@@ -351,6 +373,36 @@ public class MetaEditor {
}
/**
+ * 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<HRegionInfo> regionsToRemove, final List<HRegionInfo> regionsToAdd)
+ throws IOException {
+ List<Mutation> mutation = new ArrayList<Mutation>();
+ 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
* @param parent Parent row we're to remove daughter reference from