Java 类org.apache.hadoop.hbase.wal.WALFactory 实例源码

项目:ditb    文件:ReplicationWALReaderManager.java   
/**
 * Opens the file at the current position
 * @param path
 * @return an WAL reader.
 * @throws IOException
 */
public Reader openReader(Path path) throws IOException {
  // Detect if this is a new file, if so get a new reader else
  // reset the current reader so that we see the new data
  if (this.reader == null || !this.lastPath.equals(path)) {
    this.closeReader();
    this.reader = WALFactory.createReader(this.fs, path, this.conf);
    this.lastPath = path;
  } else {
    try {
      this.reader.reset();
    } catch (NullPointerException npe) {
      throw new IOException("NPE resetting reader, likely HDFS-4380", npe);
    }
  }
  return this.reader;
}
项目:ditb    文件:UpgradeTo96.java   
/**
 * Performs log splitting for all regionserver directories.
 * @throws Exception
 */
private void doOfflineLogSplitting() throws Exception {
  LOG.info("Starting Log splitting");
  final Path rootDir = FSUtils.getRootDir(getConf());
  final Path oldLogDir = new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME);
  // since this is the singleton, we needn't close it.
  final WALFactory factory = WALFactory.getInstance(getConf());
  FileSystem fs = FSUtils.getCurrentFileSystem(getConf());
  Path logDir = new Path(rootDir, HConstants.HREGION_LOGDIR_NAME);
  FileStatus[] regionServerLogDirs = FSUtils.listStatus(fs, logDir);
  if (regionServerLogDirs == null || regionServerLogDirs.length == 0) {
    LOG.info("No log directories to split, returning");
    return;
  }
  try {
    for (FileStatus regionServerLogDir : regionServerLogDirs) {
      // split its log dir, if exists
      WALSplitter.split(rootDir, regionServerLogDir.getPath(), oldLogDir, fs, getConf(), factory);
    }
    LOG.info("Successfully completed Log splitting");
  } catch (Exception e) {
    LOG.error("Got exception while doing Log splitting ", e);
    throw e;
  }
}
项目:ditb    文件:WALInputFormat.java   
@Override
public void initialize(InputSplit split, TaskAttemptContext context)
    throws IOException, InterruptedException {
  WALSplit hsplit = (WALSplit)split;
  Path logFile = new Path(hsplit.getLogFileName());
  Configuration conf = context.getConfiguration();
  LOG.info("Opening reader for "+split);
  try {
    this.reader = WALFactory.createReader(logFile.getFileSystem(conf), logFile, conf);
  } catch (EOFException x) {
    LOG.info("Ignoring corrupted WAL file: " + logFile
        + " (This is normal when a RegionServer crashed.)");
    this.reader = null;
  }
  this.startTime = hsplit.getStartTime();
  this.endTime = hsplit.getEndTime();
}
项目:ditb    文件:HMerge.java   
protected Merger(Configuration conf, FileSystem fs, final TableName tableName)
throws IOException {
  this.conf = conf;
  this.fs = fs;
  this.maxFilesize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
      HConstants.DEFAULT_MAX_FILE_SIZE);

  this.rootDir = FSUtils.getRootDir(conf);
  Path tabledir = FSUtils.getTableDir(this.rootDir, tableName);
  this.htd = FSTableDescriptors.getTableDescriptorFromFs(this.fs, tabledir);
  String logname = "merge_" + System.currentTimeMillis() + HConstants.HREGION_LOGDIR_NAME;

  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tabledir);
  this.walFactory = new WALFactory(walConf, null, logname);
}
项目:ditb    文件:HRegion.java   
/**
 * Convenience method creating new HRegions. Used by createTable. The {@link WAL} for the created
 * region needs to be closed explicitly, if it is not null. Use {@link HRegion#getWAL()} to get
 * access.
 *
 * @param info       Info for region to create.
 * @param rootDir    Root directory for HBase instance
 * @param tableDir   table directory
 * @param wal        shared WAL
 * @param initialize - true to initialize the region
 * @param ignoreWAL  - true to skip generate new wal if it is null, mostly for createTable
 * @return new HRegion
 * @throws IOException
 */
