syntax = "proto3";

package gitaly;

option go_package = "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb";

import "lint.proto";
import "shared.proto";

service ObjectPoolService {
  rpc CreateObjectPool(CreateObjectPoolRequest) returns (CreateObjectPoolResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }
  rpc DeleteObjectPool(DeleteObjectPoolRequest) returns (DeleteObjectPoolResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }

  // Repositories are assumed to be stored on the same disk
  rpc LinkRepositoryToObjectPool(LinkRepositoryToObjectPoolRequest) returns (LinkRepositoryToObjectPoolResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }
  rpc UnlinkRepositoryFromObjectPool(UnlinkRepositoryFromObjectPoolRequest) returns (UnlinkRepositoryFromObjectPoolResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }

  rpc ReduplicateRepository(ReduplicateRepositoryRequest) returns (ReduplicateRepositoryResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }
  rpc DisconnectGitAlternates(DisconnectGitAlternatesRequest) returns (DisconnectGitAlternatesResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }
  rpc FetchIntoObjectPool(FetchIntoObjectPoolRequest) returns (FetchIntoObjectPoolResponse) {
    option (op_type) = {
      op: MUTATOR
    };
  }
  rpc GetObjectPool(GetObjectPoolRequest) returns (GetObjectPoolResponse) {
    option (op_type) = {
      op: ACCESSOR
    };
  }
}

// Creates an object pool from the repository. The client is responsible for
// joining this pool later with this repository.
message CreateObjectPoolRequest {
  ObjectPool object_pool = 1 [(target_repository)=true];
  Repository origin = 2 [(additional_repository)=true];
}
message CreateObjectPoolResponse {}

// Removes the directory from disk, caller is responsible for leaving the object
// pool before calling this RPC
message DeleteObjectPoolRequest {
  ObjectPool object_pool = 1 [(target_repository)=true];
}
message DeleteObjectPoolResponse {}

message LinkRepositoryToObjectPoolRequest {
  ObjectPool object_pool = 1 [(additional_repository)=true];
  Repository repository = 2 [(target_repository)=true];
}
message LinkRepositoryToObjectPoolResponse {}

// This RPC doesn't require the ObjectPool as it will remove the alternates file
// from the pool participant. The caller is responsible no data loss occurs.
message UnlinkRepositoryFromObjectPoolRequest {
  Repository repository = 1 [(target_repository)=true]; // already specified as the target repo field
  ObjectPool object_pool = 2 [(additional_repository)=true];
}
message UnlinkRepositoryFromObjectPoolResponse {}

message ReduplicateRepositoryRequest {
  Repository repository = 1 [(target_repository)=true];
}
message ReduplicateRepositoryResponse {}

message DisconnectGitAlternatesRequest {
  Repository repository = 1  [(target_repository)=true];
}

message DisconnectGitAlternatesResponse {}

message FetchIntoObjectPoolRequest {
  Repository origin = 1 [(additional_repository)=true];
  ObjectPool object_pool = 2 [(target_repository)=true];
  bool repack = 3;
}
message FetchIntoObjectPoolResponse {}

message GetObjectPoolRequest {
  Repository repository = 1 [(target_repository)=true];
}

message GetObjectPoolResponse {
  ObjectPool object_pool = 1;
}


