Code Monkey home page Code Monkey logo

cassandra-playground's Introduction

cassandra-playground

Cassandra is a non-relational dataase, also known as NoSQL database,
designed to operate in distributed environment or cloud infrastructure.

wiki

https://github.com/daehwan2yo/cassandra-playground/wiki

scalable

-확장성

elastic

-탄력성

avalibility

-가용성

fault-rolerant

-장애 허용


카산드라 구조

#1

CQL

#2

분산 배치 전략

#3

카산드라 CRUD 원리

#5

카산드라 운영

백업 및 복구

#6

Configuration

#7

cassandra-playground's People

Contributors

daehwan2yo avatar

Stargazers

 avatar  avatar

Watchers

 avatar

cassandra-playground's Issues

Cassandra session pool (Connection Pooling)

reference
datastax : https://docs.datastax.com/en/developer/java-driver/2.1/manual/pooling/


datastax java driver 는 Cassandra Binary Protocol 을 통해 TCP 로 cassandra 와 connection 을 맺을 수 있으며, 비동기적으로 여러 TCP connection 을 여러 동시 요청에대해 처리가능하도록 한다.

  • query 가 수행되게 되면 connection 에 유니크한 stream id 를 할당한다.
  • driver 는 connection 에 stream id 와 query 를 담아 요청하며, 응답을 기다리지 않고 다음 작업들을 수행한다. (asynchronous, driver 는 ResultSetFuture 형식으로 응답을 한다. )
  • cassandra 가 응답을 하게되어지면 stream id 를 포함해 콜백을 수행한다.
    • driver 가 요청받은 쿼리를 완료하는 콜백을 트리거한다.

Cassandra java driver 의 경우 별도의 Connection 에 대한 관리가 필요하지 않고, 단지 Session 객체를 통해 요청을 수행하고 응답을 확인하면 된다.

  • 각 Session 이 각 요청의 Connection Pool 이 되어진다.
    • Pool 당 Connections 의 수는 커스텀 가능하며, stream id 의 개수는 protocol version 에 의존한다.
      • protocol v2 or below : 128 ids per connection
      • protocol v3 or above : up to 32768 ids per connection

스크린샷 2023-02-20 오전 2 38 04

PoolingOptions

cassandra cluster 인스턴스를 구성하면서 Pooling 에 대한 옵션값들을 세팅한 PoolingOptions 객체를 주입할 수 있다.

PoolingOptions poolingOptions = new PoolingOptions();
// customize options..

Cluster cluster = Cluster.builder()
    .withContractPoints(...)
    .withPoolingOptions(poolingOptions)
    .build();
  • poolingOptions 는 runtime 중 변경되어질 수 있다.
    • cluster.getConfigration().getPoolingOptions(). ..(customize options) ...

Pool Size

pool size 는 PoolingOptions 의 내부 옵션값들을 세팅하며 변경 가능하다.

스크린샷 2023-02-20 오전 2 43 08

Cassandra 분산 배치 전략

  • Replica-Strategy
  • Snitch
  • Partitioner

Data replication

Cassandra 는 가용성(reliability)과 결함허용성을 위해 복제본은 여러 node에서 저장한다.

Virtual Nodes

노드 생성과 제거에 있어 자동으로 빠르게 리밸런싱을 하기 위한 메커니즘이다.

Vnodes, 가상노드는 기존에 계산된 토큰을 갖는 노드들보다 더 미세하게 가상으로 토큰을 쪼개어 범위를 가상으로 정해 노드를 설정해둔다.

  • 각 노드의 Token 은 자동으로 계산되어 할당되어진다.
    • Partitioner 에 의해 계산된다.
    • murmur3
    • black box
  • 새로운 물리 Node가 Cluster 에 join 하게 되면, 자동으로 token 을 할당받고 다른 node 로 부터 데이터를 받아오게된다.
    • 가상 노드의 할당 범위를 자동으로 부여받게되는 형식

How data is distributed across a cluster

using virtual nodes

  • VNodes 는 실제 물리 노드가 Cluster 내에 분산된 여러 개의 작은 파티션을 갖게한다.

Note

DataStax 는 8 vnodes 를 활용하는것을 추천한다.

  • 8개의 vnode 를 활용하면 10% 의 차이로 시스템 간 워크로드를 분산하고 성능에 미치는 영향이 최소화된다.

