Skip to content

Commit e7cf732

Browse files
committed
Add options for specifying deletionStrategy in replication config methods/returns
1 parent e272b37 commit e7cf732

File tree

7 files changed

+125
-9
lines changed

7 files changed

+125
-9
lines changed

src/collections/config/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ export type MultiTenancyConfig = {
4040
enabled: boolean;
4141
};
4242

43+
export type ReplicationDeletionStrategy = 'DeleteOnConflict' | 'NoAutomatedResolution';
44+
4345
export type ReplicationConfig = {
4446
asyncEnabled: boolean;
47+
deletionStrategy: ReplicationDeletionStrategy;
4548
factor: number;
4649
};
4750

src/collections/config/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class ConfigMapping {
265265
return {
266266
factor: v.factor,
267267
asyncEnabled: v.asyncEnabled ? v.asyncEnabled : false,
268+
deletionStrategy: v.deletionStrategy ? v.deletionStrategy : 'NoAutomatedResolution',
268269
};
269270
}
270271
static sharding(v?: WeaviateShardingConfig): ShardingConfig {

src/collections/configure/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
InvertedIndexConfigUpdate,
44
MultiTenancyConfigCreate,
55
ReplicationConfigCreate,
6+
ReplicationDeletionStrategy,
67
ShardingConfigCreate,
78
VectorConfigUpdate,
89
VectorIndexType,
@@ -131,10 +132,19 @@ const configure = {
131132
* See [the docs](https://weaviate.io/developers/weaviate/concepts/replication-architecture#replication-vs-sharding) for more details.
132133
*
133134
* @param {boolean} [options.asyncEnabled] Whether asynchronous replication is enabled. Default is false.
135+
* @param {ReplicationDeletionStrategy} [options.deletionStrategy] The deletion strategy when replication conflicts are detected between deletes and reads.
134136
* @param {number} [options.factor] The replication factor. Default is 1.
135137
*/
136-
replication: (options: { asyncEnabled?: boolean; factor?: number }): ReplicationConfigCreate => {
137-
return { asyncEnabled: options.asyncEnabled, factor: options.factor };
138+
replication: (options: {
139+
asyncEnabled?: boolean;
140+
deletionStrategy?: ReplicationDeletionStrategy;
141+
factor?: number;
142+
}): ReplicationConfigCreate => {
143+
return {
144+
asyncEnabled: options.asyncEnabled,
145+
deletionStrategy: options.deletionStrategy,
146+
factor: options.factor,
147+
};
138148
},
139149
/**
140150
* Create a `ShardingConfigCreate` object to be used when defining the sharding configuration of your collection.
@@ -217,10 +227,19 @@ const reconfigure = {
217227
* See [the docs](https://weaviate.io/developers/weaviate/concepts/replication-architecture#replication-vs-sharding) for more details.
218228
*
219229
* @param {boolean} [options.asyncEnabled] Whether asynchronous replication is enabled.
230+
* @param {ReplicationDeletionStrategy} [options.deletionStrategy] The deletion strategy when replication conflicts are detected between deletes and reads.
220231
* @param {number} [options.factor] The replication factor.
221232
*/
222-
replication: (options: { asyncEnabled?: boolean; factor?: number }): ReplicationConfigCreate => {
223-
return { asyncEnabled: options.asyncEnabled, factor: options.factor };
233+
replication: (options: {
234+
asyncEnabled?: boolean;
235+
deletionStrategy?: ReplicationDeletionStrategy;
236+
factor?: number;
237+
}): ReplicationConfigCreate => {
238+
return {
239+
asyncEnabled: options.asyncEnabled,
240+
deletionStrategy: options.deletionStrategy,
241+
factor: options.factor,
242+
};
224243
},
225244
};
226245

src/collections/configure/types/base.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { WeaviateNestedProperty, WeaviateProperty } from '../../../openapi/types.js';
2-
import { InvertedIndexConfig, MultiTenancyConfig, ReplicationConfig } from '../../config/types/index.js';
2+
import {
3+
InvertedIndexConfig,
4+
MultiTenancyConfig,
5+
ReplicationConfig,
6+
ReplicationDeletionStrategy,
7+
} from '../../config/types/index.js';
38
import { DataType } from '../../types/index.js';
49
import { NonRefKeys, RefKeys } from '../../types/internal.js';
510

6-
export type RecursivePartial<T> = {
7-
[P in keyof T]?: RecursivePartial<T[P]>;
8-
};
11+
export type RecursivePartial<T> = T extends object
12+
? {
13+
[P in keyof T]?: RecursivePartial<T[P]>;
14+
}
15+
: T;
916

1017
export type InvertedIndexConfigCreate = RecursivePartial<InvertedIndexConfig>;
1118

@@ -133,6 +140,7 @@ export type ReplicationConfigCreate = RecursivePartial<ReplicationConfig>;
133140

134141
export type ReplicationConfigUpdate = {
135142
asyncEnabled?: boolean;
143+
deletionStragey?: ReplicationDeletionStrategy;
136144
factor?: number;
137145
};
138146

src/collections/configure/unit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ describe('Unit testing of the configure factory class', () => {
7979
it('should create the correct ReplicationConfig type with all values', () => {
8080
const config = configure.replication({
8181
asyncEnabled: true,
82+
deletionStrategy: 'DeleteOnConflict',
8283
factor: 2,
8384
});
8485
expect(config).toEqual<ReplicationConfigCreate>({
8586
asyncEnabled: true,
87+
deletionStrategy: 'DeleteOnConflict',
8688
factor: 2,
8789
});
8890
});

src/collections/integration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ describe('Testing of the collections.create method', () => {
578578

579579
expect(response.multiTenancy.enabled).toEqual(true);
580580

581+
expect(response.replication.asyncEnabled).toEqual(false);
582+
expect(response.replication.deletionStrategy).toEqual('DeleteOnConflict');
581583
expect(response.replication.factor).toEqual(2);
582584

583585
const indexConfig = response.vectorizers.default.indexConfig as VectorIndexConfigHNSW;

src/openapi/schema.ts

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,16 @@ export interface paths {
147147
head: operations['tenant.exists'];
148148
};
149149
'/backups/{backend}': {
150+
/** [Coming soon] List all backups in progress not implemented yet. */
151+
get: operations['backups.list'];
150152
/** Starts a process of creating a backup for a set of classes */
151153
post: operations['backups.create'];
152154
};
153155
'/backups/{backend}/{id}': {
154156
/** Returns status of backup creation attempt for a set of classes */
155157
get: operations['backups.create.status'];
158+
/** Cancel created backup with specified ID */
159+
delete: operations['backups.cancel'];
156160
};
157161
'/backups/{backend}/{id}/restore': {
158162
/** Returns status of a backup restoration attempt for a set of classes */
@@ -344,6 +348,11 @@ export interface definitions {
344348
factor?: number;
345349
/** @description Enable asynchronous replication */
346350
asyncEnabled?: boolean;
351+
/**
352+
* @description Conflict resolution strategy for deleted objects
353+
* @enum {string}
354+
*/
355+
deletionStrategy?: 'NoAutomatedResolution' | 'DeleteOnConflict';
347356
};
348357
/** @description tuning parameters for the BM25 algorithm */
349358
BM25Config: {
@@ -572,7 +581,7 @@ export interface definitions {
572581
* @default STARTED
573582
* @enum {string}
574583
*/
575-
status?: 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED';
584+
status?: 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED' | 'CANCELED';
576585
};
577586
/** @description The definition of a backup restore metadata */
578587
BackupRestoreStatusResponse: {
@@ -648,6 +657,20 @@ export interface definitions {
648657
*/
649658
status?: 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED';
650659
};
660+
/** @description The definition of a backup create response body */
661+
BackupListResponse: {
662+
/** @description The ID of the backup. Must be URL-safe and work as a filesystem path, only lowercase, numbers, underscore, minus characters allowed. */
663+
id?: string;
664+
/** @description destination path of backup files proper to selected backend */
665+
path?: string;
666+
/** @description The list of classes for which the existed backup process */
667+
classes?: string[];
668+
/**
669+
* @description status of backup process
670+
* @enum {string}
671+
*/
672+
status?: 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED' | 'CANCELED';
673+
}[];
651674
/** @description Request body for restoring a backup for a set of classes */
652675
BackupRestoreRequest: {
653676
/** @description Custom configuration for the backup restoration process */
@@ -2685,6 +2708,35 @@ export interface operations {
26852708
};
26862709
};
26872710
};
2711+
/** [Coming soon] List all backups in progress not implemented yet. */
2712+
'backups.list': {
2713+
parameters: {
2714+
path: {
2715+
/** Backup backend name e.g. filesystem, gcs, s3. */
2716+
backend: string;
2717+
};
2718+
};
2719+
responses: {
2720+
/** Existed backups */
2721+
200: {
2722+
schema: definitions['BackupListResponse'];
2723+
};
2724+
/** Unauthorized or invalid credentials. */
2725+
401: unknown;
2726+
/** Forbidden */
2727+
403: {
2728+
schema: definitions['ErrorResponse'];
2729+
};
2730+
/** Invalid backup list. */
2731+
422: {
2732+
schema: definitions['ErrorResponse'];
2733+
};
2734+
/** An error has occurred while trying to fulfill the request. Most likely the ErrorResponse will contain more information about the error. */
2735+
500: {
2736+
schema: definitions['ErrorResponse'];
2737+
};
2738+
};
2739+
};
26882740
/** Starts a process of creating a backup for a set of classes */
26892741
'backups.create': {
26902742
parameters: {
@@ -2752,6 +2804,35 @@ export interface operations {
27522804
};
27532805
};
27542806
};
2807+
/** Cancel created backup with specified ID */
2808+
'backups.cancel': {
2809+
parameters: {
2810+
path: {
2811+
/** Backup backend name e.g. filesystem, gcs, s3. */
2812+
backend: string;
2813+
/** The ID of a backup. Must be URL-safe and work as a filesystem path, only lowercase, numbers, underscore, minus characters allowed. */
2814+
id: string;
2815+
};
2816+
};
2817+
responses: {
2818+
/** Successfully deleted. */
2819+
204: never;
2820+
/** Unauthorized or invalid credentials. */
2821+
401: unknown;
2822+
/** Forbidden */
2823+
403: {
2824+
schema: definitions['ErrorResponse'];
2825+
};
2826+
/** Invalid backup cancellation attempt. */
2827+
422: {
2828+
schema: definitions['ErrorResponse'];
2829+
};
2830+
/** An error has occurred while trying to fulfill the request. Most likely the ErrorResponse will contain more information about the error. */
2831+
500: {
2832+
schema: definitions['ErrorResponse'];
2833+
};
2834+
};
2835+
};
27552836
/** Returns status of a backup restoration attempt for a set of classes */
27562837
'backups.restore.status': {
27572838
parameters: {

0 commit comments

Comments
 (0)