public static HRegion createHRegion(final HRegionInfo info, final Path rootDir,
    final Path tableDir, final Configuration conf, final HTableDescriptor hTableDescriptor,
    final WAL wal, final boolean initialize, final boolean ignoreWAL) throws IOException {
  LOG.info("creating HRegion " + info.getTable().getNameAsString() + " HTD == " + hTableDescriptor
      + " RootDir = " + rootDir + " Table name == " + info.getTable().getNameAsString());
  FileSystem fs = FileSystem.get(conf);
  HRegionFileSystem.createRegionOnFileSystem(conf, fs, tableDir, info);
  WAL effectiveWAL = wal;
  if (wal == null && !ignoreWAL) {
    // TODO HBASE-11983 There'll be no roller for this wal?
    // The WAL subsystem will use the default rootDir rather than the passed
    // in rootDir
    // unless I pass along via the conf.
    Configuration confForWAL = new Configuration(conf);
    confForWAL.set(HConstants.HBASE_DIR, rootDir.toString());
    effectiveWAL = (new WALFactory(confForWAL,
        Collections.<WALActionsListener>singletonList(new MetricsWAL()),
        "hregion-" + RandomStringUtils.randomNumeric(8))).getWAL(info.getEncodedNameAsBytes());
  }
  HRegion region =
      HRegion.newHRegion(tableDir, effectiveWAL, fs, conf, info, hTableDescriptor, null);
  if (initialize) region.initialize(null);
  return region;
}
项目:ditb    文件:TestWALObserver.java   
@Before
public void setUp() throws Exception {
  this.conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
  // this.cluster = TEST_UTIL.getDFSCluster();
  this.fs = TEST_UTIL.getDFSCluster().getFileSystem();
  this.hbaseRootDir = FSUtils.getRootDir(conf);
  this.dir = new Path(this.hbaseRootDir, TestWALObserver.class.getName());
  this.oldLogDir = new Path(this.hbaseRootDir,
      HConstants.HREGION_OLDLOGDIR_NAME);
  this.logDir = new Path(this.hbaseRootDir,
      DefaultWALProvider.getWALDirectoryName(currentTest.getMethodName()));
  this.logName = HConstants.HREGION_LOGDIR_NAME;

  if (TEST_UTIL.getDFSCluster().getFileSystem().exists(this.hbaseRootDir)) {
    TEST_UTIL.getDFSCluster().getFileSystem().delete(this.hbaseRootDir, true);
  }
  this.wals = new WALFactory(conf, null, currentTest.getMethodName());
}
项目:ditb    文件:TestStoreFileRefresherChore.java   
private Region initHRegion(HTableDescriptor htd, byte[] startKey, byte[] stopKey, int replicaId)
    throws IOException {
  Configuration conf = TEST_UTIL.getConfiguration();
  Path tableDir = FSUtils.getTableDir(testDir, htd.getTableName());

  HRegionInfo info = new HRegionInfo(htd.getTableName(), startKey, stopKey, false, 0, replicaId);

  HRegionFileSystem fs = new FailingHRegionFileSystem(conf, tableDir.getFileSystem(conf), tableDir,
    info);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tableDir);
  final WALFactory wals = new WALFactory(walConf, null, "log_" + replicaId);
  HRegion region = new HRegion(fs, wals.getWAL(info.getEncodedNameAsBytes()), conf, htd, null);

  region.initialize();

  return region;
}
项目:ditb    文件:TestDurability.java   
@Test
public void testIncrementWithReturnResultsSetToFalse() throws Exception {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] col1 = Bytes.toBytes("col1");

  // Setting up region
  final WALFactory wals = new WALFactory(CONF, null, "testIncrementWithReturnResultsSetToFalse");
  byte[] tableName = Bytes.toBytes("testIncrementWithReturnResultsSetToFalse");
  final WAL wal = wals.getWAL(tableName);
  HRegion region = createHRegion(tableName, "increment", wal, Durability.USE_DEFAULT);

  Increment inc1 = new Increment(row1);
  inc1.setReturnResults(false);
  inc1.addColumn(FAMILY, col1, 1);
  Result res = region.increment(inc1);
  assertNull(res);
}
项目:incubator-tephra    文件:TransactionProcessorTest.java   
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1}, null);
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
项目:incubator-tephra    文件:TransactionProcessorTest.java   
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1}, null);
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
项目:incubator-tephra    文件:TransactionProcessorTest.java   
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1});
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
                     new LocalRegionServerServices(conf, ServerName.valueOf(
                       InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
项目:incubator-tephra    文件:TransactionProcessorTest.java   
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1});
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
                     new LocalRegionServerServices(conf, ServerName.valueOf(
                       InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
项目:incubator-tephra    文件:TransactionProcessorTest.java   
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1});
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
项目:pbase    文件:ReplicationWALReaderManager.java   
/**
 * Opens the file at the current position
 * @param path
 * @return an WAL reader.
 * @throws IOException
 */
