org.apache.hadoop.hbase.util.VersionInfo Java Examples

The following examples show how to use org.apache.hadoop.hbase.util.VersionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackwardCompatibilityIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private static List<String> computeClientVersions() throws Exception {
    String hbaseVersion = VersionInfo.getVersion();
    Pattern p = Pattern.compile("\\d+\\.\\d+");
    Matcher m = p.matcher(hbaseVersion);
    String hbaseProfile = null;
    if (m.find()) {
        hbaseProfile = m.group();
    }
    List<String> clientVersions = Lists.newArrayList();
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
    JsonNode jsonNode = mapper.readTree(new FileReader(COMPATIBLE_CLIENTS_JSON));
    JsonNode HBaseProfile = jsonNode.get(hbaseProfile);
    for (final JsonNode clientVersion : HBaseProfile) {
        clientVersions.add(clientVersion.textValue() + "-HBase-" + hbaseProfile);
    }
    return clientVersions;
}
 
Example #2
Source File: TestParalleWriterIndexCommitter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, HTableInterface> emptyMap());
  ParallelWriterIndexCommitter writer = new ParallelWriterIndexCommitter(VersionInfo.getVersion());
  Abortable mockAbort = Mockito.mock(Abortable.class);
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockAbort, mockStop, 1);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockAbort, mockStop);
}
 
Example #3
Source File: TestParalleIndexWriter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, HTableInterface> emptyMap());
  ParallelWriterIndexCommitter writer = new ParallelWriterIndexCommitter(VersionInfo.getVersion());
  Abortable mockAbort = Mockito.mock(Abortable.class);
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockAbort, mockStop, 1);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockAbort, mockStop);
}
 
Example #4
Source File: AssignmentManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get a list of servers that this region cannot be assigned to.
 * For system tables, we must assign them to a server with highest version.
 */
public List<ServerName> getExcludedServersForSystemTable() {
  // TODO: This should be a cached list kept by the ServerManager rather than calculated on each
  // move or system region assign. The RegionServerTracker keeps list of online Servers with
  // RegionServerInfo that includes Version.
  List<Pair<ServerName, String>> serverList = master.getServerManager().getOnlineServersList()
      .stream()
      .map((s)->new Pair<>(s, master.getRegionServerVersion(s)))
      .collect(Collectors.toList());
  if (serverList.isEmpty()) {
    return Collections.emptyList();
  }
  String highestVersion = Collections.max(serverList,
      (o1, o2) -> VersionInfo.compareVersion(o1.getSecond(), o2.getSecond())).getSecond();
  return serverList.stream()
      .filter((p)->!p.getSecond().equals(highestVersion))
      .map(Pair::getFirst)
      .collect(Collectors.toList());
}
 
Example #5
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get a protocol buffer VersionInfo
 *
 * @return the converted protocol buffer VersionInfo
 */
public static HBaseProtos.VersionInfo getVersionInfo() {
  HBaseProtos.VersionInfo.Builder builder = HBaseProtos.VersionInfo.newBuilder();
  String version = VersionInfo.getVersion();
  builder.setVersion(version);
  String[] components = version.split("\\.");
  if (components != null && components.length > 2) {
    builder.setVersionMajor(Integer.parseInt(components[0]));
    builder.setVersionMinor(Integer.parseInt(components[1]));
  }
  builder.setUrl(VersionInfo.getUrl());
  builder.setRevision(VersionInfo.getRevision());
  builder.setUser(VersionInfo.getUser());
  builder.setDate(VersionInfo.getDate());
  builder.setSrcChecksum(VersionInfo.getSrcChecksum());
  return builder.build();
}
 
Example #6
Source File: RESTServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * The main method for the HBase rest server.
 * @param args command-line arguments
 * @throws Exception exception
 */
public static void main(String[] args) throws Exception {
  LOG.info("***** STARTING service '" + RESTServer.class.getSimpleName() + "' *****");
  VersionInfo.logVersion();
  final Configuration conf = HBaseConfiguration.create();
  parseCommandLine(args, conf);
  RESTServer server = new RESTServer(conf);

  try {
    server.run();
    server.join();
  } catch (Exception e) {
    System.exit(1);
  }

  LOG.info("***** STOPPING service '" + RESTServer.class.getSimpleName() + "' *****");
}
 
