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();
});
๊ด๋ จ ๋ฆฌ์์ค
์น ์ธ๋ฏธ๋
๋ฐฑ์
๋๋ผ์ด ๊ณ ๊ฐ ๊ฒฝํ์ ๋ง๋ค ์ค๋น๊ฐ ๋์ จ๋์?
Couchbase๋ฅผ ์์ํ๋ ๊ฐ์ฅ ์ฝ๊ณ ๋น ๋ฅธ ๋ฐฉ๋ฒ