public Reader openReader(Path path) throws IOException {
  // Detect if this is a new file, if so get a new reader else
  // reset the current reader so that we see the new data
  if (this.reader == null || !this.lastPath.equals(path)) {
    this.closeReader();
    this.reader = WALFactory.createReader(this.fs, path, this.conf);
    this.lastPath = path;
  } else {
    try {
      this.reader.reset();
    } catch (NullPointerException npe) {
      throw new IOException("NPE resetting reader, likely HDFS-4380", npe);
    }
  }
  return this.reader;
}
项目:pbase    文件:UpgradeTo96.java   
/**
 * Performs log splitting for all regionserver directories.
 * @throws Exception
 */
private void doOfflineLogSplitting() throws Exception {
  LOG.info("Starting Log splitting");
  final Path rootDir = FSUtils.getRootDir(getConf());
  final Path oldLogDir = new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME);
  // since this is the singleton, we needn't close it.
  final WALFactory factory = WALFactory.getInstance(getConf());
  FileSystem fs = FSUtils.getCurrentFileSystem(getConf());
  Path logDir = new Path(rootDir, HConstants.HREGION_LOGDIR_NAME);
  FileStatus[] regionServerLogDirs = FSUtils.listStatus(fs, logDir);
  if (regionServerLogDirs == null || regionServerLogDirs.length == 0) {
    LOG.info("No log directories to split, returning");
    return;
  }
  try {
    for (FileStatus regionServerLogDir : regionServerLogDirs) {
      // split its log dir, if exists
      WALSplitter.split(rootDir, regionServerLogDir.getPath(), oldLogDir, fs, getConf(), factory);
    }
    LOG.info("Successfully completed Log splitting");
  } catch (Exception e) {
    LOG.error("Got exception while doing Log splitting ", e);
    throw e;
  }
}
项目:pbase    文件:WALInputFormat.java   
@Override
public void initialize(InputSplit split, TaskAttemptContext context)
    throws IOException, InterruptedException {
  WALSplit hsplit = (WALSplit)split;
  Path logFile = new Path(hsplit.getLogFileName());
  Configuration conf = context.getConfiguration();
  LOG.info("Opening reader for "+split);
  try {
    this.reader = WALFactory.createReader(logFile.getFileSystem(conf), logFile, conf);
  } catch (EOFException x) {
    LOG.info("Ignoring corrupted WAL file: " + logFile
        + " (This is normal when a RegionServer crashed.)");
    this.reader = null;
  }
  this.startTime = hsplit.getStartTime();
  this.endTime = hsplit.getEndTime();
}
项目:pbase    文件:HMerge.java   
protected Merger(Configuration conf, FileSystem fs, final TableName tableName)
throws IOException {
  this.conf = conf;
  this.fs = fs;
  this.maxFilesize = conf.getLong(HConstants.HREGION_MAX_FILESIZE,
      HConstants.DEFAULT_MAX_FILE_SIZE);

  this.rootDir = FSUtils.getRootDir(conf);
  Path tabledir = FSUtils.getTableDir(this.rootDir, tableName);
  this.htd = FSTableDescriptors.getTableDescriptorFromFs(this.fs, tabledir);
  String logname = "merge_" + System.currentTimeMillis() + HConstants.HREGION_LOGDIR_NAME;

  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tabledir);
  this.walFactory = new WALFactory(walConf, null, logname);
}
项目:pbase    文件:TestDistributedLogSplitting.java   
private int countWAL(Path log, FileSystem fs, Configuration conf)
throws IOException {
  int count = 0;
  WAL.Reader in = WALFactory.createReader(fs, log, conf);
  try {
    WAL.Entry e;
    while ((e = in.next()) != null) {
      if (!WALEdit.isMetaEditFamily(e.getEdit().getCells().get(0))) {
        count++;
      }
    }
  } finally {
    try {
      in.close();
    } catch (IOException exception) {
      LOG.warn("Problem closing wal: " + exception.getMessage());
      LOG.debug("exception details.", exception);
    }
  }
  return count;
}
项目:pbase    文件:TestWALObserver.java   
@Before
public void setUp() throws Exception {
  this.conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
  // this.cluster = TEST_UTIL.getDFSCluster();
  this.fs = TEST_UTIL.getDFSCluster().getFileSystem();
  this.hbaseRootDir = FSUtils.getRootDir(conf);
  this.dir = new Path(this.hbaseRootDir, TestWALObserver.class.getName());
  this.oldLogDir = new Path(this.hbaseRootDir,
      HConstants.HREGION_OLDLOGDIR_NAME);
  this.logDir = new Path(this.hbaseRootDir,
      DefaultWALProvider.getWALDirectoryName(currentTest.getMethodName()));
  this.logName = HConstants.HREGION_LOGDIR_NAME;

  if (TEST_UTIL.getDFSCluster().getFileSystem().exists(this.hbaseRootDir)) {
    TEST_UTIL.getDFSCluster().getFileSystem().delete(this.hbaseRootDir, true);
  }
  this.wals = new WALFactory(conf, null, currentTest.getMethodName());
}
项目:pbase    文件:TestStoreFileRefresherChore.java   
private HRegion initHRegion(HTableDescriptor htd, byte[] startKey, byte[] stopKey, int replicaId) throws IOException {
  Configuration conf = TEST_UTIL.getConfiguration();
  Path tableDir = FSUtils.getTableDir(testDir, htd.getTableName());

  HRegionInfo info = new HRegionInfo(htd.getTableName(), startKey, stopKey, false, 0, replicaId);

  HRegionFileSystem fs = new FailingHRegionFileSystem(conf, tableDir.getFileSystem(conf), tableDir, info);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tableDir);
  final WALFactory wals = new WALFactory(walConf, null, "log_" + replicaId);
  HRegion region = new HRegion(fs, wals.getWAL(info.getEncodedNameAsBytes()), conf, htd, null);

  region.initialize();

  return region;
}
项目:hbase    文件:HBaseFsck.java   
/**
 * This borrows code from MasterFileSystem.bootstrap(). Explicitly creates it's own WAL, so be
 * sure to close it as well as the region when you're finished.
 * @param walFactoryID A unique identifier for WAL factory. Filesystem implementations will use
 *          this ID to make a directory inside WAL directory path.
 * @return an open hbase:meta HRegion
 */
