syntax = "proto3";
package raft_serverpb;

import "eraftpb.proto";
import "metapb.proto";
import "kvrpcpb.proto";
import "disk_usage.proto";
import "rustproto.proto";

option (rustproto.lite_runtime_all) = true;

option java_package = "org.tikv.kvproto";

message RaftMessage {
    uint64 region_id = 1;
    metapb.Peer from_peer = 2;
    metapb.Peer to_peer = 3;
    eraftpb.Message message = 4;
    metapb.RegionEpoch region_epoch = 5;
    // true means to_peer is a tombstone peer and it should remove itself.
    bool is_tombstone = 6;
    // Region key range [start_key, end_key).
    bytes start_key = 7;
    bytes end_key = 8;
    // If it has value, to_peer should be removed if merge is never going to complete.
    metapb.Region merge_target = 9;
    ExtraMessage extra_msg = 10;
    bytes extra_ctx = 11;

    disk_usage.DiskUsage disk_usage = 12;
}

message RaftTruncatedState {
    uint64 index = 1;
    uint64 term = 2;
}

message SnapshotCFFile {
    string cf = 1;
    uint64 size = 2;
    uint32 checksum = 3;
}

message SnapshotMeta {
    repeated SnapshotCFFile cf_files = 1;
    // true means this snapshot is triggered for load balance
    bool for_balance = 2;
}

message SnapshotChunk {
    RaftMessage message = 1;
    bytes data = 2;
}

message Done {}

message KeyValue {
    bytes key      = 1;
    bytes value    = 2;
}

message RaftSnapshotData {
    metapb.Region region = 1;
    uint64 file_size = 2;
    repeated KeyValue data = 3;
    uint64 version = 4;
    SnapshotMeta meta = 5;
}

message StoreIdent {
    uint64 cluster_id = 1;
    uint64 store_id = 2;
    kvrpcpb.APIVersion api_version = 3;
}

message RaftLocalState {
    eraftpb.HardState hard_state = 1;
    uint64 last_index = 2;
}

message RaftApplyState {
    uint64 applied_index = 1;
    uint64 last_commit_index = 3;
    uint64 commit_index = 4;
    uint64 commit_term = 5;
    RaftTruncatedState truncated_state = 2;
}

enum PeerState {
    Normal = 0;
    Applying = 1;
    Tombstone = 2;
    Merging = 3;
}

message MergeState {
    uint64 min_index = 1;
    metapb.Region target = 2;
    uint64 commit = 3;
}

message RegionLocalState {
    PeerState state = 1;
    metapb.Region region = 2;
    MergeState merge_state = 3;
}

enum ExtraMessageType {
    MsgRegionWakeUp = 0;
    MsgWantRollbackMerge = 1;
    MsgCheckStalePeer = 2;
    MsgCheckStalePeerResponse = 3;
    // If leader is going to sleep, it will send requests to all its followers
    // to make sure they all agree to sleep.
    MsgHibernateRequest = 4;
    MsgHibernateResponse = 5;
}

message ExtraMessage {
    ExtraMessageType type = 1;
    uint64 premerge_commit = 2;
    repeated metapb.Peer check_peers = 3;
}
