diff --git a/.changeset/slow-hounds-walk.md b/.changeset/slow-hounds-walk.md new file mode 100644 index 000000000..1745e4389 --- /dev/null +++ b/.changeset/slow-hounds-walk.md @@ -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. diff --git a/libs/lib-mongodb/src/db/mongo.ts b/libs/lib-mongodb/src/db/mongo.ts index 5062043b0..ddeaf39dc 100644 --- a/libs/lib-mongodb/src/db/mongo.ts +++ b/libs/lib-mongodb/src/db/mongo.ts @@ -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. @@ -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, { @@ -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: diff --git a/modules/module-mongodb-storage/src/storage/implementation/util.ts b/modules/module-mongodb-storage/src/storage/implementation/util.ts index ea6b587f3..2c9a05d53 100644 --- a/modules/module-mongodb-storage/src/storage/implementation/util.ts +++ b/modules/module-mongodb-storage/src/storage/implementation/util.ts @@ -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); }; diff --git a/modules/module-mongodb/src/replication/MongoManager.ts b/modules/module-mongodb/src/replication/MongoManager.ts index d2cc2cee2..3742406ba 100644 --- a/modules/module-mongodb/src/replication/MongoManager.ts +++ b/modules/module-mongodb/src/replication/MongoManager.ts @@ -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; @@ -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. diff --git a/modules/module-mysql/src/replication/BinLogReplicationJob.ts b/modules/module-mysql/src/replication/BinLogReplicationJob.ts index 49280c9e3..24a07a49a 100644 --- a/modules/module-mysql/src/replication/BinLogReplicationJob.ts +++ b/modules/module-mysql/src/replication/BinLogReplicationJob.ts @@ -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 });