Example #7
Source File: TestParalleWriterIndexCommitter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, Table> emptyMap());
  TrackingParallelWriterIndexCommitter writer = new TrackingParallelWriterIndexCommitter(VersionInfo.getVersion());
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  RegionCoprocessorEnvironment e =Mockito.mock(RegionCoprocessorEnvironment.class);
  Configuration conf =new Configuration();
  Mockito.when(e.getConfiguration()).thenReturn(conf);
  Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
  // create a simple writer
  writer.setup(factory, exec, mockStop, e);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockStop);
}
 
Example #8
Source File: TestParalleIndexWriter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  RegionCoprocessorEnvironment e =Mockito.mock(RegionCoprocessorEnvironment.class);
  Configuration conf =new Configuration();
  Mockito.when(e.getConfiguration()).thenReturn(conf);
  Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, Table> emptyMap());
  TrackingParallelWriterIndexCommitter writer = new TrackingParallelWriterIndexCommitter(VersionInfo.getVersion());
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockStop,e);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockStop);
}
 
Example #9
Source File: MetaDataUtilTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Put generateOriginalPut() {
    String version = VersionInfo.getVersion();
    KeyValueBuilder builder = KeyValueBuilder.get(version);
    KeyValue kv = builder.buildPut(wrap(ROW), wrap(TABLE_FAMILY_BYTES), wrap(QUALIFIER),
            wrap(ORIGINAL_VALUE));
    Put put = new Put(ROW);
    KeyValueBuilder.addQuietly(put, kv);
    return put;
}
 
Example #10
Source File: FailForUnsupportedHBaseVersionsIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * We don't support WAL Compression for HBase &lt; 0.94.9, so we shouldn't even allow the server
 * to start if both indexing and WAL Compression are enabled for the wrong versions.
 */
@Test
public void testDoesNotSupportCompressedWAL() {
    Configuration conf = HBaseConfiguration.create();
    IndexTestingUtils.setupConfig(conf);
    // get the current version
    String version = VersionInfo.getVersion();

    // ensure WAL Compression not enabled
    conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, false);

    //we support all versions without WAL Compression
    String supported = Indexer.validateVersion(version, conf);
    assertNull(
            "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! All versions should"
                    + " support writing without a compressed WAL. Message: "+supported, supported);

    // enable WAL Compression
    conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true);

    // set the version to something we know isn't supported
    version = "0.94.4";
    supported = Indexer.validateVersion(version, conf);
    assertNotNull("WAL Compression was enabled, but incorrectly marked version as supported",
            supported);

    //make sure the first version of 0.94 that supports Indexing + WAL Compression works
    version = "0.94.9";
    supported = Indexer.validateVersion(version, conf);
    assertNull(
            "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! Message: "+supported, supported);

    //make sure we support snapshot builds too
    version = "0.94.9-SNAPSHOT";
    supported = Indexer.validateVersion(version, conf);
    assertNull(
            "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! Message: "+supported, supported);
}
 
Example #11
Source File: StateDumpServlet.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected void dumpVersionInfo(PrintWriter out) {
  VersionInfo.writeTo(out);

  out.println("Hadoop " + org.apache.hadoop.util.VersionInfo.getVersion());
  out.println("Source code repository " + org.apache.hadoop.util.VersionInfo.getUrl()
    + " revision=" + org.apache.hadoop.util.VersionInfo.getRevision());
  out.println("Compiled by " + org.apache.hadoop.util.VersionInfo.getUser() +
      " on " + org.apache.hadoop.util.VersionInfo.getDate());
}
 
