-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compensations are stored as a special-form updates that don't specify previous row values. Previously, such updates were treated as inserts by the server, but now they are converted to an update that doesn't mark any columns as modified. This allows PG to just use the tag for reviving the row as needed. This is covered by an e2e test. Closes VAX-801
- Loading branch information
1 parent
3cf2bc2
commit f60ce16
Showing
25 changed files
with
1,667 additions
and
950 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@core/electric": patch | ||
"electric-sql": patch | ||
--- | ||
|
||
Implemented correct semantics for compensations to work across the stack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import test from 'ava' | ||
import { mergeEntries } from '../../src/satellite/merge' | ||
import { OplogEntry, primaryKeyToStr } from '../../src/satellite/oplog' | ||
|
||
test('merging entries: local no-op updates should cancel incoming delete', (t) => { | ||
const pk = primaryKeyToStr({ id: 1 }) | ||
|
||
const local: OplogEntry[] = [ | ||
{ | ||
rowid: 0, | ||
namespace: 'main', | ||
tablename: 'public', | ||
optype: 'UPDATE', | ||
timestamp: '1970-01-02T03:46:41.000Z', // 100001000 as a unix timestamp | ||
primaryKey: pk, | ||
newRow: JSON.stringify({ id: 1 }), | ||
oldRow: undefined, | ||
clearTags: JSON.stringify(['common@100000000']), | ||
}, | ||
] | ||
|
||
const remote: OplogEntry[] = [ | ||
{ | ||
rowid: 0, | ||
namespace: 'main', | ||
tablename: 'public', | ||
optype: 'DELETE', | ||
timestamp: '1970-01-02T03:46:42.000Z', // 100002000 as a unix timestamp | ||
primaryKey: pk, | ||
oldRow: JSON.stringify({ id: 1, value: 'TEST' }), | ||
clearTags: JSON.stringify(['common@100000000']), | ||
}, | ||
] | ||
|
||
const merged = mergeEntries('local', local, 'remote', remote) | ||
|
||
// Merge should resolve into the UPSERT for this row, since the remote DELETE didn't observe this local update | ||
t.like(merged, { 'main.public': { [pk]: { optype: 'UPSERT' } } }) | ||
t.deepEqual(merged['main.public'][pk].tags, ['local@100001000']) | ||
t.deepEqual(merged['main.public'][pk].fullRow, { id: 1, value: 'TEST' }) | ||
}) |
Oops, something went wrong.