Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/perfect-kiwis-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@powersync/service-module-mongodb-storage': patch
'@powersync/service-rsocket-router': patch
'@powersync/service-module-mongodb': patch
'@powersync/service-core': patch
'@powersync/lib-services-framework': patch
'@powersync/lib-service-mongodb': patch
---

Upgrade mongodb driver to improve stability.
6 changes: 3 additions & 3 deletions libs/lib-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
},
"dependencies": {
"@powersync/lib-services-framework": "workspace:*",
"bson": "^6.10.3",
"mongodb": "^6.14.1",
"bson": "^6.10.4",
"mongodb": "^6.20.0",
"mongodb-connection-string-url": "^3.0.2",
"ts-codec": "^1.3.0"
},
"devDependencies": {}
}
}
1 change: 1 addition & 0 deletions libs/lib-mongodb/src/db/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function createMongoClient(config: BaseMongoConfigDecoded, options?: Mong

// Identify the client
appName: options?.powersyncVersion ? `powersync-storage ${options.powersyncVersion}` : 'powersync-storage',
// Deprecated in the driver - in a future release we may have to rely on appName only.
driverInfo: {
// This is merged with the node driver info.
name: 'powersync-storage',
Expand Down
4 changes: 2 additions & 2 deletions libs/lib-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@powersync/service-sync-rules": "workspace:*",
"ajv": "^8.12.0",
"better-ajv-errors": "^1.2.0",
"bson": "^6.10.3",
"bson": "^6.10.4",
"dotenv": "^16.4.5",
"ipaddr.js": "^2.1.0",
"lodash": "^4.17.21",
Expand All @@ -37,4 +37,4 @@
"@types/lodash": "^4.17.5",
"vitest": "^3.2.4"
}
}
}
4 changes: 2 additions & 2 deletions modules/module-mongodb-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@powersync/service-jsonbig": "workspace:*",
"@powersync/service-sync-rules": "workspace:*",
"@powersync/service-types": "workspace:*",
"bson": "^6.10.3",
"bson": "^6.10.4",
"ix": "^5.0.0",
"lru-cache": "^10.2.2",
"ts-codec": "^1.3.0",
Expand All @@ -43,4 +43,4 @@
"devDependencies": {
"@powersync/service-core-tests": "workspace:*"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ export class MongoCompactor {
}
}
],
{ batchSize: this.moveBatchQueryLimit }
{
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: this.moveBatchQueryLimit + 1
}
);
// We don't limit to a single batch here, since that often causes MongoDB to scan through more than it returns.
// Instead, we load up to the limit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ export class MongoSyncBucketStorage
limit: batchLimit,
// Increase batch size above the default 101, so that we can fill an entire batch in
// one go.
batchSize: batchLimit,
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: batchLimit + 1,
// Raw mode is returns an array of Buffer instead of parsed documents.
// We use it so that:
// 1. We can calculate the document size accurately without serializing again.
Expand Down Expand Up @@ -905,7 +907,9 @@ export class MongoSyncBucketStorage
'_id.b': 1
},
limit: limit + 1,
batchSize: limit + 1,
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: limit + 2,
singleBatch: true
}
)
Expand Down Expand Up @@ -935,7 +939,9 @@ export class MongoSyncBucketStorage
lookup: 1
},
limit: limit + 1,
batchSize: limit + 1,
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: limit + 2,
singleBatch: true
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class MongoWriteCheckpointAPI implements storage.WriteCheckpointAPI {
},
{
limit: limit + 1,
batchSize: limit + 1,
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: limit + 2,
singleBatch: true
}
)
Expand Down Expand Up @@ -140,7 +142,9 @@ export class MongoWriteCheckpointAPI implements storage.WriteCheckpointAPI {
},
{
limit: limit + 1,
batchSize: limit + 1,
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: limit + 2,
singleBatch: true
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function generateSlotName(prefix: string, sync_rules_id: number) {
* However, that makes `has_more` detection very difficult, since the cursor is always closed
* after the first batch. Instead, we do a workaround to only fetch a single batch below.
*
* For this to be effective, set batchSize = limit in the find command.
* For this to be effective, set batchSize = limit + 1 in the find command.
*/
export async function readSingleBatch<T>(cursor: mongo.AbstractCursor<T>): Promise<{ data: T[]; hasMore: boolean }> {
try {
Expand Down
4 changes: 2 additions & 2 deletions modules/module-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@powersync/service-jsonbig": "workspace:*",
"@powersync/service-sync-rules": "workspace:*",
"@powersync/service-types": "workspace:*",
"bson": "^6.10.3",
"bson": "^6.10.4",
"ts-codec": "^1.3.0",
"uuid": "^11.1.0"
},
Expand All @@ -43,4 +43,4 @@
"@powersync/service-module-mongodb-storage": "workspace:*",
"@powersync/service-module-postgres-storage": "workspace:*"
}
}
}
4 changes: 2 additions & 2 deletions modules/module-mongodb/src/replication/ChangeStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,8 @@ export class ChangeStream {
// Checkpoint out of order - should never happen with MongoDB.
// If it does happen, we throw an error to stop the replication - restarting should recover.
// Since we use batch.lastCheckpointLsn for the next resumeAfter, this should not result in an infinite loop.
// This is a workaround for the issue below, but we can keep this as a safety-check even if the issue is fixed.
// Driver issue report: https://jira.mongodb.org/browse/NODE-7042
// Originally a workaround for https://jira.mongodb.org/browse/NODE-7042.
// This has been fixed in the driver in the meantime, but we still keep this as a safety-check.
throw new ReplicationAssertionError(
`Change resumeToken ${(changeDocument._id as any)._data} (${timestampToDate(changeDocument.clusterTime!).toISOString()}) is less than last checkpoint LSN ${batch.lastCheckpointLsn}. Restarting replication.`
);
Expand Down
1 change: 1 addition & 0 deletions modules/module-mongodb/src/replication/MongoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class MongoManager {

// Identify the client
appName: `powersync ${POWERSYNC_VERSION}`,
// Deprecated in the driver - in a future release we may have to rely on appName only.
driverInfo: {
// This is merged with the node driver info.
name: 'powersync',
Expand Down
4 changes: 3 additions & 1 deletion modules/module-mongodb/src/replication/MongoSnapshotQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ export class ChunkedSnapshotQuery implements AsyncDisposable {
const filter: mongo.Filter<mongo.Document> =
this.lastKey == null ? {} : { $expr: { $gt: ['$_id', { $literal: this.lastKey }] } };
cursor = this.collection.find(filter, {
batchSize: this.batchSize,
readConcern: 'majority',
limit: this.batchSize,
// batchSize is 1 more than limit to auto-close the cursor.
// See https://github.com/mongodb/node-mongodb-native/pull/4580
batchSize: this.batchSize + 1,
sort: { _id: 1 }
});
newCursor = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@changesets/cli": "^2.27.8",
"@types/node": "^22.16.2",
"async": "^3.2.4",
"bson": "^6.10.3",
"bson": "^6.10.4",
"concurrently": "^8.2.2",
"inquirer": "^9.2.7",
"npm-check-updates": "^17.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/rsocket-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"@types/ws": "~8.2.0",
"bson": "^6.10.3",
"bson": "^6.10.4",
"rsocket-websocket-client": "1.0.0-alpha.3"
}
}
}
4 changes: 2 additions & 2 deletions packages/service-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@powersync/service-types": "workspace:*",
"async": "^3.2.4",
"async-mutex": "^0.5.0",
"bson": "^6.10.3",
"bson": "^6.10.4",
"commander": "^12.0.0",
"cors": "^2.8.5",
"ipaddr.js": "^2.1.0",
Expand All @@ -52,4 +52,4 @@
"fastify": "^5.4.0",
"fastify-plugin": "^5.0.1"
}
}
}
56 changes: 28 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.