use of org.apache.hadoop.hbase.regionserver.RegionServerAccounting in project phoenix by apache.
the class WALReplayWithIndexWritesAndCompressedWALIT method testReplayEditsWrittenViaHRegion.
/**
* Test writing edits into an region, closing it, splitting logs, opening Region again. Verify
* seqids.
* @throws Exception on failure
*/
@SuppressWarnings("deprecation")
@Test
public void testReplayEditsWrittenViaHRegion() throws Exception {
final String tableNameStr = "testReplayEditsWrittenViaHRegion";
final HRegionInfo hri = new HRegionInfo(org.apache.hadoop.hbase.TableName.valueOf(tableNameStr), null, null, false);
final Path basedir = FSUtils.getTableDir(hbaseRootDir, org.apache.hadoop.hbase.TableName.valueOf(tableNameStr));
deleteDir(basedir);
final HTableDescriptor htd = createBasic3FamilyHTD(tableNameStr);
//setup basic indexing for the table
// enable indexing to a non-existant index table
byte[] family = new byte[] { 'a' };
ColumnGroup fam1 = new ColumnGroup(INDEX_TABLE_NAME);
fam1.add(new CoveredColumn(family, CoveredColumn.ALL_QUALIFIERS));
CoveredColumnIndexSpecifierBuilder builder = new CoveredColumnIndexSpecifierBuilder();
builder.addIndexGroup(fam1);
builder.build(htd);
// create the region + its WAL
// FIXME: Uses private type
HRegion region0 = HRegion.createHRegion(hri, hbaseRootDir, this.conf, htd);
region0.close();
region0.getWAL().close();
WALFactory walFactory = new WALFactory(this.conf, null, "localhost,1234");
WAL wal = createWAL(this.conf, walFactory);
RegionServerServices mockRS = Mockito.mock(RegionServerServices.class);
// mock out some of the internals of the RSS, so we can run CPs
when(mockRS.getWAL(null)).thenReturn(wal);
RegionServerAccounting rsa = Mockito.mock(RegionServerAccounting.class);
when(mockRS.getRegionServerAccounting()).thenReturn(rsa);
ServerName mockServerName = Mockito.mock(ServerName.class);
when(mockServerName.getServerName()).thenReturn(tableNameStr + ",1234");
when(mockRS.getServerName()).thenReturn(mockServerName);
HRegion region = spy(new HRegion(basedir, wal, this.fs, this.conf, hri, htd, mockRS));
region.initialize();
when(region.getSequenceId()).thenReturn(0l);
//make an attempted write to the primary that should also be indexed
byte[] rowkey = Bytes.toBytes("indexed_row_key");
Put p = new Put(rowkey);
p.add(family, Bytes.toBytes("qual"), Bytes.toBytes("value"));
region.put(p);
// we should then see the server go down
Mockito.verify(mockRS, Mockito.times(1)).abort(Mockito.anyString(), Mockito.any(Exception.class));
// then create the index table so we are successful on WAL replay
CoveredColumnIndexer.createIndexTable(UTIL.getHBaseAdmin(), INDEX_TABLE_NAME);
// run the WAL split and setup the region
runWALSplit(this.conf, walFactory);
WAL wal2 = createWAL(this.conf, walFactory);
HRegion region1 = new HRegion(basedir, wal2, this.fs, this.conf, hri, htd, mockRS);
// initialize the region - this should replay the WALEdits from the WAL
region1.initialize();
// now check to ensure that we wrote to the index table
HTable index = new HTable(UTIL.getConfiguration(), INDEX_TABLE_NAME);
int indexSize = getKeyValueCount(index);
assertEquals("Index wasn't propertly updated from WAL replay!", 1, indexSize);
Get g = new Get(rowkey);
final Result result = region1.get(g);
assertEquals("Primary region wasn't updated from WAL replay!", 1, result.size());
// cleanup the index table
HBaseAdmin admin = UTIL.getHBaseAdmin();
admin.disableTable(INDEX_TABLE_NAME);
admin.deleteTable(INDEX_TABLE_NAME);
admin.close();
}
Aggregations