Example #12
Source File: HBaseConfiguration.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void checkDefaultsVersion(Configuration conf) {
  if (conf.getBoolean("hbase.defaults.for.version.skip", Boolean.FALSE)) return;
  String defaultsVersion = conf.get("hbase.defaults.for.version");
  String thisVersion = VersionInfo.getVersion();
  if (!thisVersion.equals(defaultsVersion)) {
    throw new RuntimeException(
      "hbase-default.xml file seems to be for an older version of HBase (" +
      defaultsVersion + "), this version is " + thisVersion);
  }
}
 
Example #13
Source File: MetaDataUtilTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testConditionallyAddTagsToPutCells( ) {
    List<Tag> tags = TagUtil.asList(VIEW_MODIFIED_PROPERTY_BYTES, 0, VIEW_MODIFIED_PROPERTY_BYTES.length);
    assertEquals(tags.size(), 1);
    Tag expectedTag = tags.get(0);

    String version = VersionInfo.getVersion();
    KeyValueBuilder builder = KeyValueBuilder.get(version);
    KeyValue kv = builder.buildPut(wrap(ROW), wrap(TABLE_FAMILY_BYTES), wrap(UPDATE_CACHE_FREQUENCY_BYTES), wrap(
            PLong.INSTANCE.toBytes(0)));
    Put put = new Put(ROW);
    KeyValueBuilder.addQuietly(put, kv);

    ExtendedCellBuilder cellBuilder = (ExtendedCellBuilder) RawCellBuilderFactory.create();
    MetaDataUtil.conditionallyAddTagsToPutCells(put, TABLE_FAMILY_BYTES, UPDATE_CACHE_FREQUENCY_BYTES, cellBuilder,
            PInteger.INSTANCE.toBytes(1), VIEW_MODIFIED_PROPERTY_BYTES);

    Cell cell = put.getFamilyCellMap().get(TABLE_FAMILY_BYTES).get(0);

    // To check the cell tag whether view has modified this property
    assertTrue(Bytes.compareTo(expectedTag.getValueArray(), TagUtil.concatTags(EMPTY_BYTE_ARRAY, cell)) == 0);
    assertTrue(Bytes.contains(TagUtil.concatTags(EMPTY_BYTE_ARRAY, cell), expectedTag.getValueArray()));

    // To check tag data can be correctly deserialized
    Iterator<Tag> tagIterator = PrivateCellUtil.tagsIterator(cell);
    assertTrue(tagIterator.hasNext());
    Tag actualTag = tagIterator.next();
    assertTrue(Bytes.compareTo(actualTag.getValueArray(), actualTag.getValueOffset(), actualTag.getValueLength(),
            expectedTag.getValueArray(), expectedTag.getValueOffset(), expectedTag.getValueLength()) == 0);
    assertFalse(tagIterator.hasNext());
}
 
Example #14
Source File: MinVersionTestRunner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void runChild(FrameworkMethod method, RunNotifier notifier) {
    MinVersion methodCondition = method.getAnnotation(MinVersion.class);
    MinVersion classCondition = this.getTestClass().getJavaClass().getAnnotation(MinVersion.class);
    String versionStr = VersionInfo.getVersion();
    int version = VersionUtil.encodeVersion(versionStr);
    if (  (methodCondition == null || version >= VersionUtil.encodeVersion(methodCondition.value()))
       && (classCondition == null || version >= VersionUtil.encodeVersion(classCondition.value()))) {
        super.runChild(method, notifier);
    } else {
        notifier.fireTestIgnored(describeChild(method));
    }
}
 
Example #15
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.hadoop.hbase.regionserver.HRegionServerCommandLine
 */
public static void main(String[] args) {
  LOG.info("STARTING executorService " + HRegionServer.class.getSimpleName());
  VersionInfo.logVersion();
  Configuration conf = HBaseConfiguration.create();
  @SuppressWarnings("unchecked")
  Class<? extends HRegionServer> regionServerClass = (Class<? extends HRegionServer>) conf
      .getClass(HConstants.REGION_SERVER_IMPL, HRegionServer.class);

  new HRegionServerCommandLine(regionServerClass).doMain(args);
}
 
