use of com.eightkdata.mongowp.exceptions.MongoException in project torodb by torodb.
the class AkkaDbCloner method cloneDatabase.
@Override
public void cloneDatabase(String dstDb, MongoClient remoteClient, MongodServer localServer, CloneOptions opts) throws CloningException, NotMasterException, MongoException {
Preconditions.checkState(isRunning(), "This db cloner is not running");
if (!remoteClient.isRemote() && opts.getDbToClone().equals(dstDb)) {
LOGGER.warn("Trying to clone a database to itself! Ignoring it");
return;
}
String fromDb = opts.getDbToClone();
CursorResult<Entry> listCollections;
try (MongoConnection remoteConnection = remoteClient.openConnection()) {
listCollections = ListCollectionsRequester.getListCollections(remoteConnection, fromDb, null);
} catch (MongoException ex) {
throw new CloningException("It was impossible to get information from the remote server", ex);
}
if (!opts.getWritePermissionSupplier().get()) {
throw new NotMasterException("Destiny database cannot be written");
}
List<Entry> collsToClone = getCollsToClone(listCollections, fromDb, opts);
if (!opts.getWritePermissionSupplier().get()) {
throw new NotMasterException("Destiny database cannot be written " + "after get collections info");
}
try {
for (Entry entry : collsToClone) {
prepareCollection(localServer, dstDb, entry);
}
} catch (RollbackException ex) {
throw new AssertionError("Unexpected rollback exception", ex);
}
Materializer materializer = ActorMaterializer.create(getActorSystem());
try (MongoConnection remoteConnection = remoteClient.openConnection()) {
if (opts.isCloneData()) {
for (Entry entry : collsToClone) {
LOGGER.info("Cloning collection data {}.{} into {}.{}", fromDb, entry.getCollectionName(), dstDb, entry.getCollectionName());
try {
cloneCollection(localServer, remoteConnection, dstDb, opts, materializer, entry);
} catch (CompletionException completionException) {
Throwable cause = completionException.getCause();
if (cause instanceof RollbackException) {
throw (RollbackException) cause;
}
throw completionException;
}
}
}
if (opts.isCloneIndexes()) {
for (Entry entry : collsToClone) {
LOGGER.info("Cloning collection indexes {}.{} into {}.{}", fromDb, entry.getCollectionName(), dstDb, entry.getCollectionName());
try {
cloneIndex(localServer, dstDb, dstDb, remoteConnection, opts, entry.getCollectionName(), entry.getCollectionName());
} catch (CompletionException completionException) {
Throwable cause = completionException.getCause();
if (cause instanceof RollbackException) {
throw (RollbackException) cause;
}
throw completionException;
}
}
}
}
}
use of com.eightkdata.mongowp.exceptions.MongoException in project torodb by torodb.
the class TorodbSafeRequestProcessor method query.
@Override
public ReplyMessage query(MongodConnection connection, Request req, int requestId, QueryRequest queryRequest) throws MongoException {
FindArgument findArg = new FindArgument.Builder().setCollection(queryRequest.getCollection()).setFilter(queryRequest.getQuery() != null ? queryRequest.getQuery() : DefaultBsonValues.EMPTY_DOC).build();
Status<FindResult> status = execute(req, FindCommand.INSTANCE, findArg, connection);
if (!status.isOk()) {
throw new MongoException(status.getErrorCode(), status.getErrorMsg());
}
FindResult result = status.getResult();
assert result != null;
return new ReplyMessage(EmptyBsonContext.getInstance(), requestId, false, false, false, false, result.getCursor().getCursorId(), queryRequest.getNumberToSkip(), IterableDocumentProvider.of(Lists.newArrayList(result.getCursor().getFirstBatch())));
}
use of com.eightkdata.mongowp.exceptions.MongoException in project torodb by torodb.
the class ReplSetHeartbeatReplyMarshaller method checkCommandError.
private static void checkCommandError(BsonDocument bson, String setName) throws MongoException {
if (setName == null && !BsonReaderTool.isPseudoTrue(bson, OK_FIELD)) {
String errMsg = BsonReaderTool.getString(bson, ERR_MSG_FIELD, "");
assert errMsg != null;
Entry<?> errorCodeEntry = BsonReaderTool.getEntry(bson, ERROR_CODE_FIELD, null);
if (errorCodeEntry != null) {
if (!errorCodeEntry.getValue().isNumber()) {
throw new BadValueException(ERROR_CODE_FIELD + " is " + "not a number");
}
ErrorCode errorCode = ErrorCode.fromErrorCode(errorCodeEntry.getValue().asNumber().intValue());
throw new MongoException(errMsg, errorCode);
}
throw new UnknownErrorException(errMsg);
}
}
Aggregations