Skip to content

Implement start saving history the near the head - #235

Merged
JonoPrest merged 4 commits into
mainfrom
jp/copy-at-the-head
Oct 1, 2024
Merged

Implement start saving history the near the head#235
JonoPrest merged 4 commits into
mainfrom
jp/copy-at-the-head

Conversation

@JonoPrest

@JonoPrest JonoPrest commented Sep 30, 2024

Copy link
Copy Markdown
Collaborator
  • Implements a way to only start saving history when we start processing events within the the confirmed block threshold

I have just run a number of manual tests so far to see that it's working as expected.

I still need to add some tests and thinking about the best way for this.

@JonoPrest
JonoPrest requested a review from DZakh September 30, 2024 13:41
@JonoPrest
JonoPrest marked this pull request as ready for review September 30, 2024 13:41
Comment on lines +236 to +237
Set(entity)->Types.mkEntityUpdate(~eventIdentifier, ~entityId, ~shouldSaveHistory),
~shouldSaveHistory,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise that there is logic duplication here for "shouldSaveHistory" and I want to refactor that code.

let executeBatch = async (sql, ~inMemoryStore: InMemoryStore.t, ~isInReorgThreshold) => {
let entityDbExecutionComposer =
RegisterHandlers.getConfig()->Config.shouldRollbackOnReorg
RegisterHandlers.getConfig()->Config.shouldSaveHistory(~isInReorgThreshold)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now only start saving history when we are in a threshold for reorgs

Comment on lines +123 to +129
let shouldSaveHistory = (config, ~isInReorgThreshold) =>
switch config.historyConfig {
| {rollbackFlag: RollbackOnReorg} if isInReorgThreshold => true
| {historyFlag: FullHistory} => true
| _ => false
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously was using the shouldRollbackOnReorg function. But this is more specific. If we are saving full history it should always be true, if it's just standard rollback on reorg config it should only save if the indexer is in the reorg threshold

inMemTable: t<'entity>,
entityUpdate: Types.entityUpdate<'entity>,
~shouldRollbackOnReorg,
~shouldSaveHistory,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this, since it's more appropriate for the usecase

Comment on lines +96 to +102
let mk = cmp => {
{
val: Some(cmp),
isInReorgThreshold: isInReorgThreshold ||
cmp.earliestEvent->FetchState.queueItemIsInReorgThreshold(~heighestBlockBelowThreshold),
}
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now calculate if an event is in reorg threshold as we create a batch

//If there is item on the arbitray events queue, and it is earlier than
//than the earlist event, take the item off from there
| Some(itemWithPopFn)
| Some({val: itemWithPopFn, isInReorgThreshold})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the isInReorgThreshold as part of the eventBatchQueueItem instead of calculating it in the chainManager? I think it'd simplify quite a lot of code. Honestly, I don't like the increased complexity, and I hope it can be simplified to a single bool field with primitive logic.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't just be on the eventBatchQueue item because it's not a static value, it changes as the head moves on and it's only relevant at the point in time when we create a batch.

  1. We would still have to reduce through the created batch to see whether any item was within the threshold
  2. A queue with no item that was fetching in the threshold would also be a valid point to start saving items.

fetchStatesMap: ChainMap.t<PartitionedFetchState.t>,
arbitraryEventQueue: array<Types.eventBatchQueueItem>,
let hasChainItemsOnArbQueue = (self: t, ~chain): bool => {
self.arbitraryEventQueue->Js.Array2.find(item => item.chain == chain)->Option.isSome

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonoPrest JonoPrest changed the title Implement add saving history at the near the head Implement start saving history the near the head Oct 1, 2024
@JonoPrest
JonoPrest enabled auto-merge (squash) October 1, 2024 13:40
@JonoPrest
JonoPrest merged commit 8e0f015 into main Oct 1, 2024
@JonoPrest
JonoPrest deleted the jp/copy-at-the-head branch October 1, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants