Skip to content

Commit e6a2428

Browse files
committed
fix hbase tablegroup operations being hold for a long time
1 parent 8a49a99 commit e6a2428

File tree

4 files changed

+97
-35
lines changed

4 files changed

+97
-35
lines changed

src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,9 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
19931993
ObPartitionLocationInfo obPartitionLocationInfo = null;
19941994
if (ObGlobal.obVsnMajor() >= 4) {
19951995
obPartitionLocationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
1996+
if (obPartitionLocationInfo.getPartitionLocation() == null) {
1997+
throw new ObTableNotExistException("partition location is null after refresh, table: { " + tableName + " } may not exist");
1998+
}
19961999
replica = getPartitionLocation(obPartitionLocationInfo, route);
19972000
/**
19982001
* Normally, getOrRefreshPartitionInfo makes sure that a thread only continues if it finds the leader
@@ -2145,6 +2148,9 @@ private List<ObPair<Long, ReplicaLocation>> getPartitionReplica(TableEntry table
21452148
for (Long partId : partIds) {
21462149
long tabletId = getTabletIdByPartId(tableEntry, partId);
21472150
ObPartitionLocationInfo locationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
2151+
if (locationInfo.getPartitionLocation() == null) {
2152+
throw new ObTableNotExistException("partition location is null after refresh, table: { " + tableName + " } may not exist");
2153+
}
21482154
replicas.add(new ObPair<>(partId, getPartitionLocation(locationInfo, route)));
21492155
}
21502156
} else {

src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,19 +1294,20 @@ private static ObPartitionEntry getPartitionLocationFromResultSetByTablet(TableE
12941294
}
12951295
location.addReplicaLocation(replica);
12961296

1297-
if (location.getLeader() != null && partitionLocationInfo.initialized.compareAndSet(false, true)) {
1298-
partitionLocationInfo.initializationLatch.countDown();
1297+
if (location.getLeader() != null) {
1298+
partitionLocationInfo.initialized.compareAndSet(false, true);
12991299
} else if (rs.isLast() && location.getLeader() == null) {
13001300
partitionLocationInfo.initializationLatch.countDown();
13011301
RUNTIME.error(LCD.convert("01-00028"), partitionId, partitionEntry, tableEntry);
13021302
RUNTIME.error(format(
1303-
"partition=%d has no leader partitionEntry=%s original tableEntry=%s",
1304-
partitionId, partitionEntry, tableEntry));
1303+
"partition=%d has no leader partitionEntry=%s original tableEntry=%s",
1304+
partitionId, partitionEntry, tableEntry));
13051305
throw new ObTablePartitionNoMasterException(format(
1306-
"partition=%d has no leader partitionEntry=%s original tableEntry=%s",
1307-
partitionId, partitionEntry, tableEntry));
1306+
"partition=%d has no leader partitionEntry=%s original tableEntry=%s",
1307+
partitionId, partitionEntry, tableEntry));
13081308
}
13091309
}
1310+
partitionLocationInfo.initializationLatch.countDown();
13101311

13111312
return partitionEntry;
13121313
}

src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void addOperation(Get get) throws Exception {
300300
Object[] rowKeyValues = get.getRowKey().getValues();
301301
String[] propertiesNames = get.getSelectColumns();
302302
ObTableSingleOpEntity entity = ObTableSingleOpEntity.getInstance(rowKeyNames, rowKeyValues,
303-
propertiesNames, null);
303+
propertiesNames, null);
304304
ObTableSingleOp singleOp = new ObTableSingleOp();
305305
singleOp.setSingleOpType(ObTableOperationType.GET);
306306
singleOp.addEntity(entity);
@@ -344,8 +344,8 @@ public List<Object> executeWithResult() throws Exception {
344344
}
345345
} else {
346346
results.add(ExceptionUtil.convertToObTableException(result.getExecuteHost(),
347-
result.getExecutePort(), result.getSequence(), result.getUniqueId(), errCode,
348-
result.getHeader().getErrMsg()));
347+
result.getExecutePort(), result.getSequence(), result.getUniqueId(), errCode,
348+
result.getHeader().getErrMsg()));
349349
}
350350
}
351351
return results;
@@ -393,16 +393,33 @@ public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSing
393393
if (this.entityType == ObTableEntityType.HKV && obTableClient.isTableGroupName(tableName)) {
394394
real_tableName = obTableClient.tryGetTableNameFromTableGroupCache(tableName, false);
395395
}
396-
ObPair<Long, ObTableParam> tableObPair= obTableClient.getTable(real_tableName, rowKey,
397-
false, false, obTableClient.getRoute(false));
398-
long lsId = tableObPair.getRight().getLsId();
396+
ObPair<Long, ObTableParam> tableObPair = null;
397+
long lsId = INVALID_LS_ID;
398+
try {
399+
tableObPair = obTableClient.getTable(real_tableName, rowKey,
400+
false, false, obTableClient.getRoute(false));
401+
lsId = tableObPair.getRight().getLsId();
402+
} catch (ObTableNotExistException e) {
403+
if (this.entityType == ObTableEntityType.HKV
404+
&& obTableClient.isTableGroupName(tableName)
405+
&& obTableClient.getTableGroupInverted().get(real_tableName) != null) {
406+
obTableClient.eraseTableGroupFromCache(tableName);
407+
real_tableName = obTableClient.tryGetTableNameFromTableGroupCache(tableName, true);
408+
tableObPair = obTableClient.getTable(real_tableName, rowKey,
409+
false, false, obTableClient.getRoute(false));
410+
lsId = tableObPair.getRight().getLsId();
411+
} else {
412+
throw e;
413+
}
414+
}
399415

400416
Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperations
401417
= lsOperationsMap.computeIfAbsent(lsId, k -> new HashMap<>());
402418
// if ls id not exists
403419

420+
ObPair<Long, ObTableParam> finalTableObPair = tableObPair;
404421
ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>> singleOperations =
405-
tabletOperations.computeIfAbsent(tableObPair.getLeft(), k -> new ObPair<>(tableObPair.getRight(), new ArrayList<>()));
422+
tabletOperations.computeIfAbsent(tableObPair.getLeft(), k -> new ObPair<>(finalTableObPair.getRight(), new ArrayList<>()));
406423
// if tablet id not exists
407424
singleOperations.getRight().add(operationsWithIndex.get(i));
408425
}
@@ -565,6 +582,14 @@ public void partitionExecute(ObTableSingleOpResult[] results,
565582
} else if (ex instanceof ObTableException
566583
&& ((ObTableException) ex).isNeedRefreshTableEntry()) {
567584
needRefreshTableEntry = true;
585+
if (((ObTableException) ex).getErrorCode() == ResultCodes.OB_TABLE_NOT_EXIST.errorCode
586+
&& obTableClient.isTableGroupName(tableName)
587+
&& obTableClient.getTableGroupInverted().get(realTableName) != null) {
588+
// TABLE_NOT_EXIST + tableName is tableGroup + TableGroup cache is not empty
589+
// means tableGroupName cache need to refresh
590+
obTableClient.eraseTableGroupFromCache(tableName);
591+
realTableName = obTableClient.tryGetTableNameFromTableGroupCache(tableName, true);
592+
}
568593
if (obTableClient.isRetryOnChangeMasterTimes()
569594
&& (tryTimes - 1) < obTableClient.getRuntimeRetryTimes()) {
570595
if (ex instanceof ObTableNeedFetchAllException) {

src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import com.alipay.oceanbase.rpc.ObTableClient;
2222
import com.alipay.oceanbase.rpc.exception.FeatureNotSupportedException;
2323
import com.alipay.oceanbase.rpc.exception.ObTableException;
24+
import com.alipay.oceanbase.rpc.exception.ObTableNotExistException;
25+
import com.alipay.oceanbase.rpc.exception.ObTableUnexpectedException;
2426
import com.alipay.oceanbase.rpc.location.model.partition.ObPair;
2527
import com.alipay.oceanbase.rpc.mutation.Row;
2628
import com.alipay.oceanbase.rpc.protocol.payload.ObPayload;
@@ -133,12 +135,13 @@ public void checkArgumentBeforeExec() throws Exception {
133135
throw new IllegalArgumentException("table name is null");
134136
} else if (tableQuery.isFTSQuery()) {
135137
if (!ObGlobal.isFtsQuerySupport()) {
136-
throw new FeatureNotSupportedException("full text query is not supported in "+ObGlobal.obVsnString());
138+
throw new FeatureNotSupportedException("full text query is not supported in "
139+
+ ObGlobal.obVsnString());
137140
}
138141
if (tableQuery.getIndexName() == null || tableQuery.getIndexName().isEmpty()
139-
|| tableQuery.getIndexName().equalsIgnoreCase("primary")) {
142+
|| tableQuery.getIndexName().equalsIgnoreCase("primary")) {
140143
throw new IllegalArgumentException(
141-
"use fulltext search but specified index name is not fulltext index");
144+
"use fulltext search but specified index name is not fulltext index");
142145
}
143146
}
144147
}
@@ -176,31 +179,27 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
176179
if (obTableClient.isOdpMode()) {
177180
if (tableQuery.getScanRangeColumns().isEmpty()) {
178181
if (tableQuery.getIndexName() != null
179-
&& !tableQuery.getIndexName().equalsIgnoreCase("primary") && !tableQuery.isFTSQuery()) {
182+
&& !tableQuery.getIndexName().equalsIgnoreCase("primary")
183+
&& !tableQuery.isFTSQuery()) {
180184
throw new ObTableException("key range columns must be specified when use index");
181185
}
182186
}
183-
if (getPartId() != null && tableQuery.getIndexName() == null) {
184-
String realTableName = tableName;
187+
if (entityType != ObTableEntityType.HKV && getPartId() != null
188+
&& tableQuery.getIndexName() == null) {
185189
try {
186-
if (this.entityType == ObTableEntityType.HKV
187-
&& obTableClient.isTableGroupName(tableName)) {
188-
indexTableName = obTableClient.tryGetTableNameFromTableGroupCache(tableName,
189-
false);
190-
realTableName = indexTableName;
191-
}
192190
ObPair<Long, ObTableParam> odpTable = obTableClient.getODPTableWithPartId(
193-
realTableName, getPartId(), false);
191+
tableName, getPartId(), false);
194192
partitionObTables.put(odpTable.getLeft(), odpTable);
195193
} catch (Exception e) {
196194
if (e instanceof ObTableException) {
197195
if (((ObTableException) e).getErrorCode() == ResultCodes.OB_NOT_SUPPORTED.errorCode) {
198196
// current ODP version does not support get partition meta information
199-
throw new FeatureNotSupportedException("current ODP version does not support query with part id", e);
197+
throw new FeatureNotSupportedException(
198+
"current ODP version does not support query with part id", e);
200199
} else if (((ObTableException) e).getErrorCode() == ResultCodes.OB_ERR_KV_ROUTE_ENTRY_EXPIRE.errorCode) {
201200
// retry one time with force-renew flag
202-
ObPair<Long, ObTableParam> odpTable = obTableClient.getODPTableWithPartId(
203-
realTableName, getPartId(), true);
201+
ObPair<Long, ObTableParam> odpTable = obTableClient
202+
.getODPTableWithPartId(tableName, getPartId(), true);
204203
partitionObTables.put(odpTable.getLeft(), odpTable);
205204
} else {
206205
throw e;
@@ -211,7 +210,7 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
211210
}
212211
} else {
213212
partitionObTables.put(0L, new ObPair<Long, ObTableParam>(0L, new ObTableParam(
214-
obTableClient.getOdpTable())));
213+
obTableClient.getOdpTable())));
215214
}
216215
} else {
217216
if (getPartId() == null) {
@@ -224,9 +223,26 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
224223
indexTableName = obTableClient.tryGetTableNameFromTableGroupCache(tableName,
225224
false);
226225
}
227-
ObPair<Long, ObTableParam> table = obTableClient.getTableWithPartId(indexTableName,
228-
getPartId(), false, false, false, obTableClient.getRoute(false));
229-
partitionObTables.put(table.getLeft(), table);
226+
try {
227+
ObPair<Long, ObTableParam> table = obTableClient.getTableWithPartId(
228+
indexTableName, getPartId(), false, false, false,
229+
obTableClient.getRoute(false));
230+
partitionObTables.put(table.getLeft(), table);
231+
} catch (ObTableNotExistException e) {
232+
if (this.entityType == ObTableEntityType.HKV
233+
&& obTableClient.isTableGroupName(tableName)
234+
&& obTableClient.getTableGroupInverted().get(indexTableName) != null) {
235+
obTableClient.eraseTableGroupFromCache(indexTableName);
236+
indexTableName = obTableClient.tryGetTableNameFromTableGroupCache(
237+
tableName, true);
238+
ObPair<Long, ObTableParam> table = obTableClient.getTableWithPartId(
239+
indexTableName, getPartId(), false, false, false,
240+
obTableClient.getRoute(false));
241+
partitionObTables.put(table.getLeft(), table);
242+
} else {
243+
throw e;
244+
}
245+
}
230246
}
231247
}
232248

@@ -318,8 +334,22 @@ public Map<Long, ObPair<Long, ObTableParam>> initPartitions(ObTableQuery tableQu
318334
}
319335
ObBorderFlag borderFlag = range.getBorderFlag();
320336
// pairs -> List<Pair<logicId, param>>
321-
List<ObPair<Long, ObTableParam>> pairs = this.obTableClient.getTables(indexTableName, tableQuery, start,
322-
borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), false, false);
337+
List<ObPair<Long, ObTableParam>> pairs = null;
338+
try {
339+
pairs = this.obTableClient.getTables(indexTableName, tableQuery, start,
340+
borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), false, false);
341+
} catch (ObTableNotExistException e) {
342+
if (this.entityType == ObTableEntityType.HKV
343+
&& obTableClient.isTableGroupName(tableName)
344+
&& obTableClient.getTableGroupInverted().get(indexTableName) != null) {
345+
obTableClient.eraseTableGroupFromCache(indexTableName);
346+
indexTableName = obTableClient.tryGetTableNameFromTableGroupCache(tableName, true);
347+
pairs = this.obTableClient.getTables(indexTableName, tableQuery, start,
348+
borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), false, false);
349+
} else {
350+
throw e;
351+
}
352+
}
323353
if (tableQuery.getScanOrder() == ObScanOrder.Reverse) {
324354
for (int i = pairs.size() - 1; i >= 0; i--) {
325355
partitionObTables.put(pairs.get(i).getLeft(), pairs.get(i));

0 commit comments

Comments
 (0)