syntax="proto2";

package jraft;
import "raft.proto";

option java_package="com.alipay.sofa.jraft.rpc";
option java_outer_classname = "RpcRequests";

message PingRequest {
  required int64 send_timestamp = 1;
}

message ErrorResponse {
  required int32 errorCode = 1;
  optional string errorMsg = 2;
}

message InstallSnapshotRequest {
  required string group_id = 1;
  required string server_id = 2;
  required string peer_id = 3;
  required int64 term = 4;
  required SnapshotMeta meta = 5;
  required string uri = 6;
};

message InstallSnapshotResponse {
  required int64 term = 1;
  required bool success = 2;
  optional ErrorResponse errorResponse = 99;
};

message TimeoutNowRequest {
  required string group_id = 1;
  required string server_id = 2;
  required string peer_id = 3;
  required int64 term = 4;
}

message TimeoutNowResponse {
  required int64 term = 1;
  required bool success = 2;
  optional ErrorResponse errorResponse = 99;
}

message RequestVoteRequest {
  required string group_id = 1;
  required string server_id = 2;
  required string peer_id = 3;
  required int64 term = 4;
  required int64 last_log_term = 5;
  required int64 last_log_index = 6;
  required bool pre_vote = 7;
};

message RequestVoteResponse {
  required int64 term = 1;
  required bool granted = 2;
  optional ErrorResponse errorResponse = 99;
};

message AppendEntriesRequestHeader {
  required string group_id = 1;
  required string server_id = 2;
  required string peer_id = 3;
};

message AppendEntriesRequest {
  required string group_id = 1;
  required string server_id = 2;
  required string peer_id = 3;
  required int64 term = 4;
  required int64 prev_log_term = 5;
  required int64 prev_log_index = 6;
  repeated EntryMeta entries = 7;
  required int64 committed_index = 8;
  optional bytes data = 9;
};

message AppendEntriesResponse {
  required int64 term = 1;
  required bool success = 2;
  optional int64 last_log_index = 3;
  optional ErrorResponse errorResponse = 99;
};

message GetFileRequest {
  required int64 reader_id = 1;
  required string filename = 2;
  required int64 count = 3;
  required int64 offset = 4;
  optional bool read_partly = 5;
}

message GetFileResponse {
  // Data is in attachment
  required bool eof = 1;
  required bytes data = 2;
  optional int64 read_size = 3;
  optional ErrorResponse errorResponse = 99;
}

message ReadIndexRequest {
  required string group_id = 1;
  required string server_id = 2;
  repeated bytes entries = 3;
  optional string peer_id = 4;
}

message ReadIndexResponse {
  required int64 index = 1;
  required bool success = 2;
  optional ErrorResponse errorResponse = 99;
}
