orez 0.2.13 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91,8 +91,21 @@ export class InProcessWriter implements ReplicationWriter {
91
91
  }
92
92
  }
93
93
 
94
- // current lsn counter
95
- let currentLsn = 0x1000000n
94
+ const MIN_LSN = 0x1000000n
95
+ const LSN_INCREMENT = 0x1_0000_0000n
96
+ const LSN_TIME_SHIFT = 12n
97
+
98
+ function lsnFloorFromTime(): bigint {
99
+ const timeLsn = BigInt(Date.now()) << LSN_TIME_SHIFT
100
+ return timeLsn > MIN_LSN ? timeLsn : MIN_LSN
101
+ }
102
+
103
+ // current lsn counter. seed from wall time so a restarted browser proxy never
104
+ // emits stream lsns behind zero-cache's persisted initial-sync watermark.
105
+ // use a large stride because zero-cache's initial backfill can reserve
106
+ // watermarks after slot creation while app writes are already queued; the next
107
+ // streamed transaction still has to land beyond that warmup range.
108
+ let currentLsn = lsnFloorFromTime()
96
109
  // persistent watermark across handler restarts so new handlers
97
110
  // don't replay already-streamed changes
98
111
  let lastStreamedWatermark = 0
@@ -116,14 +129,16 @@ let cachedColumnTypeOids: Map<string, Map<string, number>> | null = null
116
129
 
117
130
  /** reset module state (for tests) */
118
131
  export function resetReplicationState(): void {
119
- currentLsn = 0x1000000n
132
+ currentLsn = lsnFloorFromTime()
120
133
  lastStreamedWatermark = 0
121
134
  cachedTableKeyColumns = null
122
135
  cachedExcludedColumns = null
123
136
  cachedColumnTypeOids = null
124
137
  }
125
138
  function nextLsn(): bigint {
126
- currentLsn += 0x100n
139
+ const floor = lsnFloorFromTime()
140
+ if (currentLsn < floor) currentLsn = floor
141
+ currentLsn += LSN_INCREMENT
127
142
  return currentLsn
128
143
  }
129
144