use of com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand.CreateIndexesArgument in project torodb by torodb.
the class AkkaDbCloner method cloneIndex.
private void cloneIndex(MongodServer localServer, String fromDb, String dstDb, MongoConnection remoteConnection, CloneOptions opts, String fromCol, String toCol) throws CloningException {
WriteMongodTransaction transaction = createWriteMongodTransaction(localServer);
try {
try {
List<IndexOptions> indexesToClone = getIndexesToClone(Lists.newArrayList(ListIndexesRequester.getListCollections(remoteConnection, dstDb, fromCol).getFirstBatch()), dstDb, toCol, fromDb, fromCol, opts);
if (indexesToClone.isEmpty()) {
return;
}
Status<CreateIndexesResult> status = transaction.execute(new Request(dstDb, null, true, null), CreateIndexesCommand.INSTANCE, new CreateIndexesArgument(fromCol, indexesToClone));
if (!status.isOk()) {
throw new CloningException("Error while cloning indexes: " + status.getErrorMsg());
}
transaction.commit();
} catch (UserException | MongoException ex) {
throw new CloningException("Unexpected error while cloning indexes", ex);
}
} finally {
transaction.close();
}
}
use of com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand.CreateIndexesArgument in project torodb by torodb.
the class TransactionalDbCloner method cloneIndex.
private void cloneIndex(String dstDb, MongoConnection remoteConnection, WriteMongodTransaction transaction, CloneOptions opts, String fromCol, CollectionOptions collOptions) throws CloningException {
try {
String fromDb = opts.getDbToClone();
HostAndPort remoteAddress = remoteConnection.getClientOwner().getAddress();
String remoteAddressString = remoteAddress != null ? remoteAddress.toString() : "local";
LOGGER.info("copying indexes from {}.{} on {} to {}.{} on local server", fromDb, fromCol, remoteAddressString, dstDb, fromCol);
Status<?> status;
List<IndexOptions> indexes = Lists.newArrayList(ListIndexesRequester.getListCollections(remoteConnection, dstDb, fromCol).getFirstBatch());
if (indexes.isEmpty()) {
return;
}
status = transaction.execute(new Request(dstDb, null, true, null), CreateIndexesCommand.INSTANCE, new CreateIndexesArgument(fromCol, indexes));
if (!status.isOk()) {
throw new CloningException("Error while trying to fetch indexes from remote: " + status);
}
} catch (MongoException ex) {
throw new CloningException("Error while trying to fetch indexes from remote", ex);
}
}
use of com.torodb.mongodb.commands.signatures.admin.CreateIndexesCommand.CreateIndexesArgument in project torodb by torodb.
the class OplogOperationApplier method insertIndex.
private void insertIndex(BsonDocument indexDoc, String database, ExclusiveWriteMongodTransaction trans) throws OplogApplyingException {
try {
CreateIndexesCommand command = CreateIndexesCommand.INSTANCE;
IndexOptions indexOptions = IndexOptions.unmarshall(indexDoc);
CreateIndexesArgument arg = new CreateIndexesArgument(indexOptions.getCollection(), Arrays.asList(new IndexOptions[] { indexOptions }));
Status executionResult = executeReplCommand(database, command, arg, trans.getTorodTransaction());
if (!executionResult.isOk()) {
throw new OplogApplyingException(new MongoException(executionResult));
}
} catch (MongoException ex) {
throw new OplogApplyingException(ex);
}
}
Aggregations