Skip to content

Commit bcfca4f

Browse files
committed
Added maxTimeMS support for index operations
CreateIndexOperation and DropIndexOperation now support maxTimeMS JAVA-2537
1 parent c4d636d commit bcfca4f

File tree

12 files changed

+634
-108
lines changed

12 files changed

+634
-108
lines changed

driver-async/src/main/com/mongodb/async/client/MongoCollection.java

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import com.mongodb.bulk.BulkWriteResult;
2626
import com.mongodb.client.model.BulkWriteOptions;
2727
import com.mongodb.client.model.CountOptions;
28+
import com.mongodb.client.model.CreateIndexOptions;
2829
import com.mongodb.client.model.DeleteOptions;
30+
import com.mongodb.client.model.DropIndexOptions;
2931
import com.mongodb.client.model.FindOneAndDeleteOptions;
3032
import com.mongodb.client.model.FindOneAndReplaceOptions;
3133
import com.mongodb.client.model.FindOneAndUpdateOptions;
@@ -1210,7 +1212,7 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
12101212
void createIndex(ClientSession clientSession, Bson key, IndexOptions options, SingleResultCallback<String> callback);
12111213

12121214
/**
1213-
* Create multiple indexes. If successful, the callback will be executed with a list of the namess of the created index as the result.
1215+
* Create multiple indexes. If successful, the callback will be executed with a list of the names of the created indexes as the result.
12141216
*
12151217
* @param indexes the list of indexes
12161218
* @param callback the callback that is completed once the indexes has been created
@@ -1220,7 +1222,18 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
12201222
void createIndexes(List<IndexModel> indexes, SingleResultCallback<List<String>> callback);
12211223

12221224
/**
1223-
* Create multiple indexes. If successful, the callback will be executed with a list of the namess of the created index as the result.
1225+
* Create multiple indexes. If successful, the callback will be executed with a list of the names of the created indexes as the result.
1226+
*
1227+
* @param indexes the list of indexes
1228+
* @param createIndexOptions options to use when creating indexes
1229+
* @param callback the callback that is completed once the indexes has been created
1230+
* @mongodb.driver.manual reference/command/createIndexes Create indexes
1231+
* @since 3.6
1232+
*/
1233+
void createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions, SingleResultCallback<List<String>> callback);
1234+
1235+
/**
1236+
* Create multiple indexes. If successful, the callback will be executed with a list of the names of the created indexes as the result.
12241237
*
12251238
* @param clientSession the client session with which to associate this operation
12261239
* @param indexes the list of indexes
@@ -1231,6 +1244,20 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
12311244
*/
12321245
void createIndexes(ClientSession clientSession, List<IndexModel> indexes, SingleResultCallback<List<String>> callback);
12331246

1247+
/**
1248+
* Create multiple indexes. If successful, the callback will be executed with a list of the names of the created indexes as the result.
1249+
*
1250+
* @param clientSession the client session with which to associate this operation
1251+
* @param indexes the list of indexes
1252+
* @param createIndexOptions options to use when creating indexes
1253+
* @param callback the callback that is completed once the indexes has been created
1254+
* @mongodb.driver.manual reference/command/createIndexes Create indexes
1255+
* @since 3.6
1256+
* @mongodb.server.release 3.6
1257+
*/
1258+
void createIndexes(ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions,
1259+
SingleResultCallback<List<String>> callback);
1260+
12341261
/**
12351262
* Get all the indexes in this collection.
12361263
*
@@ -1282,6 +1309,17 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
12821309
*/
12831310
void dropIndex(String indexName, SingleResultCallback<Void> callback);
12841311

1312+
/**
1313+
* Drops the index given its name.
1314+
*
1315+
* @param indexName the name of the index to remove
1316+
* @param dropIndexOptions options to use when dropping indexes
1317+
* @param callback the callback that is completed once the index has been dropped
1318+
* @mongodb.driver.manual reference/command/dropIndexes/ Drop indexes
1319+
* @since 3.6
1320+
*/
1321+
void dropIndex(String indexName, DropIndexOptions dropIndexOptions, SingleResultCallback<Void> callback);
1322+
12851323
/**
12861324
* Drops the index given the keys used to create it.
12871325
*
@@ -1291,6 +1329,17 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
12911329
*/
12921330
void dropIndex(Bson keys, SingleResultCallback<Void> callback);
12931331

