16 Haziran 2020 Salı

Couchbase - Document Store - Availability Önemlidir

Giriş
NoSQL veri tabanlarından bir tanesidir. Veriyi JSON olarak saklar. Açıklaması şöyle
Couchbase Server documents of are stored as JSON.
XML veriyi saklamak için bir yazı burada.

Couchbase vs MongoDB
Couchbase ve MongoDB birbirleriyle rakipler. Aralarındaki en önemli farklar şöyle. Couchbase en baştan dağıtık olacak şekilde tasarlanmış. Ayrıca sorgulama dili SQL'e benziyor.
- Couchbase is designed to be distributed from the get-go. For example, the data container Bucket is always distributed — nothing to share. Simply add new nodes and the system will automatically distribute. Intra cluster replication requires no new servers - simply set the number of replicas and you're all set. 
- From the developer interaction perspective, the big difference is the query language itself - MongoDB has a proprietary query language and Couchbase has N1QL - SQL for JSON. MongoDB uses its B-Tree-based index for search as well and recently released $searchbeta for the Atlas service using Apache Lucene; Couchbase has a built-in Full-Text Search.
Couchbase vs Relational DB
Şeklen şöyle


Couchbase ve Önemli Kavramlar
Bunlar şöyle
- N1QL (nickel diye teleffuz edilir)
- Indexing,
- Full-Text Search,
- Eventing
- Analytics.

CouchbaseDB ve Couchbase
Bunlar farklı ürünler

CouchBase Komutları
Couchbase Komutları yazısına taşıdım.

Keys
Açıklaması şöyle. Yani tekil olmalı. Bunda zaten şaşılacak bir şey yok.
Each document in a bucket will have a user-generated unique document key. This uniqueness is enforced during insertion of the data.
Açıklaması şöyle. Key String olmalı
Each value (binary or JSON) is identified by a unique key, defined by the user or application when the item is saved. The key is immutable: once the item is saved, the key cannot be changed. Note that Couchbase also refers to an item's key as its id.

Each key:

- Must be a UTF-8 string with no spaces. Special characters, such as (, %, /, " and _ are acceptable.
- May be no longer than 250 bytes.
- Must be unique within its bucket.
Values
Açıklaması şöyle. Value Binary veya JSON olabilir.
The maximum size of a value is 20 MiB. A value can be either:

- Binary: Any form of binary is acceptable. Note that a binary value cannot be parsed, indexed or queried. It can only be retrieved by key.
- JSON: A JSON value, referred to as a document, can be parsed, indexed, and queried. Each document consists of one or more attributes, each of which has its own value. An attribute's value can be a basic type — such as a number, string, or Boolean — or a complex, such as an embedded document or an array.

N1QL (Nickel) Nedir
Açıklaması şöyle
N1QL (pronounced “nickel”) is Couchbase's next-generation query language. N1QL aims to meet the query needs of distributed document-oriented databases. 
N1QL Statements Nedir
Açıklaması şöyle. Burada sanırım bir tek START TRANSACTION eksik. Aslında N1QL Statement aynı normal SQL cümlelerine benziyorlar. N1QL "REST over HTTP/S" kullanır
N1QL DML statements include SELECT, INSERT, UPDATE, UPSERT, DELETE, and MERGE.
Optimistic Concurrency
Couchbase READ COMMITTED isolation seviyesini kullanır. Ayrıca Optimistic Concurrency modelini benimser. Dolayısıyla commit işlemlerinin başarısız olma ihtimali var. Bu durumda transaction tekrarlanmalıdır. Açıklaması şöyle.
Remember we use optimistic concurrency control.  That means, even after the INSERT is successful,  the commit stage can still run into a write-write conflict because some other session could have inserted between the insert and commit.   You’ll have to retry the transaction on such failures.
N1QL INSERT INTO
örnek
Şöyle yaparız
INSERT INTO customer
VALUES(“cx4872”, {“cid”: 4872, “name”:”John Doe”, “balance”:724.23});
INSERT INTO customer
VALUES(“cx1924”, {“cid”: 1924, “name”:”Bob Stanton”, “balance”:2735.48});
N1QL START TRANSACTION
Buna aynı zamanda BEGIN WORK te deniliyor. Açıklaması şöyle. Yani transaction hangi Query Node üzerinde başladıysa, orada devam edip bitmek zorunda
This statement starts a new transaction, assigns a new transaction ID, and returns the transaction ID to the caller. There are two rules the SDKs, tools (e.g. CBQ shell) follow to successfully execute the rest of the transaction.

1. Send this transaction ID as a parameter every subsequent statement within the transaction.  This is how the query service knows the statement should be run as part of a particular transaction.

2. Couchbase can have multiple query service nodes, but a single transaction is executed on a single query node. You can start a new transaction in ANY QUERY NODE. However, the rest of the statements FOR THAT SINGLE TRANSACTION should be sent to the VERY SAME query node.
Örnek
Şöyle yaparız
START TRANSACTION;
UPDATE customer SET balance = balance + 100 WHERE cid = 4872;
SELECT cid, name, balance  FROM customer;
UPDATE customer SET balance = balance – 100 WHERE cid = 1924;
SELECT cid, name, balance FROM customer;
COMMIT ;
Örnek - Save Point İle
Şöyle yaparız
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 ;

Index Kategorileri
1. Standard Secondary
Açıklaması şöyle
The standard secondary index in 5.0 uses the plasma storage engine in the enterprise edition, which uses the lock-free skip list like MOI, but supports large indexes that don't fit in memory.
2. Memory Optimized Index
Açıklaması şöyle
A memory-optimized index uses a novel lock-free skiplist to maintain the index and keeps 100% of the index data in memory. A memory-optimized index (MOI) has better latency for index scans and can also process the mutations of the data much faster.
Full Text Search
Açıklaması şöyle
Couchbase Full-Text Search (FTS) is created with three main motivations:

- Transparently search across multiple fields within a document
- Go beyond the exact matching of values by providing language based stemming, fuzzy matching, etc.
- Provide the search results based on relevance
Full Text Search kullanarak Geospatial arama yapmak bile mümkün. Bir örnek burada

Hiç yorum yok:

Yorum Gönder