Beispiel #1
0
 /**
  * Used to create a parameter to the HServerLoad constructor so that HServerLoad can provide
  * information about the coprocessors loaded by this regionserver. (HBASE-4070: Improve region
  * server metrics to report loaded coprocessors to master).
  */
 public Set<String> getCoprocessors() {
   Set<String> returnValue = new TreeSet<String>();
   for (CoprocessorEnvironment e : coprocessors) {
     returnValue.add(e.getInstance().getClass().getSimpleName());
   }
   return returnValue;
 }
Beispiel #2
0
 public void shutdown(CoprocessorEnvironment e) {
   if (e instanceof Environment) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Stop coprocessor " + e.getInstance().getClass().getName());
     }
     ((Environment) e).shutdown();
   } else {
     LOG.warn("Shutdown called on unknown environment: " + e.getClass().getName());
   }
 }
  @Override
  public void start(CoprocessorEnvironment env) {
    this.env = (RegionCoprocessorEnvironment) env;
    random = new SecureRandom();
    conf = env.getConfiguration();
    baseStagingDir = SecureBulkLoadUtil.getBaseStagingDir(conf);
    this.userProvider = UserProvider.instantiate(conf);

    try {
      fs = FileSystem.get(conf);
      fs.mkdirs(baseStagingDir, PERM_HIDDEN);
      fs.setPermission(baseStagingDir, PERM_HIDDEN);
      // no sticky bit in hadoop-1.0, making directory nonempty so it never gets erased
      fs.mkdirs(new Path(baseStagingDir, "DONOTERASE"), PERM_HIDDEN);
      FileStatus status = fs.getFileStatus(baseStagingDir);
      if (status == null) {
        throw new IllegalStateException("Failed to create staging directory");
      }
      if (!status.getPermission().equals(PERM_HIDDEN)) {
        throw new IllegalStateException(
            "Directory already exists but permissions aren't set to '-rwx--x--x' ");
      }
    } catch (IOException e) {
      throw new IllegalStateException("Failed to get FileSystem instance", e);
    }
  }
Beispiel #4
0
 @Override
 public void start(CoprocessorEnvironment env) throws IOException {
   LOG.info("-------------DominoEndpoint starting, version:{} ------------", Version.VERSION);
   this.env = env;
   conf = env.getConfiguration();
   this.region = ((RegionCoprocessorEnvironment) env).getRegion();
   try {
     getTrxMetaTable();
   } catch (IOException e) {
   }
 }
Beispiel #5
0
 public int compare(final CoprocessorEnvironment env1, final CoprocessorEnvironment env2) {
   if (env1.getPriority() < env2.getPriority()) {
     return -1;
   } else if (env1.getPriority() > env2.getPriority()) {
     return 1;
   }
   if (env1.getLoadSequence() < env2.getLoadSequence()) {
     return -1;
   } else if (env1.getLoadSequence() > env2.getLoadSequence()) {
     return 1;
   }
   return 0;
 }
Beispiel #6
0
 /**
  * This is used by coprocessor hooks which are declared to throw IOException (or its subtypes).
  * For such hooks, we should handle throwable objects depending on the Throwable's type. Those
  * which are instances of IOException should be passed on to the client. This is in conformance
  * with the HBase idiom regarding IOException: that it represents a circumstance that should be
  * passed along to the client for its own handling. For example, a coprocessor that implements
  * access controls would throw a subclass of IOException, such as AccessDeniedException, in its
  * preGet() method to prevent an unauthorized client's performing a Get on a particular table.
  *
  * @param env Coprocessor Environment
  * @param e Throwable object thrown by coprocessor.
  * @exception IOException Exception
  */
 protected void handleCoprocessorThrowable(final CoprocessorEnvironment env, final Throwable e)
     throws IOException {
   if (e instanceof IOException) {
     throw (IOException) e;
   }
   // If we got here, e is not an IOException. A loaded coprocessor has a
   // fatal bug, and the server (master or regionserver) should remove the
   // faulty coprocessor from its set of active coprocessors. Setting
   // 'hbase.coprocessor.abortonerror' to true will cause abortServer(),
   // which may be useful in development and testing environments where
   // 'failing fast' for error analysis is desired.
   if (env.getConfiguration().getBoolean(ABORT_ON_ERROR_KEY, DEFAULT_ABORT_ON_ERROR)) {
     // server is configured to abort.
     abortServer(env, e);
   } else {
     LOG.error(
         "Removing coprocessor '"
             + env.toString()
             + "' from "
             + "environment because it threw:  "
             + e,
         e);
     coprocessors.remove(env);
     try {
       shutdown(env);
     } catch (Exception x) {
       LOG.error("Uncaught exception when shutting down coprocessor '" + env.toString() + "'", x);
     }
     throw new DoNotRetryIOException(
         "Coprocessor: '"
             + env.toString()
             + "' threw: '"
             + e
             + "' and has been removed from the active "
             + "coprocessor set.",
         e);
   }
 }
Beispiel #7
0
 private HTableInterface getTrxMetaTable() throws IOException {
   HTableInterface meta = metaTable.get();
   if (meta != null) {
     return meta;
   }
   synchronized (metaTable) {
     meta = metaTable.get();
     if (meta != null) {
       return meta;
     }
     HBaseAdmin admin = new HBaseAdmin(conf);
     if (!admin.tableExists(DominoConst.TRANSACTION_META)) {
       while (true) {
         try {
           admin.createTable(DominoConst.TRANSACTION_META_DESCRIPTOR);
         } catch (PleaseHoldException phe) {
           LOG.info("Failed to create transaction meta table: Got a PleaseHoldException.");
           try {
             Thread.sleep(200);
           } catch (InterruptedException ie) {
             break;
           }
           continue;
         } catch (IOException e) {
           LOG.warn("Failed to create transaction meta table. ", e);
         }
         break;
       }
     }
     admin.close();
     try {
       meta = env.getTable(DominoConst.TRANSACTION_META.getBytes(DominoConst.META_CHARSET));
       metaTable.set(meta);
     } catch (IOException e) {
       LOG.error("Failed to open transaction meta table: {}.", e.toString());
       throw e;
     }
   }
   return meta;
 }
Beispiel #8
0
 protected void abortServer(final CoprocessorEnvironment environment, final Throwable e) {
   abortServer(environment.getInstance().getClass().getName(), e);
 }