syntax = "proto3";

package volume_server_pb;

//////////////////////////////////////////////////

service VolumeServer {
    //Experts only: takes multiple fid parameters. This function does not propagate deletes to replicas.
    rpc BatchDelete (BatchDeleteRequest) returns (BatchDeleteResponse) {
    }
    rpc VacuumVolumeCheck (VacuumVolumeCheckRequest) returns (VacuumVolumeCheckResponse) {
    }
    rpc VacuumVolumeCompact (VacuumVolumeCompactRequest) returns (VacuumVolumeCompactResponse) {
    }
    rpc VacuumVolumeCommit (VacuumVolumeCommitRequest) returns (VacuumVolumeCommitResponse) {
    }
    rpc VacuumVolumeCleanup (VacuumVolumeCleanupRequest) returns (VacuumVolumeCleanupResponse) {
    }

    rpc DeleteCollection (DeleteCollectionRequest) returns (DeleteCollectionResponse) {
    }
    rpc AllocateVolume (AllocateVolumeRequest) returns (AllocateVolumeResponse) {
    }

    rpc VolumeSyncStatus (VolumeSyncStatusRequest) returns (VolumeSyncStatusResponse) {
    }
    rpc VolumeIncrementalCopy (VolumeIncrementalCopyRequest) returns (stream VolumeIncrementalCopyResponse) {
    }

    rpc VolumeMount (VolumeMountRequest) returns (VolumeMountResponse) {
    }
    rpc VolumeUnmount (VolumeUnmountRequest) returns (VolumeUnmountResponse) {
    }
    rpc VolumeDelete (VolumeDeleteRequest) returns (VolumeDeleteResponse) {
    }

    // copy the .idx .dat files, and mount this volume
    rpc VolumeCopy (VolumeCopyRequest) returns (VolumeCopyResponse) {
    }
    rpc ReadVolumeFileStatus (ReadVolumeFileStatusRequest) returns (ReadVolumeFileStatusResponse) {
    }
    rpc CopyFile (CopyFileRequest) returns (stream CopyFileResponse) {
    }

    rpc VolumeTailSender (VolumeTailSenderRequest) returns (stream VolumeTailSenderResponse) {
    }
    rpc VolumeTailReceiver (VolumeTailReceiverRequest) returns (VolumeTailReceiverResponse) {
    }

    // erasure coding
    rpc VolumeEcShardsGenerate (VolumeEcShardsGenerateRequest) returns (VolumeEcShardsGenerateResponse) {
    }
    rpc VolumeEcShardsRebuild (VolumeEcShardsRebuildRequest) returns (VolumeEcShardsRebuildResponse) {
    }
    rpc VolumeEcShardsCopy (VolumeEcShardsCopyRequest) returns (VolumeEcShardsCopyResponse) {
    }
    rpc VolumeEcShardsDelete (VolumeEcShardsDeleteRequest) returns (VolumeEcShardsDeleteResponse) {
    }
    rpc VolumeEcShardsMount (VolumeEcShardsMountRequest) returns (VolumeEcShardsMountResponse) {
    }
    rpc VolumeEcShardsUnmount (VolumeEcShardsUnmountRequest) returns (VolumeEcShardsUnmountResponse) {
    }
    rpc VolumeEcShardRead (VolumeEcShardReadRequest) returns (stream VolumeEcShardReadResponse) {
    }

}

//////////////////////////////////////////////////

message BatchDeleteRequest {
    repeated string file_ids = 1;
}

message BatchDeleteResponse {
    repeated DeleteResult results = 1;
}
message DeleteResult {
    string file_id = 1;
    int32 status = 2;
    string error = 3;
    uint32 size = 4;
}

message Empty {
}

message VacuumVolumeCheckRequest {
    uint32 volume_id = 1;
}
message VacuumVolumeCheckResponse {
    double garbage_ratio = 1;
}

message VacuumVolumeCompactRequest {
    uint32 volume_id = 1;
    int64 preallocate = 2;
}
message VacuumVolumeCompactResponse {
}

message VacuumVolumeCommitRequest {
    uint32 volume_id = 1;
}
message VacuumVolumeCommitResponse {
}

message VacuumVolumeCleanupRequest {
    uint32 volume_id = 1;
}
message VacuumVolumeCleanupResponse {
}

message DeleteCollectionRequest {
    string collection = 1;
}
message DeleteCollectionResponse {
}

message AllocateVolumeRequest {
    uint32 volume_id = 1;
    string collection = 2;
    int64 preallocate = 3;
    string replication = 4;
    string ttl = 5;
}
message AllocateVolumeResponse {
}

message VolumeSyncStatusRequest {
    uint32 volume_id = 1;
}
message VolumeSyncStatusResponse {
    uint32 volume_id = 1;
    string collection = 2;
    string replication = 4;
    string ttl = 5;
    uint64 tail_offset = 6;
    uint32 compact_revision = 7;
    uint64 idx_file_size = 8;
}

message VolumeIncrementalCopyRequest {
    uint32 volume_id = 1;
    uint64 since_ns = 2;
}
message VolumeIncrementalCopyResponse {
    bytes file_content = 1;
}

message VolumeMountRequest {
    uint32 volume_id = 1;
}
message VolumeMountResponse {
}

message VolumeUnmountRequest {
    uint32 volume_id = 1;
}
message VolumeUnmountResponse {
}

message VolumeDeleteRequest {
    uint32 volume_id = 1;
}
message VolumeDeleteResponse {
}

message VolumeCopyRequest {
    uint32 volume_id = 1;
    string collection = 2;
    string replication = 3;
    string ttl = 4;
    string source_data_node = 5;
}
message VolumeCopyResponse {
    uint64 last_append_at_ns = 1;
}

message CopyFileRequest {
    uint32 volume_id = 1;
    string ext = 2;
    uint32 compaction_revision = 3;
    uint64 stop_offset = 4;
    string collection = 5;
    bool is_ec_volume = 6;
}
message CopyFileResponse {
    bytes file_content = 1;
}

message VolumeTailSenderRequest {
    uint32 volume_id = 1;
    uint64 since_ns = 2;
    uint32 idle_timeout_seconds = 3;
}
message VolumeTailSenderResponse {
    bytes needle_header = 1;
    bytes needle_body = 2;
    bool is_last_chunk = 3;
}

message VolumeTailReceiverRequest {
    uint32 volume_id = 1;
    uint64 since_ns = 2;
    uint32 idle_timeout_seconds = 3;
    string source_volume_server = 4;
}
message VolumeTailReceiverResponse {
}

message VolumeEcShardsGenerateRequest {
    uint32 volume_id = 1;
    string collection = 2;
}
message VolumeEcShardsGenerateResponse {
}

message VolumeEcShardsRebuildRequest {
    uint32 volume_id = 1;
    string collection = 2;
}
message VolumeEcShardsRebuildResponse {
    repeated uint32 rebuilt_shard_ids = 1;
}

message VolumeEcShardsCopyRequest {
    uint32 volume_id = 1;
    string collection = 2;
    repeated uint32 shard_ids = 3;
    bool copy_ecx_file = 4;
    string source_data_node = 5;
}
message VolumeEcShardsCopyResponse {
}

message VolumeEcShardsDeleteRequest {
    uint32 volume_id = 1;
    string collection = 2;
    repeated uint32 shard_ids = 3;
}
message VolumeEcShardsDeleteResponse {
}

message VolumeEcShardsMountRequest {
    uint32 volume_id = 1;
    string collection = 2;
    repeated uint32 shard_ids = 3;
}
message VolumeEcShardsMountResponse {
}

message VolumeEcShardsUnmountRequest {
    uint32 volume_id = 1;
    repeated uint32 shard_ids = 3;
}
message VolumeEcShardsUnmountResponse {
}

message VolumeEcShardReadRequest {
    uint32 volume_id = 1;
    uint32 shard_id = 2;
    int64 offset = 3;
    int64 size = 4;
}
message VolumeEcShardReadResponse {
    bytes data = 1;
}

message ReadVolumeFileStatusRequest {
    uint32 volume_id = 1;
}
message ReadVolumeFileStatusResponse {
    uint32 volume_id = 1;
    uint64 idx_file_timestamp_seconds = 2;
    uint64 idx_file_size = 3;
    uint64 dat_file_timestamp_seconds = 4;
    uint64 dat_file_size = 5;
    uint64 file_count = 6;
    uint32 compaction_revision = 7;
    string collection = 8;
}

message DiskStatus {
    string dir = 1;
    uint64 all = 2;
    uint64 used = 3;
    uint64 free = 4;
}

message MemStatus {
    int32 goroutines = 1;
    uint64 all = 2;
    uint64 used = 3;
    uint64 free = 4;
    uint64 self = 5;
    uint64 heap = 6;
    uint64 stack = 7;
}
