Skip to content

Commit

Permalink
Optimize obkv_params method
Browse files Browse the repository at this point in the history
  • Loading branch information
HexyinUESTC committed Sep 6, 2024
1 parent cb92eca commit 96cd23d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,12 @@ public void setScanRangeColumns(List<String> scanRangeColumns) {
this.scanRangeColumns = scanRangeColumns;
}

// This interface is just for OBKV-Hbase
public void setObKVParams(ObKVParams obKVParams) {
if (!(obKVParams.getObParamsBase() instanceof ObHBaseParams)) {
throw new FeatureNotSupportedException("only ObHBaseParams support currently");
public void setHBaseParams(ObHBaseParams obHBaseParams) {
if (obKVParams == null) {
this.obKVParams = new ObKVParams();
}
this.obKVParams.setObParamsBase(obHBaseParams);
this.isHbaseQuery = true;
this.obKVParams = obKVParams;
}

public ObKVParams getObKVParams() {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/alipay/oceanbase/rpc/table/ObHBaseParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ObHBaseParams extends ObKVParamsBase {
private static final int FLAG_IS_CACHE_BLOCK = 1 << 1;
private static final int FLAG_CHECK_EXISTENCE_ONLY = 1 << 2;

private static final int FLAG_BYTE_LENGTH = 1;
private static final int BOOLEAN_BYTE_LENGTH = 1; // all boolean to one byte

public ObHBaseParams() {
pType = paramType.HBase;
}
Expand Down Expand Up @@ -61,11 +64,6 @@ public void setCheckExistenceOnly(boolean checkExistenceOnly) {
this.checkExistenceOnly = checkExistenceOnly;
}

private int getContentSize() {
return 4 + Serialization.getNeedBytes(caching) + Serialization.getNeedBytes(callTimeout)
+ 1;
}

public int getCaching() {
return caching;
}
Expand Down Expand Up @@ -134,8 +132,9 @@ public Object decode(ByteBuf buf) {
}

public long getPayloadContentSize() {
return 1 + Serialization.getNeedBytes(caching) + Serialization.getNeedBytes(callTimeout)
+ 1; // all boolean to one byte
return FLAG_BYTE_LENGTH
+ Serialization.getNeedBytes(caching) + Serialization.getNeedBytes(callTimeout)
+ BOOLEAN_BYTE_LENGTH;
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public byte getValue() {
}
}

public int byteSize;
public paramType pType;

public paramType getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ public void setOperationType(ObTableOperationType operationType) {

public void setObKVParams(ObTableQuery query) {
ObHBaseParams params = new ObHBaseParams();
ObKVParams obKVParams = new ObKVParams();
obKVParams.setObParamsBase(params);
query.setObKVParams(obKVParams);
query.setHBaseParams(params);
}

public ObTableAbstractOperationRequest obTableOperationRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public void test_ObTableQueryWithHbaseQuery() {
ObTableQuery obTableQuery = getObTableQuery();
obTableQuery.sethTableFilter(getObHTableFilter());
ObHBaseParams hBaseParams = new ObHBaseParams();
ObKVParams kv_prams = new ObKVParams();
kv_prams.setObParamsBase(hBaseParams);
obTableQuery.setObKVParams(kv_prams);
obTableQuery.setHBaseParams(hBaseParams);

byte[] bytes = obTableQuery.encode();
ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
Expand Down

0 comments on commit 96cd23d

Please sign in to comment.