private HRegion createNewMeta(String walFactoryID) throws IOException {
  Path rootdir = FSUtils.getRootDir(getConf());
  Configuration c = getConf();
  RegionInfo metaHRI = RegionInfoBuilder.FIRST_META_REGIONINFO;
  TableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME);
  MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, false);
  // The WAL subsystem will use the default rootDir rather than the passed in rootDir
  // unless I pass along via the conf.
  Configuration confForWAL = new Configuration(c);
  confForWAL.set(HConstants.HBASE_DIR, rootdir.toString());
  WAL wal = new WALFactory(confForWAL, walFactoryID).getWAL(metaHRI);
  HRegion meta = HRegion.createHRegion(metaHRI, rootdir, c, metaDescriptor, wal);
  MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, true);
  return meta;
}
项目:hbase    文件:HRegionServer.java   
/**
 * Setup WAL log and replication if enabled. Replication setup is done in here because it wants to
 * be hooked up to WAL.
 */
private void setupWALAndReplication() throws IOException {
  WALFactory factory = new WALFactory(conf, serverName.toString());

  // TODO Replication make assumptions here based on the default filesystem impl
  Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
  String logName = AbstractFSWALProvider.getWALDirectoryName(this.serverName.toString());

  Path logDir = new Path(walRootDir, logName);
  LOG.debug("logDir={}", logDir);
  if (this.walFs.exists(logDir)) {
    throw new RegionServerRunningException(
        "Region server has already created directory at " + this.serverName.toString());
  }
  // Instantiate replication if replication enabled. Pass it the log directories.
  createNewReplicationInstance(conf, this, this.walFs, logDir, oldLogDir,
    factory.getWALProvider());
  this.walFactory = factory;
}
项目:hbase    文件:AbstractFSWAL.java   
private static void split(final Configuration conf, final Path p) throws IOException {
  FileSystem fs = FSUtils.getWALFileSystem(conf);
  if (!fs.exists(p)) {
    throw new FileNotFoundException(p.toString());
  }
  if (!fs.getFileStatus(p).isDirectory()) {
    throw new IOException(p + " is not a directory");
  }

  final Path baseDir = FSUtils.getWALRootDir(conf);
  Path archiveDir = new Path(baseDir, HConstants.HREGION_OLDLOGDIR_NAME);
  if (conf.getBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR,
    AbstractFSWALProvider.DEFAULT_SEPARATE_OLDLOGDIR)) {
    archiveDir = new Path(archiveDir, p.getName());
  }
  WALSplitter.split(baseDir, p, archiveDir, fs, conf, WALFactory.getInstance(conf));
}
项目:hbase    文件:TestWALObserver.java   
@Before
public void setUp() throws Exception {
  this.conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
  // this.cluster = TEST_UTIL.getDFSCluster();
  this.fs = TEST_UTIL.getDFSCluster().getFileSystem();
  this.hbaseRootDir = FSUtils.getRootDir(conf);
  this.hbaseWALRootDir = FSUtils.getWALRootDir(conf);
  this.oldLogDir = new Path(this.hbaseWALRootDir,
      HConstants.HREGION_OLDLOGDIR_NAME);
  String serverName = ServerName.valueOf(currentTest.getMethodName(), 16010,
      System.currentTimeMillis()).toString();
  this.logDir = new Path(this.hbaseWALRootDir,
    AbstractFSWALProvider.getWALDirectoryName(serverName));

  if (TEST_UTIL.getDFSCluster().getFileSystem().exists(this.hbaseRootDir)) {
    TEST_UTIL.getDFSCluster().getFileSystem().delete(this.hbaseRootDir, true);
  }
  if (TEST_UTIL.getDFSCluster().getFileSystem().exists(this.hbaseWALRootDir)) {
    TEST_UTIL.getDFSCluster().getFileSystem().delete(this.hbaseWALRootDir, true);
  }
  this.wals = new WALFactory(conf, serverName);
}
项目:hbase    文件:TestStoreFileRefresherChore.java   
private HRegion initHRegion(TableDescriptor htd, byte[] startKey, byte[] stopKey, int replicaId)
    throws IOException {
  Configuration conf = TEST_UTIL.getConfiguration();
  Path tableDir = FSUtils.getTableDir(testDir, htd.getTableName());

  RegionInfo info = RegionInfoBuilder.newBuilder(htd.getTableName()).setStartKey(startKey)
      .setEndKey(stopKey).setRegionId(0L).setReplicaId(replicaId).build();
  HRegionFileSystem fs =
      new FailingHRegionFileSystem(conf, tableDir.getFileSystem(conf), tableDir, info);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tableDir);
  final WALFactory wals = new WALFactory(walConf, "log_" + replicaId);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  HRegion region =
      new HRegion(fs, wals.getWAL(info),
          conf, htd, null);

  region.initialize();

  return region;
}
项目:hbase    文件:TestHStore.java   
private void initHRegion(String methodName, Configuration conf, TableDescriptorBuilder builder,
    ColumnFamilyDescriptor hcd, MyStoreHook hook, boolean switchToPread) throws IOException {
  TableDescriptor htd = builder.addColumnFamily(hcd).build();
  Path basedir = new Path(DIR + methodName);
  Path tableDir = FSUtils.getTableDir(basedir, htd.getTableName());
  final Path logdir = new Path(basedir, AbstractFSWALProvider.getWALDirectoryName(methodName));

  FileSystem fs = FileSystem.get(conf);

  fs.delete(logdir, true);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false,
    MemStoreLABImpl.CHUNK_SIZE_DEFAULT, 1, 0, null);
  RegionInfo info = RegionInfoBuilder.newBuilder(htd.getTableName()).build();
  Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, basedir);
  WALFactory wals = new WALFactory(walConf, methodName);
  region = new HRegion(new HRegionFileSystem(conf, fs, tableDir, info), wals.getWAL(info), conf,
      htd, null);
}
项目:hbase    文件:TestHMobStore.java   
private void init(String methodName, Configuration conf, HTableDescriptor htd,
    HColumnDescriptor hcd, boolean testStore) throws IOException {
  //Setting up tje Region and Store
  Path basedir = new Path(DIR+methodName);
  Path tableDir = FSUtils.getTableDir(basedir, htd.getTableName());
  String logName = "logs";
  Path logdir = new Path(basedir, logName);
  FileSystem fs = FileSystem.get(conf);
  fs.delete(logdir, true);

  htd.addFamily(hcd);
  HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, basedir);
  final WALFactory wals = new WALFactory(walConf, methodName);
  region = new HRegion(tableDir, wals.getWAL(info), fs, conf, info, htd, null);
  store = new HMobStore(region, hcd, conf);
  if(testStore) {
    init(conf, hcd);
  }
}
项目:hbase    文件:TestCompactionInDeadRegionServer.java   
@Before
public void setUp() throws Exception {
  UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, walProvider, WALProvider.class);
  UTIL.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
  UTIL.getConfiguration().setClass(HConstants.REGION_SERVER_IMPL, IgnoreYouAreDeadRS.class,
    HRegionServer.class);
  UTIL.startMiniCluster(2);
  Table table = UTIL.createTable(TABLE_NAME, CF);
  for (int i = 0; i < 10; i++) {
    table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
  UTIL.getAdmin().flush(TABLE_NAME);
  for (int i = 10; i < 20; i++) {
    table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
  UTIL.getAdmin().flush(TABLE_NAME);
}
项目:hbase    文件:TestLogRolling.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // TODO: testLogRollOnDatanodeDeath fails if short circuit reads are on under the hadoop2
  // profile. See HBASE-9337 for related issues.
  System.setProperty("hbase.tests.use.shortcircuit.reads", "false");

  /**** configuration for testLogRollOnDatanodeDeath ****/
  // lower the namenode & datanode heartbeat so the namenode
  // quickly detects datanode failures
  Configuration conf= TEST_UTIL.getConfiguration();
  conf.setInt("dfs.namenode.heartbeat.recheck-interval", 5000);
  conf.setInt("dfs.heartbeat.interval", 1);
  // the namenode might still try to choose the recently-dead datanode
  // for a pipeline, so try to a new pipeline multiple times
  conf.setInt("dfs.client.block.write.retries", 30);
  conf.setInt("hbase.regionserver.hlog.tolerable.lowreplication", 2);
  conf.setInt("hbase.regionserver.hlog.lowreplication.rolllimit", 3);
  conf.set(WALFactory.WAL_PROVIDER, "filesystem");
  conf.set(WALFactory.META_WAL_PROVIDER, "filesystem");
  AbstractTestLogRolling.setUpBeforeClass();
}
项目:hbase    文件:TestDurability.java   
/**
 * Test when returnResults set to false in increment it should not return the result instead it
 * resturn null.
 */
