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/slow-hounds-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@powersync/service-module-mongodb-storage': patch
'@powersync/service-module-mongodb': patch
'@powersync/service-module-mysql': patch
'@powersync/lib-service-mongodb': patch
'@powersync/service-core': patch
'@powersync/service-image': patch
---

Add 'powersync' as the app name for MongoDB and MySQL connections.
7 changes: 6 additions & 1 deletion libs/lib-mongodb/src/db/mongo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as mongo from 'mongodb';
import * as timers from 'timers/promises';
import { BaseMongoConfigDecoded, normalizeMongoConfig } from '../types/types.js';
import { validateIpHostname } from '@powersync/lib-services-framework';

/**
* Time for new connection to timeout.
Expand Down Expand Up @@ -33,6 +32,9 @@ export interface MongoConnectionOptions {
maxPoolSize: number;
}

/**
* Create a MongoClient for the storage database.
*/
export function createMongoClient(config: BaseMongoConfigDecoded, options?: MongoConnectionOptions) {
const normalized = normalizeMongoConfig(config);
return new mongo.MongoClient(normalized.uri, {
Expand All @@ -47,6 +49,9 @@ export function createMongoClient(config: BaseMongoConfigDecoded, options?: Mong
// How long to wait for new primary selection
serverSelectionTimeoutMS: 30_000,

// Identify the client
appName: 'powersync-storage',

lookup: normalized.lookup,

// Avoid too many connections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function replicaIdToSubkey(table: bson.ObjectId, id: storage.ReplicaId):
/**
* Helper function for creating a MongoDB client from consumers of this package
*/
export const createMongoClient = (url: string, options?: mongo.MongoClientOptions) => {
const createMongoClient = (url: string, options?: mongo.MongoClientOptions) => {
return new mongo.MongoClient(url, options);
};

Expand Down
6 changes: 6 additions & 0 deletions modules/module-mongodb/src/replication/MongoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { mongo } from '@powersync/lib-service-mongodb';
import { NormalizedMongoConnectionConfig } from '../types/types.js';
import { BSON_DESERIALIZE_DATA_OPTIONS } from '@powersync/service-core';

/**
* Manage a MongoDB source database connection.
*/
export class MongoManager {
public readonly client: mongo.MongoClient;
public readonly db: mongo.Db;
Expand All @@ -26,6 +29,9 @@ export class MongoManager {
// How long to wait for new primary selection
serverSelectionTimeoutMS: 30_000,

// Identify the client
appName: 'powersync',

// Avoid too many connections:
// 1. It can overwhelm the source database.
// 2. Processing too many queries in parallel can cause the process to run out of memory.
Expand Down
11 changes: 10 additions & 1 deletion modules/module-mysql/src/replication/BinLogReplicationJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ export class BinLogReplicationJob extends replication.AbstractReplicationJob {
// such as caused by cached PG schemas.
const connectionManager = this.connectionFactory.create({
// Pool connections are only used intermittently.
idleTimeout: 30_000
idleTimeout: 30_000,

connectAttributes: {
// https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html
// These do not appear to be supported by Zongji yet, so we only specify it here.
// Query using `select * from performance_schema.session_connect_attrs`.
program_name: 'powersync'

// _client_name and _client_version is specified by the driver
}
});
try {
await this.rateLimiter?.waitUntilAllowed({ signal: this.abortController.signal });
Expand Down