Skip to content

Commit 0398ec8

Browse files
committed
Merge branch 'main' into metrics-refactor
# Conflicts: # modules/module-mongodb/test/src/change_stream_utils.ts # modules/module-mysql/test/src/BinlogStreamUtils.ts # modules/module-postgres/test/src/wal_stream_utils.ts # packages/service-core-tests/src/tests/register-sync-tests.ts # packages/service-core/src/routes/endpoints/socket-route.ts # packages/service-core/src/routes/endpoints/sync-stream.ts # packages/service-core/src/system/ServiceContext.ts
2 parents bf0e399 + 04e6fcc commit 0398ec8

File tree

76 files changed

+856
-419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+856
-419
lines changed

libs/lib-mongodb/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @powersync/lib-service-mongodb
22

3+
## 0.5.0
4+
5+
### Minor Changes
6+
7+
- ba7baeb: Make some service limits configurable.
8+
39
## 0.4.3
410

511
### Patch Changes

libs/lib-mongodb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@powersync/lib-service-mongodb",
33
"repository": "https://github.com/powersync-ja/powersync-service",
44
"types": "dist/index.d.ts",
5-
"version": "0.4.3",
5+
"version": "0.5.0",
66
"main": "dist/index.js",
77
"license": "FSL-1.1-Apache-2.0",
88
"type": "module",

libs/lib-mongodb/src/db/mongo.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export const MONGO_OPERATION_TIMEOUT_MS = 30_000;
2929
*/
3030
export const MONGO_CLEAR_OPERATION_TIMEOUT_MS = 5_000;
3131

