From f4bd83f86ee1d5f50da274fec551da98f5fac49a Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 27 Sep 2024 12:03:49 -0700 Subject: [PATCH] Add a leader state and failover operation. --- .../java/org/cojen/tupl/jmx/DatabaseMBean.java | 4 ++++ .../java/org/cojen/tupl/jmx/Registration.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/org/cojen/tupl/jmx/DatabaseMBean.java b/src/main/java/org/cojen/tupl/jmx/DatabaseMBean.java index 435811265..260787d45 100644 --- a/src/main/java/org/cojen/tupl/jmx/DatabaseMBean.java +++ b/src/main/java/org/cojen/tupl/jmx/DatabaseMBean.java @@ -43,6 +43,8 @@ public interface DatabaseMBean { long getReplicationBacklog(); + boolean isLeader(); + void flush(); void sync(); @@ -52,4 +54,6 @@ public interface DatabaseMBean { void compactFile(double target); void verify(); + + boolean failover(); } diff --git a/src/main/java/org/cojen/tupl/jmx/Registration.java b/src/main/java/org/cojen/tupl/jmx/Registration.java index b0d7cfa72..5a14780d4 100644 --- a/src/main/java/org/cojen/tupl/jmx/Registration.java +++ b/src/main/java/org/cojen/tupl/jmx/Registration.java @@ -291,6 +291,12 @@ public long getReplicationBacklog() { return stats == null ? 0 : stats.replicationBacklog; } + @Override + public boolean isLeader() { + Database db = db(); + return db == null ? false : db.isLeader(); + } + @Override public void flush() { asyncOp(db -> { @@ -377,6 +383,16 @@ public boolean indexNodeFailed(long id, int level, String message) { } } + @Override + public boolean failover() { + try { + Database db = db(); + return db == null ? false : db.failover(); + } catch (IOException e) { + return false; + } + } + private DatabaseStats stats() { synchronized (this) { DatabaseStats stats = mStats;