Skip to content

Commit 9c91703

Browse files
authored
Merge branch 'main' into feat/ssb
2 parents 16cb74a + b74d4eb commit 9c91703

13 files changed

Lines changed: 1139 additions & 715 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ Backup backup = client.backup.create(
755755
// Now you can poll backup status to know when it is succeedes (or fails).
756756
757757
Backup status = client.backup.getCreateStatus(backup.id(), backup.backend());
758-
if (status.status() == BackupStatus.SUCCESSFUL) {
758+
if (status.status() == BackupStatus.SUCCESS) {
759759
System.out.println("Yay!");
760760
System.exit(0);
761761
}

src/it/java/io/weaviate/ConcurrentTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,37 @@ public static void requireAtLeast(Weaviate.Version required) {
126126
.isGreaterThanOrEqualTo(required.semver);
127127
}
128128

129+
@FunctionalInterface
130+
public interface ThrowingRunnable {
131+
void run() throws Exception;
132+
}
133+
134+
/**
135+
* Run a block of code only if the server version is recent enough.
136+
*
137+
* @param required Minimal required version.
138+
* @param r Runnable.
139+
*/
129140
public static void requireAtLeast(Weaviate.Version required, Runnable r) {
130141
var actual = SemanticVersion.of(Weaviate.VERSION);
131142
if (actual.compareTo(required.semver) >= 0) {
132143
r.run();
133144
}
134145
}
146+
147+
/**
148+
* Wraps a {@link ThrowingRunnable} as {@link Runnable} that
149+
* re-throws all exceptions as {@link RuntimeException}.
150+
*
151+
* @param tr Runnable which may throw a checked exception.
152+
*/
153+
public static Runnable throwing(ThrowingRunnable tr) {
154+
return () -> {
155+
try {
156+
tr.run();
157+
} catch (Exception e) {
158+
throw new RuntimeException(e);
159+
}
160+
};
161+
}
135162
}

src/it/java/io/weaviate/integration/BackupITest.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.assertj.core.api.InstanceOfAssertFactories;
1515
import org.junit.Test;
1616

17+
import com.sun.nio.sctp.IllegalUnbindException;
18+
1719
import io.weaviate.ConcurrentTest;
1820
import io.weaviate.client6.v1.api.WeaviateClient;
1921
import io.weaviate.client6.v1.api.backup.Backup;
@@ -112,14 +114,22 @@ public void test_lifecycle() throws IOException, TimeoutException {
112114

113115
// Act: delete data and restore backup #1
114116
client.collections.delete(nsA);
115-
client.backup.restore(backup_1, backend, restore -> restore.includeCollections(nsA));
117+
var restoreMe = client.backup.restore(backup_1, backend, restore -> restore.includeCollections(nsA));
116118

117119
// Assert: object inserted in the beginning of the test is present
118-
var restore_1 = client.backup.getRestoreStatus(backup_1, backend)
119-
.orElseThrow().waitForCompletion(client);
120-
Assertions.assertThat(restore_1).as("restore backup #1")
120+
restoreMe = restoreMe.waitForCompletion(client);
121+
Assertions.assertThat(restoreMe).as("restore backup #1")
121122
.returns(BackupStatus.SUCCESS, Backup::status);
122123
Assertions.assertThat(collectionA.size()).as("after restore backup #1").isEqualTo(1);
124+
125+
// Act: restore and cancel
126+
requireAtLeast(Weaviate.Version.V136, throwing(() -> {
127+
var restore_2 = client.backup.restore(backup_2, backend);
128+
client.backup.cancelRestore(backup_2, backend);
129+
var canceledRestore = restore_2.waitForStatus(client, BackupStatus.CANCELED);
130+
Assertions.assertThat(canceledRestore).as("cancel backup restore #2")
131+
.returns(BackupStatus.CANCELED, Backup::status);
132+
}));
123133
}
124134

125135
@Test
@@ -215,13 +225,11 @@ public void test_lifecycle_async() throws ExecutionException, InterruptedExcepti
215225

216226
// Act: delete data and restore backup #1
217227
async.collections.delete(nsA).join();
218-
async.backup.restore(backup_1, backend, restore -> restore.includeCollections(nsA)).join();
228+
var restoreMe = async.backup.restore(backup_1, backend, restore -> restore.includeCollections(nsA)).join();
219229

220230
// Assert: object inserted in the beginning of the test is present
221-
var restore_1 = async.backup.getRestoreStatus(backup_1, backend)
222-
.thenCompose(bak -> bak.orElseThrow().waitForCompletion(async))
223-
.join();
224-
Assertions.assertThat(restore_1).as("restore backup #1")
231+
restoreMe = restoreMe.waitForCompletion(async).join();
232+
Assertions.assertThat(restoreMe).as("restore backup #1")
225233
.returns(BackupStatus.SUCCESS, Backup::status);
226234
Assertions.assertThat(collectionA.size().join()).as("after restore backup #1").isEqualTo(1);
227235
}

