Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1k
PHOENIX-6472 In case of region inconsistency phoenix should stop grac…#1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -81,6 +81,7 @@ | ||
| import java.io.IOException; | ||
| import java.lang.management.ManagementFactory; | ||
| import java.lang.ref.WeakReference; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSetMetaData; | ||
| import java.sql.SQLException; | ||
| @@ -648,6 +649,20 @@ public void clearTableRegionCache(byte[] tableName) throws SQLException { | ||
| connection.clearRegionCache(TableName.valueOf(tableName)); | ||
| } | ||
| public byte[] getNextRegionStartKey(HRegionLocation regionLocation, byte[] currentKey) throws IOException { | ||
| // in order to check the overlap/inconsistencies bad region info, we have to make sure | ||
| // the current endKey always increasing(compare the previous endKey) | ||
| if (Bytes.compareTo(regionLocation.getRegionInfo().getEndKey(), currentKey) <= 0 | ||
| && !Bytes.equals(currentKey, HConstants.EMPTY_START_ROW) | ||
| && !Bytes.equals(regionLocation.getRegionInfo().getEndKey(), HConstants.EMPTY_END_ROW)) { | ||
| String regionNameString = | ||
| new String(regionLocation.getRegionInfo().getRegionName(), StandardCharsets.UTF_8); | ||
| throw new IOException(String.format( | ||
| "HBase region information overlap/inconsistencies on region %s", regionNameString)); | ||
| } | ||
| return regionLocation.getRegionInfo().getEndKey(); | ||
| } | ||
| @Override | ||
| public List<HRegionLocation> getAllTableRegions(byte[] tableName) throws SQLException { | ||
| /* | ||
| @@ -666,8 +681,8 @@ public List<HRegionLocation> getAllTableRegions(byte[] tableName) throws SQLExce | ||
| do { | ||
| HRegionLocation regionLocation = connection.getRegionLocation( | ||
| TableName.valueOf(tableName), currentKey, reload); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this is the reason that we need to make sure the end key always increasing. | ||
| currentKey = getNextRegionStartKey(regionLocation, currentKey); | ||
| locations.add(regionLocation); | ||
| currentKey = regionLocation.getRegionInfo().getEndKey(); | ||
| } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW)); | ||
| return locations; | ||
| } catch (org.apache.hadoop.hbase.TableNotFoundException e) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -46,6 +46,8 @@ | ||
| import org.apache.hadoop.hbase.HColumnDescriptor; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.HTableDescriptor; | ||
| import org.apache.hadoop.hbase.HRegionInfo; | ||
| import org.apache.hadoop.hbase.HRegionLocation; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.TableNotFoundException; | ||
| import org.apache.hadoop.hbase.client.ClusterConnection; | ||
| @@ -157,6 +159,63 @@ public void testExceptionHandlingOnSystemNamespaceCreation() throws Exception { | ||
| } | ||
| } | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe one more test for the start/end keys. | ||
| @Test | ||
| public void testGetNextRegionStartKey() { | ||
| HRegionInfo mockHRegionInfo = org.mockito.Mockito.mock(HRegionInfo.class); | ||
| HRegionLocation mockRegionLocation = org.mockito.Mockito.mock(HRegionLocation.class); | ||
| ConnectionQueryServicesImpl mockCqsi = org.mockito.Mockito.mock(ConnectionQueryServicesImpl.class, | ||
| org.mockito.Mockito.CALLS_REAL_METHODS); | ||
| byte[] corruptedStartAndEndKey = "0x3000".getBytes(); | ||
| byte[] corruptedDecreasingKey = "0x2999".getBytes(); | ||
| byte[] notCorruptedStartKey = "0x2999".getBytes(); | ||
| byte[] notCorruptedEndKey = "0x3000".getBytes(); | ||
| byte[] notCorruptedNewKey = "0x3001".getBytes(); | ||
| byte[] mockTableName = "dummyTable".getBytes(); | ||
| when(mockRegionLocation.getRegionInfo()).thenReturn(mockHRegionInfo); | ||
| when(mockHRegionInfo.getRegionName()).thenReturn(mockTableName); | ||
| // comparing the current regionInfo endKey is equal to the previous endKey | ||
| // [0x3000, Ox3000) vs 0x3000 | ||
| when(mockHRegionInfo.getStartKey()).thenReturn(corruptedStartAndEndKey); | ||
| when(mockHRegionInfo.getEndKey()).thenReturn(corruptedStartAndEndKey); | ||
| testGetNextRegionStartKey(mockCqsi, mockRegionLocation, corruptedStartAndEndKey, true); | ||
| // comparing the current regionInfo endKey is less than previous endKey | ||
| // [0x3000,0x2999) vs 0x3000 | ||
| when(mockHRegionInfo.getStartKey()).thenReturn(corruptedStartAndEndKey); | ||
| when(mockHRegionInfo.getEndKey()).thenReturn(corruptedDecreasingKey); | ||
| testGetNextRegionStartKey(mockCqsi, mockRegionLocation, corruptedStartAndEndKey, true); | ||
| // comparing the current regionInfo endKey is greater than the previous endKey | ||
| // [0x3000,0x3000) vs 0x3001 | ||
| when(mockHRegionInfo.getStartKey()).thenReturn(notCorruptedStartKey); | ||
| when(mockHRegionInfo.getEndKey()).thenReturn(notCorruptedNewKey); | ||
| testGetNextRegionStartKey(mockCqsi, mockRegionLocation, notCorruptedEndKey, false); | ||
| // test EMPTY_START_ROW | ||
| when(mockHRegionInfo.getStartKey()).thenReturn(HConstants.EMPTY_START_ROW); | ||
| when(mockHRegionInfo.getEndKey()).thenReturn(notCorruptedEndKey); | ||
| testGetNextRegionStartKey(mockCqsi, mockRegionLocation, HConstants.EMPTY_START_ROW, false); | ||
| //test EMPTY_END_ROW | ||
| when(mockHRegionInfo.getStartKey()).thenReturn(notCorruptedStartKey); | ||
| when(mockHRegionInfo.getEndKey()).thenReturn(HConstants.EMPTY_END_ROW); | ||
| testGetNextRegionStartKey(mockCqsi, mockRegionLocation, notCorruptedStartKey, false); | ||
| } | ||
| private void testGetNextRegionStartKey(ConnectionQueryServicesImpl mockCqsi, | ||
| HRegionLocation mockRegionLocation, byte[] key, boolean isCorrupted) { | ||
| try { | ||
| mockCqsi.getNextRegionStartKey(mockRegionLocation, key); | ||
| if (isCorrupted) { | ||
| fail(); | ||
| } | ||
| } catch (IOException e) { | ||
| if (!isCorrupted) { | ||
| fail(); | ||
| } | ||
| } | ||
| } | ||
| @Test | ||
| public void testSysMutexCheckReturnsFalseWhenTableAbsent() throws Exception { | ||
| // Override the getTableDescriptor() call to throw instead | ||
Uh oh!
There was an error while loading. Please reload this page.