@Test
public void testIncrementWithReturnResultsSetToFalse() throws Exception {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] col1 = Bytes.toBytes("col1");

  // Setting up region
  WALFactory wals = new WALFactory(CONF,
      ServerName
          .valueOf("testIncrementWithReturnResultsSetToFalse", 16010, System.currentTimeMillis())
          .toString());
  HRegion region = createHRegion(wals, Durability.USE_DEFAULT);

  Increment inc1 = new Increment(row1);
  inc1.setReturnResults(false);
  inc1.addColumn(FAMILY, col1, 1);
  Result res = region.increment(inc1);
  assertTrue(res.isEmpty());
}
项目:hbase    文件:TestLogRollAbort.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Tweak default timeout values down for faster recovery
  TEST_UTIL.getConfiguration().setInt(
      "hbase.regionserver.logroll.errors.tolerated", 2);
  TEST_UTIL.getConfiguration().setInt("hbase.rpc.timeout", 10 * 1000);

  // Increase the amount of time between client retries
  TEST_UTIL.getConfiguration().setLong("hbase.client.pause", 5 * 1000);

  // lower the namenode & datanode heartbeat so the namenode
  // quickly detects datanode failures
  TEST_UTIL.getConfiguration().setInt("dfs.namenode.heartbeat.recheck-interval", 5000);
  TEST_UTIL.getConfiguration().setInt("dfs.heartbeat.interval", 1);
  // the namenode might still try to choose the recently-dead datanode
  // for a pipeline, so try to a new pipeline multiple times
  TEST_UTIL.getConfiguration().setInt("dfs.client.block.write.retries", 10);
  TEST_UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, "filesystem");
}
项目:hbase    文件:AbstractTestWALReplay.java   
@Before
public void setUp() throws Exception {
  this.conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
  this.fs = TEST_UTIL.getDFSCluster().getFileSystem();
  this.hbaseRootDir = FSUtils.getRootDir(this.conf);
  this.oldLogDir = new Path(this.hbaseRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
  String serverName =
    ServerName.valueOf(currentTest.getMethodName() + "-manual", 16010, System.currentTimeMillis())
        .toString();
  this.logName = AbstractFSWALProvider.getWALDirectoryName(serverName);
  this.logDir = new Path(this.hbaseRootDir, logName);
  if (TEST_UTIL.getDFSCluster().getFileSystem().exists(this.hbaseRootDir)) {
    TEST_UTIL.getDFSCluster().getFileSystem().delete(this.hbaseRootDir, true);
  }
  this.wals = new WALFactory(conf, currentTest.getMethodName());
}
项目:hbase    文件:TestCompactionArchiveConcurrentClose.java   
private HRegion initHRegion(TableDescriptor htd, RegionInfo info) throws IOException {
  Configuration conf = testUtil.getConfiguration();
  Path tableDir = FSUtils.getTableDir(testDir, htd.getTableName());

  HRegionFileSystem fs =
      new WaitingHRegionFileSystem(conf, tableDir.getFileSystem(conf), tableDir, info);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tableDir);
  final WALFactory wals = new WALFactory(walConf, "log_" + info.getEncodedName());
  HRegion region = new HRegion(fs, wals.getWAL(info), conf, htd, null);

  region.initialize();

  return region;
}
项目:hbase    文件:TestCompactionArchiveIOException.java   
private HRegion initHRegion(TableDescriptor htd, RegionInfo info) throws IOException {
  Configuration conf = testUtil.getConfiguration();
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  Path tableDir = FSUtils.getTableDir(testDir, htd.getTableName());
  Path regionDir = new Path(tableDir, info.getEncodedName());
  Path storeDir = new Path(regionDir, htd.getColumnFamilies()[0].getNameAsString());

  FileSystem errFS = spy(testUtil.getTestFileSystem());
  // Prior to HBASE-16964, when an exception is thrown archiving any compacted file,
  // none of the other files are cleared from the compactedfiles list.
  // Simulate this condition with a dummy file
  doThrow(new IOException("Error for test")).when(errFS)
      .rename(eq(new Path(storeDir, ERROR_FILE)), any());

  HRegionFileSystem fs = new HRegionFileSystem(conf, errFS, tableDir, info);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tableDir);
  final WALFactory wals = new WALFactory(walConf, "log_" + info.getEncodedName());
  HRegion region = new HRegion(fs, wals.getWAL(info), conf, htd, null);

  region.initialize();

  return region;
}
项目:hbase    文件:TestWALMonotonicallyIncreasingSeqId.java   
private HRegion initHRegion(TableDescriptor htd, byte[] startKey, byte[] stopKey, int replicaId)
    throws IOException {
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.set("hbase.wal.provider", walProvider);
  conf.setBoolean("hbase.hregion.mvcc.preassign", false);
  Path tableDir = FSUtils.getTableDir(testDir, htd.getTableName());

  RegionInfo info = RegionInfoBuilder.newBuilder(htd.getTableName()).setStartKey(startKey)
      .setEndKey(stopKey).setReplicaId(replicaId).setRegionId(0).build();
  fileSystem = tableDir.getFileSystem(conf);
  final Configuration walConf = new Configuration(conf);
  FSUtils.setRootDir(walConf, tableDir);
  this.walConf = walConf;
  wals = new WALFactory(walConf, "log_" + replicaId);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  HRegion region = HRegion.createHRegion(info, TEST_UTIL.getDefaultRootDirPath(), conf, htd,
    wals.getWAL(info));
  return region;
}
项目:ditb    文件:MetaUtils.java   
/**
 * @return the WAL associated with the given region
 * @throws IOException e
 */