1332+
/**
1333+
* Drops the index given the keys used to create it.
1334+
*
1335+
* @param keys the keys of the index to remove
1336+
* @param dropIndexOptions options to use when dropping indexes
1337+
* @param callback the callback that is completed once the index has been dropped
1338+
* @mongodb.driver.manual reference/command/dropIndexes/ Drop indexes
1339+
* @since 3.6
1340+
*/
1341+
void dropIndex(Bson keys, DropIndexOptions dropIndexOptions, SingleResultCallback<Void> callback);
1342+
12941343
/**
12951344
* Drops the index given its name.
12961345
*
@@ -1303,6 +1352,20 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
13031352
*/
13041353
void dropIndex(ClientSession clientSession, String indexName, SingleResultCallback<Void> callback);
13051354

1355+
/**
1356+
* Drops the index given its name.
1357+
*
1358+
* @param clientSession the client session with which to associate this operation
1359+
* @param indexName the name of the index to remove
1360+
* @param dropIndexOptions options to use when dropping indexes
1361+
* @param callback the callback that is completed once the index has been dropped
1362+
* @mongodb.driver.manual reference/command/dropIndexes/ Drop indexes
1363+
* @since 3.6
1364+
* @mongodb.server.release 3.6
1365+
*/
1366+
void dropIndex(ClientSession clientSession, String indexName, DropIndexOptions dropIndexOptions,
1367+
SingleResultCallback<Void> callback);
1368+
13061369
/**
13071370
* Drops the index given the keys used to create it.
13081371
*
@@ -1315,6 +1378,19 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
13151378
*/
13161379
void dropIndex(ClientSession clientSession, Bson keys, SingleResultCallback<Void> callback);
13171380

1381+
/**
1382+
* Drops the index given the keys used to create it.
1383+
*
1384+
* @param clientSession the client session with which to associate this operation
1385+
* @param keys the keys of the index to remove
1386+
* @param dropIndexOptions options to use when dropping indexes
1387+
* @param callback the callback that is completed once the index has been dropped
1388+
* @mongodb.driver.manual reference/command/dropIndexes/ Drop indexes
1389+
* @since 3.6
1390+
* @mongodb.server.release 3.6
1391+
*/
1392+
void dropIndex(ClientSession clientSession, Bson keys, DropIndexOptions dropIndexOptions, SingleResultCallback<Void> callback);
1393+
13181394
/**
13191395
* Drop all the indexes on this collection, except for the default on _id.
13201396
*
@@ -1323,6 +1399,16 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
13231399
*/
13241400
void dropIndexes(SingleResultCallback<Void> callback);
13251401

1402+
/**
1403+
* Drop all the indexes on this collection, except for the default on _id.
1404+
*
1405+
* @param dropIndexOptions options to use when dropping indexes
1406+
* @param callback the callback that is completed once all the indexes have been dropped
1407+
* @mongodb.driver.manual reference/command/dropIndexes/ Drop indexes
1408+
* @since 3.6
1409+
*/
1410+
void dropIndexes(DropIndexOptions dropIndexOptions, SingleResultCallback<Void> callback);
1411+
13261412
/**
13271413
* Drop all the indexes on this collection, except for the default on _id.
13281414
*
@@ -1334,6 +1420,18 @@ void findOneAndUpdate(ClientSession clientSession, Bson filter, Bson update, Fin
13341420
*/
13351421
void dropIndexes(ClientSession clientSession, SingleResultCallback<Void> callback);
13361422

