arangodb::aql::Graph* arangodb::lookupGraphByName(TRI_vocbase_t* vocbase, std::string const& name) { SingleCollectionTransaction trx(StandaloneTransactionContext::Create(vocbase), GRAPHS, TRI_TRANSACTION_READ); int res = trx.begin(); if (res != TRI_ERROR_NO_ERROR) { THROW_ARANGO_EXCEPTION_FORMAT(res, "while looking up graph '%s'", name.c_str()); } VPackBuilder b; { VPackObjectBuilder guard(&b); b.add(StaticStrings::KeyString, VPackValue(name)); } // Default options are enough here OperationOptions options; OperationResult result = trx.document(GRAPHS, b.slice(), options); // Commit or abort. res = trx.finish(result.code); if (!result.successful()) { THROW_ARANGO_EXCEPTION_FORMAT(result.code, "while looking up graph '%s'", name.c_str()); } if (res != TRI_ERROR_NO_ERROR) { THROW_ARANGO_EXCEPTION_FORMAT(res, "while looking up graph '%s'", name.c_str()); } return new arangodb::aql::Graph(result.slice()); }
bool PaymentOpFrame::doApply(medida::MetricsRegistry& metrics, LedgerDelta& delta, LedgerManager& ledgerManager) { // if sending to self directly, just mark as success if (mPayment.destination == getSourceID()) { metrics.NewMeter({"op-payment", "success", "apply"}, "operation") .Mark(); innerResult().code(PAYMENT_SUCCESS); return true; } // build a pathPaymentOp Operation op; op.sourceAccount = mOperation.sourceAccount; op.body.type(PATH_PAYMENT); PathPaymentOp& ppOp = op.body.pathPaymentOp(); ppOp.sendAsset = mPayment.asset; ppOp.destAsset = mPayment.asset; ppOp.destAmount = mPayment.amount; ppOp.sendMax = mPayment.amount; ppOp.destination = mPayment.destination; OperationResult opRes; opRes.code(opINNER); opRes.tr().type(PATH_PAYMENT); PathPaymentOpFrame ppayment(op, opRes, mParentTx); ppayment.setSourceAccountPtr(mSourceAccount); if (!ppayment.doCheckValid(metrics) || !ppayment.doApply(metrics, delta, ledgerManager)) { if (ppayment.getResultCode() != opINNER) { throw std::runtime_error("Unexpected error code from pathPayment"); } PaymentResultCode res; switch (PathPaymentOpFrame::getInnerCode(ppayment.getResult())) { case PATH_PAYMENT_UNDERFUNDED: metrics.NewMeter({"op-payment", "failure", "underfunded"}, "operation").Mark(); res = PAYMENT_UNDERFUNDED; break; case PATH_PAYMENT_SRC_NOT_AUTHORIZED: metrics.NewMeter({"op-payment", "failure", "src-not-authorized"}, "operation").Mark(); res = PAYMENT_SRC_NOT_AUTHORIZED; break; case PATH_PAYMENT_SRC_NO_TRUST: metrics.NewMeter({"op-payment", "failure", "src-no-trust"}, "operation").Mark(); res = PAYMENT_SRC_NO_TRUST; break; case PATH_PAYMENT_NO_DESTINATION: metrics.NewMeter({"op-payment", "failure", "no-destination"}, "operation").Mark(); res = PAYMENT_NO_DESTINATION; break; case PATH_PAYMENT_NO_TRUST: metrics.NewMeter({"op-payment", "failure", "no-trust"}, "operation") .Mark(); res = PAYMENT_NO_TRUST; break; case PATH_PAYMENT_NOT_AUTHORIZED: metrics.NewMeter({"op-payment", "failure", "not-authorized"}, "operation").Mark(); res = PAYMENT_NOT_AUTHORIZED; break; case PATH_PAYMENT_LINE_FULL: metrics.NewMeter({"op-payment", "failure", "line-full"}, "operation").Mark(); res = PAYMENT_LINE_FULL; break; case PATH_PAYMENT_NO_ISSUER: metrics.NewMeter({"op-payment", "failure", "no-issuer"}, "operation").Mark(); res = PAYMENT_NO_ISSUER; break; default: throw std::runtime_error("Unexpected error code from pathPayment"); } innerResult().code(res); return false; } assert(PathPaymentOpFrame::getInnerCode(ppayment.getResult()) == PATH_PAYMENT_SUCCESS); metrics.NewMeter({"op-payment", "success", "apply"}, "operation").Mark(); innerResult().code(PAYMENT_SUCCESS); return true; }
void RestVocbaseBaseHandler::generateTransactionError( OperationResult const& result) { switch (result.code) { case TRI_ERROR_ARANGO_READ_ONLY: generateError(GeneralResponse::ResponseCode::FORBIDDEN, result.code, "collection is read-only"); return; case TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED: generateError(GeneralResponse::ResponseCode::CONFLICT, result.code, "cannot create document, unique constraint violated"); return; case TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD: generateError(GeneralResponse::ResponseCode::BAD, result.code, "invalid document key"); return; case TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD: generateError(GeneralResponse::ResponseCode::BAD, result.code, "invalid document handle"); return; case TRI_ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE: generateError(GeneralResponse::ResponseCode::BAD, result.code, "invalid edge attribute"); return; case TRI_ERROR_ARANGO_OUT_OF_KEYS: generateError(GeneralResponse::ResponseCode::SERVER_ERROR, result.code, "out of keys"); return; case TRI_ERROR_ARANGO_DOCUMENT_KEY_UNEXPECTED: generateError(GeneralResponse::ResponseCode::BAD, result.code, "collection does not allow using user-defined keys"); return; case TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND: generateError(GeneralResponse::ResponseCode::NOT_FOUND, TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND); return; case TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID: generateError(GeneralResponse::ResponseCode::BAD, result.code); return; case TRI_ERROR_ARANGO_CONFLICT: generatePreconditionFailed(result.slice()); return; case TRI_ERROR_CLUSTER_SHARD_GONE: generateError(GeneralResponse::ResponseCode::SERVER_ERROR, result.code, "coordinator: no responsible shard found"); return; case TRI_ERROR_CLUSTER_TIMEOUT: generateError(GeneralResponse::ResponseCode::SERVER_ERROR, result.code); return; case TRI_ERROR_CLUSTER_MUST_NOT_CHANGE_SHARDING_ATTRIBUTES: case TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN: case TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY: { generateError(GeneralResponse::ResponseCode::BAD, result.code); return; } case TRI_ERROR_CLUSTER_UNSUPPORTED: { generateError(GeneralResponse::ResponseCode::NOT_IMPLEMENTED, result.code); return; } case TRI_ERROR_FORBIDDEN: { generateError(GeneralResponse::ResponseCode::FORBIDDEN, result.code); return; } case TRI_ERROR_OUT_OF_MEMORY: case TRI_ERROR_LOCK_TIMEOUT: case TRI_ERROR_DEBUG: case TRI_ERROR_LOCKED: case TRI_ERROR_DEADLOCK: { generateError(GeneralResponse::ResponseCode::SERVER_ERROR, result.code); return; } default: generateError( GeneralResponse::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL, "failed with error: " + std::string(TRI_errno_string(result.code))); } }
int Syncer::applyCollectionDumpMarker( arangodb::Transaction& trx, std::string const& collectionName, TRI_replication_operation_e type, VPackSlice const& old, VPackSlice const& slice, std::string& errorMsg) { int res = TRI_ERROR_INTERNAL; if (type == REPLICATION_MARKER_DOCUMENT) { // {"type":2400,"key":"230274209405676","data":{"_key":"230274209405676","_rev":"230274209405676","foo":"bar"}} OperationOptions options; options.silent = true; options.ignoreRevs = true; options.isRestore = true; try { // try insert first OperationResult opRes = trx.insert(collectionName, slice, options); if (opRes.code == TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED) { // perform an update opRes = trx.replace(collectionName, slice, options); } res = opRes.code; } catch (arangodb::basics::Exception const& ex) { res = ex.code(); } catch (...) { res = TRI_ERROR_INTERNAL; } if (res != TRI_ERROR_NO_ERROR) { errorMsg = "document insert/replace operation failed: " + std::string(TRI_errno_string(res)); } return res; } else if (type == REPLICATION_MARKER_REMOVE) { // {"type":2402,"key":"592063"} try { OperationOptions options; options.silent = true; options.ignoreRevs = true; OperationResult opRes = trx.remove(collectionName, old, options); if (opRes.successful() || opRes.code == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) { // ignore document not found errors return TRI_ERROR_NO_ERROR; } res = opRes.code; } catch (arangodb::basics::Exception const& ex) { res = ex.code(); } catch (...) { res = TRI_ERROR_INTERNAL; } if (res != TRI_ERROR_NO_ERROR) { errorMsg = "document remove operation failed: " + std::string(TRI_errno_string(res)); } return res; } res = TRI_ERROR_REPLICATION_UNEXPECTED_MARKER; errorMsg = "unexpected marker type " + StringUtils::itoa(type); return res; }
bool PaymentOpFrame::doApply(LedgerDelta& delta, LedgerManager& ledgerManager) { AccountFrame destination; // if sending to self directly, just mark as success if (mPayment.destination == getSourceID()) { innerResult().code(PAYMENT_SUCCESS); return true; } Database& db = ledgerManager.getDatabase(); if (!AccountFrame::loadAccount(mPayment.destination, destination, db)) { innerResult().code(PAYMENT_NO_DESTINATION); return false; } // build a pathPaymentOp Operation op; op.sourceAccount = mOperation.sourceAccount; op.body.type(PATH_PAYMENT); PathPaymentOp& ppOp = op.body.pathPaymentOp(); ppOp.sendCurrency = mPayment.currency; ppOp.destCurrency = mPayment.currency; ppOp.destAmount = mPayment.amount; ppOp.sendMax = mPayment.amount; ppOp.destination = mPayment.destination; OperationResult opRes; opRes.code(opINNER); opRes.tr().type(PATH_PAYMENT); PathPaymentOpFrame ppayment(op, opRes, mParentTx); ppayment.setSourceAccountPtr(mSourceAccount); if (!ppayment.doCheckValid() || !ppayment.doApply(delta, ledgerManager)) { if (ppayment.getResultCode() != opINNER) { throw std::runtime_error("Unexpected error code from pathPayment"); } PaymentResultCode res; switch (PathPaymentOpFrame::getInnerCode(ppayment.getResult())) { case PATH_PAYMENT_UNDERFUNDED: res = PAYMENT_UNDERFUNDED; break; case PATH_PAYMENT_NO_DESTINATION: res = PAYMENT_NO_DESTINATION; break; case PATH_PAYMENT_NO_TRUST: res = PAYMENT_NO_TRUST; break; case PATH_PAYMENT_NOT_AUTHORIZED: res = PAYMENT_NOT_AUTHORIZED; break; case PATH_PAYMENT_LINE_FULL: res = PAYMENT_LINE_FULL; break; default: throw std::runtime_error("Unexpected error code from pathPayment"); } innerResult().code(res); return false; } assert(PathPaymentOpFrame::getInnerCode(ppayment.getResult()) == PATH_PAYMENT_SUCCESS); innerResult().code(PAYMENT_SUCCESS); return true; }