hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r987385 - in /hbase/branches/0.90_master_rewrite/src: main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/hadoop/hbase/master/handler/ test/java/org/apache/hadoop/hbase/client/
Date Fri, 20 Aug 2010 06:25:42 GMT
Author: stack
Date: Fri Aug 20 06:25:41 2010
New Revision: 987385

URL: http://svn.apache.org/viewvc?rev=987385&view=rev
Log:
Hooking up table alter methods in HBaseAdmin.  Some exists on server-side.
Some to be written.  In below added mod of table schema with test to
prove it works (we didn't have one previous!).

M src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
  Mod to table schema test added.  Need to add column family mod next.
M src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
  New interface of Master services.  Easier passing this than the
  individual services as args to handler constructors, etc.
M src/main/java/org/apache/hadoop/hbase/master/HMaster.java
  Implement new MasterServices
M src/main/java/org/apache/hadoop/hbase/master/handler/TableModifyFamilyHandler.java
M src/main/java/org/apache/hadoop/hbase/master/handler/TableAddFamilyHandler.java
M src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
M src/main/java/org/apache/hadoop/hbase/master/handler/TableDeleteFamilyHandler.java
  Changed parent class constructor params; adjust.
M src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java
  Changed it so we don't check each region is offline figuring if
  table is disable; rather  see if its disabled in zk.
  Changed constructor to take a MasterServices rather than individual
  services.
M src/main/java/org/apache/hadoop/hbase/master/handler/ModifyTableHandler.java
  Added implementation of modify table.
M src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
  Redo modifyTable to suit new master interface.  Cleanup of old means
  of passing splits, etc., still to do.

Added:
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
Modified:
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ModifyTableHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableAddFamilyHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableDeleteFamilyHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableModifyFamilyHandler.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
Fri Aug 20 06:25:41 2010
@@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.MasterNot
 import org.apache.hadoop.hbase.RegionException;
 import org.apache.hadoop.hbase.RemoteExceptionHandler;
 import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.TableNotDisabledException;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
@@ -613,8 +614,7 @@ public class HBaseAdmin {
   public void modifyColumn(final String tableName, final String columnName,
       HColumnDescriptor descriptor)
   throws IOException {
-    modifyColumn(Bytes.toBytes(tableName), Bytes.toBytes(columnName),
-      descriptor);
+    modifyColumn(Bytes.toBytes(tableName), Bytes.toBytes(columnName), descriptor);
   }
 
   /**
@@ -800,6 +800,21 @@ public class HBaseAdmin {
     modifyTable(tableNameOrRegionName, HConstants.Modify.TABLE_SPLIT);
   }
 
+  /**
+   * Modify an existing table, more IRB friendly version.
+   * Asynchronous operation.
+   *
+   * @param tableName name of table.
+   * @param htd modified description of the table
+   * @throws IOException if a remote or network exception occurs
+   */
+  public void modifyTable(final byte [] tableName, HTableDescriptor htd)
+  throws IOException {
+    if (isTableEnabled(tableName)) throw new TableNotDisabledException(tableName);
+    getMaster().modifyTable(tableName, htd);
+  }
+
+
   /*
    * Call modifyTable using passed tableName or region name String.  If no
    * such table, presume we have been passed a region name.
@@ -821,19 +836,6 @@ public class HBaseAdmin {
   }
 
   /**
-   * Modify an existing table, more IRB friendly version.
-   * Asynchronous operation.
-   *
-   * @param tableName name of table.
-   * @param htd modified description of the table
-   * @throws IOException if a remote or network exception occurs
-   */
-  public void modifyTable(final byte [] tableName, HTableDescriptor htd)
-  throws IOException {
-    modifyTable(tableName, HConstants.Modify.TABLE_SET_HTD, htd);
-  }
-
-  /**
    * Modify an existing table.
    * Asynchronous operation.
    *
@@ -861,7 +863,7 @@ public class HBaseAdmin {
         }
         arr = new Writable[1];
         arr[0] = (HTableDescriptor)args[0];
-//        getMaster().modifyTable(tableName, op, arr);
+        // getMaster().modifyTable(tableName, htd);
         break;
 
       case TABLE_COMPACT:

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
Fri Aug 20 06:25:41 2010
@@ -108,7 +108,7 @@ import org.apache.zookeeper.Watcher;
  * @see Watcher
  */
 public class HMaster extends Thread
-implements HMasterInterface, HMasterRegionInterface, Server {
+implements HMasterInterface, HMasterRegionInterface, MasterServices, Server {
   private static final Log LOG = LogFactory.getLog(HMaster.class.getName());
 
   // MASTER is name of the webapp and the attribute name used stuffing this
@@ -376,10 +376,21 @@ implements HMasterInterface, HMasterRegi
     return this.conf;
   }
 
+  @Override
   public ServerManager getServerManager() {
     return this.serverManager;
   }
 
+  @Override
+  public ExecutorService getExecutorService() {
+    return this.executorService;
+  }
+
+  @Override
+  public MasterFileSystem getMasterFileSystem() {
+    return this.fileSystemManager;
+  }
+
   /**
    * Get the ZK wrapper object - needed by master_jsp.java
    * @return the zookeeper wrapper
@@ -583,7 +594,7 @@ implements HMasterInterface, HMasterRegi
       throw new IOException("Can't delete catalog tables");
     }
     //
-    new DeleteTableHandler(tableName, this, catalogTracker, fileSystemManager)
+    new DeleteTableHandler(tableName, this, this)
     .execute();
     LOG.info("deleted table: " + Bytes.toString(tableName));
   }
@@ -593,8 +604,7 @@ implements HMasterInterface, HMasterRegi
     if (isCatalogTable(tableName)) {
       throw new IOException("Can't modify catalog tables");
     }
-    new TableAddFamilyHandler(tableName, column, this, catalogTracker,
-        fileSystemManager).execute();
+    new TableAddFamilyHandler(tableName, column, this, this).execute();
   }
 
   public void modifyColumn(byte [] tableName, byte [] columnName,
@@ -603,8 +613,7 @@ implements HMasterInterface, HMasterRegi
     if (isCatalogTable(tableName)) {
       throw new IOException("Can't modify catalog tables");
     }
-    new TableModifyFamilyHandler(tableName, descriptor, this, catalogTracker,
-        fileSystemManager).execute();
+    new TableModifyFamilyHandler(tableName, descriptor, this, this).execute();
   }
 
   public void deleteColumn(final byte [] tableName, final byte [] c)
@@ -612,8 +621,7 @@ implements HMasterInterface, HMasterRegi
     if (isCatalogTable(tableName)) {
       throw new IOException("Can't modify catalog tables");
     }
-    new TableDeleteFamilyHandler(tableName, c, this, catalogTracker,
-        fileSystemManager).execute();
+    new TableDeleteFamilyHandler(tableName, c, this, this).execute();
   }
 
   public void enableTable(final byte [] tableName) throws IOException {
@@ -672,9 +680,7 @@ implements HMasterInterface, HMasterRegi
   @Override
   public void modifyTable(final byte[] tableName, HTableDescriptor htd)
   throws IOException {
-    LOG.info("modifyTable(SET_HTD): " + htd);
-    this.executorService.submit(new ModifyTableHandler(tableName, this, catalogTracker,
-      fileSystemManager));
+    this.executorService.submit(new ModifyTableHandler(tableName, htd, this, this));
   }
 
   /**
@@ -715,11 +721,17 @@ implements HMasterInterface, HMasterRegi
     return address.toString();
   }
 
+  @Override
   public CatalogTracker getCatalogTracker() {
     return catalogTracker;
   }
 
   @Override
+  public AssignmentManager getAssignmentManager() {
+    return this.assignmentManager;
+  }
+
+  @Override
   public void shutdown() {
     this.serverManager.shutdownCluster();
     try {

Added: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java?rev=987385&view=auto
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
(added)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
Fri Aug 20 06:25:41 2010
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.master;
+
+import org.apache.hadoop.hbase.catalog.CatalogTracker;
+import org.apache.hadoop.hbase.executor.ExecutorService;
+
+/**
+ * Services Master supplies
+ */
+public interface MasterServices {
+  /**
+   * @return Master's instance of {@link CatalogTracker}
+   */
+  public CatalogTracker getCatalogTracker();
+
+  /**
+   * @return Master's instance of the {@link AssignmentManager}
+   */
+  public AssignmentManager getAssignmentManager();
+
+  /**
+   * @return Master's filesystem {@link MasterFileSystem} utility class.
+   */
+  public MasterFileSystem getMasterFileSystem();
+
+  /**
+   * @return Master's {@link ServerManager} instance.
+   */
+  public ServerManager getServerManager();
+
+  /**
+   * @return Master's instance of {@link ExecutorService}
+   */
+  public ExecutorService getExecutorService();
+}

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
Fri Aug 20 06:25:41 2010
@@ -26,17 +26,15 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaEditor;
-import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.MasterServices;
 
 public class DeleteTableHandler extends TableEventHandler {
   private static final Log LOG = LogFactory.getLog(DeleteTableHandler.class);
 
   public DeleteTableHandler(byte [] tableName, Server server,
-      CatalogTracker catalogTracker, MasterFileSystem fileManager) {
-    super(EventType.C2M_DELETE_TABLE, tableName, server, catalogTracker,
-        fileManager);
+      final MasterServices masterServices) {
+    super(EventType.C2M_DELETE_TABLE, tableName, server, masterServices);
   }
 
   @Override
@@ -45,11 +43,11 @@ public class DeleteTableHandler extends 
     for(HRegionInfo region : regions) {
       LOG.debug("Deleting region " + region + " from META and FS");
       // Remove region from META
-      MetaEditor.deleteRegion(catalogTracker, region);
+      MetaEditor.deleteRegion(this.masterServices.getCatalogTracker(), region);
       // Delete region from FS
-      fileManager.deleteRegion(region);
+      this.masterServices.getMasterFileSystem().deleteRegion(region);
     }
     // Delete table from FS
-    fileManager.deleteTable(tableName);
+    this.masterServices.getMasterFileSystem().deleteTable(tableName);
   }
 }
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ModifyTableHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ModifyTableHandler.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ModifyTableHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ModifyTableHandler.java
Fri Aug 20 06:25:41 2010
@@ -23,16 +23,19 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaEditor;
-import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.MasterServices;
 
 public class ModifyTableHandler extends TableEventHandler {
-  public ModifyTableHandler(final byte [] tableName, final Server server,
-      final CatalogTracker catalogTracker, final MasterFileSystem fileManager) {
-    super(EventType.C2M_MODIFY_TABLE, tableName, server, catalogTracker,
-        fileManager);
+  private final HTableDescriptor htd;
+
+  public ModifyTableHandler(final byte [] tableName,
+      final HTableDescriptor htd, final Server server,
+      final MasterServices masterServices) {
+    super(EventType.C2M_MODIFY_TABLE, tableName, server, masterServices);
+    this.htd = htd;
   }
 
   @Override
@@ -40,9 +43,10 @@ public class ModifyTableHandler extends 
   throws IOException {
     for (HRegionInfo region : regions) {
       // Update region info in META
-      MetaEditor.updateRegionInfo(catalogTracker, region);
+      region.setTableDesc(this.htd);
+      MetaEditor.updateRegionInfo(this.masterServices.getCatalogTracker(), region);
       // Update region info in FS
-      this.fileManager.updateRegionInfo(region);
+      this.masterServices.getMasterFileSystem().updateRegionInfo(region);
     }
   }
-}
+}
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableAddFamilyHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableAddFamilyHandler.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableAddFamilyHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableAddFamilyHandler.java
Fri Aug 20 06:25:41 2010
@@ -27,9 +27,8 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.InvalidFamilyOperationException;
 import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaEditor;
-import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.util.Bytes;
 
 /**
@@ -40,10 +39,8 @@ public class TableAddFamilyHandler exten
   private final HColumnDescriptor familyDesc;
 
   public TableAddFamilyHandler(byte[] tableName, HColumnDescriptor familyDesc,
-      Server server, CatalogTracker catalogTracker,
-      MasterFileSystem fileManager) {
-    super(EventType.C2M_ADD_FAMILY, tableName, server, catalogTracker,
-        fileManager);
+      Server server, final MasterServices masterServices) {
+    super(EventType.C2M_ADD_FAMILY, tableName, server, masterServices);
     this.familyDesc = familyDesc;
   }
 
@@ -61,9 +58,9 @@ public class TableAddFamilyHandler exten
       // Update the HTD
       region.getTableDesc().addFamily(familyDesc);
       // Update region in META
-      MetaEditor.updateRegionInfo(catalogTracker, region);
+      MetaEditor.updateRegionInfo(this.masterServices.getCatalogTracker(), region);
       // Update region info in FS
-      fileManager.updateRegionInfo(region);
+      this.masterServices.getMasterFileSystem().updateRegionInfo(region);
     }
   }
 }
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableDeleteFamilyHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableDeleteFamilyHandler.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableDeleteFamilyHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableDeleteFamilyHandler.java
Fri Aug 20 06:25:41 2010
@@ -26,9 +26,9 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.InvalidFamilyOperationException;
 import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaEditor;
 import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.util.Bytes;
 
 /**
@@ -39,10 +39,8 @@ public class TableDeleteFamilyHandler ex
   private final byte [] familyName;
 
   public TableDeleteFamilyHandler(byte[] tableName, byte [] familyName,
-      Server server, CatalogTracker catalogTracker,
-      MasterFileSystem fileManager) {
-    super(EventType.C2M_ADD_FAMILY, tableName, server, catalogTracker,
-        fileManager);
+      Server server, final MasterServices masterServices) {
+    super(EventType.C2M_ADD_FAMILY, tableName, server, masterServices);
     this.familyName = familyName;
   }
 
@@ -58,11 +56,12 @@ public class TableDeleteFamilyHandler ex
       // Update the HTD
       region.getTableDesc().removeFamily(familyName);
       // Update region in META
-      MetaEditor.updateRegionInfo(catalogTracker, region);
+      MetaEditor.updateRegionInfo(this.masterServices.getCatalogTracker(), region);
+      MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
       // Update region info in FS
-      fileManager.updateRegionInfo(region);
+      mfs.updateRegionInfo(region);
       // Delete directory in FS
-      fileManager.deleteFamily(region, familyName);
+      mfs.deleteFamily(region, familyName);
     }
   }
 }

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java
Fri Aug 20 06:25:41 2010
@@ -28,10 +28,9 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.TableNotDisabledException;
 import org.apache.hadoop.hbase.TableNotFoundException;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaReader;
 import org.apache.hadoop.hbase.executor.EventHandler;
-import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.util.Bytes;
 
 /**
@@ -43,18 +42,16 @@ import org.apache.hadoop.hbase.util.Byte
  */
 public abstract class TableEventHandler extends EventHandler {
   private static final Log LOG = LogFactory.getLog(TableEventHandler.class);
-
+  protected final MasterServices masterServices;
   protected final byte [] tableName;
-  protected final CatalogTracker catalogTracker;
-  protected final MasterFileSystem fileManager;
+  protected final String tableNameStr;
 
-  public TableEventHandler(EventType eventType, byte [] tableName,
-      Server server, CatalogTracker catalogTracker,
-      MasterFileSystem fileManager) {
+  public TableEventHandler(EventType eventType, byte [] tableName, Server server,
+      MasterServices masterServices) {
     super(server, eventType);
+    this.masterServices = masterServices;
     this.tableName = tableName;
-    this.catalogTracker = catalogTracker;
-    this.fileManager = fileManager;
+    this.tableNameStr = Bytes.toString(this.tableName);
   }
 
   @Override
@@ -71,20 +68,19 @@ public abstract class TableEventHandler 
 
   private List<HRegionInfo> tableChecks() throws IOException {
     // Check if table exists
-    if(!MetaReader.tableExists(catalogTracker, Bytes.toString(tableName))) {
+    if (!MetaReader.tableExists(this.masterServices.getCatalogTracker(),
+        this.tableNameStr)) {
       throw new TableNotFoundException(Bytes.toString(tableName));
     }
+    // Verify table is offline
+    if (!this.masterServices.getAssignmentManager().
+        isTableDisabled(this.tableNameStr)) {
+      throw new TableNotDisabledException(tableName);
+    }
     // Get the regions of this table
     // TODO: Use in-memory state of master?
-    List<HRegionInfo> regions = MetaReader.getTableRegions(catalogTracker,
-        tableName);
-    // Verify all regions of table are disabled
-    for(HRegionInfo region : regions) {
-      if(!region.isOffline()) {
-        throw new TableNotDisabledException(tableName);
-      }
-    }
-    return regions;
+    return MetaReader.getTableRegions(this.masterServices.getCatalogTracker(),
+      tableName);
   }
 
   protected abstract void handleTableOperation(List<HRegionInfo> regions)

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableModifyFamilyHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableModifyFamilyHandler.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableModifyFamilyHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/TableModifyFamilyHandler.java
Fri Aug 20 06:25:41 2010
@@ -27,9 +27,8 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.InvalidFamilyOperationException;
 import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaEditor;
-import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.util.Bytes;
 
 /**
@@ -41,9 +40,8 @@ public class TableModifyFamilyHandler ex
 
   public TableModifyFamilyHandler(byte[] tableName,
       HColumnDescriptor familyDesc, Server server,
-      CatalogTracker catalogTracker, MasterFileSystem fileManager) {
-    super(EventType.C2M_ADD_FAMILY, tableName, server,
-        catalogTracker, fileManager);
+      final MasterServices masterServices) {
+    super(EventType.C2M_ADD_FAMILY, tableName, server, masterServices);
     this.familyDesc = familyDesc;
   }
 
@@ -60,9 +58,9 @@ public class TableModifyFamilyHandler ex
       // Update the HTD
       region.getTableDesc().addFamily(familyDesc);
       // Update region in META
-      MetaEditor.updateRegionInfo(catalogTracker, region);
+      MetaEditor.updateRegionInfo(this.masterServices.getCatalogTracker(), region);
       // Update region info in FS
-      fileManager.updateRegionInfo(region);
+      this.masterServices.getMasterFileSystem().updateRegionInfo(region);
     }
   }
-}
+}
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=987385&r1=987384&r2=987385&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Fri Aug 20 06:25:41 2010
@@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.client;
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -84,6 +85,45 @@ public class TestAdmin {
     assertEquals(numTables + 1, tables.length);
   }
 
+  /**
+   * Verify schema modification takes.
+   * @throws IOException
+   */
+  @Test public void changeTableSchema() throws IOException {
+    final byte [] tableName = Bytes.toBytes("changeTableSchema");
+    HTableDescriptor [] tables = admin.listTables();
+    int numTables = tables.length;
+    TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY);
+    tables = this.admin.listTables();
+    assertEquals(numTables + 1, tables.length);
+    HTableDescriptor htd = this.admin.getTableDescriptor(tableName);
+    // Make a copy and assert copy is good.
+    HTableDescriptor copy = new HTableDescriptor(htd);
+    assertTrue(htd.equals(copy));
+    // Now amend the copy. Introduce differences.
+    long newFlushSize = htd.getMemStoreFlushSize() / 2;
+    copy.setMemStoreFlushSize(newFlushSize);
+    final String key = "anyoldkey";
+    assertTrue(htd.getValue(key) == null);
+    copy.setValue(key, key);
+    boolean expectedException = false;
+    try {
+      this.admin.modifyTable(tableName, copy);
+    } catch (TableNotDisabledException e) {
+      expectedException = true;
+    }
+    assertTrue(expectedException);
+    this.admin.disableTable(tableName);
+    assertTrue(this.admin.isTableDisabled(tableName));
+    this.admin.modifyTable(tableName, copy);
+    HTableDescriptor modifiedhcd = this.admin.getTableDescriptor(tableName);
+    // Assert returned modifiedhcd is same as the copy.
+    assertFalse(htd.equals(modifiedhcd));
+    assertTrue(copy.equals(modifiedhcd));
+    assertEquals(newFlushSize, modifiedhcd.getMemStoreFlushSize());
+    assertEquals(key, modifiedhcd.getValue(key));
+  }
+
   @Test
   public void testCreateTableWithRegions() throws IOException {
 



Mime
View raw message