syntax = "proto2";

option java_multiple_files = true;
option java_package = "alluxio.grpc";
option java_outer_classname = "VersionProto";

package alluxio.grpc.version;


enum ServiceType {
  // FILE_SYSTEM_WORKER_WORKER_SERVICE is replaced by BLOCK_WORKER_CLIENT_SERVICE
  // as a clearer type name
  reserved 12;
  reserved "FILE_SYSTEM_WORKER_WORKER_SERVICE";

  UNKNOWN_SERVICE = 0;
  FILE_SYSTEM_MASTER_CLIENT_SERVICE = 1;
  FILE_SYSTEM_MASTER_WORKER_SERVICE = 2;
  FILE_SYSTEM_MASTER_JOB_SERVICE = 3;
  BLOCK_MASTER_CLIENT_SERVICE = 4;
  BLOCK_MASTER_WORKER_SERVICE = 5;
  META_MASTER_CONFIG_SERVICE = 6;
  META_MASTER_CLIENT_SERVICE = 7;
  META_MASTER_MASTER_SERVICE = 8;
  META_MASTER_PROXY_SERVICE = 18;
  METRICS_MASTER_CLIENT_SERVICE = 9;
  JOB_MASTER_CLIENT_SERVICE = 10;
  JOB_MASTER_WORKER_SERVICE = 11;
  JOB_MASTER_MASTER_SERVICE = 19;
  JOURNAL_MASTER_CLIENT_SERVICE = 13;
  TABLE_MASTER_CLIENT_SERVICE = 14;
  META_MASTER_BACKUP_MESSAGING_SERVICE = 15;
  RAFT_JOURNAL_SERVICE = 16;
  BLOCK_WORKER_CLIENT_SERVICE = 17;
  PRIVILEGE_MASTER_CLIENT_SERVICE = 1001;
  POLICY_MASTER_CLIENT_SERVICE = 1002;
  ENCRYPTION_MASTER_CLIENT_SERVICE = 1003;
  CROSS_CLUSTER_MASTER_CLIENT_SERVICE = 1004;
  SECURITY_SERVER_CLIENT_SERVICE = 1005;
}

message GetServiceVersionPRequest {
  optional ServiceType serviceType = 1;
  // The purpose of this field is to make grpc service on standby masters work without
  // making client changes and keeps backwards compatibility.
  // This requests to this endpoint will be rejected on standby masters by default,
  // unless this field is set.
  // Two places use this request:
  // 1. PollingMasterInquireClient uses this endpoint to tell who is the primary master.
  // 2. AbstractClient uses this endpoint to verify the version before it RPCs with the master.
  //
  // Behaviors:
  // 1. old clients -> new cluster standby masters
  // PollingMasterInquireClient does not set this field and is able to tell which one is primary master because
  // the request will be rejected on the standby master.
  // AbstractClient does not set this field.
  // Old clients only connects to primary so this doesn't break the existing behavior.
  //
  // 2. new clients -> new cluster standby masters
  // PollingMasterInquireClient does not set this field and is able to tell which one is primary master because
  // the request will be rejected on the standby master.
  // AbstractClient sets this field to true. Rpcs to standby masters can go through and pass the version verification.

  optional bool allowedOnStandbyMasters = 2;
}
message GetServiceVersionPResponse {
  optional int64 version = 1;
}

service ServiceVersionClientService {

  /**
   * Returns the version of the master service.
   * NOTE: The version should be updated every time a backwards incompatible API change occurs.
   */
  rpc getServiceVersion(GetServiceVersionPRequest) returns (GetServiceVersionPResponse);
}
