■ ArangoDB Overview
▶ Architecture
- AppendOnly / MVCC
모든 수정, 삭제 작업은 새로운 Document 를 생성함으로 객체가 보존되고 쓰기 읽기 트랜잭션이 분리 됩니다. - Mostly Memory/Durability
데이터베이스 문서는 메모리 맵 파일에 저장되며 스토리지에 즉시 동기화 되지 않습니다. - Write-ahead log (미리쓰기 로그파일)
- 서버 크래시 후 데이터 복구를 실행하는 데 사용되며 복제 설정에서도 사용할 수 있습니다.
- 기본적으로 각 미리 쓰기 로그 파일의 크기는 32MB입니다. (--wal.logfile-size)
- write-ahead log 파일이 가득차면 읽기전용으로 변경되며 다음 log 파일이 생성 됩니다. 파일 수는 조정 가능 합니다. (--wal.reserve-logfiles)
- 미리 쓰기 로그 파일의 나머지 작업이 컬렉션의 journals 또는 데이터 파일로 복사 된 경우 미리 쓰기 로그 파일은 복제에 사용되지 않으면 안전하게 제거 할 수 있습니다.
- 장기 실행 트랜잭션은 가비지 컬렉션 진행을 차단할 수 있으므로 모든 비용을 들이지 않고 피해야합니다.
(삭제 작업이 지연되거나 차단됨으로 서버 크래시 발생 시 복구오류 가능성이 존재해 보입니다)
▶ Overview
- Multi Model 데이터베이스로 documents, graphs, and key-values 값을 지원 합니다.
- 데이터 검색 및 수정을위한 강력한 쿼리 언어를 지원 합니다. (AQL)
- ACID 트랜잭션을 지원 합니다. (isolation)
- Replication and Sharding 기능을 지원 합니다.
- ArangoDB는 SSD 및 대용량 캐시와 같은 최신 스토리지 하드웨어의 모든 기능을 사용합니다.
- JavaScript 를 확장하여 고성능 응용프로그램 작성이 가능 합니다.
- 오픈소스 입니다. (Apache License 2.0)
▶ Why ArangoDB?
- 설치 및 구성이 용이함 (Easy to install and configure)
- 통합 응용프로그램 서버 (Integrated Application Servers) / Web Server 와 JavaScript 가 기본적으로 내장
- 웹 기반 콘솔 및 CLI 명령지원 (Web based console and CLI commands)
- 쉬운 관리 및 시스템 모니터링 (Easy Administration and System Monitoring)
- 다중 모델 데이터베이스 문서, 그래프, 키 지원 (Multi Model Database Document, Graphs and Keys)
▶ Performance?
single read 와 메모리 사용량을 제외하면 MongoDB 보다 ArangoDB 과 성능이 더 좋다는 결과 입니다.
추가로 single write sync 상황에서는 PostgreSQL (json) 이 가장 뛰어나다는 점도 특이한 부분 입니다.
■ ArangoDB Reference
- Installing Manual
https://docs.arangodb.com/3.1/Manual/GettingStarted/Installing/Linux.html - AQL Manual
https://docs.arangodb.com/3.1/AQL/DataQueries.html
■ ArangoDB Basic Guide Overview
ArangoDB 싱글설치 작업 및 사용방법에 대해서 가이드를 제공 합니다.
- SETP-01. ArangoDB 설치하기
- STEP-02. arangosh를 사용하여 명령 줄에 액세스
- STEP-03. 데이터베이스 사용자 추가
- STEP-04. 환경설정
- STEP-05. 웹 인터페이스 구성
- STEP-06. ArangoDB 웹 인터페이스 액세스
- STEP-07. arangosh와 함께 CRUD 작업 수행
- STEP-08. AQL을 사용하여 데이터 쿼리하기
- STEP-09. 백업 만들기
- STEP-10. 업그레이드
● STEP-01. ArangoDB 설치하기
- System
-
- AWS EC2
- Ubuntu 14.04 LTS
- ArangoDB 3.1.11
- Download
-
- https://www.arangodb.com/download-major/ubuntu/
- Server• amd64: arangodb3-3.1.11-1_amd64.deb (48 MByte)
- Client Tools• amd64: arangodb3-client-3.1.11-1_amd64.deb (32 MByte)
- Source
repository 설정
wget https://www.arangodb.com/repositories/arangodb31/xUbuntu_14.04/Release.key
apt-key add - < Release.key |
apt-get 설치
sudo apt-add-repository 'deb https://www.arangodb.com/repositories/arangodb2/xUbuntu_14.04/ /'
또는
echo 'deb https://www.arangodb.com/repositories/arangodb31/xUbuntu_14.04/ /' | sudo tee /etc/apt/sources.list.d/arangodb.list
sudo apt-get install apt-transport-https
--> Adding HTTPS Downloads Support
sudo apt-get update
sudo apt-get install arangodb3=3.1.11 |
DPKG 로 설치 시 나오는 UI 화면
> dpkg -i arangodb3-3.1.11-1_amd64.deb
> dpkg -i arangodb3-client-3.1.11-1_amd64.deb
[root / qwer1234]
|
서비스 시작, 종료
/etc/init.d/arangod start
/etc/init.d/arangod stop |
√ 기본 패키지 설치시 /usr/bin 경로에 Arango Utility 가 위치 합니다.
- arangobench - benchmark
- arangodump
- arangoimp
- arangorestore
- arangosh
- arangovpack ?
● STEP-02. arangosh를 사용하여 명령 줄에 액세스
arangosh 접속하기, 최초 접속 시 password 입력이 필요 합니다.
패스워드 접근을 위해서는 /etc/arangodb3/arangod.conf, /etc/arangodb3/arangosh.conf
설정 파일 내용 중 authentication 부분을 false 로 변경 후 서비스를 재 시작 합니다.
> arangosh
password:
|
● STEP-03. 데이터베이스 사용자 추가
Read/Write 에 대한 별도의 권한체계는 데이터베이스 접근권한만 조정 가능 합니다.
_system 데이터베이스의 계정은 root 권한과 동일하며 계정의 데이터베이스 접근권한은 언제든 필요할 때 변경 가능 합니다.
127.0.0.1:8529@_system> require("org/arangodb/users").save("sammy", "password");
127.0.0.1:8529@_system> db._users.count()
2 |
● STEP-04. 환경설정
√ Configuration 설정가능 항목
- 저장경로 설정 - 변경
- 외부오픈 설정 - 변경
- 인증조작 설정 - 사용
- 쓰레드수 설정 - 검토
- 로그경로 설정 - 변경
- 클러스터 설정 - 검토 (클러스터 설정 시 CAP 모델에서 CP 로 동작하게 됩니다.)
- foxx 확장 설정 - 권장 (프로시저와 비슷한 API 제작가능하며, 관리가 쉽다. 내부 동작 방식은 전혀 다릅니다.)
127.0.0.1:8529@_system> require("org/arangodb/users").save("sammy", "password");
127.0.0.1:8529@_system> db._users.count()
2 |
ArangoDB Configuration File
- vi /etc/arangodb3/arangod.conf
# ArangoDB configuration file
#
# Documentation:
# https://docs.arangodb.com/Manual/Administration/Configuration/
#
[database]
directory = /var/lib/arangodb3
# maximal-journal-size = 33554432
[server]
# Specify the endpoint for HTTP requests by clients.
# tcp://ipv4-address:port
# tcp://[ipv6-address]:port
# ssl://ipv4-address:port
# ssl://[ipv6-address]:port
# unix:///path/to/socket
#
# Examples:
# endpoint = tcp://0.0.0.0:8529
# endpoint = tcp://127.0.0.1:8529
# endpoint = tcp://localhost:8529
# endpoint = tcp://myserver.arangodb.com:8529
# endpoint = tcp://[::]:8529
# endpoint = tcp://[fe80::21a:5df1:aede:98cf]:8529
#
endpoint = tcp://127.0.0.1:8529
# endpoint = tcp://ec2-13-124-7-150.ap-northeast-2.compute.amazonaws.com:8529 (AWS 환경인 경우)
# resuse a port on restart or wait until it is freed by the operating system
# reuse-address = false
authentication = true
# number of server threads. use 0 to make arangod determine the
# number of threads automatically, based on available CPUs
# threads = 0
# gather server statistics
statistics = true
# the user and group are normally set in the start script
# uid = arangodb
# gid = arangodb
uid = arangodb
[scheduler]
# number of threads used for I/O, use 0 to make arangod determine
# the number of threads automatically
# threads = 0
[javascript]
startup-directory = usr/share/arangodb3/js
app-path = /var/lib/arangodb3-apps
# app-path = @HOMEDRIVE@/@HOMEPATH@/arangodb3/apps
# number of V8 contexts available for JavaScript execution. use 0 to
# make arangod determine the number of contexts automatically.
# v8-contexts = 0
[foxx]
# enable Foxx queues in the server
# queues = true
# interval (seconds) to use for polling jobs in Foxx queues
# queues-poll-interval = 1
[log]
level = info
file = /var/log/arangodb3/arangod.log
[cluster] |
ArangoDB Shell Configuration File
- vi /etc/arangodb3/arangosh.conf
[console]
pretty-print = true
[server]
endpoint = tcp://your_server:8529
# endpoint = tcp://ec2-13-124-7-150.ap-northeast-2.compute.amazonaws.com:8529 (AWS 환경인 경우) authentication = true
# username = root
# password =
[javascript]
startup-directory = usr/share/arangodb3/js |
● STEP-05. 웹 인터페이스 구성
웹 인터페이스는 ArangoDB 를 좀더 사용하기 쉽게 해주며, 다양한 편리기능을 제공한다.
√ 편리성 제공
- 모니터링 기능
- 데이터 탐색
- 대화식 API 문서
- 강력한 쿼리 편집기
- 통합된 arangosh
√ 사용을 위한 설정작업
- 인증 활성화 ( Enable authentication )
sudo sed -i.bak 's/disable-authentication = yes/disable-authentication = no/g' /etc/arangodb3/arangod.conf
- 공유 IP 설정 및 endpoint 변경작업 ( Bind ArangoDB to the public network interface )
vi /etc/arangodb3/arangod.confendpoint = tcp://your_server_ip:8529
# endpoint = tcp://ec2-xx-xxx-x-xxx.ap-northeast-2.compute.amazonaws.com:8529 (AWS 환경인 경우)
vi /etc/arangodb3/arangosh.confvi /etc/arangodb3/arangosh.conf
[console]
pretty-print = true
[server]
endpoint = tcp://your_server:8529
# endpoint = tcp://ec2-xx-xxx-x-xxx.ap-northeast-2.compute.amazonaws.com:8529 (AWS 환경인 경우)
authentication = true
# username = root
# password =
[javascript]
startup-directory = usr/share/arangodb3/js
- sed 명령을 사용하여 config 설정 변경
$sudo sed -i.bak "s/^endpoint = .*/endpoint = tcp:\/\/$(sudo ifconfig eth0 | grep "inet " | cut -d: -f 2 | awk '{print $1}'):8529/g" /etc/arangodb/arangod.conf
$sudo sed -i.bak "s/^endpoint = .*/endpoint = tcp:\/\/$(sudo ifconfig eth0 | grep "inet " | cut -d: -f 2 | awk '{print $1}'):8529/g" /etc/arangodb/arangosh.conf
- 서비스 재 시작
/etc/init.d/arangodb3 restart
● STEP-06. ArangoDB 웹 인터페이스 액세스
웹 인터페이스 접근
√ 제공기능
- 데이터베이스 관리
- 컬렉션 관리
- 쿼리편집기
- 그래프
- 계정생성
- 로그조회
- 쿼리플랜 + 화면 히스토리 기능
- API 레퍼런스 메뉴얼 : 별도의 드라이버 설치없이 javascript + 웹 서버가 포함되어 있어 외부제어가 가능 합니다.
● STEP-07. arangosh와 함께 CRUD 작업 수행
데이터베이스 및 계정생성 (Create a Account)
> arangosh
password :
127.0.0.1:8529@_system> db._createDatabase('test', {}, []);
true
127.0.0.1:8529@_system> db._useDatabase('test')
true
127.0.0.1:8529@_system> require("org/arangodb/users").save("herlock", "qwer1234"); |
※ 데이터베이스 생성 시 자동으로 디렉토리 생성 됩니다.
arangosh 접속
/usr/bin/arangosh --server.database test --server.username herlock --server.password qwer1234 |
컬렉션 생성
test> db._createDocumentCollection('songs') |
도큐멘트 생성
- _key : unique 해야하며, 없을 경우 자동으로 생성 됩니다.
- _id : Unique Key + The document handle
- _rev : ???
test> db.songs.save(
test> { title: "Immigrant Song", album: "Led Zeppelin III", artist: "Led Zeppelin", year: 1970, length: 143, _key: "immigrant_song" }
test> )
Output
{
"_id" : "songs/immigrant_song",
"_key" : "immigrant_song",
"_rev" : "_UmNYB-e---"
}
# 문서 하단 테스트를 위해 샘플 데이터 추가 입력
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Friends", artist: "Led Zeppelin", year: 1970, length: 235, _key: "friends"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Celebration Day", artist: "Led Zeppelin", year: 1970, length: 209, _key: "celebration_day"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Since I've Been Loving You", artist: "Led Zeppelin", year: 1970, length: 445, _key: "since_i_ve_been_loving_you"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Out On the Tiles", artist: "Led Zeppelin", year: 1970, length: 244, _key: "out_on_the_tiles"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Gallows Pole", artist: "Led Zeppelin", year: 1970, length: 298, _key: "gallows_pole"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Tangerine", artist: "Led Zeppelin", year: 1970, length: 192, _key: "tangerine"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "That's the Way", artist: "Led Zeppelin", year: 1970, length: 338, _key: "that_s_the_way"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Bron-Y-Aur Stomp", artist: "Led Zeppelin", year: 1970, length: 260, _key: "bron_y_aur_stomp"}
test> );
test> db.songs.save(
test> {album: "Led Zeppelin III", title: "Hats Off to (Roy) Harper", artist: "Led Zeppelin", year: 1970, length: 221, _key: "hats_off_to_roy_harper"}
test> ); |
도큐먼트 조회 (_key 값으로 조회)
db.songs.document('immigrant_song');
{
"_key" : "immigrant_song",
"_id" : "songs/immigrant_song",
"_rev" : "_UmNYB-e---",
"title" : "Immigrant Song",
"album" : "Led Zeppelin III",
"artist" : "Led Zeppelin",
"year" : 1970,
"length" : 143
} |
도큐먼트 수정
db.songs.update("songs/immigrant_song",
...> { genre: "Hard Rock" }
...> );
{
"_id" : "songs/immigrant_song",
"_key" : "immigrant_song",
"_rev" : "_UmNsMzu---",
"_oldRev" : "_UmNYB-e---"
}
test> db.songs.document('immigrant_song');
Output
{
"_key" : "immigrant_song",
"_id" : "songs/immigrant_song",
"_rev" : "_UmNsMzu---",
"title" : "Immigrant Song",
"album" : "Led Zeppelin III",
"artist" : "Led Zeppelin",
"year" : 1970,
"length" : 143,
"genre" : "Hard Rock"
}
# replace 함수를 사용하면 데이터가 destroy 됩니다.
test> db.songs.replace("songs/immigrant_song",
{ genre: "Hard Rock" }
);
Output
{
"_id" : "songs/immigrant_song",
"_key" : "immigrant_song",
"_rev" : "_UmNvBj2---",
"_oldRev" : "_UmNsMzu---"
}
# replace 함수 사용 후 genre 를 제외한 하위 속성 정보가 destory 처리 되었습니다.
test> db.songs.document('immigrant_song');
{
"_key" : "immigrant_song",
"_id" : "songs/immigrant_song",
"_rev" : "_UmNvBj2---",
"genre" : "Hard Rock"
} |
도큐먼트 삭제
test> db.songs.remove("songs/immigrant_song") |
● STEP-08. AQL을 사용하여 데이터 쿼리하기
AQL은 주로 선언적 언어입니다. 즉, 어떤 결과가 달성되어야하지만 어떻게 성취되어야 하는지를 표현하는 쿼리를 의미합니다.
- AQL은 SQL (Structured Query Language)과 유사합니다.
- AQL은 컬렉션 데이터 읽기 및 수정을 지원하지만 데이터베이스, 컬렉션 및 인덱스 만들기, 삭제와 같은 데이터 정의 작업은 지원하지 않습니다.
- AQL에서 쿼리를 읽고 수정하는 것은 ACID를 완벽하게 준수합니다.
- 데이터 정의 언어 (DDL) 나 데이터 제어 언어 (DCL)가 아닌 순수한 데이터 조작 언어 (DML)입니다.
- 작업은 전체적으로 완료되거나 전혀 완료되지 않습니다.
- 데이터 읽기는 데이터의 일관된 스냅 샷에서 발생합니다 (MVCC)
√ High level Operations
AQL은 기본적인 조작 명령어외에 고급레벨의 조작명령어를 지원 합니다.
- FOR: Iterate over all elements of an array.
- RETURN: Produce the result of a query.
- FILTER: Restrict the results to elements that match arbitrary logical conditions.
- SORT: Force a sort of the array of already produced intermediate results.
- LIMIT: Reduce the number of elements in the result to at most the specified number, optionally skip elements (pagination).
- LET: Assign an arbitrary value to a variable.
- COLLECT: Group an array by one or multiple group criteria. Can also count and aggregate.
- REMOVE: Remove documents from a collection.
- UPDATE: Partially update documents in a collection.
- REPLACE: Completely replace documents in a collection.
- INSERT: Insert new documents into a collection.
- UPSERT: Update/replace an existing document, or create it in the case it does not exist.
- WITH: Specify collections used in a query (at query begin only).
√ Web Interface - QUERIES 기능 소개
- 쿼리내 변수 값 전달기능
- 실행중인 쿼리 확인 기능
- 슬로우 쿼리 확인기능
- 자주 사용하는 쿼리 파일저장 기능
- Explain 확인 기능
- indexes 사용여부 확인
- optimization rules 확인 - Explain 히스토리 기능
- 출력결과 json 파일 다운로드 기능
데이터 삽입 (Single)
INSERT {
album: "Led Zeppelin",
title: "Good Times Bad Times",
artist: "Led Zeppelin",
length: 166,
year: 1969,
_key: "good_times_bad_times"
} IN songs |
데이터 삽입 (Multi)
FOR song IN [
{ album: "Led Zeppelin", title: "Good Times Bad Times", artist: "Led Zeppelin", length: 166, year: 1969, _key: "good_times_bad_times" } ,
{ album: "Led Zeppelin", title: "Dazed and Confused", artist: "Led Zeppelin", length: 388, year: 1969, _key: "dazed_and_confused" } ,
{ album: "Led Zeppelin", title: "Communication Breakdown", artist: "Led Zeppelin", length: 150, year: 1969, _key: "communication_breakdown" }
]
INSERT song IN songs |
데이터 조회 (Single)
/* Please insert some values for the @@collection and @value bind parameters */
FOR song IN songs
FILTER song.`album` == @value
RETURN song
Explain 확인
|
데이터 조회 (Multi)
- 단순 조회로 select * from songs 와 동일한 문장
FOR song IN songs RETURN song
ex) FOR album IN albums RETURN album |
- WHERE 조건 절 포함
FOR song IN songs
FILTER song.length > 180
RETURN song |
복잡한 AQL 구문 조회
FOR song IN songs
FILTER song.length > 180
LET minutes = FLOOR(song.length / 60)
LET seconds = song.length % 60
RETURN
{ title: song.title, duration: CONCAT_SEPARATOR(':', minutes, seconds) }
WEB Interface 사용 시 GRID 형태로 출력이 가능하며, 해당 결과를 json 파일로 Download 가능
|
JOINS in AQL 구문
- 조인 구문 테스트를 위해 albums 컬렉션을 추가 생성 합니다.
test> db._createDocumentCollection('albums')
test> db.albums.save(
{
"name": "Led Zeppelin III",
"release_date": "1970-10-05",
"producer": "Jimmy Page",
"label": "Atlantic",
"length": 2584
}
) |
- albums 컬렉션에는 조인에 필요한 _key 정보가 없습니다. name 항목으로 조인하여 _key 정보를 REPLACE 처리 합니다.
FOR album IN albums
FOR song IN songs
FILTER song.album == album.name
LET song_with_album_ref = MERGE(UNSET(song, 'album'),{ album_key: album._key })
REPLACE song WITH song_with_album_ref IN songs
|
- 다시 _key 를 이용하여 조인, 조회 합니다.
FOR song IN songs
FOR album IN albums
FILTER album._key == song.album_key
RETURN MERGE(song,
{ album: album.name }
) |
● STEP-09. 백업 만들기
- arangodump, arangorestore 유틸리티를 사용할 수 있습니다.
- Slave 장비에서 fsync 후 파일백업이 가능한지 확인 필요 합니다.
- AWS EC2 를 사용한다면 AWS 의 기능을 활용할 수 있는지 확인 필요 합니다.
● STEP-10. 업그레이드
아래는 검증되지 않은 절차에 대한 간단한 구문 입니다. (업그레이드 전 cold backup 은 필수 입니다.)
> sudo apt-get update
> sudo service arangodb stop
> sudo apt-get install arangodb
> sudo service arangodb upgrade
> sudo service arangodb start |
'NOSQL' 카테고리의 다른 글
MongoDB 에서 SSD DISK 사용 시 주의사항 (0) | 2019.08.12 |
---|---|
[ArangoDB] Replication Overview (비동기 복제) (0) | 2017.03.03 |
[MongoDB] copyDatabase (0) | 2017.02.09 |
[MongoDB] 3.4.2 버전 릴리즈 정보 (0) | 2017.02.09 |
[MongoDB] Overflow sort stage buffered data usage exceeds internal limit (0) | 2017.02.01 |
Comments