Skip to content

Commit

Permalink
Add a leader state and failover operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
broneill committed Sep 27, 2024
1 parent 021e7f3 commit f4bd83f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/cojen/tupl/jmx/DatabaseMBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public interface DatabaseMBean {

long getReplicationBacklog();

boolean isLeader();

void flush();

void sync();
Expand All @@ -52,4 +54,6 @@ public interface DatabaseMBean {
void compactFile(double target);

void verify();

boolean failover();
}
16 changes: 16 additions & 0 deletions src/main/java/org/cojen/tupl/jmx/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f4bd83f

Please sign in to comment.