src/it/java/io/weaviate/integration/CollectionsITest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.weaviate.client6.v1.api.collections.Quantization;
1919
import io.weaviate.client6.v1.api.collections.ReferenceProperty;
2020
import io.weaviate.client6.v1.api.collections.Replication;
21+
import io.weaviate.client6.v1.api.collections.Replication.AsyncReplicationConfig;
2122
import io.weaviate.client6.v1.api.collections.VectorConfig;
2223
import io.weaviate.client6.v1.api.collections.config.Shard;
2324
import io.weaviate.client6.v1.api.collections.config.ShardStatus;
@@ -328,4 +329,53 @@ public void test_objectTtl() throws IOException {
328329
.extracting(CollectionConfig::objectTtl).isNotNull()
329330
.returns(false, ObjectTtl::enabled);
330331
}
332+
333+
@Test
334+
public void test_asyncReplicationConfig() throws IOException {
335+
Weaviate.Version.latest().orSkip();
336+
337+
// Arrange
338+
var nsThings = ns("Things");
339+
340+
// Act
341+
var things = client.collections.create(nsThings,
342+
c -> c.replication(Replication.of(
343+
repl -> repl
344+
.asyncEnabled(true)
345+
.asyncReplication(AsyncReplicationConfig.of(
346+
async -> async
347+
.hashTreeHeight(1)
348+
.maxWorkers(2)
349+
.frequencyMillis(3)
350+
.frequencyMillisWhilePropagating(4)
351+
.aliveNodesCheckingFrequencyMillis(5)
352+
.loggingFrequencySeconds(6)
353+
.diffBatchSize(7)
354+
.diffPerNodeTimeoutSeconds(8)
355+
.prePropagationTimeoutSeconds(9)
356+
.propagationTimeoutSeconds(10)
357+
.propagationDelayMillis(11)
358+
.propagationLimit(12)
359+
.propagationConcurrency(13)
360+
.propagationBatchSize(14))))));
361+
362+
// Assert
363+
Assertions.assertThat(things.config.get()).get()
364+
.extracting(CollectionConfig::replication)
365+
.extracting(Replication::asyncReplicationConfig)
366+
.returns(1, AsyncReplicationConfig::hashTreeHeight)
367+
.returns(2, AsyncReplicationConfig::maxWorkers)
368+
.returns(3, AsyncReplicationConfig::frequencyMillis)
369+
.returns(4, AsyncReplicationConfig::frequencyMillisWhilePropagating)
370+
.returns(5, AsyncReplicationConfig::aliveNodesCheckingFrequencyMillis)
371+
.returns(6, AsyncReplicationConfig::loggingFrequencySeconds)
372+
.returns(7, AsyncReplicationConfig::diffBatchSize)
373+
.returns(8, AsyncReplicationConfig::diffPerNodeTimeoutSeconds)
374+
.returns(9, AsyncReplicationConfig::prePropagationTimeoutSeconds)
375+
.returns(10, AsyncReplicationConfig::propagationTimeoutSeconds)
376+
.returns(11, AsyncReplicationConfig::propagationDelayMillis)
377+
.returns(12, AsyncReplicationConfig::propagationLimit)
378+
.returns(13, AsyncReplicationConfig::propagationConcurrency)
379+
.returns(14, AsyncReplicationConfig::propagationBatchSize);
380+
}
331381
}

