Til

|
layout: post
title:  " 20200412_TIL "
category: TIL (Today I Learned)
tags: [TIL]
comments: true

2020_04_12

CQRS (Command and Query Responsibility Segregation)

  • 데이터에 대한 조작 Create, Insert, Delete, Update와 조회 Select를 구분한다

MVCC (Multi Version Concurrency Control) 다중버전 동시성 제어

과거 DBMS의 경우 lock 메커니즘을 이용하여 동시성을 제어하였다.

쓰기의 경우 exclusive-lock을 사용하여 쓰기 작업을 하는 트랜잭션이 끝나기 전까지 다른 트랜잭션이 접근 불가능 하다

반면, 읽기의 경우 shard-lock을 사용하여 해당 트랜잭션이 끝나기 전에도 다른 트랜잭션이 접근 가능하다.

lock 메커니즘을 사용할 경우 교착상태에 빠질 수 있으며, 속도적인 측면에서 불리한 점이 있어 MVCC 메커니즘이 보편화되었다.

데이터를 버저닝하여 lock없이 독립적으로 트랜잭션을 완료할 수 있다 (속도 향상, 교착상태 발생x)

구체적인 예를 보자면

  1. A가 1번째 row의 x 컬럼 값을 읽었다. 값을 10이라 가정하자.
  2. B도 1번째 row의 x 컬럼 값을 읽었다. 1과 같은 값이다.
  3. A가 10-> 15로 값을 변경하고 트랜잭션을 커밋하였다.
  4. B가 10-> 20으로 값을 변경하고 트랜잭션을 커밋했다.
  5. DB 입장에서 동일한 데이터에 대해 A가 먼저 커밋한 것을 알고 있으니 B가 커밋을 시도한 시점에 에러 메시지를 발생시키고 15인 값을 새로 읽은 다음 충돌 해결을 B에게 위임한다 (git의 conflict와 동일한 원리)

MVCC JDBC option is unsupported in 1.4.198 and 1.4.199

https://github.com/h2database/h2database/issues/2198

SpringBoot 2.2 부터는 JUnit 5가 default

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes</a>

junit의 vintage-engine을 사용할 경우 기존 junit 4 기반의 테스트 클래스들을 사용할 수 있다.

build.gradle에서 exclude 되어 있어 주석 처리하니 해결됨.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-devtools'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.h2database:h2'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
//        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

ref. h2

ref. wiki

ref. 데이터넷

ref. blog