From fee4ddf6dd8823ef25014162c3e5c9679f9efdfc Mon Sep 17 00:00:00 2001 From: ayushisingh29 Date: Mon, 20 May 2024 13:27:13 -0700 Subject: [PATCH] Return status code 409 is do_snapshot is already in progress (#1096) Co-authored-by: ayushis --- .../com/netflix/priam/backupv2/SnapshotMetaTask.java | 2 +- .../com/netflix/priam/resources/BackupServletV2.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/priam/src/main/java/com/netflix/priam/backupv2/SnapshotMetaTask.java b/priam/src/main/java/com/netflix/priam/backupv2/SnapshotMetaTask.java index bc05c1874..10afa1cec 100644 --- a/priam/src/main/java/com/netflix/priam/backupv2/SnapshotMetaTask.java +++ b/priam/src/main/java/com/netflix/priam/backupv2/SnapshotMetaTask.java @@ -198,7 +198,7 @@ public void execute() throws Exception { // as this happens on CRON. if (!lock.tryLock()) { logger.warn("SnapshotMetaService is already running! Try again later."); - throw new Exception("SnapshotMetaService already running"); + throw new IllegalStateException("SnapshotMetaService already running"); } // Save start snapshot status diff --git a/priam/src/main/java/com/netflix/priam/resources/BackupServletV2.java b/priam/src/main/java/com/netflix/priam/resources/BackupServletV2.java index 9ac66639e..5813b7599 100644 --- a/priam/src/main/java/com/netflix/priam/resources/BackupServletV2.java +++ b/priam/src/main/java/com/netflix/priam/resources/BackupServletV2.java @@ -83,7 +83,14 @@ public BackupServletV2( @GET @Path("/do_snapshot") public Response backup() throws Exception { - snapshotMetaService.execute(); + try { + snapshotMetaService.execute(); + } catch (Exception e) { + if (e instanceof IllegalStateException) { + return Response.status(409).build(); + } + return Response.serverError().build(); + } return Response.ok(REST_SUCCESS, MediaType.APPLICATION_JSON).build(); }