Skip to content

Commit 379a534

Browse files
committed
correct format
1 parent 325e25a commit 379a534

File tree

11 files changed

+267
-200
lines changed

11 files changed

+267
-200
lines changed

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,11 +1509,13 @@ public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, bo
15091509
*
15101510
* @param tableName table want to get
15111511
* @param rowKey row key values
1512+
* @param needRenew flag to re-fetch partition meta information
15121513
* @return ODP ObPair of partId and table
15131514
* @throws Exception exception
15141515
*/
1515-
public ObPair<Long, ObTableParam> getODPTableWithRowKeyValue(String tableName, Object[] rowKey, boolean needRenew)
1516-
throws Exception {
1516+
public ObPair<Long, ObTableParam> getODPTableWithRowKeyValue(String tableName, Object[] rowKey,
1517+
boolean needRenew)
1518+
throws Exception {
15171519
TableEntry odpTableEntry = getOrFetchODPPartitionMeta(tableName, needRenew);
15181520
Row row = new Row();
15191521
if (odpTableEntry.isPartitionTable()
@@ -1543,6 +1545,7 @@ public ObPair<Long, ObTableParam> getODPTableWithRowKeyValue(String tableName, O
15431545
/**
15441546
* For mutation (queryWithFilter)
15451547
* @param tableName table want to get
1548+
* @param query query
15461549
* @param keyRanges key
15471550
* @param refresh whether to refresh
15481551
* @param waitForRefresh whether wait for refresh
@@ -1644,6 +1647,7 @@ private ObPair<Long, ObTableParam> getODPTableWithRowKey(String tableName, Row r
16441647
* @param partId partId of table (logicId, partition id in 3.x)
16451648
* @param refresh whether to refresh
16461649
* @param waitForRefresh whether wait for refresh
1650+
* @param needFetchAll flag to fetch all
16471651
* @param route ObServer route
16481652
* @return ObPair of partId and table
16491653
* @throws Exception exception
@@ -1823,6 +1827,7 @@ private List<Long> getOdpPartIds(TableEntry odpTableEntry, Row startRow, boolean
18231827
/**
18241828
* 根据 start-end 获取 partition ids 和 addrs
18251829
* @param tableName table want to get
1830+
* @param query query
18261831
* @param start start key
18271832
* @param startInclusive whether include start key
18281833
* @param end end key
@@ -1844,6 +1849,7 @@ public List<ObPair<Long, ObTableParam>> getTables(String tableName, ObTableQuery
18441849
/**
18451850
* 根据 start-end 获取 partition id 和 addr
18461851
* @param tableName table want to get
1852+
* @param query query
18471853
* @param start start key
18481854
* @param startInclusive whether include start key
18491855
* @param end end key
@@ -1972,40 +1978,40 @@ private List<ObPair<Long, ObTableParam>> getODPTables(String tableName, ObTableQ
19721978
if (odpTableEntry.isPartitionTable()
19731979
&& odpTableEntry.getPartitionInfo().getLevel() != ObPartitionLevel.LEVEL_ZERO) {
19741980
if ((scanRangeColumns == null || scanRangeColumns.isEmpty()) && start.length == 1
1975-
&& start[0] instanceof ObObj && ((ObObj) start[0]).isMinObj() && end.length == 1
1976-
&& end[0] instanceof ObObj && ((ObObj) end[0]).isMaxObj()) {
1981+
&& start[0] instanceof ObObj && ((ObObj) start[0]).isMinObj() && end.length == 1
1982+
&& end[0] instanceof ObObj && ((ObObj) end[0]).isMaxObj()) {
19771983
// for getPartition to query all partitions
19781984
scanRangeColumns = new ArrayList<String>(Collections.nCopies(start.length,
1979-
"partition"));
1985+
"partition"));
19801986
}
19811987
// scanRangeColumn may be longer than start/end in prefix scanning situation
19821988
if (scanRangeColumns == null || scanRangeColumns.size() < start.length) {
19831989
throw new IllegalArgumentException(
1984-
"length of key and scan range columns do not match, please use addRowKeyElement or set scan range columns");
1990+
"length of key and scan range columns do not match, please use addRowKeyElement or set scan range columns");
19851991
}
19861992
for (int i = 0; i < start.length; i++) {
19871993
startRow.add(scanRangeColumns.get(i), start[i]);
19881994
endRow.add(scanRangeColumns.get(i), end[i]);
19891995
}
19901996
}
19911997

1992-
List<Long> partIds = getOdpPartIds(odpTableEntry, startRow, startInclusive, endRow,
1993-
endInclusive);
1994-
for (Long partId : partIds) {
1995-
ObTable obTable = odpTable;
1996-
ObTableParam param = new ObTableParam(obTable);
1997-
Long tabletId = partId;
1998-
if (ObGlobal.obVsnMajor() >= 4) {
1999-
long partIdx = odpTableEntry.getPartIdx(partId);
2000-
tabletId = odpTableEntry.isPartitionTable() ? odpTableEntry.getPartitionInfo()
2001-
.getPartTabletIdMap().get(partIdx) : partId;
2002-
param.setLsId(odpTableEntry.getPartitionEntry().getLsId(tabletId));
2003-
}
2004-
param.setTableId(odpTableEntry.getTableId());
2005-
// real partition(tablet) id
2006-
param.setPartitionId(tabletId);
2007-
obTableParams.add(new ObPair<Long, ObTableParam>(partId, param));
1998+
List<Long> partIds = getOdpPartIds(odpTableEntry, startRow, startInclusive, endRow,
1999+
endInclusive);
2000+
for (Long partId : partIds) {
2001+
ObTable obTable = odpTable;
2002+
ObTableParam param = new ObTableParam(obTable);
2003+
Long tabletId = partId;
2004+
if (ObGlobal.obVsnMajor() >= 4) {
2005+
long partIdx = odpTableEntry.getPartIdx(partId);
2006+
tabletId = odpTableEntry.isPartitionTable() ? odpTableEntry.getPartitionInfo()
2007+
.getPartTabletIdMap().get(partIdx) : partId;
2008+
param.setLsId(odpTableEntry.getPartitionEntry().getLsId(tabletId));
20082009
}
2010+
param.setTableId(odpTableEntry.getTableId());
2011+
// real partition(tablet) id
2012+
param.setPartitionId(tabletId);
2013+
obTableParams.add(new ObPair<Long, ObTableParam>(partId, param));
2014+
}
20092015

20102016
return obTableParams;
20112017
}
@@ -2809,8 +2815,7 @@ public BatchOperation batchOperation(String tableName) {
28092815
*/
28102816
public Partition getPartition(String tableName, Object[] rowKey) throws Exception {
28112817
if (rowKey == null) {
2812-
throw new Exception(
2813-
"The input row key value can not be empty");
2818+
throw new Exception("The input row key value can not be empty");
28142819
}
28152820
Map<String, Integer> rowKeyElements = getRowKeyElement(tableName);
28162821
if (rowKeyElements == null) {
@@ -2862,7 +2867,7 @@ private Partition getSinglePartitionInternal(String tableName, Row rowKey) throw
28622867
/**
28632868
* get all partition information from table
28642869
* @param tableName table name to query
2865-
* @return List<Partition> partitions
2870+
* @return partitions
28662871
* @throws Exception Exception
28672872
*/
28682873
public List<Partition> getPartition(String tableName) throws Exception {
@@ -2955,8 +2960,8 @@ private TableEntry getOrFetchODPPartitionMeta(String tableName, boolean needRene
29552960
do {
29562961
try {
29572962
ObFetchPartitionMetaRequest request = ObFetchPartitionMetaRequest.getInstance(
2958-
ObFetchPartitionMetaType.GET_PARTITION_META.getIndex(),
2959-
tableName, clusterName, tenantName, database, forceRenew,
2963+
ObFetchPartitionMetaType.GET_PARTITION_META.getIndex(), tableName,
2964+
clusterName, tenantName, database, forceRenew,
29602965
odpTable.getObTableOperationTimeout()); // TODO: timeout setting need to be verified
29612966
ObPayload result = odpTable.execute(request);
29622967
checkObFetchPartitionMetaResult(lastOdpRefreshTimeMills, request, result);
@@ -2983,7 +2988,8 @@ private TableEntry getOrFetchODPPartitionMeta(String tableName, boolean needRene
29832988
}
29842989
}
29852990

2986-
private void checkObFetchPartitionMetaResult(Long lastOdpRefreshTimeMills, ObFetchPartitionMetaRequest request,
2991+
private void checkObFetchPartitionMetaResult(Long lastOdpRefreshTimeMills,
2992+
ObFetchPartitionMetaRequest request,
29872993
ObPayload result) {
29882994
if (result == null) {
29892995
RUNTIME.error("client get unexpected NULL result");
@@ -3002,7 +3008,6 @@ private void checkObFetchPartitionMetaResult(Long lastOdpRefreshTimeMills, ObFet
30023008
}
30033009
}
30043010

3005-
30063011
}
30073012

30083013
/**

src/main/java/com/alipay/oceanbase/rpc/location/model/TableEntry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ public long getRefreshAllTimeMills() {
155155
return refreshAllTimeMills;
156156
}
157157

158-
public long getOdpRefreshTimeMills() { return odpRefreshTimeMills; }
158+
public long getOdpRefreshTimeMills() {
159+
return odpRefreshTimeMills;
160+
}
159161

160162
/*
161163
* Set refresh time mills.

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/OdpPartitionData.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030

31-
public class OdpPartitionData extends AbstractPayload{
31+
public class OdpPartitionData extends AbstractPayload {
3232
private long level;
3333
private long partNum;
3434
private String partExr = Constants.EMPTY_STRING;
@@ -42,7 +42,8 @@ public class OdpPartitionData extends AbstractPayload{
4242
private String subPartRangeType = Constants.EMPTY_STRING;
4343
private List<OdpSinglePartKey> singlePartKeys = new ArrayList<OdpSinglePartKey>();
4444

45-
public OdpPartitionData() {}
45+
public OdpPartitionData() {
46+
}
4647

4748
public OdpPartitionData(ObPartitionInfo info) {
4849
level = info.getLevel().getIndex();
@@ -140,7 +141,7 @@ public byte[] encode() {
140141
len = Serialization.getNeedBytes(singlePartKeys.size());
141142
System.arraycopy(Serialization.encodeVi64(singlePartKeys.size()), 0, bytes, idx, len);
142143
idx += len;
143-
for(OdpSinglePartKey singlePartKey : singlePartKeys) {
144+
for (OdpSinglePartKey singlePartKey : singlePartKeys) {
144145
len = (int) singlePartKey.getPayloadSize();
145146
System.arraycopy(singlePartKey.encode(), 0, bytes, idx, len);
146147
idx += len;
@@ -175,17 +176,15 @@ public OdpPartitionData decode(ByteBuf buf) {
175176

176177
@Override
177178
public long getPayloadContentSize() {
178-
long size = Serialization.getNeedBytes(level)
179-
+ Serialization.getNeedBytes(partNum)
180-
+ Serialization.getNeedBytes(partExr)
181-
+ Serialization.getNeedBytes(partType)
182-
+ Serialization.getNeedBytes(partSpace)
183-
+ Serialization.getNeedBytes(partRangeType)
184-
+ Serialization.getNeedBytes(subPartNum)
185-
+ Serialization.getNeedBytes(subPartExr)
186-
+ Serialization.getNeedBytes(subPartType)
187-
+ Serialization.getNeedBytes(subPartSpace)
188-
+ Serialization.getNeedBytes(subPartRangeType);
179+
long size = Serialization.getNeedBytes(level) + Serialization.getNeedBytes(partNum)
180+
+ Serialization.getNeedBytes(partExr) + Serialization.getNeedBytes(partType)
181+
+ Serialization.getNeedBytes(partSpace)
182+
+ Serialization.getNeedBytes(partRangeType)
183+
+ Serialization.getNeedBytes(subPartNum)
184+
+ Serialization.getNeedBytes(subPartExr)
185+
+ Serialization.getNeedBytes(subPartType)
186+
+ Serialization.getNeedBytes(subPartSpace)
187+
+ Serialization.getNeedBytes(subPartRangeType);
189188
size += Serialization.getNeedBytes(singlePartKeys.size());
190189
for (OdpSinglePartKey singlePartKey : singlePartKeys) {
191190
size += singlePartKey.getPayloadSize();

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/OdpSinglePart.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public byte[] encode() {
5454
System.arraycopy(Serialization.encodeVi64(subPartNum), 0, bytes, idx, len);
5555
idx += len;
5656

57-
5857
byte[] strbytes = Serialization.encodeVString(highBoundVal);
5958
System.arraycopy(strbytes, 0, bytes, idx, strbytes.length);
6059

@@ -74,7 +73,6 @@ public OdpSinglePart decode(ByteBuf buf) {
7473
return this;
7574
}
7675

77-
7876
public long getPartId() {
7977
return this.partId;
8078
}
@@ -97,11 +95,9 @@ public String getHighBoundVal() {
9795

9896
@Override
9997
public long getPayloadContentSize() {
100-
return Serialization.getNeedBytes(partId)
101-
+ Serialization.getNeedBytes(tabletId)
102-
+ Serialization.getNeedBytes(lsId)
103-
+ Serialization.getNeedBytes(subPartNum)
104-
+ Serialization.getNeedBytes(highBoundVal);
98+
return Serialization.getNeedBytes(partId) + Serialization.getNeedBytes(tabletId)
99+
+ Serialization.getNeedBytes(lsId) + Serialization.getNeedBytes(subPartNum)
100+
+ Serialization.getNeedBytes(highBoundVal);
105101
}
106102

107103
}

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/Partition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public ObObj getEnd() {
101101

102102
public String toString() {
103103
String msg = "The Partition info: partition_id = " + partitionId + ", part_id = " + partId
104-
+ ", table_id = " + tableId + ", ls_id = " + lsId + ", ip = " + ip + ", port = " + port;
104+
+ ", table_id = " + tableId + ", ls_id = " + lsId + ", ip = " + ip
105+
+ ", port = " + port;
105106
return msg;
106107
}
107108
}

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/column/OdpSinglePartKey.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public class OdpSinglePartKey extends AbstractPayload {
3030
private String partKeyExtra = "";
3131
private long obCollationTypeIdx;
3232

33-
public OdpSinglePartKey() {}
33+
public OdpSinglePartKey() {
34+
}
3435

3536
public OdpSinglePartKey(ObColumn column) {
3637
columnLevel = -1;
@@ -40,9 +41,10 @@ public OdpSinglePartKey(ObColumn column) {
4041
if (column instanceof ObGeneratedColumn) {
4142
String str = "";
4243
ObGeneratedColumn genCol = (ObGeneratedColumn) column;
43-
ObGeneratedColumnSubStrFunc subStrFunc = (ObGeneratedColumnSubStrFunc) genCol.getObGeneratedColumnSimpleFunc();
44-
str += "substr(" + subStrFunc.getRefColumnNames().get(0) + ","
45-
+ subStrFunc.getPos() + "," + subStrFunc.getPos() + ")";
44+
ObGeneratedColumnSubStrFunc subStrFunc = (ObGeneratedColumnSubStrFunc) genCol
45+
.getObGeneratedColumnSimpleFunc();
46+
str += "substr(" + subStrFunc.getRefColumnNames().get(0) + "," + subStrFunc.getPos()
47+
+ "," + subStrFunc.getPos() + ")";
4648
partKeyExtra = str;
4749
}
4850
obCollationTypeIdx = column.getObCollationType().getValue();
@@ -123,12 +125,10 @@ public long getObCollationTypeIdx() {
123125

124126
@Override
125127
public long getPayloadContentSize() {
126-
return Serialization.getNeedBytes(columnLevel)
127-
+ Serialization.getNeedBytes(index)
128-
+ Serialization.getNeedBytes(obObjTypeIdx)
129-
+ Serialization.getNeedBytes(columnName)
130-
+ Serialization.getNeedBytes(partKeyExtra)
131-
+ Serialization.getNeedBytes(obCollationTypeIdx);
128+
return Serialization.getNeedBytes(columnLevel) + Serialization.getNeedBytes(index)
129+
+ Serialization.getNeedBytes(obObjTypeIdx) + Serialization.getNeedBytes(columnName)
130+
+ Serialization.getNeedBytes(partKeyExtra)
131+
+ Serialization.getNeedBytes(obCollationTypeIdx);
132132
}
133133

134134
}

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/execute/ObFetchPartitionMetaRequest.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
*/
4040
public class ObFetchPartitionMetaRequest extends AbstractPayload implements Credentialable {
4141
private ObFetchPartitionMetaType obFetchPartitionMetaType;
42-
private ObBytesString credential;
43-
private String tableName;
44-
private String clusterName;
45-
private String tenantName;
46-
private String databaseName;
47-
private boolean forceRenew = false;
42+
private ObBytesString credential;
43+
private String tableName;
44+
private String clusterName;
45+
private String tenantName;
46+
private String databaseName;
47+
private boolean forceRenew = false;
4848

4949
@Override
5050
public int getPcode() {
@@ -75,9 +75,13 @@ public void setForceRenew(boolean forceRenew) {
7575
this.forceRenew = forceRenew;
7676
}
7777

78-
public void setTableName(String tableName) { this.tableName = tableName; }
78+
public void setTableName(String tableName) {
79+
this.tableName = tableName;
80+
}
7981

80-
public void setTimeout(long timeout) { this.timeout = timeout; }
82+
public void setTimeout(long timeout) {
83+
this.timeout = timeout;
84+
}
8185

8286
/*
8387
* Set credential.
@@ -100,7 +104,8 @@ public byte[] encode() {
100104

101105
// encode type
102106
int len = Serialization.getNeedBytes(obFetchPartitionMetaType.getIndex());
103-
System.arraycopy(Serialization.encodeVi32(obFetchPartitionMetaType.getIndex()), 0, bytes, idx, len);
107+
System.arraycopy(Serialization.encodeVi32(obFetchPartitionMetaType.getIndex()), 0, bytes,
108+
idx, len);
104109
idx += len;
105110

106111
// encode credential
@@ -127,7 +132,8 @@ public byte[] encode() {
127132
idx += strbytes.length;
128133

129134
// encode force_renew for ODP route
130-
System.arraycopy(Serialization.encodeI8(forceRenew ? ((byte) 1) : ((byte) 0)), 0, bytes, idx, 1);
135+
System.arraycopy(Serialization.encodeI8(forceRenew ? ((byte) 1) : ((byte) 0)), 0, bytes,
136+
idx, 1);
131137

132138
return bytes;
133139
}
@@ -149,11 +155,9 @@ public Object decode(ByteBuf buf) {
149155
@Override
150156
public long getPayloadContentSize() {
151157
return Serialization.getNeedBytes(obFetchPartitionMetaType.getIndex())
152-
+ Serialization.getNeedBytes(credential)
153-
+ Serialization.getNeedBytes(tableName)
154-
+ Serialization.getNeedBytes(clusterName)
155-
+ Serialization.getNeedBytes(tenantName)
156-
+ Serialization.getNeedBytes(databaseName) + 1;
158+
+ Serialization.getNeedBytes(credential) + Serialization.getNeedBytes(tableName)
159+
+ Serialization.getNeedBytes(clusterName) + Serialization.getNeedBytes(tenantName)
160+
+ Serialization.getNeedBytes(databaseName) + 1;
157161
}
158162

159163
private int encodeCredential(byte[] bytes, int idx) {
@@ -163,9 +167,10 @@ private int encodeCredential(byte[] bytes, int idx) {
163167
return idx;
164168
}
165169

166-
public static ObFetchPartitionMetaRequest getInstance(int typeIdx, String tableName, String clusterName,
167-
String tenantName, String databaseName,
168-
boolean forceRenew, long timeout) {
170+
public static ObFetchPartitionMetaRequest getInstance(int typeIdx, String tableName,
171+
String clusterName, String tenantName,
172+
String databaseName, boolean forceRenew,
173+
long timeout) {
169174
ObFetchPartitionMetaRequest request = new ObFetchPartitionMetaRequest();
170175
request.setObFetchPartitionMetaType(typeIdx);
171176
request.setTableName(tableName);

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/execute/ObFetchPartitionMetaResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
* private long tableId_,
5252
* private long partitionNum_,
5353
* private ObPartitionInfo partitionInfo_,
54-
* private List<ODPSinglePart> odpFirstSingleParts_,
55-
* private List<ODPSinglePart> odpSubSingleParts_,
54+
* private odpFirstSingleParts_,
55+
* private odpSubSingleParts_,
5656
* );
5757
*/
5858

0 commit comments

Comments
 (0)