Example #16
Source File: ClusterStatusPublisher.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void chore() {
  if (!isConnected()) {
    return;
  }

  List<ServerName> sns = generateDeadServersListToSend();
  if (sns.isEmpty()) {
    // Nothing to send. Done.
    return;
  }

  final long curTime = EnvironmentEdgeManager.currentTime();
  if (lastMessageTime > curTime - messagePeriod) {
    // We already sent something less than 10 second ago. Done.
    return;
  }

  // Ok, we're going to send something then.
  lastMessageTime = curTime;

  // We're reusing an existing protobuf message, but we don't send everything.
  // This could be extended in the future, for example if we want to send stuff like the
  //  hbase:meta server name.
  publisher.publish(ClusterMetricsBuilder.newBuilder()
    .setHBaseVersion(VersionInfo.getVersion())
    .setClusterId(master.getMasterFileSystem().getClusterId().toString())
    .setMasterName(master.getServerName())
    .setDeadServerNames(sns)
    .build());
}
 
Example #17
Source File: ConnectionlessQueryServicesImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ConnectionlessQueryServicesImpl(QueryServices queryServices) {
    super(queryServices);
    metaData = PMetaDataImpl.EMPTY_META_DATA;
    // find the HBase version and use that to determine the KeyValueBuilder that should be used
    String hbaseVersion = VersionInfo.getVersion();
    this.kvBuilder = KeyValueBuilder.get(hbaseVersion);
}
 
Example #18
Source File: ThriftServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void main(String [] args) throws Exception {
  LOG.info("***** STARTING service '" + ThriftServer.class.getSimpleName() + "' *****");
  VersionInfo.logVersion();
  final Configuration conf = HBaseConfiguration.create();
  // for now, only time we return is on an argument error.
  final int status = ToolRunner.run(conf, new ThriftServer(conf), args);
  LOG.info("***** STOPPING service '" + ThriftServer.class.getSimpleName() + "' *****");
  System.exit(status);
}
 
Example #19
Source File: MinVersionTestRunner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void runChild(FrameworkMethod method, RunNotifier notifier) {
    MinVersion methodCondition = method.getAnnotation(MinVersion.class);
    MinVersion classCondition = this.getTestClass().getJavaClass().getAnnotation(MinVersion.class);
    String versionStr = VersionInfo.getVersion();
    int version = VersionUtil.encodeVersion(versionStr);
    if (  (methodCondition == null || version >= VersionUtil.encodeVersion(methodCondition.value()))
       && (classCondition == null || version >= VersionUtil.encodeVersion(classCondition.value()))) {
        super.runChild(method, notifier);
    } else {
        notifier.fireTestIgnored(describeChild(method));
    }
}
 
Example #20
Source File: TestFailForUnsupportedHBaseVersions.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * We don't support WAL Compression for HBase &lt; 0.94.9, so we shouldn't even allow the server
 * to start if both indexing and WAL Compression are enabled for the wrong versions.
 */
@Test
public void testDoesNotSupportCompressedWAL() {
  Configuration conf = HBaseConfiguration.create();
  IndexTestingUtils.setupConfig(conf);
  // get the current version
  String version = VersionInfo.getVersion();
  
  // ensure WAL Compression not enabled
  conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, false);
  
  //we support all versions without WAL Compression
  String supported = Indexer.validateVersion(version, conf);
  assertNull(
    "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! All versions should"
        + " support writing without a compressed WAL. Message: "+supported, supported);

  // enable WAL Compression
  conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true);

  // set the version to something we know isn't supported
  version = "0.94.4";
  supported = Indexer.validateVersion(version, conf);
  assertNotNull("WAL Compression was enabled, but incorrectly marked version as supported",
    supported);
  
  //make sure the first version of 0.94 that supports Indexing + WAL Compression works
  version = "0.94.9";
  supported = Indexer.validateVersion(version, conf);
  assertNull(
    "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! Message: "+supported, supported);
  
  //make sure we support snapshot builds too
  version = "0.94.9-SNAPSHOT";
  supported = Indexer.validateVersion(version, conf);
  assertNull(
    "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! Message: "+supported, supported);
}
 
