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.
- package/dist/pg-proxy-browser.d.ts +11 -0
- package/dist/pg-proxy-browser.d.ts.map +1 -1
- package/dist/pg-proxy-browser.js +125 -65
- package/dist/pg-proxy-browser.js.map +1 -1
- package/dist/replication/change-tracker.js +1 -1
- package/dist/replication/change-tracker.js.map +1 -1
- package/dist/replication/handler.d.ts.map +1 -1
- package/dist/replication/handler.js +18 -4
- package/dist/replication/handler.js.map +1 -1
- package/package.json +2 -2
- package/src/pg-proxy-browser.singledb.test.ts +76 -0
- package/src/pg-proxy-browser.ts +174 -63
- package/src/replication/change-tracker.ts +1 -1
- package/src/replication/handler.ts +19 -4
|
@@ -91,8 +91,21 @@ export class InProcessWriter implements ReplicationWriter {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
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 =
|
|
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
|
-
|
|
139
|
+
const floor = lsnFloorFromTime()
|
|
140
|
+
if (currentLsn < floor) currentLsn = floor
|
|
141
|
+
currentLsn += LSN_INCREMENT
|
|
127
142
|
return currentLsn
|
|
128
143
|
}
|
|
129
144
|
|