-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add support for managing Atlas search indexes. #1158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
bb610dd
Add support for managing Atlas search indexes.
vbabanin 123c8cd
Fix formatting, spotbugs issues.
vbabanin 1dd433d
Fix formatting.
vbabanin 8ce344a
Add javadoc.
vbabanin e89553c
Fix tests.
vbabanin f977401
Change javadoc.
vbabanin ef13ea8
Change assignment ordering.
vbabanin 795d351
Remove wildcard imports.
vbabanin 891d386
Change documentation.
vbabanin ab7d67d
Change javadoc.
vbabanin 95b6810
Remove maxAwaitTime option for ListSearchIndexes iterable/publisher i…
vbabanin 78dcd04
Update driver-core/src/main/com/mongodb/internal/operation/SearchInde…
vbabanin d88b6a8
Update driver-core/src/main/com/mongodb/client/model/SearchIndexModel…
vbabanin 36c6bc8
Update driver-core/src/main/com/mongodb/internal/operation/AbstractWr…
vbabanin d7208ca
Update driver-core/src/main/com/mongodb/internal/operation/AbstractWr…
vbabanin d04f161
Update driver-core/src/main/com/mongodb/internal/operation/AbstractWr…
vbabanin a7298ad
Update driver-core/src/main/com/mongodb/internal/operation/CreateSear…
vbabanin f8879d1
Update driver-core/src/main/com/mongodb/internal/operation/CreateSear…
vbabanin eb25379
Apply suggestions from code review
vbabanin f83e870
Add retryable functionality.
vbabanin 1554663
Change javadoc.
vbabanin ba83e2e
Change Java doc of the createSearchIndexes methods.
vbabanin da5bed0
Change verb from "remove" to "drop" in javadoc.
vbabanin 7bae99b
Fix spotBugs.
vbabanin 4d8365c
Move test files.
vbabanin a24d795
Remove whitespaces.
vbabanin 7163044
Revert retryable writes.
vbabanin dc04204
Remove mentioning of nullubility from ListSearchIterable and Publishe…
vbabanin 684c455
Change javadoc.
vbabanin 2235541
Update driver-sync/src/main/com/mongodb/client/MongoCollection.java
vbabanin e7b8192
Fix spotless warnings.
vbabanin f5f6230
Make class internal.
vbabanin f63ff7b
Add null-check.
vbabanin 5cbee87
Add null-check.
vbabanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
driver-core/src/main/com/mongodb/client/model/SearchIndexModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.mongodb.client.model; | ||
|
|
||
| import com.mongodb.lang.Nullable; | ||
| import org.bson.conversions.Bson; | ||
|
|
||
| import static com.mongodb.assertions.Assertions.notNull; | ||
|
|
||
| /** | ||
| * A model describing the creation of a single Atlas Search index. | ||
| * | ||
| * @since 4.11 | ||
| * @mongodb.server.release 7.0 | ||
| */ | ||
| public class SearchIndexModel { | ||
| private final String name; | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final Bson definition; | ||
|
|
||
| /** | ||
| * Construct an instance with the given Atlas Search index definition. | ||
| * | ||
| * @param definition the search index definition. | ||
| */ | ||
| public SearchIndexModel(final Bson definition) { | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this(null, definition); | ||
stIncMale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Construct an instance with the given Atlas Search name and index definition. | ||
| * | ||
| * @param name the search index name | ||
| * @param definition the search index definition. | ||
| */ | ||
| public SearchIndexModel(@Nullable final String name, final Bson definition) { | ||
stIncMale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.definition = notNull("definition", definition); | ||
| this.name = name; | ||
| } | ||
|
|
||
| /** | ||
| * Get the Atlas Search index definition. | ||
| * | ||
| * @return the index definition. | ||
| */ | ||
| public Bson getDefinition() { | ||
| return definition; | ||
| } | ||
|
|
||
| /** | ||
| * Get the Atlas Search index name. | ||
| * | ||
| * @return the search index name. | ||
| */ | ||
| @Nullable | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "SearchIndexModel{" | ||
| + "name=" + name | ||
| + ", definition=" + definition | ||
| + '}'; | ||
| } | ||
| } | ||
101 changes: 101 additions & 0 deletions
101
driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.mongodb.internal.operation; | ||
|
|
||
|
|
||
| import com.mongodb.MongoCommandException; | ||
| import com.mongodb.MongoNamespace; | ||
| import com.mongodb.WriteConcern; | ||
| import com.mongodb.internal.async.SingleResultCallback; | ||
| import com.mongodb.internal.binding.AsyncWriteBinding; | ||
| import com.mongodb.internal.binding.WriteBinding; | ||
| import com.mongodb.lang.Nullable; | ||
| import org.bson.BsonDocument; | ||
|
|
||
| import static com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback; | ||
| import static com.mongodb.internal.operation.CommandOperationHelper.executeCommand; | ||
| import static com.mongodb.internal.operation.CommandOperationHelper.executeCommandAsync; | ||
| import static com.mongodb.internal.operation.CommandOperationHelper.writeConcernErrorTransformer; | ||
| import static com.mongodb.internal.operation.CommandOperationHelper.writeConcernErrorWriteTransformer; | ||
| import static com.mongodb.internal.operation.OperationHelper.LOGGER; | ||
| import static com.mongodb.internal.operation.OperationHelper.releasingCallback; | ||
| import static com.mongodb.internal.operation.OperationHelper.withAsyncConnection; | ||
| import static com.mongodb.internal.operation.OperationHelper.withConnection; | ||
|
|
||
| /** | ||
| * An abstract class for defining operations for managing Atlas Search indexes. | ||
| * | ||
| * <p>This class is not part of the public API and may be removed or changed at any time</p> | ||
| */ | ||
| abstract class AbstractWriteSearchIndexOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> { | ||
| private final MongoNamespace namespace; | ||
| private final WriteConcern writeConcern; | ||
vbabanin marked this conversation as resolved.
Show resolved
Hide resolved
vbabanin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| AbstractWriteSearchIndexOperation(final MongoNamespace mongoNamespace, @Nullable final WriteConcern writeConcern) { | ||
| this.namespace = mongoNamespace; | ||
| this.writeConcern = writeConcern; | ||
| } | ||
|
|
||
| @Override | ||
| public Void execute(final WriteBinding binding) { | ||
| return withConnection(binding, connection -> { | ||
| try { | ||
| executeCommand(binding, namespace.getDatabaseName(), buildCommand(), connection, writeConcernErrorTransformer()); | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (MongoCommandException mongoCommandException){ | ||
| handleCommandException(mongoCommandException); | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<Void> callback) { | ||
| withAsyncConnection(binding, (connection, connectionException) -> { | ||
| SingleResultCallback<Void> errHandlingCallback = errorHandlingCallback(callback, LOGGER); | ||
| if (connectionException != null) { | ||
| errHandlingCallback.onResult(null, connectionException); | ||
| } else { | ||
| SingleResultCallback<Void> completionCallback = releasingCallback(errHandlingCallback, connection); | ||
| try { | ||
| executeCommandAsync(binding, namespace.getDatabaseName(), | ||
| buildCommand(), connection, writeConcernErrorWriteTransformer(), | ||
| getCommandExecutionCallback(completionCallback)); | ||
stIncMale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (Throwable commandExecutionException) { | ||
| completionCallback.onResult(null, commandExecutionException); | ||
| } | ||
stIncMale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
| } | ||
stIncMale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| SingleResultCallback<Void> getCommandExecutionCallback(final SingleResultCallback<Void> completionCallback) { | ||
| return (result, commandExecutionException) -> completionCallback.onResult(null, commandExecutionException); | ||
| } | ||
|
|
||
| void handleCommandException(final MongoCommandException mongoCommandException) { | ||
| throw mongoCommandException; | ||
| } | ||
stIncMale marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| abstract BsonDocument buildCommand(); | ||
|
|
||
| public MongoNamespace getNamespace() { | ||
vbabanin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return namespace; | ||
| } | ||
|
|
||
| public WriteConcern getWriteConcern() { | ||
vbabanin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return writeConcern; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
driver-core/src/main/com/mongodb/internal/operation/CreateSearchIndexesOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.mongodb.internal.operation; | ||
|
|
||
| import com.mongodb.MongoNamespace; | ||
| import com.mongodb.WriteConcern; | ||
| import com.mongodb.lang.Nullable; | ||
| import org.bson.BsonArray; | ||
| import org.bson.BsonDocument; | ||
| import org.bson.BsonString; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static com.mongodb.assertions.Assertions.assertNotNull; | ||
| import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand; | ||
|
|
||
| /** | ||
| * An operation that creates one or more Atlas Search indexes. | ||
| * | ||
| * <p>This class is not part of the public API and may be removed or changed at any time</p> | ||
| */ | ||
| class CreateSearchIndexesOperation extends AbstractWriteSearchIndexOperation { | ||
vbabanin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private static final String COMMAND_NAME = "createSearchIndexes"; | ||
| private final List<SearchIndexRequest> indexRequests; | ||
|
|
||
| CreateSearchIndexesOperation(final MongoNamespace namespace, final List<SearchIndexRequest> indexRequests, | ||
| @Nullable final WriteConcern writeConcern) { | ||
| super(namespace, writeConcern); | ||
| this.indexRequests = assertNotNull(indexRequests); | ||
| } | ||
|
|
||
| private BsonArray convert(final List<SearchIndexRequest> requests) { | ||
| return requests.stream() | ||
| .map(this::convert) | ||
| .collect(Collectors.toCollection(BsonArray::new)); | ||
| } | ||
vbabanin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private BsonDocument convert(final SearchIndexRequest request) { | ||
vbabanin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| BsonDocument bsonIndexRequest = new BsonDocument(); | ||
| String searchIndexName = request.getIndexName(); | ||
| if (searchIndexName != null) { | ||
| bsonIndexRequest.append("name", new BsonString(searchIndexName)); | ||
| } | ||
| bsonIndexRequest.append("definition", request.getDefinition()); | ||
| return bsonIndexRequest; | ||
| } | ||
|
|
||
| @Override | ||
| BsonDocument buildCommand() { | ||
| BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName())) | ||
| .append("indexes", convert(indexRequests)); | ||
| appendWriteConcernToCommand(getWriteConcern(), command); | ||
| return command; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.