syntax = "proto3";

package iceberg_compaction;

option optimize_for = SPEED;

message SubscribeIcebergCompactionEventRequest {
  // Register provides the context_id of the corresponding Compactor.
  message Register {
    uint32 context_id = 1;
  }

  // PullTask provides the number of tasks needed for the Compactor.
  message PullTask {
    uint32 pull_task_count = 1;
  }

  message ReportTask {
    enum Status {
      UNSPECIFIED = 0;
      SUCCESS = 1;
      FAILED = 2;
    }

    uint64 task_id = 1;
    uint32 sink_id = 2;
    Status status = 3;
    reserved 4, 5;
    optional string error_message = 6;
  }

  oneof event {
    // Compactor will register its own context_id with Meta via Register and establish a bi-directional streaming rpc.
    Register register = 1;

    // Compactor will recalculate the number of tasks needed locally after receiving the PullTaskAck and get the next batch of tasks from Meta via PullTask.
    PullTask pull_task = 2;

    // Compactor reports the final task result back to Meta after all plans in the task finish.
    ReportTask report_task = 4;
  }

  uint64 create_at = 3;
}

message IcebergCompactionTask {
  uint64 task_id = 1;
  // Now we only support iceberg table full compaction.
  // compactor will get the information of the iceberg table from the properties
  map<string, string> props = 2;

  enum TaskType {
    UNSPECIFIED = 0;
    // Full compaction task.
    FULL = 1;

    // Small data file compaction task.
    SMALL_FILES = 2;

    FILES_WITH_DELETE = 3;
  }

  TaskType task_type = 3;
  uint32 sink_id = 4;
}

message SubscribeIcebergCompactionEventResponse {
  // PullTaskAck is a response, the meta will return a PullTaskAck after distributing the task requested by the PullTask.
  // The Compactor receives the PullTaskAck and remakes its state and tries to initiate the next PullTask.
  message PullTaskAck {}

  oneof event {
    IcebergCompactionTask compact_task = 1;
    PullTaskAck pull_task_ack = 2;
  }

  uint64 create_at = 7;
}
