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

项目:ditb    文件:WALFactory.java   
/**
 * @param conf must not be null, will keep a reference to read params in later reader/writer
 *     instances.
 * @param listeners may be null. will be given to all created wals (and not meta-wals)
 * @param factoryId a unique identifier for this factory. used i.e. by filesystem implementations
 *     to make a directory
 */
public WALFactory(final Configuration conf, final List<WALActionsListener> listeners,
    final String factoryId) throws IOException {
  // until we've moved reader/writer construction down into providers, this initialization must
  // happen prior to provider initialization, in case they need to instantiate a reader/writer.
  timeoutMillis = conf.getInt("hbase.hlog.open.timeout", 300000);
  /* TODO Both of these are probably specific to the fs wal provider */
  logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl", ProtobufLogReader.class,
      DefaultWALProvider.Reader.class);
  this.conf = conf;
  this.factoryId = factoryId;
  // end required early initialization
  if (conf.getBoolean("hbase.regionserver.hlog.enabled", true)) {
    provider = getProvider(WAL_PROVIDER, DEFAULT_WAL_PROVIDER, listeners, null);
  } else {
    // special handling of existing configuration behavior.
    LOG.warn("Running with WAL disabled.");
    provider = new DisabledWALProvider();
    provider.init(this, conf, null, factoryId);
  }
}
项目:pbase    文件:WALFactory.java   
/**
 * @param conf must not be null, will keep a reference to read params in later reader/writer
 *     instances.
 * @param listeners may be null. will be given to all created wals (and not meta-wals)
 * @param factoryId a unique identifier for this factory. used i.e. by filesystem implementations
 *     to make a directory
 */
public WALFactory(final Configuration conf, final List<WALActionsListener> listeners,
    final String factoryId) throws IOException {
  // until we've moved reader/writer construction down into providers, this initialization must
  // happen prior to provider initialization, in case they need to instantiate a reader/writer.
  timeoutMillis = conf.getInt("hbase.hlog.open.timeout", 300000);
  /* TODO Both of these are probably specific to the fs wal provider */
  logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl", ProtobufLogReader.class,
      DefaultWALProvider.Reader.class);
  this.conf = conf;
  this.factoryId = factoryId;
  // end required early initialization
  if (conf.getBoolean("hbase.regionserver.hlog.enabled", true)) {
    provider = getProvider(WAL_PROVIDER, DEFAULT_WAL_PROVIDER, listeners, null);
  } else {
    // special handling of existing configuration behavior.
    LOG.warn("Running with WAL disabled.");
    provider = new DisabledWALProvider();
    provider.init(this, conf, null, factoryId);
  }
}
项目:hbase    文件:WALFactory.java   
/**
 * @param conf must not be null, will keep a reference to read params in later reader/writer
 *          instances.
 * @param factoryId a unique identifier for this factory. used i.e. by filesystem implementations
 *          to make a directory
 */
