[컴][db] mysql 만 쳐서 접근이 되는 경우

 

mysql cli / 바로 접근 / mysql 만 실행하니 접근 되는 경우

mysql 만 쳐서 접근이 되는 경우

때론 mysql 로 db 서버에 접근만 쳐도 들어가는 경우가 있다. 이 경우는 mysql.user 에 현재 접속한 계정이 등록된 경우이다. 그런데 password 도 안쳐도 되는 경우라면 다음 2가지라고 한다.

  • account 에 password 가 등록되지 않은 경우
  • config file 에 password 가 포함된 경우
SELECT host, user, password FROM mysql.user; -- MySQL before 5.7
SELECT host, user, authentication_string FROM mysql.user; -- MySQL 5.7 +

Reference

  1. Mysql login without a specific user - Stack Overflow

[컴] terraform

테라폼 /

terraform

장점

위 글에 있는 terraform 장점:

  • 인프라를 배포하고 관리하는 동안 사람의 실수 가능성을 줄입니다.
  • 동일한 템플릿을 여러 번 배포하여 동일한 개발, 테스트 및 프로덕션 환경을 만듭니다.
  • 개발 및 테스트 환경을 요청 시 만들어서 비용을 줄입니다.
  • 팀 구성원은 제안된 변경 내용과 그 영향을 이해하여 보다 효과적으로 공동 작업할 수 있습니다.
  • 의도하지 않은 변경 내용은 개발 프로세스 초기에 확인할 수 있습니다.

resource 정의 하는 방법

아래처럼 resource 를 정의한다. 저기서 aws_s3_bucket 값은 terraform 에서 지정해 놓은 값이다.(참고)

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

resource "aws_s3_bucket_acl" "example" {
  bucket = aws_s3_bucket.b.id
  acl    = "private"
  arn = "arn:aws:s3:::myservice-static-files"
}

terraform으로 aws 사용

terraform doc

해당 provider 에 대한 resource, argument, attribute 를 찾는법

provider 를 선택한다. 이 provider 가 cloud 제공자(provider)가 된다.

선택후, 오른쪽에 Documentation 을 누르자. 그러면 왼쪽에 목차가 보이는데, 그것들이 전부 사용할 수 있는 resource로 보면 될 듯 하다.

terraform documentation page

이제 다시 위의 정의한 resource 를 보자.

resource "aws_vpc" "main" {
  cidr_block = "160.0.0.0/16"
  # enable_dns_hostnames = true
}
  • 여기서 aws_vpc 에 다른 resource 를 넣을 수 있다.
  • main은 이름?(label) 같은 값이라 보면된다. 우리가 설정하고 싶은 값으로 설정하면 된다.
  • cidr_blockaws_vpc 의 Argument 이다. 이 argument 는 필수적인 것도 있고, optional 도 있다.
  • ‘Attribute’ 도 넣을 수 있다. 대체로 이 attribute 는 현재 resource가 가지고 있는 값이라 보면 될 듯 하다. argument 로 넘기는 값들은 내가 바꾸고 싶은 값이고, 만약 우리가 terracognita 등을 이용해서 aws 의 infra 내용을 terraform 으로 가져온다면, attribute 가 설정될 것이다. 그래서 enable_dns_hostnamesattributeargument 둘다에 들어가 있다.

terraform 사용 명령어

  • terraform init : terraform 을 시작하려면 terraform init 을 하면 된다. 그런데 terraform init을 위해서는 terraform configuration file (version.tf) 가 필요하다. 이미 만들어진 tf 가 있는경우 terraform init 을 하면 필요한 plugin 들을 download 하게된다.
  • terraform plan : terraform plan 을 실행하면 execution plan 을 생성한다.
  • terraform apply : 설정(configuration) 파일을 변경한 후 deploy 할 때 사용
  • terraform -v : terraform 버전 확인

terracognita

terracognita 를 이용해서 aws 등에 이미 설치된 infra 대한 terraform 값을 얻을 수 있다.

