Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move retry logic to mongochangestream. #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dubiousdavid
Copy link
Member

  • Latest mongochangestream - Move retry logic to mongochangestream.
  • Removed immutable option.

Copy link
Contributor

@daveyarwood daveyarwood left a comment

Choose a reason for hiding this comment

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

I think this will accidentally result in there not being any retries in mongo2crate.

I was looking at this recently, and I noticed that there are a couple of try/catches in syncData.ts (example) around Crate operations, so if they fail, we're catching the error and emitting an "error" event instead. In that case, because no error is thrown, mongochangestream would not retry.

I think we need to remove the try/catches too, but it would also be good to ensure that only one "error" event is emitted at the end after the retries, which I think indicates that we need to emit the error event in mongochangestream. See my WIP PR: smartprocure/mongochangestream#30

src/syncData.ts Outdated Show resolved Hide resolved
const redis = new Redis({ keyPrefix: 'testing:' })
// MongoDB
const mongoClient = await MongoClient.connect(
process.env.MONGO_CONN as string
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a blocker, but it would be helpful to document in the README how to set up your environment and run the tests.

// Wait for the change stream events to be processed
await setTimeout(ms('6s'))
const countResponse = await crate.query(
`SELECT COUNT(*) FROM ${sync.qualifiedName} WHERE "createdAt" >= '${date.toISOString()}'`
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't they all be equal to date?

@@ -14,6 +12,7 @@ import {
} from './crate/util.js'

const debug = _debug('mongo2crate:crate')
debug.log = console.log.bind(console)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this line?

@@ -132,6 +136,7 @@ export const initSync = (
}
} catch (e) {
emit('error', { error: e, changeStream: true })
Copy link
Contributor

@daveyarwood daveyarwood Jan 9, 2025

Choose a reason for hiding this comment

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

Just checking my understanding: in the event of an error, we'll emit an error event here in mongo2crate (potentially multiple times, once for each retry), then a processError event in mongochangestream once all the retries are exhausted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great thoughts.

Copy link
Contributor

@daveyarwood daveyarwood left a comment

Choose a reason for hiding this comment

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

Looks good overall. I think the way you have it now, the scenario I mentioned on my last review won't be an issue.

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.

3 participants