// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package ldlm;

enum ErrorCode {
  Unknown = 0;
  LockDoesNotExist = 1;
  InvalidLockKey = 2;
  LockWaitTimeout = 3;
  NotLocked = 4;
  LockDoesNotExistOrInvalidKey = 5;
  LockSizeMismatch = 6;
  InvalidLockSize = 7;
}

message Error {
  ErrorCode code = 1;
  string message = 2;
}

message LockRequest {
  string name = 1;
  optional int32 wait_timeout_seconds = 3;
  optional int32 lock_timeout_seconds = 100;
  optional int32 size = 4;
}

message TryLockRequest {
  string name = 1;
  optional int32 lock_timeout_seconds = 100;
  optional int32 size = 4;
}

message LockResponse {
  bool locked = 1;
  string name = 2;
  string key = 3;
  optional Error error = 4;
}

message UnlockRequest {
  string name = 1;
  string key = 2;
}

message UnlockResponse {
  bool unlocked = 1;
  string name = 2;
  optional Error error = 3;
}

message RenewRequest {
  string name = 1;
  string key = 2;
  int32 lock_timeout_seconds = 100;
}

service LDLM {
  rpc Lock(LockRequest) returns (LockResponse) { }
  rpc TryLock(TryLockRequest) returns (LockResponse) { }
  rpc Unlock(UnlockRequest) returns (UnlockResponse) { }
  rpc Renew(RenewRequest) returns (LockResponse) {}
}