terracognita aws --hcl vpc --tfstate terraform.tfstate --aws-default-region ap-northeast-2 -i aws_vpc
  • --hcl vpc 를 하면 vpc folder 를 만들고 그 안에 .tf file들을 만든다.
  • --tfstate terraform.tfstate : TFState 을 기록할 파일이름
  • --aws-default-region string : 검색한 region 을 정해준다. terracognita aws 일 때 쓰이는 flag이다.
  • -i vpc : 특정 resource에 대한 terraform 을 가져올 때 사용, -i option 을 하지 않으면 전부 가져온다.
d:\a\prog\terracognita\demo1>d:\a\apps\terracognita\terracognita-windows-amd64.exe --help
Reads from Providers and generates a Terraform configuration, all the flags can be used also with ENV (ex: --aws-access-key == AWS_ACCESS_KEY)

Usage:
  terracognita [command]

Available Commands:
  aws         Terracognita reads from AWS and generates hcl resources and/or terraform state
  azurerm     Terracognita reads from Azure and generates hcl resources and/or terraform state
  google      Terracognita reads from GCP and generates hcl resources and/or terraform state
  help        Help about any command
  version     Prints the current build version
  vsphere     Terracognita reads from vSphere and generates hcl resources and/or terraform state

Flags:
  -d, --debug                     Activate the debug mode which includes TF logs via TF_LOG=TRACE|DEBUG|INFO|WARN|ERROR configuration https://www.terraform.io/docs/internals/debugging.html
  -e, --exclude strings           List of resources to not import, this names are the ones on TF (ex: aws_instance). If not set then means that none the resources will be excluded
      --hcl string                HCL output file or directory. If it's a directory it'll be emptied before importing
      --hcl-provider-block        Generate or not the 'provider {}' block for the imported provider (default true)
  -h, --help                      help for terracognita
  -i, --include strings           List of resources to import, this names are the ones on TF (ex: aws_instance). If not set then means that all the resources will be imported
      --interpolate               Activate the interpolation for the HCL and the dependencies building for the State file (default true)
      --log-file string           Write the logs with -v to this destination (default "C:\\Users\\namh\\AppData\\Local\\cache/terracognita/terracognita.log")
      --module string             Generates the output in module format into the directory specified. With this flag (--module) the --hcl is ignored and will be generated inside of the module
      --module-variables string   Path to a file containing the list of attributes to use as variables when building the module. The format is a JSON/YAML, more information on https://github.com/cycloidio/terracognita#modules
      --target strings            List of resources to import via ID, those IDs are the ones documented on Terraform that are needed to Import. The format is 'aws_instance.ID'
      --tfstate string            TFState output file
  -v, --verbose                   Activate the verbose mode

Use "terracognita [command] --help" for more information about a command.

d:\a\prog\terracognita\demo1>d:\a\apps\terracognita\terracognita-windows-amd64.exe aws --help
Terracognita reads from AWS and generates hcl resources and/or terraform state

Usage:
  terracognita aws [flags]
  terracognita aws [command]

Available Commands:
  resources   List of all the AWS supported Resources

Flags:
      --aws-access-key string                Access Key (required)
      --aws-default-region string            Region to search in, for now * is not supported (required)
      --aws-profile string                   Name of the Profile to use with the Credentials
      --aws-secret-access-key string         Secret Key (required)
      --aws-session-token string             Use to validate the temporary security credentials
      --aws-shared-credentials-file string   Path to the AWS credential path
  -h, --help                                 help for aws
  -t, --tags strings                         List of tags to filter with format 'NAME:VALUE'

