Skip to content

Commit e552174

Browse files
committed
Merge remote-tracking branch 'upstream/hbase_compat_3_2.0' into hbase_compat_3_2.0_enable_disable
2 parents 701c1e9 + fead4db commit e552174

File tree

11 files changed

+1351
-142
lines changed

11 files changed

+1351
-142
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,8 @@ private ObTableQuery buildObTableQuery(ObHTableFilter filter, final Scan scan) {
19481948
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE));
19491949
obTableQuery.setObKVParams(buildOBKVParams(scan));
19501950
obTableQuery.setScanRangeColumns("K", "Q", "T");
1951+
byte[] hotOnly = scan.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
1952+
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
19511953
return obTableQuery;
19521954
}
19531955

@@ -1965,6 +1967,8 @@ private ObTableQuery buildObTableQuery(final Get get, Collection<byte[]> columnQ
19651967
}
19661968
obTableQuery.setObKVParams(buildOBKVParams(get));
19671969
obTableQuery.setScanRangeColumns("K", "Q", "T");
1970+
byte[] hotOnly = get.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
1971+
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
19681972
return obTableQuery;
19691973
}
19701974

src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
public final class OHConstants {
2424

2525
/**
26-
* ocenbase hbase root server http url
26+
* oceanbase hbase root server http url
2727
*/
2828
public static final String HBASE_OCEANBASE_PARAM_URL = "hbase.oceanbase.paramURL";
2929

3030
/**
31-
* ocenbase hbase connect server username
31+
* oceanbase hbase connect server username
3232
*/
3333
public static final String HBASE_OCEANBASE_FULL_USER_NAME = "hbase.oceanbase.fullUserName";
3434

3535
/**
36-
* ocenbase hbase connect server password
36+
* oceanbase hbase connect server password
3737
*/
3838
public static final String HBASE_OCEANBASE_PASSWORD = "hbase.oceanbase.password";
3939

@@ -48,39 +48,39 @@ public final class OHConstants {
4848
public static final String HBASE_OCEANBASE_SYS_PASSWORD = "hbase.oceanbase.sysPassword";
4949

5050
/**
51-
* ocenbase hbase connect server password
51+
* oceanbase hbase connect server password
5252
*/
5353
public static final String HBASE_OCEANBASE_BATCH_EXECUTOR = "hbase.oceanbase.batch.executor";
5454

5555
/**
56-
* ocenbase hbase connect server ODP address
56+
* oceanbase hbase connect server ODP address
5757
*/
5858
public static final String HBASE_OCEANBASE_ODP_ADDR = "hbase.oceanbase.odpAddr";
5959

6060
/**
61-
* ocenbase hbase connect server ODP port
61+
* oceanbase hbase connect server ODP port
6262
*/
6363
public static final String HBASE_OCEANBASE_ODP_PORT = "hbase.oceanbase.odpPort";
6464

6565
/**
66-
* ocenbase hbase connect server ODP mode
66+
* oceanbase hbase connect server ODP mode
6767
*/
6868
public static final String HBASE_OCEANBASE_ODP_MODE = "hbase.oceanbase.odpMode";
6969

7070
/**
71-
* ocenbase hbase connect server database
71+
* oceanbase hbase connect server database
7272
*/
7373
public static final String HBASE_OCEANBASE_DATABASE = "hbase.oceanbase.database";
7474

7575
/**
76-
* ocenbase hbase model rowkey column is consist of following column
76+
* oceanbase hbase model rowkey column is consist of following column
7777
* K, Q, T hbase value
7878
*/
7979
public static final String[] ROW_KEY_COLUMNS = new String[] { "K",
8080
"Q", "T" };
8181

8282
/**
83-
* ocenbase hbase model value column is consist of following column
83+
* oceanbase hbase model value column is consist of following column
8484
* V hbase value
8585
*/
8686
public static final String[] V_COLUMNS = new String[] { "V" };
@@ -124,6 +124,11 @@ public final class OHConstants {
124124
*/
125125
public static final String DEFAULT_HBASE_HTABLE_TEST_LOAD_SUFFIX = "_t";
126126

127+
/**
128+
* use to specify whether to query only the data in hot storage when performing a query.
129+
*/
130+
public static final String HBASE_HTABLE_QUERY_HOT_ONLY = "hbase.htable.query.hot_only";
131+
127132
/*-------------------------------------------------------------------------------------------------------------*/
128133

129134
/**

src/main/java/com/alipay/oceanbase/hbase/util/OHAdmin.java

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,20 @@ public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundEx
170170

171171
@Override
172172
public void createTable(TableDescriptor tableDescriptor) throws IOException {
173-
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
174-
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableDescriptor.getTableName(), connectionConf);
175-
OHCreateTableExecutor executor = new OHCreateTableExecutor(tableClient);
176-
try {
177-
executor.createTable(tableDescriptor, null);
178-
} catch (IOException e) {
179-
if (e.getCause() instanceof ObTableTransportException
180-
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
181-
throw new TimeoutIOException(e.getCause());
182-
} else {
183-
throw e;
184-
}
185-
}
173+
throw new FeatureNotSupportedException("does not support yet");
174+
// OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
175+
// ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableDescriptor.getTableName(), connectionConf);
176+
// OHCreateTableExecutor executor = new OHCreateTableExecutor(tableClient);
177+
// try {
178+
// executor.createTable(tableDescriptor, null);
179+
// } catch (IOException e) {
180+
// if (e.getCause() instanceof ObTableTransportException
181+
// && ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
182+
// throw new TimeoutIOException(e.getCause());
183+
// } else {
184+
// throw e;
185+
// }
186+
// }
186187
}
187188

188189
@Override
@@ -202,19 +203,20 @@ public Future<Void> createTableAsync(TableDescriptor tableDescriptor, byte[][] b
202203

203204
@Override
204205
public void deleteTable(TableName tableName) throws IOException {
205-
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
206-
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
207-
OHDeleteTableExecutor executor = new OHDeleteTableExecutor(tableClient);
208-
try {
209-
executor.deleteTable(tableName.getNameAsString());
210-
} catch (IOException e) {
211-
if (e.getCause() instanceof ObTableTransportException
212-
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
213-
throw new TimeoutIOException(e.getCause());
214-
} else {
215-
throw e;
216-
}
217-
}
206+
throw new FeatureNotSupportedException("does not support yet");
207+
// OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
208+
// ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
209+
// OHDeleteTableExecutor executor = new OHDeleteTableExecutor(tableClient);
210+
// try {
211+
// executor.deleteTable(tableName.getNameAsString());
212+
// } catch (IOException e) {
213+
// if (e.getCause() instanceof ObTableTransportException
214+
// && ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
215+
// throw new TimeoutIOException(e.getCause());
216+
// } else {
217+
// throw e;
218+
// }
219+
// }
218220
}
219221

220222
@Override
@@ -244,19 +246,20 @@ public Future<Void> truncateTableAsync(TableName tableName, boolean b) throws IO
244246

245247
@Override
246248
public void enableTable(TableName tableName) throws IOException {
247-
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
248-
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
249-
OHTableAccessControlExecutor executor = new OHTableAccessControlExecutor(tableClient, ObTableRpcMetaType.HTABLE_ENABLE_TABLE);
250-
try {
251-
executor.enableTable(tableName.getNameAsString());
252-
} catch (IOException e) {
253-
if (e.getCause() instanceof ObTableTransportException
254-
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
255-
throw new TimeoutIOException(e.getCause());
256-
} else {
257-
throw e;
258-
}
259-
}
249+
throw new FeatureNotSupportedException("does not support yet");
250+
// OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
251+
// ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
252+
// OHTableAccessControlExecutor executor = new OHTableAccessControlExecutor(tableClient, ObTableRpcMetaType.HTABLE_ENABLE_TABLE);
253+
// try {
254+
// executor.enableTable(tableName.getNameAsString());
255+
// } catch (IOException e) {
256+
// if (e.getCause() instanceof ObTableTransportException
257+
// && ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
258+
// throw new TimeoutIOException(e.getCause());
259+
// } else {
260+
// throw e;
261+
// }
262+
// }
260263
}
261264

262265
@Override
@@ -308,12 +311,14 @@ public HTableDescriptor[] disableTables(Pattern pattern) throws IOException {
308311

309312
@Override
310313
public boolean isTableEnabled(TableName tableName) throws IOException {
311-
return isDisabled(tableName) == false;
314+
throw new FeatureNotSupportedException("does not support yet");
315+
// return isDisabled(tableName) == false;
312316
}
313317

314318
@Override
315319
public boolean isTableDisabled(TableName tableName) throws IOException {
316-
return isDisabled(tableName) == true;
320+
throw new FeatureNotSupportedException("does not support yet");
321+
// return isDisabled(tableName) == true;
317322
}
318323

319324
private boolean isDisabled(TableName tableName) throws IOException {

src/test/java/com/alipay/oceanbase/hbase/OHConnectionTest.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import com.alipay.oceanbase.hbase.util.OHBufferedMutatorImpl;
2121
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
2222
import org.apache.hadoop.conf.Configuration;
23-
import org.apache.hadoop.hbase.Cell;
24-
import org.apache.hadoop.hbase.CellUtil;
25-
import org.apache.hadoop.hbase.HConstants;
26-
import org.apache.hadoop.hbase.TableName;
23+
import org.apache.hadoop.hbase.*;
2724
import org.apache.hadoop.hbase.client.*;
2825
import org.apache.hadoop.hbase.util.Bytes;
2926
import org.apache.hadoop.hbase.util.Threads;
@@ -992,6 +989,52 @@ public void testRangePartitionWithRegionLocator() throws Exception {
992989
});
993990
}
994991
}
992+
993+
@Test
994+
public void testHRegionLocation() throws IOException {
995+
final String tableNameStr = "test_region_locator";
996+
997+
final byte[][] splitPoints = new byte[][] {
998+
Bytes.toBytes("c"), // p1: < 'c'
999+
Bytes.toBytes("e"), // p2: < 'e'
1000+
Bytes.toBytes("g"), // p3: < 'g'
1001+
Bytes.toBytes("i"), // p4: < 'i'
1002+
Bytes.toBytes("l"), // p5: < 'l'
1003+
Bytes.toBytes("n"), // p6: < 'n'
1004+
Bytes.toBytes("p"), // p7: < 'p'
1005+
Bytes.toBytes("s"), // p8: < 's'
1006+
Bytes.toBytes("v") // p9: < 'v'
1007+
};
1008+
1009+
final TableName tableName = TableName.valueOf(tableNameStr);
1010+
final Configuration conf = ObHTableTestUtil.newConfiguration();
1011+
connection = ConnectionFactory.createConnection(conf);
1012+
hTable = connection.getTable(tableName);
1013+
// (min, c), [c, e), [e, g), [g, i), [i, l), [l, n), [n, p), [p, s), [s, v), [v, max)
1014+
try (RegionLocator locator = connection.getRegionLocator(tableName)) {
1015+
Assert.assertEquals(locator.getStartKeys().length, locator.getEndKeys().length);
1016+
Assert.assertEquals(locator.getStartKeys().length, 10);
1017+
HRegionLocation loc = locator.getRegionLocation(HConstants.EMPTY_BYTE_ARRAY);
1018+
RegionInfo info = loc.getRegion();
1019+
Assert.assertEquals(Arrays.toString(locator.getStartKeys()[0]), Arrays.toString(info.getStartKey()));
1020+
Assert.assertEquals(Arrays.toString(locator.getEndKeys()[0]), Arrays.toString(info.getEndKey()));
1021+
for (int i = 1; i < locator.getStartKeys().length; i++) {
1022+
loc = locator.getRegionLocation(splitPoints[i - 1]);
1023+
info = loc.getRegion();
1024+
Assert.assertEquals(Arrays.toString(locator.getStartKeys()[i]), Arrays.toString(info.getStartKey()));
1025+
Assert.assertEquals(Arrays.toString(locator.getEndKeys()[i]), Arrays.toString(info.getEndKey()));
1026+
}
1027+
} finally {
1028+
Optional.ofNullable(hTable).ifPresent(table -> {
1029+
try {
1030+
table.close();
1031+
} catch (IOException e) {
1032+
e.printStackTrace();
1033+
}
1034+
});
1035+
}
1036+
}
1037+
9951038
@Test
9961039
public void testKeyPartitionWithRegionLocator() throws IOException {
9971040
final String tableNameStr = "test_multi_cf";

0 commit comments

Comments
 (0)