Example #21
Source File: IndexMaintainerTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void testIndexRowKeyBuilding(String schemaName, String tableName, String dataColumns, String pk, String indexColumns, Object[] values, String includeColumns, String dataProps, String indexProps) throws Exception {
    KeyValueBuilder builder = GenericKeyValueBuilder.INSTANCE;
    testIndexRowKeyBuilding(schemaName, tableName, dataColumns, pk, indexColumns, values, includeColumns, dataProps, indexProps, builder);

    //do the same, but with the client key-value builder, to ensure that works the same
    
    String hbaseVersion = VersionInfo.getVersion();
    if (KeyValueBuilder.get(hbaseVersion) == ClientKeyValueBuilder.INSTANCE) {
        builder = ClientKeyValueBuilder.INSTANCE;
        testIndexRowKeyBuilding(schemaName, tableName, dataColumns, pk, indexColumns, values, includeColumns, dataProps, indexProps, builder);
    }
}
 
Example #22
Source File: FailForUnsupportedHBaseVersionsIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * We don't support WAL Compression for HBase &lt; 0.94.9, so we shouldn't even allow the server
 * to start if both indexing and WAL Compression are enabled for the wrong versions.
 */
@Test
public void testDoesNotSupportCompressedWAL() {
  Configuration conf = HBaseConfiguration.create();
  IndexTestingUtils.setupConfig(conf);
  // get the current version
  String version = VersionInfo.getVersion();
  
  // ensure WAL Compression not enabled
  conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, false);
  
  //we support all versions without WAL Compression
  String supported = Indexer.validateVersion(version, conf);
  assertNull(
    "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! All versions should"
        + " support writing without a compressed WAL. Message: "+supported, supported);

  // enable WAL Compression
  conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true);

  // set the version to something we know isn't supported
  version = "0.94.4";
  supported = Indexer.validateVersion(version, conf);
  assertNotNull("WAL Compression was enabled, but incorrectly marked version as supported",
    supported);
  
  //make sure the first version of 0.94 that supports Indexing + WAL Compression works
  version = "0.94.9";
  supported = Indexer.validateVersion(version, conf);
  assertNull(
    "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! Message: "+supported, supported);
  
  //make sure we support snapshot builds too
  version = "0.94.9-SNAPSHOT";
  supported = Indexer.validateVersion(version, conf);
  assertNull(
    "WAL Compression wasn't enabled, but version "+version+" of HBase wasn't supported! Message: "+supported, supported);
}
 
Example #23
Source File: HBaseStoreTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void stopHBase() {
    // Workaround for https://issues.apache.org/jira/browse/HBASE-10312
    if (VersionInfo.getVersion().startsWith("0.96"))
        HBaseStorageSetup.killIfRunning();
}
 
Example #24
Source File: HBaseOperationCountingTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void stopHBase() {
    // Workaround for https://issues.apache.org/jira/browse/HBASE-10312
    if (VersionInfo.getVersion().startsWith("0.96"))
        HBaseStorageSetup.killIfRunning();
}
 
Example #25
Source File: HBaseProcessTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void stopHBase() {
    // Workaround for https://issues.apache.org/jira/browse/HBASE-10312
    if (VersionInfo.getVersion().startsWith("0.96"))
        HBaseStorageSetup.killIfRunning();
}
 
Example #26
Source File: FailForUnsupportedHBaseVersionsIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Test that we correctly abort a RegionServer when we run tests with an unsupported HBase
 * version. The 'completeness' of this test requires that we run the test with both a version of
 * HBase that wouldn't be supported with WAL Compression. Currently, this is the default version
 * (0.94.4) so just running 'mvn test' will run the full test. However, this test will not fail
 * when running against a version of HBase with WALCompression enabled. Therefore, to fully test
 * this functionality, we need to run the test against both a supported and an unsupported version
 * of HBase (as long as we want to support an version of HBase that doesn't support custom WAL
 * Codecs).
 * @throws Exception on failure
 */
