@powersync/service-core 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/api/RouteAPI.d.ts +2 -2
- package/dist/api/diagnostics.d.ts +12 -1
- package/dist/api/diagnostics.js +34 -22
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +1 -1
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +6 -2
- package/dist/modules/AbstractModule.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +2 -2
- package/dist/replication/AbstractReplicator.js +24 -23
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.d.ts +3 -3
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +12 -12
- package/dist/routes/endpoints/admin.d.ts +24 -24
- package/dist/routes/endpoints/admin.js +44 -34
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.js +1 -1
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +1 -1
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +22 -13
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +1 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/runner/teardown.js +8 -8
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +0 -6
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +22 -27
- package/dist/storage/BucketStorageFactory.js +4 -18
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/ParsedSyncConfigSet.d.ts +23 -0
- package/dist/storage/ParsedSyncConfigSet.js +2 -0
- package/dist/storage/ParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/PersistedReplicationStream.d.ts +32 -0
- package/dist/storage/PersistedReplicationStream.js +26 -0
- package/dist/storage/PersistedReplicationStream.js.map +1 -0
- package/dist/storage/PersistedSyncConfigContent.d.ts +60 -0
- package/dist/storage/PersistedSyncConfigContent.js +123 -0
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/PersistedSyncConfigStatus.d.ts +13 -0
- package/dist/storage/PersistedSyncConfigStatus.js +2 -0
- package/dist/storage/PersistedSyncConfigStatus.js.map +1 -0
- package/dist/storage/SourceTable.d.ts +9 -3
- package/dist/storage/SourceTable.js +13 -3
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +59 -16
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +117 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +277 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.d.ts +6 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +31 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.d.ts +17 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +62 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.d.ts +15 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js +20 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js.map +1 -0
- package/dist/storage/storage-index.d.ts +8 -1
- package/dist/storage/storage-index.js +8 -1
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/sync.js +5 -0
- package/dist/sync/sync.js.map +1 -1
- package/dist/util/checkpointing.js +1 -1
- package/dist/util/checkpointing.js.map +1 -1
- package/dist/util/config/types.d.ts +1 -1
- package/dist/util/lsn.d.ts +4 -0
- package/dist/util/lsn.js +10 -0
- package/dist/util/lsn.js.map +1 -1
- package/package.json +6 -7
- package/src/api/RouteAPI.ts +2 -2
- package/src/api/diagnostics.ts +43 -26
- package/src/entry/commands/compact-action.ts +1 -1
- package/src/modules/AbstractModule.ts +6 -2
- package/src/replication/AbstractReplicator.ts +27 -26
- package/src/replication/ReplicationModule.ts +2 -3
- package/src/routes/endpoints/admin.ts +70 -49
- package/src/routes/endpoints/checkpointing.ts +1 -1
- package/src/routes/endpoints/socket-route.ts +1 -1
- package/src/routes/endpoints/sync-rules.ts +23 -13
- package/src/routes/endpoints/sync-stream.ts +1 -1
- package/src/runner/teardown.ts +8 -8
- package/src/storage/BucketStorageBatch.ts +0 -7
- package/src/storage/BucketStorageFactory.ts +30 -39
- package/src/storage/ParsedSyncConfigSet.ts +25 -0
- package/src/storage/PersistedReplicationStream.ts +55 -0
- package/src/storage/PersistedSyncConfigContent.ts +188 -0
- package/src/storage/PersistedSyncConfigStatus.ts +14 -0
- package/src/storage/SourceTable.ts +20 -3
- package/src/storage/SyncRulesBucketStorage.ts +64 -16
- package/src/storage/implementation/BucketDefinitionMapping.ts +436 -0
- package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +41 -0
- package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +109 -0
- package/src/storage/implementation/ReplicationStreamStorageIds.ts +21 -0
- package/src/storage/storage-index.ts +9 -1
- package/src/sync/sync.ts +5 -0
- package/src/util/checkpointing.ts +1 -1
- package/src/util/config/types.ts +1 -1
- package/src/util/lsn.ts +9 -0
- package/test/src/diagnostics.test.ts +61 -34
- package/test/src/module-loader.test.ts +33 -1
- package/test/src/routes/admin.test.ts +180 -18
- package/test/src/routes/mocks.ts +6 -2
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +0 -59
- package/dist/storage/PersistedSyncRulesContent.js +0 -100
- package/dist/storage/PersistedSyncRulesContent.js.map +0 -1
- package/src/storage/PersistedSyncRulesContent.ts +0 -174
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { logger as defaultLogger, ErrorCode, ServiceError } from '@powersync/lib-services-framework';
|
|
2
|
+
import {
|
|
3
|
+
CompatibilityContext,
|
|
4
|
+
CompatibilityOption,
|
|
5
|
+
DEFAULT_HYDRATION_STATE,
|
|
6
|
+
deserializeSyncPlan,
|
|
7
|
+
ErrorLocation,
|
|
8
|
+
HydratedSyncConfig,
|
|
9
|
+
HydrationState,
|
|
10
|
+
nodeSqlite,
|
|
11
|
+
PrecompiledSyncConfig,
|
|
12
|
+
SqlEventDescriptor,
|
|
13
|
+
SqlSyncRules,
|
|
14
|
+
SyncConfigWithErrors,
|
|
15
|
+
versionedHydrationState,
|
|
16
|
+
YamlError
|
|
17
|
+
} from '@powersync/service-sync-rules';
|
|
18
|
+
import * as sqlite from 'node:sqlite';
|
|
19
|
+
import { Logger } from 'winston';
|
|
20
|
+
import { SerializedSyncPlan, UpdateSyncRulesOptions } from './BucketStorageFactory.js';
|
|
21
|
+
import { ParsedSyncConfigSet } from './ParsedSyncConfigSet.js';
|
|
22
|
+
import { PersistedSyncConfigStatus } from './PersistedSyncConfigStatus.js';
|
|
23
|
+
import { STORAGE_VERSION_CONFIG, StorageVersionConfig } from './StorageVersionConfig.js';
|
|
24
|
+
|
|
25
|
+
export interface ParsePersistedSyncConfigContentOptions {
|
|
26
|
+
content: string;
|
|
27
|
+
compiledPlan: SerializedSyncPlan | null;
|
|
28
|
+
storageVersion: number;
|
|
29
|
+
parseOptions: ParseSyncConfigOptions;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function parsePersistedSyncConfigContent(options: ParsePersistedSyncConfigContentOptions): SyncConfigWithErrors {
|
|
33
|
+
const { content, compiledPlan, storageVersion, parseOptions } = options;
|
|
34
|
+
|
|
35
|
+
if (compiledPlan == null) {
|
|
36
|
+
// Fallback: Only parse from YAML if no compiled plan is available.
|
|
37
|
+
return SqlSyncRules.fromYaml(content, parseOptions);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const plan = deserializeSyncPlan(compiledPlan.plan);
|
|
41
|
+
const compatibility = CompatibilityContext.deserialize(compiledPlan.compatibility);
|
|
42
|
+
const eventDefinitions: SqlEventDescriptor[] = [];
|
|
43
|
+
for (const [name, queries] of Object.entries(compiledPlan.eventDescriptors)) {
|
|
44
|
+
const descriptor = new SqlEventDescriptor(name, compatibility);
|
|
45
|
+
for (const query of queries) {
|
|
46
|
+
descriptor.addSourceQuery(query, parseOptions);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
eventDefinitions.push(descriptor);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const precompiled = new PrecompiledSyncConfig(plan, compatibility, eventDefinitions, {
|
|
53
|
+
defaultSchema: parseOptions.defaultSchema,
|
|
54
|
+
sourceText: content
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Note: If the original content did not define a storage version, this will still set the storage version.
|
|
58
|
+
// This means asUpdateOptions will not change the storage version, even if the default changes.
|
|
59
|
+
precompiled.storageVersion = storageVersion;
|
|
60
|
+
|
|
61
|
+
const errors: YamlError[] = [];
|
|
62
|
+
if (compiledPlan.errors) {
|
|
63
|
+
for (const error of compiledPlan.errors) {
|
|
64
|
+
const location: ErrorLocation | undefined = error.location && {
|
|
65
|
+
start: error.location.start_offset,
|
|
66
|
+
end: error.location.end_offset
|
|
67
|
+
};
|
|
68
|
+
const asYamlError = new YamlError(new Error(error.message), location);
|
|
69
|
+
asYamlError.type = error.level;
|
|
70
|
+
|
|
71
|
+
errors.push(asYamlError);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { config: precompiled, errors };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Immutable sync config content for one sync config inside a replication stream.
|
|
80
|
+
*
|
|
81
|
+
* This represents the persisted config content. Fetch per-config status with
|
|
82
|
+
* {@link getSyncConfigStatus}. Use {@link PersistedReplicationStream} for stream
|
|
83
|
+
* lifecycle concerns such as locking and termination.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
export abstract class PersistedSyncConfigContent implements PersistedSyncConfigContentData {
|
|
87
|
+
readonly replicationStreamId: number;
|
|
88
|
+
readonly sync_rules_content: string;
|
|
89
|
+
readonly compiled_plan: SerializedSyncPlan | null;
|
|
90
|
+
readonly replicationStreamName: string;
|
|
91
|
+
readonly storageVersion: number;
|
|
92
|
+
readonly logger: Logger;
|
|
93
|
+
readonly syncConfigId: PersistedSyncConfigId | null;
|
|
94
|
+
|
|
95
|
+
constructor(data: PersistedSyncConfigContentData) {
|
|
96
|
+
this.replicationStreamId = data.replicationStreamId;
|
|
97
|
+
this.sync_rules_content = data.sync_rules_content;
|
|
98
|
+
this.compiled_plan = data.compiled_plan;
|
|
99
|
+
this.replicationStreamName = data.replicationStreamName;
|
|
100
|
+
this.storageVersion = data.storageVersion;
|
|
101
|
+
this.syncConfigId = data.syncConfigId ?? null;
|
|
102
|
+
this.logger = defaultLogger.child({ prefix: `[${this.replicationStreamName}] ` });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Load the storage config.
|
|
107
|
+
*
|
|
108
|
+
* This may throw if the persisted storage version is not supported.
|
|
109
|
+
*/
|
|
110
|
+
getStorageConfig(): StorageVersionConfig {
|
|
111
|
+
const storageConfig = STORAGE_VERSION_CONFIG[this.storageVersion];
|
|
112
|
+
if (storageConfig == null) {
|
|
113
|
+
throw new ServiceError(
|
|
114
|
+
ErrorCode.PSYNC_S1005,
|
|
115
|
+
`Unsupported storage version ${this.storageVersion} for replication stream ${this.replicationStreamId}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return storageConfig;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Parse only this config's content into a single {@link SyncConfigWithErrors}.
|
|
123
|
+
*
|
|
124
|
+
* This does not depend on any other configs in the same replication stream.
|
|
125
|
+
*/
|
|
126
|
+
protected parseSingleConfig(options: ParseSyncConfigOptions): SyncConfigWithErrors {
|
|
127
|
+
return parsePersistedSyncConfigContent({
|
|
128
|
+
content: this.sync_rules_content,
|
|
129
|
+
compiledPlan: this.compiled_plan,
|
|
130
|
+
storageVersion: this.storageVersion,
|
|
131
|
+
parseOptions: options
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
parsed(options: ParseSyncConfigOptions): ParsedSyncConfigSet {
|
|
136
|
+
let hydrationState: HydrationState;
|
|
137
|
+
const config = this.parseSingleConfig(options);
|
|
138
|
+
|
|
139
|
+
const storageConfig = this.getStorageConfig();
|
|
140
|
+
if (
|
|
141
|
+
storageConfig.versionedBuckets ||
|
|
142
|
+
config.config.compatibility.isEnabled(CompatibilityOption.versionedBucketIds)
|
|
143
|
+
) {
|
|
144
|
+
hydrationState = versionedHydrationState(this.replicationStreamId);
|
|
145
|
+
} else {
|
|
146
|
+
hydrationState = DEFAULT_HYDRATION_STATE;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let hydrated: HydratedSyncConfig | undefined;
|
|
150
|
+
return {
|
|
151
|
+
replicationStreamId: this.replicationStreamId,
|
|
152
|
+
replicationStreamName: this.replicationStreamName,
|
|
153
|
+
syncConfigs: [config],
|
|
154
|
+
hydrationState,
|
|
155
|
+
get hydratedSyncConfig(): HydratedSyncConfig {
|
|
156
|
+
hydrated ??= config.config.hydrate({ hydrationState, sqlite: nodeSqlite(sqlite) });
|
|
157
|
+
return hydrated;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
asUpdateOptions(options?: Omit<UpdateSyncRulesOptions, 'config'>): UpdateSyncRulesOptions {
|
|
163
|
+
// defaultSchema is not relevant for the parsed version here
|
|
164
|
+
const parsed = this.parseSingleConfig({ defaultSchema: 'not_applicable' });
|
|
165
|
+
return {
|
|
166
|
+
config: { yaml: this.sync_rules_content, plan: this.compiled_plan, parsed },
|
|
167
|
+
...options
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Fetch the current persisted state for this exact sync config.
|
|
173
|
+
*/
|
|
174
|
+
abstract getSyncConfigStatus(): Promise<PersistedSyncConfigStatus | null>;
|
|
175
|
+
}
|
|
176
|
+
export interface PersistedSyncConfigContentData {
|
|
177
|
+
readonly replicationStreamId: number;
|
|
178
|
+
readonly sync_rules_content: string;
|
|
179
|
+
readonly compiled_plan: SerializedSyncPlan | null;
|
|
180
|
+
readonly replicationStreamName: string;
|
|
181
|
+
readonly storageVersion: number;
|
|
182
|
+
|
|
183
|
+
readonly syncConfigId?: PersistedSyncConfigId | null;
|
|
184
|
+
}
|
|
185
|
+
export type PersistedSyncConfigId = string;
|
|
186
|
+
export interface ParseSyncConfigOptions {
|
|
187
|
+
defaultSchema: string;
|
|
188
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SyncRuleState } from './BucketStorage.js';
|
|
2
|
+
import { PersistedSyncConfigId } from './PersistedSyncConfigContent.js';
|
|
3
|
+
|
|
4
|
+
export interface PersistedSyncConfigStatus {
|
|
5
|
+
readonly id: PersistedSyncConfigId;
|
|
6
|
+
readonly replicationStreamId: number;
|
|
7
|
+
readonly state: SyncRuleState;
|
|
8
|
+
readonly snapshot_done?: boolean;
|
|
9
|
+
readonly last_checkpoint_lsn: string | null;
|
|
10
|
+
readonly last_fatal_error?: string | null;
|
|
11
|
+
readonly last_fatal_error_ts?: Date | null;
|
|
12
|
+
readonly last_keepalive_ts?: Date | null;
|
|
13
|
+
readonly last_checkpoint_ts?: Date | null;
|
|
14
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BucketDataSource,
|
|
3
|
+
BucketDefinitionId,
|
|
3
4
|
DEFAULT_TAG,
|
|
5
|
+
ParameterIndexId,
|
|
4
6
|
ParameterIndexLookupCreator,
|
|
5
7
|
SourceTableRef
|
|
6
8
|
} from '@powersync/service-sync-rules';
|
|
@@ -21,6 +23,8 @@ export interface SourceTableOptions {
|
|
|
21
23
|
snapshotComplete: boolean;
|
|
22
24
|
bucketDataSources: BucketDataSource[];
|
|
23
25
|
parameterLookupSources: ParameterIndexLookupCreator[];
|
|
26
|
+
bucketDataSourceIds?: Set<BucketDefinitionId>;
|
|
27
|
+
parameterLookupSourceIds?: Set<ParameterIndexId>;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
export interface TableSnapshotStatus {
|
|
@@ -57,9 +61,11 @@ export class SourceTable {
|
|
|
57
61
|
public syncParameters = true;
|
|
58
62
|
|
|
59
63
|
/**
|
|
60
|
-
* True if
|
|
64
|
+
* True if this table should fire events for row changes.
|
|
61
65
|
*
|
|
62
|
-
* This value is resolved externally, and cached here.
|
|
66
|
+
* This value is resolved externally, and cached here. When multiple SourceTables exist
|
|
67
|
+
* for the same SourceTableRef (v3 storage), resolveTables designates exactly one of them
|
|
68
|
+
* as the event carrier, so that a row change saved once per table fires each event once.
|
|
63
69
|
*
|
|
64
70
|
* Defaults to true for tests.
|
|
65
71
|
*/
|
|
@@ -122,6 +128,14 @@ export class SourceTable {
|
|
|
122
128
|
return this.options.parameterLookupSources;
|
|
123
129
|
}
|
|
124
130
|
|
|
131
|
+
get bucketDataSourceIds() {
|
|
132
|
+
return this.options.bucketDataSourceIds;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get parameterLookupSourceIds() {
|
|
136
|
+
return this.options.parameterLookupSourceIds;
|
|
137
|
+
}
|
|
138
|
+
|
|
125
139
|
/**
|
|
126
140
|
* Sanitized name of the entity in the format of "{schema}.{entity name}".
|
|
127
141
|
* Suitable for safe use in Postgres queries.
|
|
@@ -145,7 +159,10 @@ export class SourceTable {
|
|
|
145
159
|
replicaIdColumns: this.replicaIdColumns,
|
|
146
160
|
snapshotComplete: this.snapshotComplete,
|
|
147
161
|
bucketDataSources: this.bucketDataSources,
|
|
148
|
-
parameterLookupSources: this.parameterLookupSources
|
|
162
|
+
parameterLookupSources: this.parameterLookupSources,
|
|
163
|
+
bucketDataSourceIds: this.bucketDataSourceIds == null ? undefined : new Set(this.bucketDataSourceIds),
|
|
164
|
+
parameterLookupSourceIds:
|
|
165
|
+
this.parameterLookupSourceIds == null ? undefined : new Set(this.parameterLookupSourceIds)
|
|
149
166
|
});
|
|
150
167
|
copy.syncData = this.syncData;
|
|
151
168
|
copy.syncParameters = this.syncParameters;
|
|
@@ -10,7 +10,8 @@ import { PerformanceTracer } from '../tracing/PerformanceTracer.js';
|
|
|
10
10
|
import * as util from '../util/util-index.js';
|
|
11
11
|
import { BucketStorageBatch, FlushedResult, SaveUpdate } from './BucketStorageBatch.js';
|
|
12
12
|
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
13
|
-
import {
|
|
13
|
+
import { ParsedSyncConfigSet } from './ParsedSyncConfigSet.js';
|
|
14
|
+
import { ParseSyncConfigOptions } from './PersistedSyncConfigContent.js';
|
|
14
15
|
import { SourceEntityDescriptor } from './SourceEntity.js';
|
|
15
16
|
import { SourceTable } from './SourceTable.js';
|
|
16
17
|
import { StorageVersionConfig } from './StorageVersionConfig.js';
|
|
@@ -22,8 +23,8 @@ import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js';
|
|
|
22
23
|
export interface SyncRulesBucketStorage
|
|
23
24
|
extends ObserverClient<SyncRulesBucketStorageListener>,
|
|
24
25
|
SyncStorageWriteCheckpointAPI {
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
26
|
+
readonly replicationStreamId: number;
|
|
27
|
+
readonly replicationStreamName: string;
|
|
27
28
|
readonly storageConfig: StorageVersionConfig;
|
|
28
29
|
|
|
29
30
|
readonly factory: BucketStorageFactory;
|
|
@@ -44,7 +45,20 @@ export interface SyncRulesBucketStorage
|
|
|
44
45
|
callback: (batch: BucketStorageBatch) => Promise<void>
|
|
45
46
|
): Promise<FlushedResult | null>;
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Get the canonical parsed sync config set for the given parse options.
|
|
50
|
+
*
|
|
51
|
+
* Repeated calls with the same options return the same instance for the lifetime of
|
|
52
|
+
* this storage instance. This is the identity boundary for parsed sync config state:
|
|
53
|
+
* all operations against this storage instance must use parsed objects from sets
|
|
54
|
+
* returned here, never from an independent parse of the same content.
|
|
55
|
+
*/
|
|
56
|
+
getParsedSyncConfigSet(options: ParseSyncConfigOptions): ParsedSyncConfigSet;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Shortcut for `getParsedSyncConfigSet(options).hydratedSyncConfig`.
|
|
60
|
+
*/
|
|
61
|
+
getParsedSyncRules(options: ParseSyncConfigOptions): HydratedSyncConfig;
|
|
48
62
|
|
|
49
63
|
/**
|
|
50
64
|
* Terminate the replication stream.
|
|
@@ -55,7 +69,7 @@ export interface SyncRulesBucketStorage
|
|
|
55
69
|
*/
|
|
56
70
|
terminate(options?: TerminateOptions): Promise<void>;
|
|
57
71
|
|
|
58
|
-
getStatus(): Promise<
|
|
72
|
+
getStatus(): Promise<ReplicationStreamStatus>;
|
|
59
73
|
|
|
60
74
|
/**
|
|
61
75
|
* Clear the storage, without changing state.
|
|
@@ -133,6 +147,12 @@ export interface SyncRulesBucketStorage
|
|
|
133
147
|
* Clear checksum cache. Primarily intended for tests.
|
|
134
148
|
*/
|
|
135
149
|
clearChecksumCache(): void;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Optional storage-provider cleanup for sync configs that have been stopped
|
|
153
|
+
* inside this replication stream.
|
|
154
|
+
*/
|
|
155
|
+
cleanupStoppedSyncConfigs?(options: CleanupStoppedSyncConfigsOptions): Promise<CleanupStoppedSyncConfigsResult>;
|
|
136
156
|
}
|
|
137
157
|
|
|
138
158
|
export interface SyncRulesBucketStorageListener {
|
|
@@ -149,15 +169,15 @@ export interface BucketChecksumRequest {
|
|
|
149
169
|
source: BucketDataSource;
|
|
150
170
|
}
|
|
151
171
|
|
|
152
|
-
export interface
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
172
|
+
export interface ReplicationStreamStatus {
|
|
173
|
+
/**
|
|
174
|
+
* Source position to resume replication from.
|
|
175
|
+
*/
|
|
176
|
+
resumeLsn: string | null;
|
|
157
177
|
/**
|
|
158
|
-
*
|
|
178
|
+
* True if _every_ active/processing sync config has a client-visible checkpoint.
|
|
159
179
|
*/
|
|
160
|
-
|
|
180
|
+
snapshotDone: boolean;
|
|
161
181
|
}
|
|
162
182
|
export interface ResolveTablesOptions {
|
|
163
183
|
connection_id: number;
|
|
@@ -167,9 +187,9 @@ export interface ResolveTablesOptions {
|
|
|
167
187
|
*/
|
|
168
188
|
idGenerator?: () => string | bson.ObjectId;
|
|
169
189
|
/**
|
|
170
|
-
* For tests only - override the sync
|
|
190
|
+
* For tests only - override the parsed sync config set used.
|
|
171
191
|
*/
|
|
172
|
-
|
|
192
|
+
parsedSyncConfig?: ParsedSyncConfigSet;
|
|
173
193
|
}
|
|
174
194
|
|
|
175
195
|
export interface ResolveTablesResult {
|
|
@@ -177,7 +197,7 @@ export interface ResolveTablesResult {
|
|
|
177
197
|
dropTables: SourceTable[];
|
|
178
198
|
}
|
|
179
199
|
|
|
180
|
-
export interface CreateWriterOptions extends
|
|
200
|
+
export interface CreateWriterOptions extends ParseSyncConfigOptions {
|
|
181
201
|
zeroLSN: string;
|
|
182
202
|
/**
|
|
183
203
|
* Whether or not to store a copy of the current data.
|
|
@@ -262,6 +282,9 @@ export interface CompactOptions {
|
|
|
262
282
|
/** Minimum of 1 */
|
|
263
283
|
moveBatchQueryLimit?: number;
|
|
264
284
|
|
|
285
|
+
/** Byte cap per read batch for streaming compaction. Default 16MB. */
|
|
286
|
+
moveBatchByteLimit?: number;
|
|
287
|
+
|
|
265
288
|
/**
|
|
266
289
|
* Minimum number new operations in a bucket to trigger compaction of that bucket.
|
|
267
290
|
*
|
|
@@ -287,7 +310,14 @@ export interface CompactOptions {
|
|
|
287
310
|
}
|
|
288
311
|
|
|
289
312
|
export interface PopulateChecksumCacheOptions {
|
|
290
|
-
|
|
313
|
+
/**
|
|
314
|
+
* Compute checksums up to this op id.
|
|
315
|
+
*
|
|
316
|
+
* Defaults to the highest persisted op id for the replication stream, which covers
|
|
317
|
+
* the common case of populating the cache right after initial replication, before
|
|
318
|
+
* the first checkpoint exists.
|
|
319
|
+
*/
|
|
320
|
+
maxOpId?: util.InternalOpId;
|
|
291
321
|
minBucketChanges?: number;
|
|
292
322
|
signal?: AbortSignal;
|
|
293
323
|
}
|
|
@@ -303,6 +333,24 @@ export interface ClearStorageOptions {
|
|
|
303
333
|
signal?: AbortSignal;
|
|
304
334
|
}
|
|
305
335
|
|
|
336
|
+
export interface CleanupStoppedSyncConfigsOptions {
|
|
337
|
+
signal?: AbortSignal;
|
|
338
|
+
logger?: Logger;
|
|
339
|
+
defaultSchema: string;
|
|
340
|
+
sourceConnectionTag: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface CleanupStoppedSyncConfigsResult {
|
|
344
|
+
stoppedSyncConfigsRemoved: number;
|
|
345
|
+
bucketDataCollectionsDropped: number;
|
|
346
|
+
parameterIndexCollectionsDropped: number;
|
|
347
|
+
/** Best-effort number, not accurate if the operation takes longer than the timeout. */
|
|
348
|
+
bucketStateDocumentsDeleted: number;
|
|
349
|
+
sourceRecordCollectionsDropped: number;
|
|
350
|
+
sourceTablesUpdated: number;
|
|
351
|
+
sourceTablesDeleted: number;
|
|
352
|
+
}
|
|
353
|
+
|
|
306
354
|
export interface TerminateOptions extends ClearStorageOptions {
|
|
307
355
|
/**
|
|
308
356
|
* If true, also clear the storage before terminating.
|