/** * Enable a table, if existed. * * @param tableName name of table to enable * @throws IOException-if a remote or network exception occurs */ public void enableTable(TableName tableName) throws IOException { HTableDescriptor desc = admin.getTableDescriptor(tableName); if (isIndexTable(desc)) { throw new TableNotFoundException(tableName); } IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc); if (indexDesc.hasIndex()) { for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) { if (admin.tableExists(indexSpec.getIndexTableName())) { admin.enableTable(indexSpec.getIndexTableName()); } else { throw new IndexMissingException(tableName, indexSpec); } } } admin.enableTable(tableName); }
@Test(timeout=60000) public void testCreateTwiceWithSameNonce() throws Exception { final TableName tableName = TableName.valueOf("testCreateTwiceWithSameNonce"); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final HTableDescriptor htd = MasterProcedureTestingUtility.createHTD(tableName, "f"); final HRegionInfo[] regions = ModifyRegionUtils.createHRegionInfos(htd, null); // create the table long procId1 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); // create another with the same name long procId2 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); ProcedureTestingUtility.waitProcedure(procExec, procId1); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId1)); ProcedureTestingUtility.waitProcedure(procExec, procId2); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId2)); assertTrue(procId1 == procId2); }
protected void addEdits(WAL log, HRegionInfo hri, HTableDescriptor htd, int times, MultiVersionConcurrencyControl mvcc) throws IOException { final byte[] row = Bytes.toBytes("row"); for (int i = 0; i < times; i++) { long timestamp = System.currentTimeMillis(); WALEdit cols = new WALEdit(); cols.add(new KeyValue(row, row, row, timestamp, row)); WALKey key = new WALKey(hri.getEncodedNameAsBytes(), htd.getTableName(), WALKey.NO_SEQUENCE_ID, timestamp, WALKey.EMPTY_UUIDS, HConstants.NO_NONCE, HConstants.NO_NONCE, mvcc); log.append(htd, hri, key, cols, true); } log.sync(); }
private static void rewriteTableDescriptor(final FileSystem fs, final FileStatus status, final HTableDescriptor td) throws IOException { Path tableInfoDir = status.getPath().getParent(); Path tableDir = tableInfoDir.getParent(); writeTableDescriptor(fs, td, tableDir, status); }
Region initHRegion (TableName tableName, String callingMethod, Configuration conf, Class<?> [] implClasses, byte [][] families) throws IOException { HTableDescriptor htd = new HTableDescriptor(tableName); for(byte [] family : families) { htd.addFamily(new HColumnDescriptor(family)); } HRegionInfo info = new HRegionInfo(tableName, null, null, false); Path path = new Path(DIR + callingMethod); HRegion r = HRegion.createHRegion(info, path, conf, htd); // this following piece is a hack. RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf); r.setCoprocessorHost(host); for (Class<?> implClass : implClasses) { host.load(implClass, Coprocessor.PRIORITY_USER, conf); Coprocessor c = host.findCoprocessor(implClass.getName()); assertNotNull(c); } // Here we have to call pre and postOpen explicitly. host.preOpen(); host.postOpen(); return r; }
public ClientSideRegionScanner(Configuration conf, FileSystem fs, Path rootDir, HTableDescriptor htd, HRegionInfo hri, Scan scan, ScanMetrics scanMetrics) throws IOException { // region is immutable, set isolation level scan.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED); // open region from the snapshot directory this.region = HRegion.openHRegion(conf, fs, rootDir, hri, htd, null, null, null); // create an internal region scanner this.scanner = region.getScanner(scan); values = new ArrayList<Cell>(); if (scanMetrics == null) { initScanMetrics(scan); } else { this.scanMetrics = scanMetrics; } region.startRegionOperation(); }
private HRegion testRegionWithFamiliesAndSpecifiedTableName(TableName tableName, byte[]... families) throws IOException { HRegionInfo hRegionInfo = new HRegionInfo(tableName); HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName); for (byte[] family : families) { hTableDescriptor.addFamily(new HColumnDescriptor(family)); } // TODO We need a way to do this without creating files return HRegion.createHRegion(hRegionInfo, new Path(testFolder.newFolder().toURI()), conf, hTableDescriptor, log); }
/** * This is a special case hole -- when the first region of a table is * missing from META, HBase doesn't acknowledge the existance of the * table. */ @Override public void handleRegionStartKeyNotEmpty(HbckInfo next) throws IOException { errors.reportError(ERROR_CODE.FIRST_REGION_STARTKEY_NOT_EMPTY, "First region should start with an empty key. Creating a new " + "region and regioninfo in HDFS to plug the hole.", getTableInfo(), next); HTableDescriptor htd = getTableInfo().getHTD(); // from special EMPTY_START_ROW to next region's startKey HRegionInfo newRegion = new HRegionInfo(htd.getTableName(), HConstants.EMPTY_START_ROW, next.getStartKey()); // TODO test HRegion region = HBaseFsckRepair.createHDFSRegionDir(conf, newRegion, htd); LOG.info("Table region start key was not empty. Created new empty region: " + newRegion + " " +region); fixes++; }
public void initialize(InputSplit split, Configuration conf) throws IOException { this.scan = TableMapReduceUtil.convertStringToScan(split.getScan()); this.split = split; HTableDescriptor htd = split.htd; HRegionInfo hri = this.split.getRegionInfo(); FileSystem fs = FSUtils.getCurrentFileSystem(conf); // region is immutable, this should be fine, // otherwise we have to set the thread read point scan.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED); // disable caching of data blocks scan.setCacheBlocks(false); scanner = new ClientSideRegionScanner(conf, fs, new Path(split.restoreDir), htd, hri, scan, null); }
public static void generateHBaseDatasetNullStr(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception { if (admin.tableExists(tableName)) { admin.disableTable(tableName); admin.deleteTable(tableName); } HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor("f")); if (numberRegions > 1) { admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1)); } else { admin.createTable(desc); } BufferedMutator table = conn.getBufferedMutator(tableName); Put p = new Put("a1".getBytes()); p.addColumn("f".getBytes(), "c1".getBytes(), "".getBytes()); p.addColumn("f".getBytes(), "c2".getBytes(), "".getBytes()); p.addColumn("f".getBytes(), "c3".getBytes(), "5".getBytes()); p.addColumn("f".getBytes(), "c4".getBytes(), "".getBytes()); table.mutate(p); table.close(); }
@Test public void shouldBulkLoadSingleFamilyHLog() throws IOException { when(log.append(any(HTableDescriptor.class), any(HRegionInfo.class), any(WALKey.class), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)), any(boolean.class))).thenAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { WALKey walKey = invocation.getArgumentAt(2, WALKey.class); MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); if (mvcc != null) { MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); walKey.setWriteEntry(we); } return 01L; }; }); testRegionWithFamilies(family1).bulkLoadHFiles(withFamilyPathsFor(family1), false, null); verify(log).sync(anyLong()); }
public TestScanRow() throws IOException, InterruptedException { Configuration config = HBaseConfiguration.create(); Connection connection = ConnectionFactory.createConnection(config); familyName = config.get("hbase.client.tablestore.family"); columnName = "col_1"; columnValue = "col_1_var"; TableName tableName = TableName.valueOf(config.get("hbase.client.tablestore.table")); if (!connection.getAdmin().tableExists(tableName)) { HTableDescriptor descriptor = new HTableDescriptor(tableName); connection.getAdmin().createTable(descriptor); TimeUnit.SECONDS.sleep(1); } table = connection.getTable(tableName); }
private static long writeMarker(final WAL wal, final HTableDescriptor htd, final HRegionInfo hri, final WALEdit edit, final MultiVersionConcurrencyControl mvcc, final boolean sync) throws IOException { // TODO: Pass in current time to use? WALKey key = new HLogKey(hri.getEncodedNameAsBytes(), hri.getTable(), System.currentTimeMillis(), mvcc); // Add it to the log but the false specifies that we don't need to add it to the memstore long trx = MultiVersionConcurrencyControl.NONE; try { trx = wal.append(htd, hri, key, edit, false); if (sync) wal.sync(trx); } finally { // If you get hung here, is it a real WAL or a mocked WAL? If the latter, you need to // trip the latch that is inside in getWriteEntry up in your mock. See down in the append // called from onEvent in FSHLog. MultiVersionConcurrencyControl.WriteEntry we = key.getWriteEntry(); if (mvcc != null && we != null) mvcc.complete(we); } return trx; }
@Test(timeout = 300000) public void testDisableTableAndRestart() throws Exception { final TableName tableName = TableName.valueOf("testDisableTableAndRestart"); final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); final HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); final HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(FAMILYNAME)); admin.createTable(desc); admin.disableTable(tableName); TEST_UTIL.waitTableDisabled(tableName.getName()); TEST_UTIL.getHBaseCluster().shutdown(); TEST_UTIL.getHBaseCluster().waitUntilShutDown(); TEST_UTIL.restartHBaseCluster(2); admin.enableTable(tableName); TEST_UTIL.waitTableEnabled(tableName); }
public static Class<? extends RegionSplitPolicy> getSplitPolicyClass( HTableDescriptor htd, Configuration conf) throws IOException { String className = htd.getRegionSplitPolicyClassName(); if (className == null) { className = conf.get(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, DEFAULT_SPLIT_POLICY_CLASS.getName()); } try { Class<? extends RegionSplitPolicy> clazz = Class.forName(className).asSubclass(RegionSplitPolicy.class); return clazz; } catch (Exception e) { throw new IOException( "Unable to load configured region split policy '" + className + "' for table '" + htd.getTableName() + "'", e); } }
/** * Creates a table with given table name and specified number of column * families if the table does not already exist. */ private void setupTable(final Connection connection, TableName table, int cfs) throws IOException { try { LOG.info("Creating table " + table); HTableDescriptor htd = new HTableDescriptor(table); for (int i = 0; i < cfs; i++) { htd.addFamily(new HColumnDescriptor(family(i))); } try (Admin admin = connection.getAdmin()) { admin.createTable(htd); } } catch (TableExistsException tee) { LOG.info("Table " + table + " already exists"); } }
public static HRegionInfo[] createHRegionInfos(HTableDescriptor hTableDescriptor, byte[][] splitKeys) { long regionId = System.currentTimeMillis(); HRegionInfo[] hRegionInfos = null; if (splitKeys == null || splitKeys.length == 0) { hRegionInfos = new HRegionInfo[]{ new HRegionInfo(hTableDescriptor.getTableName(), null, null, false, regionId) }; } else { int numRegions = splitKeys.length + 1; hRegionInfos = new HRegionInfo[numRegions]; byte[] startKey = null; byte[] endKey = null; for (int i = 0; i < numRegions; i++) { endKey = (i == splitKeys.length) ? null : splitKeys[i]; hRegionInfos[i] = new HRegionInfo(hTableDescriptor.getTableName(), startKey, endKey, false, regionId); startKey = endKey; } } return hRegionInfos; }
@Override public int runTestFromCommandLine() throws Exception { IntegrationTestingUtility.setUseDistributedCluster(getConf()); int numPresplits = getConf().getInt("loadmapper.numPresplits", 5); // create HTableDescriptor for specified table HTableDescriptor htd = new HTableDescriptor(getTablename()); htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); Admin admin = new HBaseAdmin(getConf()); try { admin.createTable(htd, Bytes.toBytes(0L), Bytes.toBytes(-1L), numPresplits); } finally { admin.close(); } doLoad(getConf(), htd); doVerify(getConf(), htd); getTestingUtil(getConf()).deleteTable(htd.getName()); return 0; }
private void addWALEdits(final TableName tableName, final HRegionInfo hri, final byte[] rowName, final byte[] family, final int count, EnvironmentEdge ee, final WAL wal, final HTableDescriptor htd, final MultiVersionConcurrencyControl mvcc) throws IOException { String familyStr = Bytes.toString(family); long txid = -1; for (int j = 0; j < count; j++) { byte[] qualifierBytes = Bytes.toBytes(Integer.toString(j)); byte[] columnBytes = Bytes.toBytes(familyStr + ":" + Integer.toString(j)); WALEdit edit = new WALEdit(); edit.add(new KeyValue(rowName, family, qualifierBytes, ee.currentTime(), columnBytes)); // uses WALKey instead of HLogKey on purpose. will only work for tests where we don't care // about legacy coprocessors txid = wal.append(htd, hri, new WALKey(hri.getEncodedNameAsBytes(), tableName, ee.currentTime(), mvcc), edit, true); } if (-1 != txid) { wal.sync(txid); } }
@Test public void shouldBulkLoadManyFamilyHLog() throws IOException { when(log.append(any(HTableDescriptor.class), any(HRegionInfo.class), any(WALKey.class), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)), any(boolean.class))).thenAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { WALKey walKey = invocation.getArgumentAt(2, WALKey.class); MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); if (mvcc != null) { MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); walKey.setWriteEntry(we); } return 01L; }; }); testRegionWithFamilies(family1, family2).bulkLoadHFiles(withFamilyPathsFor(family1, family2), false, null); verify(log).sync(anyLong()); }
/** * Disable a table, if existed. * * @param tableName name of table to disable * @throws IOException-if a remote or network exception occurs */ public void disableTable(TableName tableName) throws IOException { HTableDescriptor desc = admin.getTableDescriptor(tableName); if (isIndexTable(desc)) { throw new TableNotFoundException(tableName); } IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc); if (indexDesc.hasIndex()) { for (IndexSpecification indexSpec : indexDesc.getIndexSpecifications()) { if (admin.tableExists(indexSpec.getIndexTableName())) { admin.disableTable(indexSpec.getIndexTableName()); } else { throw new IndexMissingException(tableName, indexSpec); } } } admin.disableTable(tableName); }
/** * Callers must afterward call {@link HRegion#closeHRegion(HRegion)} * @param tableName * @param callingMethod * @param conf * @param family * @throws IOException * @return created and initialized region. */ private HRegion initHRegion(byte[] tableName, String callingMethod, HBaseConfiguration conf, String family) throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName)); HColumnDescriptor familyDesc; for (int i = 0; i < BLOOM_TYPE.length; i++) { BloomType bloomType = BLOOM_TYPE[i]; familyDesc = new HColumnDescriptor(family + "_" + bloomType) .setBlocksize(1) .setBloomFilterType(BLOOM_TYPE[i]); htd.addFamily(familyDesc); } HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); Path path = new Path(DIR + callingMethod); HRegion r = HRegion.createHRegion(info, path, conf, htd); blockCache = new CacheConfig(conf).getBlockCache(); return r; }
@Override public void deserializeStateData(final InputStream stream) throws IOException { super.deserializeStateData(stream); MasterProcedureProtos.CreateTableStateData state = MasterProcedureProtos.CreateTableStateData.parseDelimitedFrom(stream); user = MasterProcedureUtil.toUserInfo(state.getUserInfo()); hTableDescriptor = HTableDescriptor.convert(state.getTableSchema()); if (state.getRegionInfoCount() == 0) { newRegions = null; } else { newRegions = new ArrayList<HRegionInfo>(state.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) { newRegions.add(HRegionInfo.convert(hri)); } } }
private void runCoprocessorConnectionToRemoteTable(Class<? extends BaseRegionObserver> clazz, boolean[] completeCheck) throws Throwable { HTableDescriptor primary = new HTableDescriptor(primaryTable); primary.addFamily(new HColumnDescriptor(family)); // add our coprocessor primary.addCoprocessor(clazz.getName()); HTableDescriptor other = new HTableDescriptor(otherTable); other.addFamily(new HColumnDescriptor(family)); Admin admin = UTIL.getHBaseAdmin(); admin.createTable(primary); admin.createTable(other); Table table = new HTable(UTIL.getConfiguration(), TableName.valueOf("primary")); Put p = new Put(new byte[] { 'a' }); p.add(family, null, new byte[] { 'a' }); table.put(p); table.close(); Table target = new HTable(UTIL.getConfiguration(), otherTable); assertTrue("Didn't complete update to target table!", completeCheck[0]); assertEquals("Didn't find inserted row", 1, getKeyValueCount(target)); target.close(); }
/** * @param services Master services instance. * @param htd * @param parent * @param daughter * @param midkey * @param top True if we are to write a 'top' reference. * @return Path to reference we created. * @throws IOException */ private Path createReferences(final MasterServices services, final HTableDescriptor htd, final HRegionInfo parent, final HRegionInfo daughter, final byte [] midkey, final boolean top) throws IOException { Path rootdir = services.getMasterFileSystem().getRootDir(); Path tabledir = FSUtils.getTableDir(rootdir, parent.getTable()); Path storedir = HStore.getStoreHomedir(tabledir, daughter, htd.getColumnFamilies()[0].getName()); Reference ref = top? Reference.createTopReference(midkey): Reference.createBottomReference(midkey); long now = System.currentTimeMillis(); // Reference name has this format: StoreFile#REF_NAME_PARSER Path p = new Path(storedir, Long.toString(now) + "." + parent.getEncodedName()); FileSystem fs = services.getMasterFileSystem().getFileSystem(); ref.write(fs, p); return p; }
@Before public void setupMocks() { conf = HBaseConfiguration.create(); HRegionInfo hri = new HRegionInfo(TABLENAME); htd = new HTableDescriptor(TABLENAME); mockRegion = Mockito.mock(HRegion.class); Mockito.doReturn(htd).when(mockRegion).getTableDesc(); Mockito.doReturn(hri).when(mockRegion).getRegionInfo(); stores = new ArrayList<Store>(); Mockito.doReturn(stores).when(mockRegion).getStores(); }
@Before public void setUp() throws Exception { TableName tableName = TableName.valueOf(getClass().getSimpleName()); HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(fam).setDataBlockEncoding(DataBlockEncoding.PREFIX_TREE)); HRegionInfo info = new HRegionInfo(tableName, null, null, false); Path path = testUtil.getDataTestDir(getClass().getSimpleName()); region = HRegion.createHRegion(info, path, testUtil.getConfiguration(), htd); }
private HTableDescriptor getTableSchema() throws IOException, TableNotFoundException { Table table = servlet.getTable(tableResource.getName()); try { return table.getTableDescriptor(); } finally { table.close(); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); Admin admin = TEST_UTIL.getHBaseAdmin(); if (admin.tableExists(TABLE)) { return; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); admin.createTable(htd); }
@Override public HTableDescriptor getDesc() { final HTableDescriptor desc = new HTableDescriptor(getName()); final HColumnDescriptor colDesc = new HColumnDescriptor(NAME_FAMILY); colDesc.setMaxVersions(1); desc.addFamily(colDesc); return desc; }
@Override public HTableDescriptor getDesc() { final HTableDescriptor desc = new HTableDescriptor(getName()); final HColumnDescriptor colDesc = new HColumnDescriptor(ID_FAMILY); colDesc.setMaxVersions(1); desc.addFamily(colDesc); return desc; }
@BeforeClass public static void beforeClass() throws Exception { Configuration conf = HTU.getConfiguration(); conf.setBoolean(HConstants.REPLICATION_ENABLE_KEY, true); conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_CONF_KEY, true); conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_WAIT_FOR_PRIMARY_FLUSH_CONF_KEY, false); // install WALObserver coprocessor for tests String walCoprocs = HTU.getConfiguration().get(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY); if (walCoprocs == null) { walCoprocs = WALEditCopro.class.getName(); } else { walCoprocs += "," + WALEditCopro.class.getName(); } HTU.getConfiguration().set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, walCoprocs); HTU.startMiniCluster(NB_SERVERS); // Create table then get the single region for our new table. HTableDescriptor htd = HTU.createTableDescriptor(tableName.toString()); table = HTU.createTable(htd, new byte[][]{f}, HTU.getConfiguration()); hriPrimary = table.getRegionLocation(row, false).getRegionInfo(); // mock a secondary region info to open hriSecondary = new HRegionInfo(hriPrimary.getTable(), hriPrimary.getStartKey(), hriPrimary.getEndKey(), hriPrimary.isSplit(), hriPrimary.getRegionId(), 1); // No master TestRegionServerNoMaster.stopMasterAndAssignMeta(HTU); rs0 = HTU.getMiniHBaseCluster().getRegionServer(0); rs1 = HTU.getMiniHBaseCluster().getRegionServer(1); }
public CreateTableProcedure(final MasterProcedureEnv env, final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions, final ProcedurePrepareLatch syncLatch) throws IOException { this.hTableDescriptor = hTableDescriptor; this.newRegions = newRegions != null ? Lists.newArrayList(newRegions) : null; this.user = env.getRequestUser().getUGI(); this.setOwner(this.user.getShortUserName()); // used for compatibility with clients without procedures // they need a sync TableExistsException this.syncLatch = syncLatch; }
/** * Test that region state transition call is idempotent */ @Test(timeout = 60000) public void testReportRegionStateTransition() throws Exception { String table = "testReportRegionStateTransition"; try { MyRegionServer.simulateRetry = true; HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(table)); desc.addFamily(new HColumnDescriptor(FAMILY)); admin.createTable(desc); Table meta = new HTable(conf, TableName.META_TABLE_NAME); HRegionInfo hri = new HRegionInfo(desc.getTableName(), Bytes.toBytes("A"), Bytes.toBytes("Z")); MetaTableAccessor.addRegionToMeta(meta, hri); HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); master.assignRegion(hri); AssignmentManager am = master.getAssignmentManager(); am.waitForAssignment(hri); RegionStates regionStates = am.getRegionStates(); ServerName serverName = regionStates.getRegionServerOfRegion(hri); // Assert the the region is actually open on the server TEST_UTIL.assertRegionOnServer(hri, serverName, 6000); // Closing region should just work fine admin.disableTable(TableName.valueOf(table)); assertTrue(regionStates.isRegionOffline(hri)); List<HRegionInfo> regions = TEST_UTIL.getHBaseAdmin().getOnlineRegions(serverName); assertTrue(!regions.contains(hri)); } finally { MyRegionServer.simulateRetry = false; TEST_UTIL.deleteTable(Bytes.toBytes(table)); } }
public static void generateHBaseDatasetIntOB(HBaseAdmin admin, String tableName, int numberRegions) throws Exception { if (admin.tableExists(tableName)) { admin.disableTable(tableName); admin.deleteTable(tableName); } HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(FAMILY_F)); if (numberRegions > 1) { admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1)); } else { admin.createTable(desc); } HTable table = new HTable(admin.getConfiguration(), tableName); for (int i = -49; i <= 100; i ++) { byte[] bytes = new byte[5]; org.apache.hadoop.hbase.util.PositionedByteRange br = new org.apache.hadoop.hbase.util.SimplePositionedByteRange(bytes, 0, 5); org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, i, org.apache.hadoop.hbase.util.Order.ASCENDING); Put p = new Put(bytes); p.add(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes()); table.put(p); } table.flushCommits(); table.close(); admin.flush(tableName); }
@Test (timeout=300000) public void testCreateTableWithOnlyEmptyStartRow() throws IOException { byte[] tableName = Bytes.toBytes("testCreateTableWithOnlyEmptyStartRow"); byte[][] splitKeys = new byte[1][]; splitKeys[0] = HConstants.EMPTY_BYTE_ARRAY; HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor("col")); try { admin.createTable(desc, splitKeys); fail("Test case should fail as empty split key is passed."); } catch (IllegalArgumentException e) { } }
public static void generateHBaseDatasetFloatOBDesc(HBaseAdmin admin, String tableName, int numberRegions) throws Exception { if (admin.tableExists(tableName)) { admin.disableTable(tableName); admin.deleteTable(tableName); } HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(FAMILY_F)); if (numberRegions > 1) { admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1)); } else { admin.createTable(desc); } HTable table = new HTable(admin.getConfiguration(), tableName); for (float i = (float)0.5; i <= 100.00; i += 0.75) { byte[] bytes = new byte[5]; org.apache.hadoop.hbase.util.PositionedByteRange br = new org.apache.hadoop.hbase.util.SimplePositionedByteRange(bytes, 0, 5); org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, i, org.apache.hadoop.hbase.util.Order.DESCENDING); Put p = new Put(bytes); p.add(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes()); table.put(p); } table.flushCommits(); table.close(); admin.flush(tableName); }
public CloneSnapshotHandler(final MasterServices masterServices, final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) { super(masterServices, masterServices.getMasterFileSystem(), hTableDescriptor, masterServices.getConfiguration(), null, masterServices); // Snapshot information this.snapshot = snapshot; // Monitor this.monitor = new ForeignExceptionDispatcher(); this.status = TaskMonitor.get().createStatus("Cloning snapshot '" + snapshot.getName() + "' to table " + hTableDescriptor.getTableName()); }
public static void generateHBaseDatasetIntOBDesc(HBaseAdmin admin, String tableName, int numberRegions) throws Exception { if (admin.tableExists(tableName)) { admin.disableTable(tableName); admin.deleteTable(tableName); } HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(FAMILY_F)); if (numberRegions > 1) { admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1)); } else { admin.createTable(desc); } HTable table = new HTable(admin.getConfiguration(), tableName); for (int i = -49; i <= 100; i ++) { byte[] bytes = new byte[5]; org.apache.hadoop.hbase.util.PositionedByteRange br = new org.apache.hadoop.hbase.util.SimplePositionedByteRange(bytes, 0, 5); org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, i, org.apache.hadoop.hbase.util.Order.DESCENDING); Put p = new Put(bytes); p.add(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes()); table.put(p); } table.flushCommits(); table.close(); admin.flush(tableName); }
/** * Check that the table descriptor for the snapshot is a valid table descriptor * @param manifest snapshot manifest to inspect */ private void verifyTableInfo(final SnapshotManifest manifest) throws IOException { HTableDescriptor htd = manifest.getTableDescriptor(); if (htd == null) { throw new CorruptedSnapshotException("Missing Table Descriptor", snapshot); } if (!htd.getNameAsString().equals(snapshot.getTable())) { throw new CorruptedSnapshotException("Invalid Table Descriptor. Expected " + snapshot.getTable() + " name, got " + htd.getNameAsString(), snapshot); } }