Skip to content

Commit

Permalink
[desk-tool] Fix translog alignment of initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr authored and rexxars committed Oct 6, 2020
1 parent c4d247f commit efa1ecf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class Aligner {
}

appendRemoteSnapshotEvent(evt: RemoteSnapshotVersionEvent) {
console.log({type: 'remote', evt})
const state = this._states[evt.version]

if (evt.type === 'snapshot') {
Expand Down Expand Up @@ -131,19 +132,7 @@ export class Aligner {
const idx = align(evt, state)

if (idx >= 0) {
// These we must only apply locally since they are present in the fetched translog.
for (const mutEvt of state.events.slice(0, idx)) {
this._apply(state, mutEvt)
}

// ... while these must also be pushed to the timeline:
for (const mutEvt of state.events.slice(idx)) {
this._apply(state, mutEvt)
this.timeline.addRemoteMutation(mutEvt)
}

state.events = []
state.aligned = true
this._alignAtIndex(state, idx)
}
}
}
Expand All @@ -152,6 +141,16 @@ export class Aligner {
this.earliestTransactionId = evt.id
}

didReachEarliestEntry() {
for (const state of Object.values(this._states)) {
if (!state.aligned) {
if (state.attrs !== null) throw new Error('unable to find translog entry to align to')
this._alignAtIndex(state, 0)
}
}
this.timeline.didReachEarliestEntry()
}

get isAligned() {
return Object.values(this._states).every(state => state.aligned)
}
Expand All @@ -164,6 +163,22 @@ export class Aligner {
return {draft: this._states.draft.attrs, published: this._states.published.attrs}
}

private _alignAtIndex(state: VersionState, idx: number) {
// These we must only apply locally since they are present in the fetched translog.
for (const mutEvt of state.events.slice(0, idx)) {
this._apply(state, mutEvt)
}

// ... while these must also be pushed to the timeline:
for (const mutEvt of state.events.slice(idx)) {
this._apply(state, mutEvt)
this.timeline.addRemoteMutation(mutEvt)
}

state.events = []
state.aligned = true
}

private get _isComplete() {
return Object.values(this._states).every(state => state.hasAttrs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,13 @@ export class Controller {
tid = this._aligner.earliestTransactionId
}

// Same consistency checking here:
if (this._aligner.earliestTransactionId !== tid || !this._aligner.acceptsHistory) {
return
}

if (count < limit) {
this.timeline.didReachEarliestEntry()
this._aligner.didReachEarliestEntry()
}

this.markChange()
Expand Down

0 comments on commit efa1ecf

Please sign in to comment.