Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

refactor(rpc): refactor request meta to adapt to new version of rpc protocol #82

Merged
merged 21 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions idl/replication.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ struct query_cfg_response
4:bool is_stateful;
5:list<partition_configuration> partitions;
}

struct request_meta {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields should be defined optional, be consistent with what server-side defines.

Actually I suggest just copy the thrift codes from pegasus.

// Metadata field of the request in rDSN's thrift protocol (version 1).                                                                                                                                   
// TODO(wutao1): add design doc of the thrift protocol.                                                                                                                                                   
struct thrift_request_meta_v1                                                                                                                                                                             
{                                                                                                                                                                                                         
    // The replica's gpid.                                                                                                                                                                                
    1:optional i32 app_id;                                                                                                                                                                                
    2:optional i32 partition_index;                                                                                                                                                                       
                                                                                                                                                                                                          
    // The timeout of this request that's set on client side.                                                                                                                                             
    3:optional i32 client_timeout;                                                                                                                                                                        
                                                                                                                                                                                                          
    // The hash value calculated from the hash key.                                                                                                                                                       
    4:optional i64 client_partition_hash;                                                                                                                                                                 
                                                                                                                                                                                                          
    // Whether it is a backup request. If true, this request (only if it's a read) can be handled by                                                                                                      
    // a secondary replica, which does not guarantee strong consistency.                                                                                                                                  
    5:optional bool is_backup_request;                                                                                                                                                                    
} 

Copy link
Contributor Author

@levy5307 levy5307 Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don`t suggest to use optional in java client. We use optional in pegasus server because we want it to have good compatibility, so we can delete these data in later version of java client. But in this version, these data is a must.

1:i32 app_id;
2:i32 partition_index;
3:i32 client_timeout;
4:i64 partition_hash;
}
6 changes: 4 additions & 2 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ if [[ $(git status -s) ]]; then
exit 1
fi

PEGASUS_PKG="pegasus-tools-1.11.6-9f4e5ae-glibc2.12-release"
PEGASUS_PKG_URL="https://github.com/XiaoMi/pegasus/releases/download/v1.11.6/pegasus-tools-1.11.6-9f4e5ae-glibc2.12-release.tar.gz"
# The new version of pegasus client is not compatible with old version server which contains old rpc protocol,
# So we use snapshot version of pegasus-tools, because we don`t have a new release version, which contains the new version of rpc protocol,
PEGASUS_PKG="pegasus-tools-1.13.SNAPSHOT-695b366-glibc2.17-release"
levy5307 marked this conversation as resolved.
Show resolved Hide resolved
PEGASUS_PKG_URL="https://github.com/XiaoMi/pegasus-common/releases/download/deps/pegasus-tools-1.13.SNAPSHOT-695b366-glibc2.17-release.tar.gz"

# start pegasus onebox environment
if [ ! -f $PEGASUS_PKG.tar.gz ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@

import com.xiaomi.infra.pegasus.base.error_code;
import com.xiaomi.infra.pegasus.base.gpid;
import com.xiaomi.infra.pegasus.replication.request_meta;
import com.xiaomi.infra.pegasus.rpc.ThriftHeader;
import com.xiaomi.infra.pegasus.thrift.TException;
import com.xiaomi.infra.pegasus.tools.Tools;

public abstract class client_operator {
public client_operator(gpid gpid, String tableName) {
this.header = new ThriftHeader();
this.header.app_id = gpid.get_app_id();
this.header.partition_index = gpid.get_pidx();
this.meta = new request_meta();
this.meta.setApp_id(gpid.get_app_id());
this.meta.setPartition_index(gpid.get_pidx());
this.pid = gpid;
this.tableName = tableName;
this.rpc_error = new error_code();
}

public client_operator(gpid gpid, String tableName, long partitionHash) {
this(gpid, tableName);
this.header.partition_hash = partitionHash;
this.meta.setPartition_hash(partitionHash);
}

public final byte[] prepare_thrift_header(int body_length, int client_timeout) {
header.body_length = body_length;
header.header_length = ThriftHeader.HEADER_LENGTH;
header.client_timeout = client_timeout;
header.thread_hash = Tools.dsn_gpid_to_thread_hash(header.app_id, header.partition_index);
public final byte[] prepare_thrift_header(int meta_length, int body_length) {
this.header.meta_length = meta_length;
this.header.body_length = body_length;
return header.toByteArray();
}

public final void prepare_thrift_meta(
com.xiaomi.infra.pegasus.thrift.protocol.TProtocol oprot, int client_timeout)
throws TException {
this.meta.setClient_timeout(client_timeout);
this.meta.write(oprot);
}

public String getQPSCounter() {
String mark;
switch (rpc_error.errno) {
Expand Down Expand Up @@ -79,6 +85,7 @@ public abstract void recv_data(com.xiaomi.infra.pegasus.thrift.protocol.TProtoco
throws TException;

public ThriftHeader header;
public request_meta meta;
public gpid pid;
public String tableName; // only for metrics
public error_code rpc_error;
Expand Down
Loading