Skip to content

Commit

Permalink
[PLAT-15970] Supporting HA across timezones
Browse files Browse the repository at this point in the history
Summary: Issue with timezones not being stored in PG database so changing node timezone had weird effects on HA failovers. By storing the bigint directly we have no ambiguous conversion from pg timestamp to java timestamp and always rely on epoch millisecond time.

Test Plan:
Set up HA with active (A)/standby (B) on UTC

Change standby (B)  to America/Chicago

Promote standby (B)

Change new standby (A) from UTC to America/NewYork

Promote standby (A)

Reviewers: nsingh

Reviewed By: nsingh

Subscribers: sanketh, yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D41534
  • Loading branch information
mchiddy committed Jan 31, 2025
1 parent 7c858c4 commit 65f65b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
Expand Down Expand Up @@ -68,9 +66,7 @@ public class HighAvailabilityConfig extends Model {
@JsonProperty("cluster_key")
private String clusterKey;

@Temporal(TemporalType.TIMESTAMP)
@JsonProperty("last_failover")
private Date lastFailover;
private Long lastFailover;

@OneToMany(mappedBy = "config", cascade = CascadeType.ALL)
private List<PlatformInstance> instances;
Expand All @@ -80,15 +76,20 @@ public class HighAvailabilityConfig extends Model {
private boolean acceptAnyCertificate;

public void updateLastFailover(Date lastFailover) {
this.lastFailover = lastFailover;
this.lastFailover = lastFailover.getTime();
this.update();
}

public void updateLastFailover() {
this.lastFailover = new Date();
this.lastFailover = new Date().getTime();
this.update();
}

@JsonProperty("last_failover")
public Date getLastFailover() {
return (this.lastFailover != null) ? new Date(this.lastFailover) : null;
}

public void updateAcceptAnyCertificate(boolean acceptAnyCertificate) {
this.acceptAnyCertificate = acceptAnyCertificate;
this.update();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Copyright (c) YugaByte, Inc.

-- Change last_failover column from timestamp without tz to epoch time in ms
ALTER TABLE high_availability_config
ALTER COLUMN last_failover TYPE bigint
USING (EXTRACT(EPOCH FROM last_failover) * 1000)::bigint;

0 comments on commit 65f65b7

Please sign in to comment.