src/main/java/io/weaviate/client6/v1/api/backup/BackupStatus.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ public enum BackupStatus {
99
/** Backup in progress, data is being transferred. */
1010
@SerializedName("TRANSFERRING")
1111
TRANSFERRING,
12+
/**
13+
* Cancellation has been claimed by a coordinator.
14+
* Used as a distributed lock to prevent race conditions when multiple
15+
* coordinators attempt to cancel the same restore.
16+
*/
17+
@SerializedName("CANCELLING")
18+
CANCELLING,
19+
/**
20+
* File staging is complete and schema changes are being applied.
21+
* Cancellation is blocked.
22+
*/
23+
@SerializedName("FINALIZING")
24+
FINALIZING,
1225
/** Backup creation / restoration completed successfully. */
1326
@SerializedName("SUCCESS")
1427
SUCCESS,
1528
/** Backup creation / restoration failed. */
1629
@SerializedName("FAILED")
1730
FAILED,
18-
/**
19-
* Backup creation canceled.
20-
* This status is never returned for backup restorations.
21-
*/
31+
/** Backup creation canceled. */
2232
@SerializedName("CANCELED")
2333
CANCELED;
2434
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.weaviate.client6.v1.api.backup;
2+
3+
import java.util.Collections;
4+
5+
import io.weaviate.client6.v1.internal.rest.Endpoint;
6+
import io.weaviate.client6.v1.internal.rest.SimpleEndpoint;
7+
8+
public record CancelBackupRestoreRequest(String backupId, String backend) {
9+
10+
public static Endpoint<CancelBackupRestoreRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect(
11+
request -> "DELETE",
12+
request -> "/backups/" + request.backend + "/" + request.backupId + "/restore",
13+
request -> Collections.emptyMap());
14+
}

src/main/java/io/weaviate/client6/v1/api/backup/WeaviateBackupClient.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,49 @@ public List<Backup> list(String backend, Function<ListBackupsRequest.Builder, Ob
179179
/**
180180
* Cancel in-progress backup.
181181
*
182-
* <p>
183-
* This method cannot be called cancel backup restore.
184-
*
185182
* @param backupId Backup ID.
186183
* @param backend Backup storage backend.
187184
* @throws WeaviateApiException in case the server returned with an
188185
* error status code.
189186
* @throws IOException in case the request was not sent successfully
190187
* due to a malformed request, a networking error
191188
* or the server being unavailable.
189+
* @deprecated This method forwards to {@link #cancelCreate}. Prefer using the
190+
* latter, as it is less ambiguous.
192191
*/
192+
@Deprecated
193193
public void cancel(String backupId, String backend) throws IOException {
194+
cancelCreate(backupId, backend);
195+
}
196+
197+
/**
198+
* Cancel in-progress backup creation.
199+
*
200+
* @param backupId Backup ID.
201+
* @param backend Backup storage backend.
202+
* @throws WeaviateApiException in case the server returned with an
203+
* error status code.
204+
* @throws IOException in case the request was not sent successfully
205+
* due to a malformed request, a networking error
206+
* or the server being unavailable.
207+
*/
208+
public void cancelCreate(String backupId, String backend) throws IOException {
194209
this.restTransport.performRequest(new CancelBackupRequest(backupId, backend), CancelBackupRequest._ENDPOINT);
195210
}
211+
212+
/**
213+
* Cancel in-progress backup restore.
214+
*
215+
* @param backupId Backup ID.
216+
* @param backend Backup storage backend.
217+
* @throws WeaviateApiException in case the server returned with an
218+
* error status code.
219+
* @throws IOException in case the request was not sent successfully
220+
* due to a malformed request, a networking error
221+
* or the server being unavailable.
222+
*/
223+
public void cancelRestore(String backupId, String backend) throws IOException {
224+
this.restTransport.performRequest(new CancelBackupRestoreRequest(backupId, backend),
225+
CancelBackupRestoreRequest._ENDPOINT);
226+
}
196227
}

src/main/java/io/weaviate/client6/v1/api/backup/WeaviateBackupClientAsync.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,37 @@ public CompletableFuture<List<Backup>> list(String backend,
124124
}
125125

126126
/**
127-
* Cancel in-progress backup.
128-
*
129-
* <p>
130-
* This method cannot be called cancel backup restore.
127+
* Cancel in-progress backup creation.
131128
*
132129
* @param backupId Backup ID.
133130
* @param backend Backup storage backend.
131+
* @deprecated This method forwards to {@link #cancelCreate}. Prefer using the
132+
* latter, as it is less ambiguous.
134133
*/
134+
@Deprecated
135135
public CompletableFuture<Void> cancel(String backupId, String backend) {
136+
return cancelCreate(backupId, backend);
137+
}
138+
139+
/**
140+
* Cancel in-progress backup creation.
141+
*
142+
* @param backupId Backup ID.
143+
* @param backend Backup storage backend.
144+
*/
145+
public CompletableFuture<Void> cancelCreate(String backupId, String backend) {
136146
return this.restTransport.performRequestAsync(new CancelBackupRequest(backupId, backend),
137147
CancelBackupRequest._ENDPOINT);
138148
}
149+
150+
/**
151+
* Cancel in-progress backup restore.
152+
*
153+
* @param backupId Backup ID.
154+
* @param backend Backup storage backend.
155+
*/
156+
public CompletableFuture<Void> cancelRestore(String backupId, String backend) {
157+
return this.restTransport.performRequestAsync(new CancelBackupRestoreRequest(backupId, backend),
158+
CancelBackupRestoreRequest._ENDPOINT);
159+
}
139160
}

src/main/java/io/weaviate/client6/v1/api/collections/InvertedIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Bm25 build() {
7474
}
7575
}
7676

77-
public record Stopwords(
77+
public static record Stopwords(
7878
/** Selected preset. */
7979
@SerializedName("preset") String preset,
8080
/** Custom words added to the selected preset. */

0 commit comments

Comments
 (0)