Skip to content
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

Remove write and read concern from Atlas Search Index commands. #1241

Merged
merged 9 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

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;
Expand All @@ -40,12 +39,9 @@
*/
abstract class AbstractWriteSearchIndexOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
private final MongoNamespace namespace;
private final WriteConcern writeConcern;

AbstractWriteSearchIndexOperation(final MongoNamespace mongoNamespace,
final WriteConcern writeConcern) {
AbstractWriteSearchIndexOperation(final MongoNamespace mongoNamespace) {
this.namespace = mongoNamespace;
this.writeConcern = writeConcern;
}

@Override
Expand Down Expand Up @@ -101,8 +97,4 @@ <E extends Throwable> void swallowOrThrow(@Nullable final E mongoExecutionExcept
MongoNamespace getNamespace() {
return namespace;
}

WriteConcern getWriteConcern() {
return writeConcern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.mongodb.internal.operation;

import com.mongodb.MongoNamespace;
import com.mongodb.WriteConcern;
import org.bson.BsonArray;
import org.bson.BsonDocument;
import org.bson.BsonString;
Expand All @@ -26,7 +25,6 @@
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.
Expand All @@ -37,9 +35,8 @@ final class CreateSearchIndexesOperation extends AbstractWriteSearchIndexOperati
private static final String COMMAND_NAME = "createSearchIndexes";
private final List<SearchIndexRequest> indexRequests;

CreateSearchIndexesOperation(final MongoNamespace namespace, final List<SearchIndexRequest> indexRequests,
final WriteConcern writeConcern) {
super(namespace, writeConcern);
CreateSearchIndexesOperation(final MongoNamespace namespace, final List<SearchIndexRequest> indexRequests) {
super(namespace);
this.indexRequests = assertNotNull(indexRequests);
}

Expand All @@ -61,9 +58,7 @@ private static BsonDocument convert(final SearchIndexRequest request) {

@Override
BsonDocument buildCommand() {
BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName()))
return new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName()))
.append("indexes", convert(indexRequests));
appendWriteConcernToCommand(getWriteConcern(), command);
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
package com.mongodb.internal.operation;

import com.mongodb.MongoNamespace;
import com.mongodb.WriteConcern;
import com.mongodb.lang.Nullable;
import org.bson.BsonDocument;
import org.bson.BsonString;

import static com.mongodb.internal.operation.CommandOperationHelper.isNamespaceError;
import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand;

/**
* An operation that drops an Alas Search index.
Expand All @@ -34,9 +32,8 @@ final class DropSearchIndexOperation extends AbstractWriteSearchIndexOperation {
private static final String COMMAND_NAME = "dropSearchIndex";
private final String indexName;

DropSearchIndexOperation(final MongoNamespace namespace, final String indexName,
final WriteConcern writeConcern) {
super(namespace, writeConcern);
DropSearchIndexOperation(final MongoNamespace namespace, final String indexName) {
super(namespace);
this.indexName = indexName;
}

Expand All @@ -49,9 +46,7 @@ <E extends Throwable> void swallowOrThrow(@Nullable final E mongoExecutionExcept

@Override
BsonDocument buildCommand() {
BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName()))
return new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName()))
.append("name", new BsonString(indexName));
appendWriteConcernToCommand(getWriteConcern(), command);
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -651,20 +651,19 @@ CreateSearchIndexesOperation createSearchIndexes(final List<SearchIndexModel> in
.map(this::createSearchIndexRequest)
.collect(Collectors.toList());

return new CreateSearchIndexesOperation(assertNotNull(namespace), indexRequests, writeConcern);
return new CreateSearchIndexesOperation(assertNotNull(namespace), indexRequests);
}

UpdateSearchIndexesOperation updateSearchIndex(final String indexName, final Bson definition) {
BsonDocument definitionDocument = assertNotNull(toBsonDocument(definition));
SearchIndexRequest searchIndexRequest = new SearchIndexRequest(definitionDocument, indexName);

return new UpdateSearchIndexesOperation(assertNotNull(namespace), searchIndexRequest,
writeConcern);
return new UpdateSearchIndexesOperation(assertNotNull(namespace), searchIndexRequest);
}


DropSearchIndexOperation dropSearchIndex(final String indexName) {
return new DropSearchIndexOperation(assertNotNull(namespace), indexName, writeConcern);
return new DropSearchIndexOperation(assertNotNull(namespace), indexName);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
package com.mongodb.internal.operation;

import com.mongodb.MongoNamespace;
import com.mongodb.WriteConcern;
import org.bson.BsonDocument;
import org.bson.BsonString;

import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand;

/**
* An operation that updates an Atlas Search index.
*
Expand All @@ -32,19 +29,16 @@ final class UpdateSearchIndexesOperation extends AbstractWriteSearchIndexOperati
private static final String COMMAND_NAME = "updateSearchIndex";
private final SearchIndexRequest request;

UpdateSearchIndexesOperation(final MongoNamespace namespace, final SearchIndexRequest request,
final WriteConcern writeConcern) {
super(namespace, writeConcern);
UpdateSearchIndexesOperation(final MongoNamespace namespace, final SearchIndexRequest request) {
super(namespace);
this.request = request;
}

@Override
BsonDocument buildCommand() {
BsonDocument command = new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName()))
return new BsonDocument(COMMAND_NAME, new BsonString(getNamespace().getCollectionName()))
.append("name", new BsonString(request.getIndexName()))
.append("definition", request.getDefinition());
appendWriteConcernToCommand(getWriteConcern(), command);
return command;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.mongodb.client;

import com.mongodb.MongoClientSettings;
import com.mongodb.WriteConcern;
import com.mongodb.client.model.SearchIndexModel;
import org.bson.Document;
import org.bson.conversions.Bson;
Expand Down Expand Up @@ -75,7 +76,7 @@ public abstract class AbstractAtlasSearchIndexManagementProseTest {

protected AbstractAtlasSearchIndexManagementProseTest() {
Assumptions.assumeTrue(serverVersionAtLeast(6, 0));
Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled"); //TODO enable by flag
Assumptions.assumeTrue(hasAtlasSearchIndexHelperEnabled(), "Atlas Search Index tests are disabled");
}

private static boolean hasAtlasSearchIndexHelperEnabled() {
Expand All @@ -84,7 +85,12 @@ private static boolean hasAtlasSearchIndexHelperEnabled() {

@BeforeEach
public void setUp() {
client = createMongoClient(getMongoClientSettings());
MongoClientSettings mongoClientSettings = MongoClientSettings.builder(getMongoClientSettings())
jyemin marked this conversation as resolved.
Show resolved Hide resolved
/* Specifying the write concern here ensures that we test the use case where the write concern
is not passed down to the server. If a write concern is attached to the command, the server will fail with an error. */
.writeConcern(WriteConcern.MAJORITY).build();

client = createMongoClient(mongoClientSettings);
db = client.getDatabase("test");

String collectionName = UUID.randomUUID().toString();
Expand Down