1423+
/**
1424+
* Drop all the indexes on this collection, except for the default on _id.
1425+
*
1426+
* @param clientSession the client session with which to associate this operation
1427+
* @param dropIndexOptions options to use when dropping indexes
1428+
* @param callback the callback that is completed once all the indexes have been dropped
1429+
* @mongodb.driver.manual reference/command/dropIndexes/ Drop indexes
1430+
* @since 3.6
1431+
* @mongodb.server.release 3.6
1432+
*/
1433+
void dropIndexes(ClientSession clientSession, DropIndexOptions dropIndexOptions, SingleResultCallback<Void> callback);
1434+
13371435
/**
13381436
* Rename the collection with oldCollectionName to the newCollectionName.
13391437
*

driver-async/src/main/com/mongodb/async/client/MongoCollectionImpl.java

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
import com.mongodb.bulk.WriteRequest;
3636
import com.mongodb.client.model.BulkWriteOptions;
3737
import com.mongodb.client.model.CountOptions;
38+
import com.mongodb.client.model.CreateIndexOptions;
3839
import com.mongodb.client.model.DeleteManyModel;
3940
import com.mongodb.client.model.DeleteOneModel;
4041
import com.mongodb.client.model.DeleteOptions;
42+
import com.mongodb.client.model.DropIndexOptions;
4143
import com.mongodb.client.model.FindOneAndDeleteOptions;
4244
import com.mongodb.client.model.FindOneAndReplaceOptions;
4345
import com.mongodb.client.model.FindOneAndUpdateOptions;
@@ -908,19 +910,32 @@ public void onResult(final List<String> result, final Throwable t) {
908910

909911
@Override
910912
public void createIndexes(final List<IndexModel> indexes, final SingleResultCallback<List<String>> callback) {
911-
executeCreateIndexes(null, indexes, callback);
913+
createIndexes(indexes, new CreateIndexOptions(), callback);
914+
}
915+
916+
@Override
917+
public void createIndexes(final List<IndexModel> indexes, final CreateIndexOptions createIndexOptions,
918+
final SingleResultCallback<List<String>> callback) {
919+
executeCreateIndexes(null, indexes, createIndexOptions, callback);
912920
}
913921

914922
@Override
915923
public void createIndexes(final ClientSession clientSession, final List<IndexModel> indexes,
916924
final SingleResultCallback<List<String>> callback) {
925+
createIndexes(clientSession, indexes, new CreateIndexOptions(), callback);
926+
}
927+
928+
@Override
929+
public void createIndexes(final ClientSession clientSession, final List<IndexModel> indexes,
930+
final CreateIndexOptions createIndexOptions, final SingleResultCallback<List<String>> callback) {
917931
notNull("clientSession", clientSession);
918-
executeCreateIndexes(clientSession, indexes, callback);
932+
executeCreateIndexes(clientSession, indexes, createIndexOptions, callback);
919933
}
920934

921935
private void executeCreateIndexes(final ClientSession clientSession, final List<IndexModel> indexes,
922-
final SingleResultCallback<List<String>> callback) {
936+
final CreateIndexOptions createIndexOptions, final SingleResultCallback<List<String>> callback) {
923937
notNull("indexes", indexes);
938+
notNull("createIndexOptions", createIndexOptions);
924939

925940
List<IndexRequest> indexRequests = new ArrayList<IndexRequest>(indexes.size());
926941
for (IndexModel model : indexes) {
@@ -947,7 +962,8 @@ private void executeCreateIndexes(final ClientSession clientSession, final List<
947962
.partialFilterExpression(toBsonDocument(model.getOptions().getPartialFilterExpression()))
948963
.collation(model.getOptions().getCollation()));
949964
}
950-
final CreateIndexesOperation createIndexesOperation = new CreateIndexesOperation(getNamespace(), indexRequests, writeConcern);
965+
final CreateIndexesOperation createIndexesOperation = new CreateIndexesOperation(getNamespace(), indexRequests, writeConcern)
966+
.maxTime(createIndexOptions.getMaxTime(MILLISECONDS), MILLISECONDS);
951967
executor.execute(createIndexesOperation, clientSession, new SingleResultCallback<Void>() {
952968
@Override
953969
public void onResult(final Void result, final Throwable t) {
@@ -988,43 +1004,79 @@ private <TResult> ListIndexesIterable<TResult> createListIndexesIterable(final C
9881004

9891005
@Override
9901006
public void dropIndex(final String indexName, final SingleResultCallback<Void> callback) {
991-
executeDropIndex(null, indexName, callback);
1007+
dropIndex(indexName, new DropIndexOptions(), callback);
1008+
}
1009+
1010+
@Override
1011+
public void dropIndex(final String indexName, final DropIndexOptions dropIndexOptions, final SingleResultCallback<Void> callback) {
1012+
executeDropIndex(null, indexName, dropIndexOptions, callback);
9921013
}
9931014

9941015
@Override
9951016
public void dropIndex(final Bson keys, final SingleResultCallback<Void> callback) {
996-
executeDropIndex(null, keys, callback);
1017+
dropIndex(keys, new DropIndexOptions(), callback);
1018+
}
1019+
1020+
@Override
1021+
public void dropIndex(final Bson keys, final DropIndexOptions dropIndexOptions, final SingleResultCallback<Void> callback) {
1022+
executeDropIndex(null, keys, dropIndexOptions, callback);
9971023
}
9981024

9991025
@Override
10001026
public void dropIndex(final ClientSession clientSession, final String indexName, final SingleResultCallback<Void> callback) {
1027+
dropIndex(clientSession, indexName, new DropIndexOptions(), callback);
1028+
}
1029+
1030+
@Override
1031+
public void dropIndex(final ClientSession clientSession, final String indexName, final DropIndexOptions dropIndexOptions,
1032+
final SingleResultCallback<Void> callback) {
10011033
notNull("clientSession", clientSession);
1002-
executeDropIndex(clientSession, indexName, callback);
1034+
executeDropIndex(clientSession, indexName, dropIndexOptions, callback);
10031035
}
10041036

10051037
@Override
10061038
public void dropIndex(final ClientSession clientSession, final Bson keys, final SingleResultCallback<Void> callback) {
1039+
dropIndex(clientSession, keys, new DropIndexOptions(), callback);
1040+
}
1041+
1042+
@Override
1043+
public void dropIndex(final ClientSession clientSession, final Bson keys, final DropIndexOptions dropIndexOptions,
1044+
final SingleResultCallback<Void> callback) {
10071045
notNull("clientSession", clientSession);
1008-
executeDropIndex(clientSession, keys, callback);
1046+
executeDropIndex(clientSession, keys, dropIndexOptions, callback);
10091047
}
10101048

10111049
@Override
10121050
public void dropIndexes(final SingleResultCallback<Void> callback) {
1013-
dropIndex("*", callback);
1051+
dropIndexes(new DropIndexOptions(), callback);
1052+
}
1053+
1054+
@Override
1055+
public void dropIndexes(final DropIndexOptions dropIndexOptions, final SingleResultCallback<Void> callback) {
1056+
dropIndex("*", dropIndexOptions, callback);
10141057
}
10151058

10161059
@Override
10171060
public void dropIndexes(final ClientSession clientSession, final SingleResultCallback<Void> callback) {
1018-
dropIndex(clientSession, "*", callback);
1061+
dropIndexes(clientSession, new DropIndexOptions(), callback);
1062+
}
1063+
1064+
@Override
1065+
public void dropIndexes(final ClientSession clientSession, final DropIndexOptions dropIndexOptions,
1066+
final SingleResultCallback<Void> callback) {
1067+
dropIndex(clientSession, "*", dropIndexOptions, callback);
10191068
}
10201069

1021-
private void executeDropIndex(final ClientSession clientSession, final Bson keys, final SingleResultCallback<Void> callback) {
1022-
executor.execute(new DropIndexOperation(namespace, keys.toBsonDocument(BsonDocument.class, codecRegistry), writeConcern),
1023-
clientSession, callback);
1070+
private void executeDropIndex(final ClientSession clientSession, final Bson keys,
1071+
final DropIndexOptions dropIndexOptions, final SingleResultCallback<Void> callback) {
1072+
executor.execute(new DropIndexOperation(namespace, keys.toBsonDocument(BsonDocument.class, codecRegistry), writeConcern)
1073+
.maxTime(dropIndexOptions.getMaxTime(MILLISECONDS), MILLISECONDS), clientSession, callback);
10241074
}
10251075

1026-
private void executeDropIndex(final ClientSession clientSession, final String indexName, final SingleResultCallback<Void> callback) {
1027-
executor.execute(new DropIndexOperation(namespace, indexName, writeConcern), clientSession, callback);
1076+
private void executeDropIndex(final ClientSession clientSession, final String indexName,
1077+
final DropIndexOptions dropIndexOptions, final SingleResultCallback<Void> callback) {
1078+
executor.execute(new DropIndexOperation(namespace, indexName, writeConcern)
1079+
.maxTime(dropIndexOptions.getMaxTime(MILLISECONDS), MILLISECONDS), clientSession, callback);
10281080
}
10291081

10301082
@Override

0 commit comments

Comments
 (0)