Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ public void append(TableName tableName, byte[] encodedRegionName, byte[] row,
// keep going to the cache, we will not learn of the replicas and their locations after
// they come online.
if (useCache && locations.size() == 1 && TableName.isMetaTableName(tableName)) {
if (tableDescriptors.get(tableName).getRegionReplication() > 1) {
TableDescriptor td = tableDescriptors.get(tableName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just noticed a few additional concerns after approving
I found the issue doesn't seem to exist for branch-2.5.
The code is only executed when seCache && locations.size() == 1 && TableName.isMetaTableName(tableName) is true, whch means that it's meta table, and the td of meta table is not null in here . right ? @krconv

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see; agreed it doesn't seem to apply here. Thank you for finding that! I'll close this.

if (td != null && td.getRegionReplication() > 1) {
// Make an obnoxious log here. See how bad this issue is. Add a timer if happening
// too much.
LOG.info("Skipping location cache; only one location found for {}", tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -42,7 +46,9 @@
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.RegionLocations;
import org.apache.hadoop.hbase.ReplicationPeerNotFoundException;
import org.apache.hadoop.hbase.TableDescriptors;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.client.Admin;
Expand Down Expand Up @@ -507,6 +513,59 @@ public void testRegionReplicaReplicationIgnores(boolean dropTable, boolean disab
}
}

@Test
public void testNullTableDescriptorDoesNotCauseNPE() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
int regionReplication = 2;
HTableDescriptor htd = HTU.createTableDescriptor(tableName);
htd.setRegionReplication(regionReplication);
createOrEnableTableWithRetries(htd, true);

Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
Table table = connection.getTable(tableName);

try {
HTU.loadNumericRows(table, HBaseTestingUtility.fam1, 0, 100);

RegionLocator rl = connection.getRegionLocator(tableName);
HRegionLocation hrl = rl.getRegionLocation(HConstants.EMPTY_BYTE_ARRAY);
byte[] encodedRegionName = hrl.getRegionInfo().getEncodedNameAsBytes();
rl.close();

AtomicLong skippedEdits = new AtomicLong();
RegionReplicaReplicationEndpoint.RegionReplicaOutputSink sink =
mock(RegionReplicaReplicationEndpoint.RegionReplicaOutputSink.class);
when(sink.getSkippedEditsCounter()).thenReturn(skippedEdits);

TableDescriptors mockTableDescriptors = mock(TableDescriptors.class);
when(mockTableDescriptors.get(tableName)).thenReturn(null);

RegionLocations singleLocation = new RegionLocations(hrl);
ClusterConnection mockConnection = mock(ClusterConnection.class);
when(mockConnection.locateRegion(eq(tableName), any(byte[].class), anyBoolean(), anyBoolean(),
anyInt())).thenReturn(singleLocation);
when(mockConnection.getConfiguration()).thenReturn(HTU.getConfiguration());

RegionReplicaReplicationEndpoint.RegionReplicaSinkWriter sinkWriter =
new RegionReplicaReplicationEndpoint.RegionReplicaSinkWriter(sink, mockConnection,
Executors.newSingleThreadExecutor(), Integer.MAX_VALUE, mockTableDescriptors);

Cell cell = CellBuilderFactory.create(CellBuilderType.DEEP_COPY)
.setRow(Bytes.toBytes("testRow")).setFamily(HBaseTestingUtility.fam1)
.setValue(Bytes.toBytes("testValue")).setType(Type.Put).build();

Entry entry =
new Entry(new WALKeyImpl(encodedRegionName, tableName, 1), new WALEdit().add(cell));

sinkWriter.append(tableName, encodedRegionName, Bytes.toBytes("testRow"),
Lists.newArrayList(entry));

} finally {
table.close();
connection.close();
}
}

private void createOrEnableTableWithRetries(TableDescriptor htd, boolean createTableOperation) {
// Helper function to run create/enable table operations with a retry feature
boolean continueToRetry = true;
Expand Down