@Test(timeout = 300000 /* 5 mins */)
public void testDoesNotStartRegionServerForUnsupportedCompressionAndVersion() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    setUpConfigForMiniCluster(conf);
    IndexTestingUtils.setupConfig(conf);
    // enable WAL Compression
    conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, true);

    // check the version to see if it isn't supported
    String version = VersionInfo.getVersion();
    boolean supported = false;
    if (Indexer.validateVersion(version, conf) == null) {
        supported = true;
    }

    // start the minicluster
    HBaseTestingUtility util = new HBaseTestingUtility(conf);
    util.startMiniCluster();

    try {
        // setup the primary table
        TableDescriptorBuilder descBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf(
                "testDoesNotStartRegionServerForUnsupportedCompressionAndVersion"));
        byte[] family = Bytes.toBytes("f");
        
        descBuilder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
        TableDescriptor desc=descBuilder.build();
        // enable indexing to a non-existant index table
        String indexTableName = "INDEX_TABLE";
        ColumnGroup fam1 = new ColumnGroup(indexTableName);
        fam1.add(new CoveredColumn(family, CoveredColumn.ALL_QUALIFIERS));
        CoveredColumnIndexSpecifierBuilder builder = new CoveredColumnIndexSpecifierBuilder();
        builder.addIndexGroup(fam1);
        builder.build(desc);

        // get a reference to the regionserver, so we can ensure it aborts
        HRegionServer server = util.getMiniHBaseCluster().getRegionServer(0);

        // create the primary table
        Admin admin = util.getAdmin();
        if (supported) {
            admin.createTable(desc);
            assertFalse("Hosting regeion server failed, even the HBase version (" + version
                    + ") supports WAL Compression.", server.isAborted());
        } else {
            admin.createTableAsync(desc, null);

            // wait for the regionserver to abort - if this doesn't occur in the timeout, assume its
            // broken.
            while (!server.isAborted()) {
                LOGGER.debug("Waiting on regionserver to abort..");
            }
        }

    } finally {
        // cleanup
        util.shutdownMiniCluster();
    }
}
 
Example #27
Source File: TestIndexWriter.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * With the move to using a pool of threads to write, we need to ensure that we still block until
 * all index writes for a mutation/batch are completed.
 * @throws Exception on failure
 */
