
// Indices into resource vectors.
// A resource vector maps a resource index to the number
// of units of that resource required.

table Arg {
  // Object ID for pass-by-reference arguments. Normally there is only one
  // object ID in this list which represents the object that is being passed.
  // However to support reducers in a MapReduce workload, we also support
  // passing multiple object IDs for each argument.
  object_ids: [string];
  // Data for pass-by-value arguments.
  data: string;
}

table ResourcePair {
  // The name of the resource.
  key: string;
  // The quantity of the resource.
  value: double;
}

// NOTE: This enum is duplicate with the `Language` enum in `gcs.fbs`,
// because we cannot include this file in `gcs.fbs` due to cyclic dependency.
// TODO(raulchen): remove it once we get rid of legacy ray.
enum TaskLanguage:int {
  PYTHON = 0,
  JAVA = 1
}

table TaskInfo {
  // ID of the driver that created this task.
  driver_id: string;
  // Task ID of the task.
  task_id: string;
  // Task ID of the parent task.
  parent_task_id: string;
  // A count of the number of tasks submitted by the parent task before this one.
  parent_counter: int;
  // The ID of the actor to create if this is an actor creation task.
  actor_creation_id: string;
  // The dummy object ID of the actor creation task if this is an actor method.
  actor_creation_dummy_object_id: string;
  // Actor ID of the task. This is the actor that this task is executed on
  // or NIL_ACTOR_ID if the task is just a normal task.
  actor_id: string;
  // The ID of the handle that was used to submit the task. This should be
  // unique across handles with the same actor_id.
  actor_handle_id: string;
  // Number of tasks that have been submitted to this actor so far.
  actor_counter: int;
  // True if this task is an actor checkpoint task and false otherwise.
  is_actor_checkpoint_method: bool;
  // Function ID of the task.
  function_id: string;
  // Task arguments.
  args: [Arg];
  // Object IDs of return values.
  returns: [string];
  // The required_resources vector indicates the quantities of the different
  // resources required by this task.
  required_resources: [ResourcePair];
  // The language that this task belongs to
  language: TaskLanguage;
}

// Object information data structure.
table ObjectInfo {
  // Object ID of this object.
  object_id: string;
  // Number of bytes the content of this object occupies in memory.
  data_size: long;
  // Number of bytes the metadata of this object occupies in memory.
  metadata_size: long;
  // Unix epoch of when this object was created.
  create_time: long;
  // How long creation of this object took.
  construct_duration: long;
  // Hash of the object content.
  digest: string;
  // Specifies if this object was deleted or added.
  is_deletion: bool;
}

root_type TaskInfo;

table TaskExecutionDependencies {
  // A list of object IDs representing this task's dependencies at execution
  // time.
  execution_dependencies: [string];
}

root_type TaskExecutionDependencies;

table SubscribeToNotificationsReply {
  // The object ID of the object that the notification is about.
  object_id: string;
  // The size of the object.
  object_size: long;
  // The IDs of the managers that contain this object.
  manager_ids: [string];
}

root_type SubscribeToNotificationsReply;

table TaskReply {
  // The task ID of the task that the message is about.
  task_id: string;
  // The state of the task. This is encoded as a bit mask of scheduling_state
  // enum values in task.h.
  state: long;
  // A local scheduler ID.
  local_scheduler_id: string;
  // A string of bytes representing the task's TaskExecutionDependencies.
  execution_dependencies: string;
  // A string of bytes representing the task specification.
  task_spec: string;
  // The number of times the task was spilled back by local schedulers.
  spillback_count: long;
  // A boolean representing whether the update was successful. This field
  // should only be used for test-and-set operations.
  updated: bool;
}

root_type TaskReply;

table SubscribeToDBClientTableReply {
  // The db client ID of the client that the message is about.
  db_client_id: string;
  // The type of the client.
  client_type: string;
  // If the client is a local scheduler, this is the address of the plasma
  // manager that the local scheduler is connected to. Otherwise, it is empty.
  manager_address: string;
  // True if the message is about the addition of a client and false if it is
  // about the deletion of a client.
  is_insertion: bool;
}

root_type SubscribeToDBClientTableReply;

table LocalSchedulerInfoMessage {
  // The db client ID of the client that the message is about.
  db_client_id: string;
  // The total number of workers that are connected to this local scheduler.
  total_num_workers: long;
  // The number of tasks queued in this local scheduler.
  task_queue_length: long;
  // The number of workers that are available and waiting for tasks.
  available_workers: long;
  // The resources generally available to this local scheduler.
  static_resources: [ResourcePair];
  // The resources currently available to this local scheduler.
  dynamic_resources: [ResourcePair];
  // Whether the local scheduler is dead. If true, then all other fields
  // besides `db_client_id` will not be set.
  is_dead: bool;
}

root_type LocalSchedulerInfoMessage;

table ResultTableReply {
  // The task ID of the task that created the object.
  task_id: string;
  // Whether the task created the object through a ray.put.
  is_put: bool;
  // The size of the object created.
  data_size: long;
  // The hash of the object created.
  hash: string;
}

root_type ResultTableReply;

table DriverTableMessage {
  // The driver ID of the driver that died.
  driver_id: string;
}

table ActorCreationNotification {
  // The ID of the actor that was created.
  actor_id: string;
  // The ID of the driver that created the actor.
  driver_id: string;
  // The ID of the local scheduler that created the actor.
  local_scheduler_id: string;
}
