hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mberto...@apache.org
Subject [6/6] hbase git commit: HBASE-16649 Truncate table with splits preserved can cause both data loss and truncated data appeared again
Date Mon, 26 Sep 2016 20:49:59 GMT
HBASE-16649 Truncate table with splits preserved can cause both data loss and truncated data
appeared again


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1bdf05b1
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1bdf05b1
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1bdf05b1

Branch: refs/heads/0.98
Commit: 1bdf05b1fa1c3d09b9e3c4fb43957c5ff32ac701
Parents: 88bba51
Author: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Authored: Mon Sep 26 13:48:20 2016 -0700
Committer: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Committed: Mon Sep 26 13:48:20 2016 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/master/CatalogJanitor.java |  3 +++
 .../apache/hadoop/hbase/master/ServerManager.java  | 17 +++++++++++++++++
 .../hbase/master/handler/DeleteTableHandler.java   |  3 +++
 .../hbase/master/handler/TruncateTableHandler.java | 14 +++++++++++++-
 .../hadoop/hbase/master/TestCatalogJanitor.java    |  4 +++-
 5 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1bdf05b1/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
index 8e6c675..2edc480 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java
@@ -204,6 +204,8 @@ public class CatalogJanitor extends Chore {
       HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionA);
       HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, regionB);
       MetaEditor.deleteMergeQualifiers(server.getCatalogTracker(), mergedRegion);
+      services.getServerManager().removeRegion(regionA);
+      services.getServerManager().removeRegion(regionB);
       return true;
     }
     return false;
@@ -336,6 +338,7 @@ public class CatalogJanitor extends Chore {
       if (LOG.isTraceEnabled()) LOG.trace("Archiving parent region: " + parent);
       HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, parent);
       MetaEditor.deleteRegion(this.server.getCatalogTracker(), parent);
+      services.getServerManager().removeRegion(parent);
       result = true;
     }
     return result;

http://git-wip-us.apache.org/repos/asf/hbase/blob/1bdf05b1/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
index 452ec14..ca34de5 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
@@ -1058,4 +1058,21 @@ public class ServerManager {
       deadservers.cleanAllPreviousInstances(serverName);
     }
   }
+
+  /**
+   * Called by delete table and similar to notify the ServerManager that a region was removed.
+   */
+  public void removeRegion(final HRegionInfo regionInfo) {
+    final byte[] encodedName = regionInfo.getEncodedNameAsBytes();
+    flushedSequenceIdByRegion.remove(encodedName);
+  }
+
+  /**
+   * Called by delete table and similar to notify the ServerManager that a region was removed.
+   */
+  public void removeRegions(final List<HRegionInfo> regions) {
+    for (HRegionInfo hri: regions) {
+      removeRegion(hri);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1bdf05b1/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
index 474da0a..7172e98 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
@@ -134,6 +134,9 @@ public class DeleteTableHandler extends TableEventHandler {
 
       // 9. Clean up any remaining rows for this table
       cleanAnyRemainingRows();
+
+      // clean region references from the server manager
+      this.masterServices.getServerManager().removeRegions(regions);
     }
 
     if (cpHost != null) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/1bdf05b1/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TruncateTableHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TruncateTableHandler.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TruncateTableHandler.java
index 17d87bb..6acfc35 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TruncateTableHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TruncateTableHandler.java
@@ -109,7 +109,7 @@ public class TruncateTableHandler extends DeleteTableHandler {
 
       HRegionInfo[] newRegions;
       if (this.preserveSplits) {
-        newRegions = regions.toArray(new HRegionInfo[regions.size()]);
+        newRegions = recreateRegionInfo(regions);
         LOG.info("Truncate will preserve " + newRegions.length + " regions");
       } else {
         newRegions = new HRegionInfo[1];
@@ -190,6 +190,9 @@ public class TruncateTableHandler extends DeleteTableHandler {
     LOG.debug("Deleting regions from META");
     MetaEditor.deleteRegions(this.server.getCatalogTracker(), regions);
 
+    // clean region references from the server manager
+    this.masterServices.getServerManager().removeRegions(regions);
+
     // -----------------------------------------------------------------------
     // NOTE: At this point we still have data on disk, but nothing in .META.
     // if the rename below fails, hbck will report an inconsistency.
@@ -244,4 +247,13 @@ public class TruncateTableHandler extends DeleteTableHandler {
       }
     }
   }
+
+  private static HRegionInfo[] recreateRegionInfo(final List<HRegionInfo> regions)
{
+    HRegionInfo[] newRegions = new HRegionInfo[regions.size()];
+    int index = 0;
+    for (HRegionInfo hri: regions) {
+      newRegions[index++] = new HRegionInfo(hri.getTable(), hri.getStartKey(), hri.getEndKey());
+    }
+    return newRegions;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1bdf05b1/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
index d39fb86..009d212 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java
@@ -176,10 +176,12 @@ public class TestCatalogJanitor {
   class MockMasterServices implements MasterServices {
     private final MasterFileSystem mfs;
     private final AssignmentManager asm;
+    private final ServerManager sm;
 
     MockMasterServices(final Server server) throws IOException {
       this.mfs = new MasterFileSystem(server, this, false);
       this.asm = Mockito.mock(AssignmentManager.class);
+      this.sm = Mockito.mock(ServerManager.class);
     }
 
     @Override
@@ -215,7 +217,7 @@ public class TestCatalogJanitor {
 
     @Override
     public ServerManager getServerManager() {
-      return null;
+      return sm;
     }
 
     @Override


Mime
View raw message