Couchbase SQL++의 ACID 데이터베이스 트랜잭션
Couchbase는 성능과 고가용성의 저하 없이 대규모의 분산된 다중 문서 ACID 데이터베이스 트랜잭션을 지원합니다. 관계형 데이터베이스 애플리케이션을 Couchbase로 마이그레이션하고 풍부한 SQL 지원을 활용하면서 ACID 규정을 준수하세요.

ACID란 무엇인가요?
데이터베이스에서 ACID는 트랜잭션을 일관성 있고 안전하며 안정적으로 처리하는 방법을 설명하는 약어입니다:
A | 원자성 | 모든 문서를 업데이트할 수 있도록 보장합니다. |
C | 일관성 | 복제본, 인덱스 및 XDCR의 일관성이 자동으로 유지됩니다. |
I | 격리 | 동시 독자를 위한 읽기 커밋 격리. |
D | 내구성 | 내구성 수준을 조정할 수 있는 장애 시 데이터 보호. |
트랜잭션 코드 샘플
다음은 일반적인 거래 시나리오에 대한 세 가지 코드 샘플입니다. 첫 번째는 두 계정이 모두 수정되거나 수정되지 않도록 하는 직불/신용 거래입니다. 두 번째는 SQL++를 사용하여 부서의 모든 직원을 일괄 업데이트하여 모든 직원이 업데이트되었는지 또는 아무도 업데이트되지 않았는지 확인하는 것입니다.
START TRANSACTION;
UPDATE customer SET balance = balance + 100 WHERE cid = 4872;
SELECT cid, name, balance from customer;
SAVEPOINT s1;
UPDATE customer SET balance = balance – 100 WHERE cid = 1924;
SELECT cid, name, balance from customer;
ROLLBACK WORK TO SAVEPOINT s1;
SELECT cid, name, balance from customer;
COMMIT ;
// Transfer money from Beth’s account to Andy’s account
transactions.run((txnctx) -> {
var andy = txnctx.get(collection, "Andy");
var andyContent = andy.contentAsObject();
int andyBalance = andyContent.getInt("account_balance");
var beth = txnctx.get(collection, "Beth");
var bethContent = beth.contentAsObject();
int bethBalance = bethContent.getInt("account_balance");
if (bethBalance > transferAmount) {
andyContent.put("account_balance", andyBalance + transferAmount);
txnctx.replace(andy, andyContent);
bethContent.put("account_balance", bethBalance - transferAmount);
txnctx.replace(beth, bethContent);
}
else throw new InsufficientFunds();
txnctx.commit();
});
// Bulk update salaries of all employees in a department
transactions.run((ctx) -> {
var auditLine = JsonObject.create().put("content", "Update on 4/20/2020");
ctx.insert(auditCollection, "Dept10", auditLine);
ctx.query("UPDATE employees
SET salary = salary * 1.1
WHERE dept = 10 AND salary < 50000");
ctx.query("UPDATE department
SET status = 'updated'
WHERE dept = 10");
txnctx.commit();
});