Global Flags:
  -d, --debug                     Activate the debug mode which includes TF logs via TF_LOG=TRACE|DEBUG|INFO|WARN|ERROR configuration https://www.terraform.io/docs/internals/debugging.html
  -e, --exclude strings           List of resources to not import, this names are the ones on TF (ex: aws_instance). If not set then means that none the resources will be excluded
      --hcl string                HCL output file or directory. If it's a directory it'll be emptied before importing
      --hcl-provider-block        Generate or not the 'provider {}' block for the imported provider (default true)
  -i, --include strings           List of resources to import, this names are the ones on TF (ex: aws_instance). If not set then means that all the resources will be imported
      --interpolate               Activate the interpolation for the HCL and the dependencies building for the State file (default true)
      --log-file string           Write the logs with -v to this destination (default "C:\\Users\\namh\\AppData\\Local\\cache/terracognita/terracognita.log")
      --module string             Generates the output in module format into the directory specified. With this flag (--module) the --hcl is ignored and will be generated inside of the module
      --module-variables string   Path to a file containing the list of attributes to use as variables when building the module. The format is a JSON/YAML, more information on https://github.com/cycloidio/terracognita#modules
      --target strings            List of resources to import via ID, those IDs are the ones documented on Terraform that are needed to Import. The format is 'aws_instance.ID'
      --tfstate string            TFState output file
  -v, --verbose                   Activate the verbose mode

Use "terracognita aws [command] --help" for more information about a command.

terraform.tfstate 저장

tools

See Also

  1. GitHub - shuaibiyy/awesome-terraform: Curated list of resources on HashiCorp's Terraform : terraform 관련 자료들을 모아놓았다.
  2. Export your Google Cloud resources into Terraform format : gcp 설정을 terraform 으로 export
  3. AWS Import/Export infrastructure as code (CloudFormation | Terraform) | by Exequiel Barrirero | binbash | Medium :
  4. Cloudcraft – Draw AWS diagrams : aws 와 연동해서 현재 구성도를 그려준다.
  5. Provision Infrastructure As Code – AWS CloudFormation – Amazon Web Services : aws 에서 제공하는 Infrastructure As Code(IAC), AWS CloudFormation
  6. Import Existing AWS Infrastructure to Terraform | by Melissa Gibson | Oct, 2022 | Towards AWS : aws infra 를 terraform 으로 변경, cycloidio/terracognita 를 사용한다.
  7. Windows 에서 AWS CLI 사용하기
  8. Understanding Meta-Arguments in Terraform - Knoldus Blogs : terraform 의 meta-arguments 
  9. Terraform Best Practices: terraform 을 작성할 때도 modulization 을 고려해서 작성하는 법을 알려준다.(코드 구조등)
  10. 5 Essential Terraform Tools To Use Everyday | Better Programming
  11. Tools to Visualize your Terraform plan - DEV Community 👩‍💻👨‍💻 : terraform graph 에 대한 이야기

[컴] buildscript.repositories 와 repositories 의 차이

 

build gradle / repository / repositories 차이

buildscript.repositoriesrepositories 의 차이

repository 는 dendency 를 어디서 가져올 것인가를 정해주는 것으로 보면 된다.

그래서 buildscript안의 repository 는 buildscript안의 dependency들을 가져오기 위해 쓰이고, root 에 있는 repositories는 project 를 build 하는데 필요한 dependency 를 가져오는 데 쓰인다.

그러면 buildscript 안의 dependency 는 뭐가 다를까?

그것은 buildscript 가 필요한 부분, 즉, gradle 이 사용할 class 등을 정의하게 된다. ref. 3 의 예제를 보면 이해가 쉬울 수 있다.

import org.apache.commons.codec.binary.Base64

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
    }
}

tasks.register('encode') {
    doLast {
        def byte[] encodedString = new Base64().encode('hello world\n'.getBytes())
        println new String(encodedString)
    }
}

