private static void bootstrap(final Path rd, final Configuration c)
 throws IOException {
   LOG.info("BOOTSTRAP: creating ROOT and first META regions");
   try {
     // Bootstrapping, make sure blockcache is off.  Else, one will be
     // created here in bootstap and it'll need to be cleaned up.  Better to
     // not make it in first place.  Turn off block caching for bootstrap.
     // Enable after.
     HRegionInfo rootHRI = new HRegionInfo(HRegionInfo.ROOT_REGIONINFO);
     setInfoFamilyCachingForRoot(false);
     HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
     setInfoFamilyCachingForMeta(false);
     HRegion root = HRegion.createHRegion(rootHRI, rd, c,
         HTableDescriptor.ROOT_TABLEDESC);
     HRegion meta = HRegion.createHRegion(metaHRI, rd, c,
         HTableDescriptor.META_TABLEDESC);
     setInfoFamilyCachingForRoot(true);
     setInfoFamilyCachingForMeta(true);
     // Add first region from the META table to the ROOT region.
     HRegion.addRegionToMETA(root, meta);
     root.close();
     root.getLog().closeAndDelete();
     meta.close();
     meta.getLog().closeAndDelete();
   } catch (IOException e) {
     e = RemoteExceptionHandler.checkIOException(e);
     LOG.error("bootstrap", e);
     throw e;
   }
 }
예제 #2
0
 private HRegion openRegion(
     final FileSystem fs, final Path dir, final HTableDescriptor htd, final HLog hlog)
     throws IOException {
   // Initialize HRegion
   HRegionInfo regionInfo = new HRegionInfo(htd.getTableName());
   return HRegion.createHRegion(regionInfo, dir, getConf(), htd, hlog);
 }
예제 #3
0
  /** Creates, flushes, and closes a new region. */
  public static HRegion createHDFSRegionDir(
      Configuration conf, HRegionInfo hri, HTableDescriptor htd) throws IOException {
    // Create HRegion
    Path root = FSUtils.getRootDir(conf);
    HRegion region = HRegion.createHRegion(hri, root, conf, htd, null);

    // Close the new region to flush to disk. Close log file too.
    region.close();
    return region;
  }
예제 #4
0
 // lifted from TestAtomicOperation
 private HRegion createHRegion(
     byte[] tableName, String callingMethod, WAL log, Durability durability) throws IOException {
   HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
   htd.setDurability(durability);
   HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
   htd.addFamily(hcd);
   HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
   Path path = new Path(DIR + callingMethod);
   if (FS.exists(path)) {
     if (!FS.delete(path, true)) {
       throw new IOException("Failed delete of " + path);
     }
   }
   return HRegion.createHRegion(info, path, CONF, htd, log);
 }
예제 #5
0
  private HRegion openRegion(
      final FileSystem fs,
      final Path dir,
      final HTableDescriptor htd,
      final WALFactory wals,
      final long whenToRoll,
      final LogRoller roller)
      throws IOException {
    // Initialize HRegion
    HRegionInfo regionInfo = new HRegionInfo(htd.getTableName());
    // Initialize WAL
    final WAL wal = wals.getWAL(regionInfo.getEncodedNameAsBytes());
    // If we haven't already, attach a listener to this wal to handle rolls and metrics.
    if (walsListenedTo.add(wal)) {
      roller.addWAL(wal);
      wal.registerWALActionsListener(
          new WALActionsListener.Base() {
            private int appends = 0;

            @Override
            public void visitLogEntryBeforeWrite(
                HTableDescriptor htd, WALKey logKey, WALEdit logEdit) {
              this.appends++;
              if (this.appends % whenToRoll == 0) {
                LOG.info("Rolling after " + appends + " edits");
                // We used to do explicit call to rollWriter but changed it to a request
                // to avoid dead lock (there are less threads going on in this class than
                // in the regionserver -- regionserver does not have the issue).
                DefaultWALProvider.requestLogRoll(wal);
              }
            }

            @Override
            public void postSync(final long timeInNanos, final int handlerSyncs) {
              syncMeter.mark();
              syncHistogram.update(timeInNanos);
              syncCountHistogram.update(handlerSyncs);
            }

            @Override
            public void postAppend(final long size, final long elapsedTime) {
              appendMeter.mark(size);
            }
          });
    }

    return HRegion.createHRegion(regionInfo, dir, getConf(), htd, wal);
  }
 HRegion initHRegion(
     byte[] tableName, String callingMethod, Configuration conf, byte[]... families)
     throws IOException {
   HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
   for (byte[] family : families) {
     htd.addFamily(new HColumnDescriptor(family));
   }
   HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
   Path path = new Path(DIR + callingMethod);
   HRegion r = HRegion.createHRegion(info, path, conf, htd);
   // this following piece is a hack. currently a coprocessorHost
   // is secretly loaded at OpenRegionHandler. we don't really
   // start a region server here, so just manually create cphost
   // and set it to region.
   RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf);
   r.setCoprocessorHost(host);
   return r;
 }
예제 #7
0
  @Before
  public void setUp() throws Exception {
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLE_NAME_BYTES));
    htd.addFamily(new HColumnDescriptor(FAMILY_NAME_BYTES));
    HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
    this.region =
        HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd);

    Put put = new Put(ROW_BYTES);
    for (int i = 0; i < 10; i += 2) {
      // puts 0, 2, 4, 6 and 8
      put.add(
          FAMILY_NAME_BYTES,
          Bytes.toBytes(QUALIFIER_PREFIX + i),
          i,
          Bytes.toBytes(VALUE_PREFIX + i));
    }
    this.region.put(put);
    this.region.flushcache();
  }