public WALFactory(Configuration conf, String factoryId) throws IOException {
  // until we've moved reader/writer construction down into providers, this initialization must
  // happen prior to provider initialization, in case they need to instantiate a reader/writer.
  timeoutMillis = conf.getInt("hbase.hlog.open.timeout", 300000);
  /* TODO Both of these are probably specific to the fs wal provider */
  logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl", ProtobufLogReader.class,
    AbstractFSWALProvider.Reader.class);
  this.conf = conf;
  this.factoryId = factoryId;
  // end required early initialization
  if (conf.getBoolean("hbase.regionserver.hlog.enabled", true)) {
    provider = getProvider(WAL_PROVIDER, DEFAULT_WAL_PROVIDER, null);
  } else {
    // special handling of existing configuration behavior.
    LOG.warn("Running with WAL disabled.");
    provider = new DisabledWALProvider();
    provider.init(this, conf, factoryId);
  }
}
项目:ditb    文件:WALFactory.java   
private WALFactory(Configuration conf) {
  // this code is duplicated here so we can keep our members final.
  // until we've moved reader/writer construction down into providers, this initialization must
  // happen prior to provider initialization, in case they need to instantiate a reader/writer.
  timeoutMillis = conf.getInt("hbase.hlog.open.timeout", 300000);
  /* TODO Both of these are probably specific to the fs wal provider */
  logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl", ProtobufLogReader.class,
      DefaultWALProvider.Reader.class);
  this.conf = conf;
  // end required early initialization

  // this instance can't create wals, just reader/writers.
  provider = null;
  factoryId = SINGLETON_ID;
}
项目:pbase    文件:WALFactory.java   
private WALFactory(Configuration conf) {
  // this code is duplicated here so we can keep our members final.
  // until we've moved reader/writer construction down into providers, this initialization must
  // happen prior to provider initialization, in case they need to instantiate a reader/writer.
  timeoutMillis = conf.getInt("hbase.hlog.open.timeout", 300000);
  /* TODO Both of these are probably specific to the fs wal provider */
  logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl", ProtobufLogReader.class,
      DefaultWALProvider.Reader.class);
  this.conf = conf;
  // end required early initialization

  // this instance can't create wals, just reader/writers.
  provider = null;
  factoryId = SINGLETON_ID;
}
项目:hbase    文件:WALEntryStream.java   
private long currentTrailerSize() {
  long size = -1L;
  if (reader instanceof ProtobufLogReader) {
    final ProtobufLogReader pblr = (ProtobufLogReader) reader;
    size = pblr.trailerSize();
  }
  return size;
}
项目:hbase    文件:WALFactory.java   
private WALFactory(Configuration conf) {
  // this code is duplicated here so we can keep our members final.
  // until we've moved reader/writer construction down into providers, this initialization must
  // happen prior to provider initialization, in case they need to instantiate a reader/writer.
  timeoutMillis = conf.getInt("hbase.hlog.open.timeout", 300000);
  /* TODO Both of these are probably specific to the fs wal provider */
  logReaderClass = conf.getClass("hbase.regionserver.hlog.reader.impl", ProtobufLogReader.class,
    AbstractFSWALProvider.Reader.class);
  this.conf = conf;
  // end required early initialization

  // this instance can't create wals, just reader/writers.
  provider = null;
  factoryId = SINGLETON_ID;
}
项目:pbase    文件:TestWALSplit.java   
private void corruptWAL(Path path, Corruptions corruption, boolean close) throws IOException {
  FSDataOutputStream out;
  int fileSize = (int) fs.listStatus(path)[0].getLen();

  FSDataInputStream in = fs.open(path);
  byte[] corrupted_bytes = new byte[fileSize];
  in.readFully(0, corrupted_bytes, 0, fileSize);
  in.close();

  switch (corruption) {
    case APPEND_GARBAGE:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(corrupted_bytes);
      out.write("-----".getBytes());
      closeOrFlush(close, out);
      break;

    case INSERT_GARBAGE_ON_FIRST_LINE:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(0);
      out.write(corrupted_bytes);
      closeOrFlush(close, out);
      break;

    case INSERT_GARBAGE_IN_THE_MIDDLE:
      fs.delete(path, false);
      out = fs.create(path);
      int middle = (int) Math.floor(corrupted_bytes.length / 2);
      out.write(corrupted_bytes, 0, middle);
      out.write(0);
      out.write(corrupted_bytes, middle, corrupted_bytes.length - middle);
      closeOrFlush(close, out);
      break;

    case TRUNCATE:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(corrupted_bytes, 0, fileSize
        - (32 + ProtobufLogReader.PB_WAL_COMPLETE_MAGIC.length + Bytes.SIZEOF_INT));
      closeOrFlush(close, out);
      break;

    case TRUNCATE_TRAILER:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(corrupted_bytes, 0, fileSize - Bytes.SIZEOF_INT);// trailer is truncated.
      closeOrFlush(close, out);
      break;
  }
}
项目:hbase    文件:TestWALSplit.java   
private void corruptWAL(Path path, Corruptions corruption, boolean close) throws IOException {
  FSDataOutputStream out;
  int fileSize = (int) fs.listStatus(path)[0].getLen();

  FSDataInputStream in = fs.open(path);
  byte[] corrupted_bytes = new byte[fileSize];
  in.readFully(0, corrupted_bytes, 0, fileSize);
  in.close();

  switch (corruption) {
    case APPEND_GARBAGE:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(corrupted_bytes);
      out.write(Bytes.toBytes("-----"));
      closeOrFlush(close, out);
      break;

    case INSERT_GARBAGE_ON_FIRST_LINE:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(0);
      out.write(corrupted_bytes);
      closeOrFlush(close, out);
      break;

    case INSERT_GARBAGE_IN_THE_MIDDLE:
      fs.delete(path, false);
      out = fs.create(path);
      int middle = (int) Math.floor(corrupted_bytes.length / 2);
      out.write(corrupted_bytes, 0, middle);
      out.write(0);
      out.write(corrupted_bytes, middle, corrupted_bytes.length - middle);
      closeOrFlush(close, out);
      break;

    case TRUNCATE:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(corrupted_bytes, 0, fileSize
          - (32 + ProtobufLogReader.PB_WAL_COMPLETE_MAGIC.length + Bytes.SIZEOF_INT));
      closeOrFlush(close, out);
      break;

    case TRUNCATE_TRAILER:
      fs.delete(path, false);
      out = fs.create(path);
      out.write(corrupted_bytes, 0, fileSize - Bytes.SIZEOF_INT);// trailer is truncated.
      closeOrFlush(close, out);
      break;
  }
}