Skip to content

Commit b7d2e77

Browse files
committed
Keep only the targeted backend in the replica metadata
toReplicaEntry cloned the source entry and only updated the targeted backend, so the destination metadata inherited the statuses of the source's other destinations, frozen at queue time and never refreshed. Keep the targeted backend alone, copying it since clone() shares replicationInfo with the source. Issue: BB-875
1 parent 56a3c42 commit b7d2e77

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎lib/models/ObjectQueueEntry.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,16 @@ class ObjectQueueEntry extends ObjectMD {
232232

233233
toReplicaEntry(backend) {
234234
const newEntry = this.clone();
235+
// clone() shares replicationInfo with the source: detach before mutating.
236+
newEntry.setReplicationInfo(this.getReplicationInfo());
237+
const matched = newEntry._findBackend(backend);
235238
newEntry
236239
.setAccountId(this.getAccountId())
237240
.setBucket(this.getReplicationTargetBucket(backend))
241+
// Keep only the targeted backend: the other destinations' statuses
242+
// describe the source's own replication and would never be
243+
// refreshed here.
244+
.setReplicationBackends(matched ? [{ ...matched }] : [])
238245
.setReplicationSiteStatus(backend, 'REPLICA')
239246
.setReplicationStatus('REPLICA');
240247
return newEntry;

‎tests/unit/lib/models/ObjectQueueEntry.spec.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ describe('ObjectQueueEntry', () => {
144144
assert.strictEqual(replicaA.getBucket(), 'bucket-a');
145145
assert.strictEqual(replicaB.getBucket(), 'bucket-b');
146146
});
147+
148+
it('toReplicaEntry drops the other destinations statuses', () => {
149+
const entry = _makeEntryWithBackends([
150+
{ site: 'siteA', status: 'PENDING', dataStoreVersionId: '' },
151+
{ site: 'siteB', status: 'PENDING', dataStoreVersionId: '' },
152+
]);
153+
154+
const replica = entry.toReplicaEntry({ site: 'siteB' });
155+
assert.deepStrictEqual(
156+
replica.getReplicationBackends().map(b => b.site), ['siteB']);
157+
assert.strictEqual(replica.getReplicationSiteStatus({ site: 'siteB' }), 'REPLICA');
158+
assert.strictEqual(replica.getReplicationStatus(), 'REPLICA');
159+
assert.strictEqual(entry.getReplicationBackends().length, 2);
160+
assert.strictEqual(entry.getReplicationSiteStatus({ site: 'siteB' }), 'PENDING');
161+
});
147162
});
148163

149164
describe('same-site backend disambiguation', () => {

0 commit comments

Comments
 (0)