``` Output of gradle -q encode

gradle -q encode aGVsbG8gd29yb ``

Reference

  1. build - Gradle buildscript dependencies - Stack Overflow
  2. build.gradle buildscript dependencies vs. dependencies? - Stack Overflow
  3. Build Script Basics

[컴][db] MySQL의 spatial data types, 공간 데이터 타입

공간데이터 / rdbms 공간 타입 저장 / 기하학 정보 저장 /

MySQL의 spatial data types, 공간 데이터 타입

MySQL 에서는 OGC specification 을 따라서, 공간관련 확장(spatial extension)을 구현했다. 이것은 SQL with Geometry Types 의 부분집합이다. 다음 3가지를 지원한다.

  • data types : 공간 값을 표현하는 data types
  • functions: 공간 값들을 다룰 수 있는 함수들
  • spatial indexing: 공간 칼럼들의 access time을 증가시켜줄 index 들

지원하는 data types

  • GEOMETRY, GEOMETRYCOLECTTION : GEOMETRY 가 부모 class 이다.(참고) Geometry type 은 모든 다른 spatial type 을 포함할 수 있다.
  • POINT , MULTIPOINT
  • LINESTRING, MULTILINESTRING
  • POLYGON, MULTIPOLYGON

table 생성

다음과 같이 생성할 수 있다. 이 때 SRID 를 사용하는데, 이것이 없어도 되지만, 이것이 없으면, spatial index 를 만들수 었다. 그리고 SRID 가 정해지면, insert 시에 SRID 도 같이 명시해서 insert 해줘야 한다.

CREATE TABLE geom (
    p POINT SRID 0,
    g GEOMETRY NOT NULL SRID 4326
);

query 에서 geometry object들을 표현하기 위해서 2가지 공간데이터 포맷이 사용되어진다. MySQL 내부적으로 geometry 값들을 저장할 때는 WKB format가 비슷한 format을 사용한다. 그러나 똑같진 않다. 첫4byte 가 SRID 를 가리킨다.(참고: Internal Geometry Storage Format)

  • WKT format(Wll-known Text) : WKT 는 geometry data를 ASCII 모양으로 교환하기 위해 디자인됐다.
  • WKB format(Wll-known Binary) : geometry data 를 BLOB같은 binary stream들로 교환하기 위해 사용된다. 여기 에서 WKB format에 대한 설명을 보면 된다. 대략적으로 이야기하면, 0101000000000000000000F03F000000000000F0BF 이런식으로 표현되는 방식이다.

WKT

아래처럼 POINT(15 20) text 를 ST_GeomFromText() 를 사용해서 Point object로 변환한다. 그리고 여기서 ST_X() 를 이용해서 X 값을 얻어내는 것이다.

mysql> SELECT ST_X(ST_GeomFromText('POINT(15 20)'));
+---------------------------------------+
| ST_X(ST_GeomFromText('POINT(15 20)')) |
+---------------------------------------+
|                                    15 |
+---------------------------------------+

ST_IsValid()

from : 11.4.4 Geometry Well-Formedness and Validity

  • 잘못된 기하학적 형상(geometrically invalid geometries)을 insert, select, update 할 수 있지만 구성이 잘 되어 있어야 한다.(syntactically well-formed).
  • 계산 비용 때문에 MySQL은 기하학적 타당성(geometric validity)을 명시적으로 확인하지 않는다.
  • 공간 계산(Spatial computations)은 잘못된 기하학의 몇몇 사례를 감지하고 오류를 발생시킬 수 있지만, invalidity 를 발견하지 않은채로 undefined result를 return할 수도 있다.
  • 기하학적으로 유효한 geomery들이 필요한 애플리케이션은 ST_IsValid() 함수를 사용하여 geometry들을 확인해야 합니다.

SRS 지원(Spatial Reference System)

공간데이터를 윈한 SRS(Spatial Reference System, 공간 참조 시스템)은 지리적인 위치들을 위한 좌표기반의 시스템이다.

  • projected SRS 는 평평한 표면에 지구본을 투영한 것. 그래서 경도, 위도가 아니라 미터,피트등으로 좌표가 표시된다. 이때 세계는 타원위에 있다. (흔히 보는 세계지도를 생각하면 된다. -> 지도(map)예)
  • geographic SRS 은 non-projected SRS 이다. 위도-경도 좌표로 타원위에 표시된다.
  • MySQL에서 ’SRID 0으로 표시된 SRS’는 축에 단위(unit)가 할당되지 않은 무한 데카르트 평면(Cartesian plane)을 나타낸다.
    projected SRS 와 다르게, 그것은 지리적으로 참조되지 않으며 반드시 지구를 나타내는 것은 아니다.
    그것은 무엇이든 사용할 수 있는 추상적인 평면(abstract plane)이다.
    SRID 0은 MySQL의 공간 데이터에 대한 기본 SRID 이다.

다음처럼 query 를 날리면, SRS 정보를 확인할 수 있다.

SELECT * FROM INFORMATION_SCHEMA.ST_SPATIAL_REFERENCE_SYSTEMS

MariaDB에서는 [SPATIAL_REF_SYS Table](https://mariadb.com/kb/en/information-schema-spatial_ref_sys-table/)를 사용해야 한다. 그리고 SRID 0 이 아니라 SRID -1 값이 할당되지 않은 SRID 값으로 보인다.

SELECT * FROM INFORMATION_SCHEMA.SPATIAL_REF_SYS;

사용법

CREATE TABLE geom (g GEOMETRY);


ALTER TABLE geom ADD pt POINT;
ALTER TABLE geom DROP pt;

INSERT INTO geom VALUES (ST_GeomFromText('POINT(1 1)'));

SET @g = 'POINT(1 1)';
INSERT INTO geom VALUES (ST_GeomFromText(@g));

SELECT ST_AsText(g) FROM geom;
SELECT ST_AsBinary(g) FROM geom;

index 생성

SPATIAL INDEX 는 R-tree 를 생성한다. 그냥 일반적인 B-tree index 도 사용할 수 있는데, 이것은 특정 값을 찾는곳에서는 유용하다. 그런데 범위를 scan 하는 용도에는 적합하지 않다.

spatial index는 geometry의 최소 경계 직사각형(minimum bounding rectangle, MBR)을 사용하여 만든다. 대부분의 geomery들에서 MBR은 geometry들을 둘러싸는 가장작은 직사각형이다. 수평선, 수직선에서 MBR은 ‘선’(linestring)이 되고, ’점(point)’에서 MBR은 ’점’이 된다.

CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326, SPATIAL INDEX(g));

// spatial index 생성시 column 은 NOT NULL 이어야만 한다.
ALTER TABLE geom ADD SPATIAL INDEX(g);  // add index
CREATE SPATIAL INDEX g ON geom (g)  // 위 add index와 같은 것.

ALTER TABLE geom DROP INDEX g;
DROP INDEX g ON geom;

spatial index 가 되어 있으면 아래처럼 query 를 날릴 수 있다. 참고로 spatial index가 없어도 아래 query 는 동작한다. 다만 더 느리다.

mysql> SET @poly =
    -> 'Polygon((30000 15000,
                 31000 15000,
                 31000 16000,
                 30000 16000,
                 30000 15000))';
mysql> SELECT fid,ST_AsText(g) FROM geom WHERE
    -> MBRContains(ST_GeomFromText(@poly),g);

See Also

  1. Geographic & Geometric Features - MariaDB Knowledge Base: MariaDB 에서도 지원한다.
  2. 공간 데이터 타입(Spatial Data Type) :: 꿈을 향하여 질주하기

References

  1. MySQL :: MySQL 8.0 Reference Manual :: 11.4 Spatial Data Types

[컴] ssh tunneling

ssh tunnel / forward / port forwarding

ssh tunneling

ssh tunnel 열기

만약 localhost 에서 2.2.2.2 를 타고, 3.3.3.3 을 가려할 때 아래처럼 하면 된다. 아래처럼 하면 localhost:3355 를 접근하면, ssh tunnel 을 통해서 3.3.3.3:3306 으로 전달해준다.

ssh myuser@2.2.2.2 -p 333 -i d:\a\etc\foodpang\pem\id_myuser -N -L 127.0.0.1:3355:3.3.3.3:3306
localhost:3355 --> 2.2.2.2:333 ---> 3.3.3.3:3306

실행

아래처럼 console 에서 실행하면 그냥 계속 block 된 상채로 prompt 만 깜빡이게 된다. 이 상태가 ssh tunnel 이 열린 상태로 보면 된다.

C:\Users\myuser>ssh myuser@2.2.2.2 -p 333 -i d:\pem\id_myuser -N -L 127.0.0.1:3355:3.3.3.3:3306
Enter passphrase for key 'd:\pem\id_myuser':

[컴][db] MariaDB Galera cluster 설정

마리아db 마리아디비 / 클러스터링 / 클러스터 방법

MariaDB Galera cluster 설정

절차

  1. MariaDB Galera 설치
  2. MariaDB Galera Cluster 설정

MariaDB Galera Cluster 설정

1번째 node 는 --wsrep-new-cluster 으로 실행해야 한다. 그 이후 cluster 에 attach 하는 node 는 --wsrep-new-cluster 옵션을 빼야 한다. --wsrep-new-cluster 을 붙이면 cluster 가 사용할 cluster UUID 를 만들기 때문에 기존의 cluster로 접속이 안된다.(다른 참고: Starting the Cluster — Galera Cluster Documentation)

만약 전체가 다 내려간 후 다시 clustering 을 시작할때도 1번째 node가 cluster 를 만들고, 그 cluster에 node를 붙이는 방식으로 해야 한다.

mysqld --wsrep-new-cluster

기존의 cluster 에 node 를 추가할 때

option file 에 아래처럼 추가하면 된다.

[mariadb]
...
wsrep_cluster_address=gcomm://192.168.0.1  # DNS names work as well, IP is preferred for performance

가장 최신 node 를 찾는데 도움이 되는 option

경우에 따라 Galera가 클러스터에서 가장 최신의 node(most advanced node)가 아닐 수 있다는 것을 감지하면 노드 bootstrap을 거부할 수 있다. Galera는 노드가 클러스터에서 마지막으로 종료된 노드가 아닌지 또는 노드가 충돌했는지 여부를 확인한다. 이러한 경우에는 수동 개입이 필요하다.

어떤 노드가 가장 높은 level인지 확실히 알고 있다면 datadir에서 grastate.dat 파일을 편집할 수 있다. 가장 최신의 node(most advanced node)에서 safe_to_bootstrap=1을 설정할 수 있다.

각 노드에서 grastate.dat을 확인하고 seqno가 가장 높은 노드를 찾아 어떤 노드가 가장 높은 level인지 확인할 수 있다. 노드가 충돌하고 seqno=-1인 경우, wsrep_recover 옵션을 사용하여 각 노드에서 seqno를 복구하여 가장 최신의 node(most advanced node)를 찾을 수 있다.

mysqld --wsrep_recover

모든 node 가 죽은 경우, 다시 bootstrap 을 할 node 를 선택할 때 어떤 노드로 시작하느냐.

The Safe-To-Bootstrap Feature — Galera Cluster Documentation → Selecting the Right Node 내용 정리

  • 순서대로 shutdown 된 경우
    • 각 노드의 grastate.dat 를 확인해서, safe_to_bootstrap: 1 인 node 를 택해서 bootstrap 을 진행한다.
  • hard crash
    • 모든 노드가 safe_to_bootstrap: 0 가 된다.
    • 클러스터에서 마지막 트랜잭션을 commit한 노드를 찾아야 한다. 이것은 mysqld --wsrep-recover 를 통해서 찾을 수 있다. 아래처럼 log 가 만들어진다. 여기서 ‘Recovered position’ 에 <UUID>:<seq_no> 가 적혀있는데, 이 때 seq_no 가 가장 큰 node 를 찾는다.
    • 그리고 그 node 의 grstate.datsafe_to_bootstrap1로 변경해서 bootstrap 을 진행한다.
    2016-11-18 01:42:15 36311 [Note] InnoDB: Database was not shutdown normally!
    2016-11-18 01:42:15 36311 [Note] InnoDB: Starting crash recovery.
    ...
    2016-11-18 01:42:16 36311 [Note] WSREP: Recovered position: 37bb872a-ad73-11e6-819f-f3b71d9c5ada:345628

모니터링(monitoring)

SHOW GLOBAL STATUS LIKE 'wsrep_%';

Clustering 사용전 알아두면 좋은 사항

swap size 요구사항

정상 작동 중에 MariaDB Galera 노드는 일반 MariaDB 서버보다 훨씬 많은 메모리를 사용하지 않는다. certification index 및 uncommitted writesets에는 추가 메모리가 사용되지만 일반적으로 일반적인 응용 프로그램에서는 이러한 메모리가 눈에 띄지 않습니다. 그러나 한 가지 예외가 있습니다.

  • 상태 전송 중 Writeset caching : 노드가 state transfer 을 수신하는 경우 아직 적용할 state가 없기 때문에 수신한 writesets을 처리하고 적용할 수 없습니다. state transfer 메커니즘(예: mysqldump)에 따라 state transfer을 전송하는 노드도 writesets를 적용하지 못할 수 있습니다. 따라서 이러한 writesets를 caching하여 후속 단계를 수행해야 한다. 현재 writesets는 메모리에 캐시되며, 만약 시스템이 메모리를 다 쓰면 2가지 경우로 처리된다. state transfer이 실패하거나, 클러스터가 state transfer이 끝나기를 기다리는 것을 block한다.

writeset cache에 대한 메모리 사용량을 제어하려면 Galera parameters(gcs.recv_q_hard_limit, gcs.recv_q_soft_limit 및 gcs.max_throttle)를 확인하자.

MariaDB Galera Cluster 의 한계

See Also

  1. 쿠…sal: [컴][db] Galera Replication

Reference

  1. Getting Started with MariaDB Galera Cluster - MariaDB Knowledge Base

[컴][db] Galera Replication

갈레라 복제 / 마리아 갈레라 / 마리아 클러스터링 / clustering / cluster / db cluster / mysql cluster

Galera Replication

ref. 1 에 Galera 에 대한 설명이 잘 되어 있다.

이 글은 ref.1 의 번역, 정리를 한다.

Galera 의 replication 이 추구하는 바는 synchronous 이긴 한데, 완전히 synchronouse 는 아니다.

However, in practice, synchronous database replication has traditionally been implemented via the so-called “2-phase commit” or distributed locking which proved to be very slow. Low performance and complexity of implementation of synchronous replication led to a situation where asynchronous replication remains the dominant means for database performance scalability and availability. Widely adopted open-source databases such as MySQL or PostgreSQL offer only asynchronous or semi-synchronous replication solutions.

Galera’s replication is not completely synchronous. It is sometimes called virtually synchronous replication.

Certification-Based Replication

synchronous replication 에 대한 대안으로 Group Communication 과 transaction ordering 기술이 제안됐다. 이것을 기반으로 Galera Replication library 와 wsrep API(write set replication API) 를 만들었다.

Galera provider 가 transaction과 관련된 write set을 인증한다.(certify) 이 인증은 클러스터의 각 노드의 commit 시간에 행해진다. 이 write set이 반드시 해당 클러스터 노드에 바로 적용되는 것은 아니다. 대신 write set은 클러스터 노드의 receive queue에 들어가고, 결국 클러스터 노드의 Galera slave thread 중 하나에 의해 처리된다.

wsrep_slave_threads system 변수로 Galera slave thread 개수를 설정할 수 있다.

Galera slave thread 는 어떤 write set 들이 병렬로 적용하는 것이 안전한지 결정할 수 있다.(determine)
그러나 만약 클러스터 노드들이 잦은 consistency 문제들을 갖는것처럼 보인다면, 값을 1로 하는것이 아마 문제를 수정할 수 있을 것이다.

wsrep_local_state_comment에서, 클러스터 노드의 state가 JOINED 인 경우에 슬레이브 스레드 수를 늘리면 클러스터 노드가 클러스터를 더 빨리 따라잡을 수 있다. 이 경우 스레드 수를 시스템의 ’CPU 수의 두 배’로 설정하는 것이 유용할 수 있다.

정리:

write set 이 commit 되면, certificate 이 수행된다. 그리고 write set 이 receive queue 에 들어가고, Galera slave thread 가 가져다가 replication 을 처리한다.?

Streaming Replication

Galera 4 에서부터 지원한다. Galera 4 는 MariaDB 10.4 부터 지원한다.

MariaDB Cluster 옛버전에서는 실행할 수 있는 transaction size가 2GB가 최고치였다.

노드는 replication 과 certification 을 수행하기 전에 트랜잭션 커밋(transaction commit)을 기다린다.

‘대규모 트랜잭션’, ‘장기간 실행되는 쓰기’, ‘대규모 데이터셋 변경’은 conflict 가 발생해서 ’비용이 크게 든 작업’(expensive operation)을 rollback할 수 밖에 없는 가능성이 더 커진다.

Streaming Replication를 사용하면, 노드는 대규모 트랜잭션을 더 작고 관리하기 쉬운 fragment로 분할한 다음, commit을 기다리는 대신 이러한 fragment들을 클러스터에 복제한다.(replicate), 그리고 인증을 하게되면, conflicting transactions 으로 인해 fragment가 중단되지 않게 된다. (me: commit 전에 그냥 fragment 로 쪼개서 바로 replicate, certificate 을 해버리는 것인듯.)

이는 실행 중이나 롤백 시 모두 성능에 영향을 미칠 수 있으므로 충돌이 일어날것 같지않은 large transactions에만 사용하는 것이 좋다.

Group Commits

Group Commits 도 Galera 4 에서부터 지원한다. Galera 4 는 MariaDB 10.4 부터 지원한다.

MariaDB Group Commit에선, 성능향상을 위해서 transaction 들의 group 들은 함께 disk 로 flushed 된다. 이것을 MariaDB 10.4부터 cluster 에서도 사용할 수 있게 됐다.

MariaDB 10.4 이전 버전에서는 이 기능을 MariaDB Cluster 에서 사용할 수 없었다. replication을 위한 트랜잭션의 global-ordering 을 방해했기 때문이다.

Galera cluster 에서 donor 와 joiner

from : donor 가 무엇인가? 에 대한 bingchat 답변

Galera cluster의 donor는 다른 노드가 cluster에 join 또는 rejoin할 때 joiner로 알려진 node에 데이터를 제공하는 노드입니다. donor는 State Snapshot Transfer (SST) 방식 또는 Incremental State Transfer (IST) 방식을 사용하여 joiner ¹²³에 데이터를 전송할 수 있다.

donor 노드는 가용성 및 안전성에 따라 cluster에서 자동으로 선택하거나 joiner 노드 ¹²에서 wsrep_sst_donor 파라미터를 설정하여 수동으로 선택할 수 있다. donor 노드가 사용 중이거나 과부하 상태인 경우, wsrep_sst_donor_rejects_queries 매개변수 ²를 설정하여 SST 요청을 거부하도록 구성할 수도 있다.

  1. Node Provisioning — Galera Cluster Documentation.
  2. State Snapshot Transfers — Galera Cluster Documentation.
  3. State Transfers — Galera Cluster Documentation.

See Also

  1. 쿠…sal: [컴][db] MariaDB Galera cluster 설정

References

  1. About Galera Replication - MariaDB Knowledge Base