Configuration VNodes

vnode 를 새로운 cluster 에 등록하는 경우

  • num_tokens
    • default : 256
    • vnode 를 활용하는 cluster에서 node에 random 하게 할당하는 token 의 개수
    • 각 node 의 물리적인 성능에 맞춰 num_tokens 를 적절하게 설정한다.
      • 만약 모든 node 의 물리적 성능이 같은 경우에는, 같은 수의 num_tokens 를 설정하는 것이 좋다.
  • initial_token
    • default : disabled
    • cassandra 1.2 이전 single-node-per-token architecture 에 대해 적용되는 구성값이다.
    • vnode 를 사용한다면 disabled 로 두면된다.

이미 운영중인 cluster 에 vnode 를 설정하는 경우

  • single-token 을 사용하는 cluster 에 vnode 를 설정하는 방법은 없다.
  • vnode 를 구성한 다른 data center 를 cluster 에 등록하여 데이터가 자동으로 분산시키는 방법은 존재한다.
    • vnode 를 구성한 새로운 data center 를 cluster 에 등록한다.
    • client 가 새로운 data center 를 바라보도록 한다.
    • nodetool repairFull Repair 를 실행한다.
      • 해당 작업은 client 가 새로운 data center 를 바라보도록 변경한 후에 이전 쓰기가 새로운 data center 로 추가되고 이전 data center 의 data 가 지워지지 않도록 한다.
    • old data center 를 참조하지 않는다고 schema 를 업데이트한다.
    • 이전 data center 를 지운다.

Cassandra Architecture

Cluster

  • node 들의 그룹
  • Master, Slave 가 존재하지 않는다.
  • 단일오류지점없이 분산 디비를 구성할 수 있다.

Snitch

한 Cluster 내 의 같은 기능을 하는 node 들끼리 어떻게 서로를 알까?
snitch 를 통해 서로를 파악한다.

  • 요청을 효과적으로 처리하기 위해 Cassandra에게 네트워크 분류(위상)을 알려준다.

  • Cassandra는 Cluster 전체에 replica 를 분산해 연관되는 오류들을 방지한다.

  • Dynamic Snitching Options

    • Simple Snitch (default)

      • 단 하나의 data center 를 운영하는 경우만 사용가능
    • RackInferring Snitch

    • PropertyFile Snitch

      • 새로운 노드가 추가될때 모든 노드에 하나씩 접근하여 수정해주어야한다.
    • GossipingPropertyFile Snitch

    • EC2 Snitch

    • EC2 MultiRegion Snitch

gossip

p2p protocol, node 들이 주기적으로 상태 정보를 변경하는것을 p2p 를 통해 공유한다.
매초마다 실행되며, 최대 3개의 다른 노드와 상태를 공유한다.
공유가될때 자신의 정보 뿐만 아니라, 다른 노드로부터 받은 정보들을 함께 공유한다.
따라서 모든 노드는 클러스터내의 다른 모든 노드들의 정보를 빠르게 알 수 있다.

  • internal communication method for node in a cluster
    (external communication 은 CQL 혹은 Thrift 를 활용한다.)

Q. cluster 내부의 node 들은 어떻게 cluster의 분류 (node 들의 상태 및 위치) 를 알까?

A. Through the snitch
snitch 는 Cassandra 내부에서 Cluster 내의 topology 를 알려주는 역할을 수행한다.

Q. Gossip 은 무엇인가?

A. Gossip 은 Cluster 내부의 node 간 상태를 공유하기 위한 p2p protocol 을 의미한다.
Gossip is just use for the nodes to talk to themselves (internal communication)
Client Application 과 같은 외부 통신 (external) 은 CQL 혹은 Thrift 를 기반으로 동작한다.

Self 환경 구성

Cluster 명

test-cluster

num_tokens

256

hinted_handoff_enabled

true

hints_directory

~/files/hints

partitioner

Murmur3

data_file_directories

~/files/data

commitlog_directory

~/files/commitlog

disk_failure_policy

stop

commit_failure_policy

stop

saved_cache_directory

~/files/cache

seed

SimpleSeedProvider,
ip 2개

listen_address

해당 노드 ip

native_transport_port

9042

rpc_address

0.0.0.0

incremental_backups

false

snapshot_before_compaction

false

auto_snapshot

true

endpoint_snitch

GossipingPropertyFileSnitch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.