32-
export function createMongoClient(config: BaseMongoConfigDecoded) {
32+
export interface MongoConnectionOptions {
33+
maxPoolSize: number;
34+
}
35+
36+
export function createMongoClient(config: BaseMongoConfigDecoded, options?: MongoConnectionOptions) {
3337
const normalized = normalizeMongoConfig(config);
3438
return new mongo.MongoClient(normalized.uri, {
3539
auth: {
@@ -48,7 +52,7 @@ export function createMongoClient(config: BaseMongoConfigDecoded) {
4852
// Avoid too many connections:
4953
// 1. It can overwhelm the source database.
5054
// 2. Processing too many queries in parallel can cause the process to run out of memory.
51-
maxPoolSize: 8,
55+
maxPoolSize: options?.maxPoolSize ?? 8,
5256

5357
maxConnecting: 3,
5458
maxIdleTimeMS: 60_000

libs/lib-postgres/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# @powersync/lib-service-postgres
22

3+
## 0.4.0
4+
5+
### Minor Changes
6+
7+
- 698467c: Use bigint everywhere internally for OpId.
8+
- ba7baeb: Make some service limits configurable.
9+
10+
### Patch Changes
11+
12+
- Updated dependencies [ba7baeb]
13+
- @powersync/service-types@0.9.0
14+
315
## 0.3.3
416

517
### Patch Changes

libs/lib-postgres/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@powersync/lib-service-postgres",
33
"repository": "https://github.com/powersync-ja/powersync-service",
44
"types": "dist/index.d.ts",
5-
"version": "0.3.3",
5+
"version": "0.4.0",
66
"main": "dist/index.js",
77
"license": "FSL-1.1-Apache-2.0",
88
"type": "module",

libs/lib-postgres/src/db/connection/DatabaseClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export class DatabaseClient extends AbstractPostgresConnection<DatabaseClientLis
4242
constructor(protected options: DatabaseClientOptions) {
4343
super();
4444
this.closed = false;
45-
this.pool = pgwire.connectPgWirePool(options.config);
45+
this.pool = pgwire.connectPgWirePool(options.config, {
46+
maxSize: options.config.max_pool_size
47+
});
4648
this.connections = Array.from({ length: TRANSACTION_CONNECTION_COUNT }, (v, index) => {
4749
// Only listen to notifications on a single (the first) connection
4850
const notificationChannels = index == 0 ? options.notificationChannels : [];

libs/lib-postgres/src/types/types.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import * as service_types from '@powersync/service-types';
44
import * as t from 'ts-codec';
55
import * as urijs from 'uri-js';
66

7-
export interface NormalizedBasePostgresConnectionConfig extends jpgwire.NormalizedConnectionConfig {}
7+
export interface NormalizedBasePostgresConnectionConfig extends jpgwire.NormalizedConnectionConfig {
8+
max_pool_size: number;
9+
}
810

911
export const POSTGRES_CONNECTION_TYPE = 'postgresql' as const;
1012

@@ -42,7 +44,9 @@ export const BasePostgresConnectionConfig = t.object({
4244
/**
4345
* Prefix for the slot name. Defaults to "powersync_"
4446
*/
45-
slot_name_prefix: t.string.optional()
47+
slot_name_prefix: t.string.optional(),
48+
49+
max_pool_size: t.number.optional()
4650
});
4751

4852
export type BasePostgresConnectionConfig = t.Encoded<typeof BasePostgresConnectionConfig>;
@@ -125,7 +129,9 @@ export function normalizeConnectionConfig(options: BasePostgresConnectionConfigD
125129
lookup,
126130

127131
client_certificate: options.client_certificate ?? undefined,
128-
client_private_key: options.client_private_key ?? undefined
132+
client_private_key: options.client_private_key ?? undefined,
133+
134+
max_pool_size: options.max_pool_size ?? 8
129135
} satisfies NormalizedBasePostgresConnectionConfig;
130136
}
131137

modules/module-mongodb-storage/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# @powersync/service-module-mongodb-storage
22

3+
## 0.7.0
4+
5+
### Minor Changes
6+
7+
- 698467c: Use bigint everywhere internally for OpId.
8+
- ba7baeb: Make some service limits configurable.
9+
10+
### Patch Changes
11+
12+
- Updated dependencies [0298720]
13+
- Updated dependencies [698467c]
14+
- Updated dependencies [ba7baeb]
15+
- @powersync/service-sync-rules@0.24.1
16+
- @powersync/service-core@1.8.0
17+
- @powersync/lib-service-mongodb@0.5.0
18+
- @powersync/service-types@0.9.0
19+
320
## 0.6.2
421

522
### Patch Changes

modules/module-mongodb-storage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@powersync/service-module-mongodb-storage",
33
"repository": "https://github.com/powersync-ja/powersync-service",
44
"types": "dist/index.d.ts",
5-
"version": "0.6.2",
5+
"version": "0.7.0",
66
"main": "dist/index.js",
77
"license": "FSL-1.1-Apache-2.0",
88
"type": "module",

modules/module-mongodb-storage/src/storage/implementation/MongoBucketBatch.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ReplicationAssertionError,
1212
ServiceError
1313
} from '@powersync/lib-services-framework';
14-
import { deserializeBson, SaveOperationTag, storage, utils } from '@powersync/service-core';
14+
import { deserializeBson, InternalOpId, SaveOperationTag, storage, utils } from '@powersync/service-core';
1515
import * as timers from 'node:timers/promises';
1616
import { PowerSyncMongo } from './db.js';
1717
import { CurrentBucket, CurrentDataDocument, SourceKey, SyncRuleDocument } from './models.js';
@@ -39,7 +39,7 @@ export interface MongoBucketBatchOptions {
3939
groupId: number;
4040
slotName: string;
4141
lastCheckpointLsn: string | null;
42-
keepaliveOp: string | null;
42+
keepaliveOp: InternalOpId | null;
4343
noCheckpointBeforeLsn: string;
4444
storeCurrentData: boolean;
4545
/**
@@ -77,12 +77,12 @@ export class MongoBucketBatch
7777

7878
private no_checkpoint_before_lsn: string;
7979

80-
private persisted_op: bigint | null = null;
80+
private persisted_op: InternalOpId | null = null;
8181

8282
/**
8383
* For tests only - not for persistence logic.
8484
*/
85-
public last_flushed_op: bigint | null = null;
85+
public last_flushed_op: InternalOpId | null = null;
8686

8787
constructor(options: MongoBucketBatchOptions) {
8888
super();
@@ -98,9 +98,7 @@ export class MongoBucketBatch
9898
this.skipExistingRows = options.skipExistingRows;
9999
this.batch = new OperationBatch();
100100

101-
if (options.keepaliveOp) {
102-
this.persisted_op = BigInt(options.keepaliveOp);
103-
}
101+
this.persisted_op = options.keepaliveOp ?? null;
104102
}
105103

106104
addCustomWriteCheckpoint(checkpoint: storage.BatchedCustomWriteCheckpointOptions): void {
@@ -135,7 +133,7 @@ export class MongoBucketBatch
135133
return null;
136134
}
137135

138-
let last_op: bigint | null = null;
136+
let last_op: InternalOpId | null = null;
139137
let resumeBatch: OperationBatch | null = null;
140138

141139
await this.withReplicationTransaction(`Flushing ${batch.length} ops`, async (session, opSeq) => {
@@ -153,7 +151,7 @@ export class MongoBucketBatch
153151

154152
this.persisted_op = last_op;
155153
this.last_flushed_op = last_op;
156-
return { flushed_op: String(last_op) };
154+
return { flushed_op: last_op };
157155
}
158156

159157
private async replicateBatch(
@@ -776,22 +774,23 @@ export class MongoBucketBatch
776774
async truncate(sourceTables: storage.SourceTable[]): Promise<storage.FlushedResult | null> {
777775
await this.flush();
778776

779-
let last_op: bigint | null = null;
777+
let last_op: InternalOpId | null = null;
780778
for (let table of sourceTables) {
781779
last_op = await this.truncateSingle(table);
782780
}
783781

784782
if (last_op) {
785783
this.persisted_op = last_op;
784+
return {
785+
flushed_op: last_op
786+
};
787+
} else {
788+
return null;
786789
}
787-
788-
return {
789-
flushed_op: String(last_op!)
790-
};
791790
}
792791

793-
async truncateSingle(sourceTable: storage.SourceTable): Promise<bigint> {
794-
let last_op: bigint | null = null;
792+
async truncateSingle(sourceTable: storage.SourceTable): Promise<InternalOpId> {
793+
let last_op: InternalOpId | null = null;
795794

796795
// To avoid too large transactions, we limit the amount of data we delete per transaction.
797796
// Since we don't use the record data here, we don't have explicit size limits per batch.

0 commit comments

Comments
 (0)