public synchronized WAL getLog(HRegionInfo info) throws IOException {
  if (this.walFactory == null) {
    String logName = 
        HConstants.HREGION_LOGDIR_NAME + "_" + System.currentTimeMillis();
    final Configuration walConf = new Configuration(this.conf);
    FSUtils.setRootDir(walConf, fs.getHomeDirectory());
    this.walFactory = new WALFactory(walConf, null, logName);
  }
  final byte[] region = info.getEncodedNameAsBytes();
  return info.isMetaRegion() ? walFactory.getMetaWAL(region) : walFactory.getWAL(region);
}
项目:ditb    文件:HRegionServer.java   
/**
 * Setup WAL log and replication if enabled.
 * Replication setup is done in here because it wants to be hooked up to WAL.
 *
 * @return A WAL instance.
 * @throws IOException
 */
private WALFactory setupWALAndReplication() throws IOException {
  // TODO Replication make assumptions here based on the default filesystem impl
  final Path oldLogDir = new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME);
  final String logName = DefaultWALProvider.getWALDirectoryName(this.serverName.toString());

  Path logdir = new Path(rootDir, logName);
  if (LOG.isDebugEnabled()) LOG.debug("logdir=" + logdir);
  if (this.fs.exists(logdir)) {
    throw new RegionServerRunningException(
        "Region server has already " + "created directory at " + this.serverName.toString());
  }

  // Instantiate replication manager if replication enabled.  Pass it the
  // log directories.
  createNewReplicationInstance(conf, this, this.fs, logdir, oldLogDir);

  // listeners the wal factory will add to wals it creates.
  final List<WALActionsListener> listeners = new ArrayList<WALActionsListener>();
  listeners.add(new MetricsWAL());
  if (this.replicationSourceHandler != null
      && this.replicationSourceHandler.getWALActionsListener() != null) {
    // Replication handler is an implementation of WALActionsListener.
    listeners.add(this.replicationSourceHandler.getWALActionsListener());
  }

  return new WALFactory(conf, listeners, serverName.toString());
}
项目:ditb    文件:FSHLog.java   
private static void split(final Configuration conf, final Path p)
throws IOException {
  FileSystem fs = FileSystem.get(conf);
  if (!fs.exists(p)) {
    throw new FileNotFoundException(p.toString());
  }
  if (!fs.getFileStatus(p).isDirectory()) {
    throw new IOException(p + " is not a directory");
  }

  final Path baseDir = FSUtils.getRootDir(conf);
  final Path archiveDir = new Path(baseDir, HConstants.HREGION_OLDLOGDIR_NAME);
  WALSplitter.split(baseDir, p, archiveDir, fs, conf, WALFactory.getInstance(conf));
}
项目:ditb    文件:Compressor.java   
private static void transformFile(Path input, Path output)
    throws IOException {
  Configuration conf = HBaseConfiguration.create();

  FileSystem inFS = input.getFileSystem(conf);
  FileSystem outFS = output.getFileSystem(conf);

  WAL.Reader in = WALFactory.createReaderIgnoreCustomClass(inFS, input, conf);
  WALProvider.Writer out = null;

  try {
    if (!(in instanceof ReaderBase)) {
      System.err.println("Cannot proceed, invalid reader type: " + in.getClass().getName());
      return;
    }
    boolean compress = ((ReaderBase)in).hasCompression();
    conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, !compress);
    out = WALFactory.createWALWriter(outFS, output, conf);

    WAL.Entry e = null;
    while ((e = in.next()) != null) out.append(e);
  } finally {
    in.close();
    if (out != null) {
      out.close();
      out = null;
    }
  }
}
项目:ditb    文件:HRegion.java   
private static void processTable(final FileSystem fs, final Path p, final WALFactory walFactory,
    final Configuration c, final boolean majorCompact) throws IOException {
  HRegion region;
  FSTableDescriptors fst = new FSTableDescriptors(c);
  // Currently expects tables have one region only.
  if (FSUtils.getTableName(p).equals(TableName.META_TABLE_NAME)) {
    final WAL wal =
        walFactory.getMetaWAL(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes());
    region = HRegion.newHRegion(p, wal, fs, c, HRegionInfo.FIRST_META_REGIONINFO,
        fst.get(TableName.META_TABLE_NAME), null);
  } else {
    throw new IOException("Not a known catalog table: " + p.toString());
  }
  try {
    region.mvcc.advanceTo(region.initialize(null));
    if (majorCompact) {
      region.compact(true);
    } else {
      // Default behavior
      Scan scan = new Scan();
      // scan.addFamily(HConstants.CATALOG_FAMILY);
      RegionScanner scanner = region.getScanner(scan);
      try {
        List<Cell> kvs = new ArrayList<Cell>();
        boolean done;
        do {
          kvs.clear();
          done = scanner.next(kvs);
          if (kvs.size() > 0) LOG.info(kvs);
        } while (done);
      } finally {
        scanner.close();
      }
    }
  } finally {
    region.close();
  }
}