@Test
public void testSynchronouslyCompletesAllWrites() throws Exception {
  LOGGER.info("Starting " + testName.getTableNameString());
  LOGGER.info("Current thread is interrupted: " + Thread.interrupted());
  Abortable abort = new StubAbortable();
  Stoppable stop = Mockito.mock(Stoppable.class);
  RegionCoprocessorEnvironment e =Mockito.mock(RegionCoprocessorEnvironment.class);
  Configuration conf =new Configuration();
  Mockito.when(e.getConfiguration()).thenReturn(conf);
  Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
  Region mockRegion = Mockito.mock(Region.class);
  Mockito.when(e.getRegion()).thenReturn(mockRegion);
  TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
  Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
  TableName mockTN = TableName.valueOf("test");
  Mockito.when(mockTableDesc.getTableName()).thenReturn(mockTN);
  Connection mockConnection = Mockito.mock(Connection.class);
  Mockito.when(e.getConnection()).thenReturn(mockConnection);
  ExecutorService exec = Executors.newFixedThreadPool(1);
  Map<ImmutableBytesPtr, Table> tables = new HashMap<ImmutableBytesPtr, Table>();
  FakeTableFactory factory = new FakeTableFactory(tables);

  byte[] tableName = this.testName.getTableName();
  Put m = new Put(row);
  m.addColumn(Bytes.toBytes("family"), Bytes.toBytes("qual"), null);
  Collection<Pair<Mutation, byte[]>> indexUpdates = Arrays.asList(new Pair<Mutation, byte[]>(m,
      tableName));

  Table table = Mockito.mock(Table.class);
  final boolean[] completed = new boolean[] { false };
      Mockito.doAnswer(new Answer<Void>() {
          @Override
          public Void answer(InvocationOnMock invocation) throws Throwable {
              // just keep track that it was called
              completed[0] = true;
              return null;
          }
      }).when(table).batch(Mockito.anyList(), Mockito.any());
  Mockito.when(table.getName()).thenReturn(TableName.valueOf(testName.getTableName()));
  // add the table to the set of tables, so its returned to the writer
  tables.put(new ImmutableBytesPtr(tableName), table);

  // setup the writer and failure policy
  TrackingParallelWriterIndexCommitter committer = new TrackingParallelWriterIndexCommitter(VersionInfo.getVersion());
  committer.setup(factory, exec, stop, e);
  KillServerOnFailurePolicy policy = new KillServerOnFailurePolicy();
  policy.setup(stop, e);
  IndexWriter writer = new IndexWriter(committer, policy);
  writer.write(indexUpdates, ScanUtil.UNKNOWN_CLIENT_VERSION);
  assertTrue("Writer returned before the table batch completed! Likely a race condition tripped",
    completed[0]);
  writer.stop(this.testName.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
}
 
Example #28
Source File: HBaseComputerTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void stopHBase() {
    // Workaround for https://issues.apache.org/jira/browse/HBASE-10312
    if (VersionInfo.getVersion().startsWith("0.96"))
        HBaseStorageSetup.killIfRunning();
}
 
Example #29
Source File: TestParalleWriterIndexCommitter.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked"})
@Test
public void testSynchronouslyCompletesAllWrites() throws Exception {
  LOGGER.info("Starting " + test.getTableNameString());
  LOGGER.info("Current thread is interrupted: " + Thread.interrupted());
  RegionCoprocessorEnvironment e =Mockito.mock(RegionCoprocessorEnvironment.class);
  Configuration conf =new Configuration();
  Mockito.when(e.getConfiguration()).thenReturn(conf);
  Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
  Region mockRegion = Mockito.mock(Region.class);
  Mockito.when(e.getRegion()).thenReturn(mockRegion);
  TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
  Mockito.when(mockTableDesc.getTableName()).thenReturn(TableName.valueOf("test"));
  Connection mockConnection = Mockito.mock(Connection.class);
  Mockito.when(e.getConnection()).thenReturn(mockConnection);
  Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
  Stoppable stop = Mockito.mock(Stoppable.class);
  ExecutorService exec = Executors.newFixedThreadPool(1);
  Map<ImmutableBytesPtr, Table> tables =
      new LinkedHashMap<ImmutableBytesPtr, Table>();
  FakeTableFactory factory = new FakeTableFactory(tables);

  ImmutableBytesPtr tableName = new ImmutableBytesPtr(this.test.getTableName());
  Put m = new Put(row);
  m.addColumn(Bytes.toBytes("family"), Bytes.toBytes("qual"), null);
  Multimap<HTableInterfaceReference, Mutation> indexUpdates =
      ArrayListMultimap.<HTableInterfaceReference, Mutation> create();
  indexUpdates.put(new HTableInterfaceReference(tableName), m);

  Table table = Mockito.mock(Table.class);
  final boolean[] completed = new boolean[] { false };
      Mockito.doAnswer(new Answer<Void>() {
          @Override
          public Void answer(InvocationOnMock invocation) throws Throwable {
              // just keep track that it was called
              completed[0] = true;
              return null;
          }
      }).when(table).batch(Mockito.anyList(), Mockito.any());
      Mockito.when(table.getName()).thenReturn(org.apache.hadoop.hbase.TableName.valueOf(test.getTableName()));
  // add the table to the set of tables, so its returned to the writer
  tables.put(tableName, table);

  // setup the writer and failure policy
  TrackingParallelWriterIndexCommitter writer = new TrackingParallelWriterIndexCommitter(VersionInfo.getVersion());
  writer.setup(factory, exec, stop, e);
  writer.write(indexUpdates, true, ScanUtil.UNKNOWN_CLIENT_VERSION);
  assertTrue("Writer returned before the table batch completed! Likely a race condition tripped",
    completed[0]);
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
}
 
Example #30
Source File: HBaseStructureTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void stopHBase() {
    // Workaround for https://issues.apache.org/jira/browse/HBASE-10312
    if (VersionInfo.getVersion().startsWith("0.96"))
        HBaseStorageSetup.killIfRunning();
}