반응형
Oracle Coherence 는 클러스터된 에플리케이션 및 어플리케이션 서버를 대상으로 한 인메모리[각주:1] 분산 데이터 그리드 솔루션입니다.

Oracle Coherence를 적용하는 것은 빈번하게 사용되는 데이터에 대해서 신속하고 신뢰성의 높은 액세스를 제공하며 미션 크리티컬한 어플리케이션을 예측 가능하게 확장할 수 있기 때문입니다. 더불어 여러대의 서버에 걸쳐있는 메모리내의 데이터를 Coherence 스스로 동적으로 파티션화하여 서버의 장애에도 계속적인 데이터의 가용성 및 트랜잭션(transaction)의 정합성을 실현합니다.

그 때문에, Oracle Coherence를 기반으로 하는 어플리케이션들은 경고한 스케일 아웃 할 수 있으면, 어플리케이션에서 필요한 메모리들도 추상적인 인메모리 데이터로 액세스 할 수 있습니다.


Installing Coherence

실습 환경


오라클 사이트에서 Coherence 를 다운로드합니다.


적당한 곳에 받아서 압축을 풉니다.

/co$ unzip coherence-java-3.7.0.0b23397.zip

이제부터 Coherence 가 설치된 디렉토리는 /co/coherence 가 됩니다.


Configure and Run the Sample Cache Server Application

JAVA_HOME 환경변수가 설정이 안되어 있다면 설정합니다.

$ export JAVA_HOME="/usr/lib/jvm/java-6-sun"
$ export PATH="${PATH}:${JAVA_HOME}/bin"

COHERENCE_HOME 환경변수를 설정합니다.

$ export COHERENCE_HOME="/co/coherence"

cache-server.sh 파일을 수정합니다.

/co/coherence/bin$ vi cache-server.sh

아래와 같이 수정합니다.

#!/bin/bash

# This will start a cache server

# specify the Coherence installation directory
SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then // if 다음에 한칸 띄기
  while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`
COHERENCE_HOME=/co/coherence

모든 sh 파일에 실행권한을 줍니다.

/co/coherence/bin$ chmod +x *.sh

쉘스크립트를 실행합니다.

/co/coherence/bin$ ./cache-server.sh

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

2011-06-24 16:29:48.790/0.261 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/co/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2011-06-24 16:29:48.839/0.310 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "jar:file:/co/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2011-06-24 16:29:48.840/0.311 Oracle Coherence 3.7.0.0 <D5> (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-override.xml" is not specified
2011-06-24 16:29:48.843/0.314 Oracle Coherence 3.7.0.0 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not specified

Oracle Coherence Version 3.7.0.0 Build 23397
 Grid Edition: Development mode
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

2011-06-24 16:29:49.059/0.530 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/co/coherence/lib/coherence.jar!/coherence-cache-config.xml"
2011-06-24 16:29:49.258/0.729 Oracle Coherence GE 3.7.0.0 <D4> (thread=main, member=n/a): TCMP bound to /192.168.0.192:8088 using SystemSocketProvider
2011-06-24 16:29:52.515/3.986 Oracle Coherence GE 3.7.0.0 <Info> (thread=Cluster, member=n/a): Created a new cluster "cluster:0x96AB" with Member(Id=1, Timestamp=2011-06-24 16:29:49.259, Address=192.168.0.192:8088, MachineId=26816, Location=process:10064, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, CpuCount=8, SocketCount=2) UID=0xC0A800C000000130C08DFECB68C01F98
2011-06-24 16:29:52.519/3.990 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Started cluster Name=cluster:0x96AB

Group{Address=224.3.7.0, Port=37000, TTL=4}

MasterMemberSet
  (
  ThisMember=Member(Id=1, Timestamp=2011-06-24 16:29:49.259, Address=192.168.0.192:8088, MachineId=26816, Location=process:10064, Role=CoherenceServer)
  OldestMember=Member(Id=1, Timestamp=2011-06-24 16:29:49.259, Address=192.168.0.192:8088, MachineId=26816, Location=process:10064, Role=CoherenceServer)
  ActualMemberSet=MemberSet(Size=1, BitSetCount=2
    Member(Id=1, Timestamp=2011-06-24 16:29:49.259, Address=192.168.0.192:8088, MachineId=26816, Location=process:10064, Role=CoherenceServer)
    )
  RecycleMillis=1200000
  RecycleSet=MemberSet(Size=0, BitSetCount=0
    )
  )

TcpRing{Connections=[]}
IpMonitor{AddressListSize=0}

2011-06-24 16:29:52.546/4.017 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:Management, member=1): Service Management joined the cluster with senior service member 1
2011-06-24 16:29:52.657/4.128 Oracle Coherence GE 3.7.0.0 <D5> (thread=DistributedCache, member=1): Service DistributedCache joined the cluster with senior service member 1
2011-06-24 16:29:52.707/4.178 Oracle Coherence GE 3.7.0.0 <D5> (thread=ReplicatedCache, member=1): Service ReplicatedCache joined the cluster with senior service member 1
2011-06-24 16:29:52.713/4.184 Oracle Coherence GE 3.7.0.0 <D5> (thread=OptimisticCache, member=1): Service OptimisticCache joined the cluster with senior service member 1
2011-06-24 16:29:52.715/4.186 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:InvocationService, member=1): Service InvocationService joined the cluster with senior service member 1
2011-06-24 16:29:52.716/4.187 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=1):
Services
  (
  ClusterService{Name=Cluster, State=(SERVICE_STARTED, STATE_JOINED), Id=0, Version=3.7, OldestMemberId=1}
  InvocationService{Name=Management, State=(SERVICE_STARTED), Id=1, Version=3.1, OldestMemberId=1}
  PartitionedCache{Name=DistributedCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=257, BackupCount=1, AssignedPartitions=257, BackupPartitions=0}
  ReplicatedCache{Name=ReplicatedCache, State=(SERVICE_STARTED), Id=3, Version=3.0, OldestMemberId=1}
  Optimistic{Name=OptimisticCache, State=(SERVICE_STARTED), Id=4, Version=3.0, OldestMemberId=1}
  InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=5, Version=3.1, OldestMemberId=1}
  )

Started DefaultCacheServer...



Configure and Run the Sample Cache Client Application

우선 JLine 을 먼저 설치합니다. 다운로드 받은 후 압축을 풉니다.

/co$ unzip jline-1.0.zip

라이브러리 파일을 복사합니다.

/co/jline-1.0$ cp jline-1.0.jar ../coherence/bin


query.sh 파일을 수정합니다.

/co/coherence/bin$ vi query.sh

아래와 같이 수정합니다.

#!/bin/bash

# This will start a command line query application

# specify the Coherence installation directory
SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then
  while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`
COHERENCE_HOME=/co/coherence

query.sh 실행합니다.

/co/coherence/bin$ ./query.sh

** Starting storage disabled console **
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

Coherence Command Line Tool
jline library cannot be loaded, so you cannot use the arrow keys for line editing and history.

CohQL>

위와 같이 CohQL[각주:2] 콘솔 화면이 나옵니다. CohQL을 이용하여 SQL과 유사한 기술로 테이터의 쿼리 처리나 집계 처리를 수행할 수 있습니다.

"help" 명령어로 이것저것 볼 수 있습니다.

명령어를 입력해 봅시다.

CohQL> create cache "products"

2011-06-24 16:59:43.067/420.632 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/co/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2011-06-24 16:59:43.115/420.681 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "jar:file:/co/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2011-06-24 16:59:43.116/420.681 Oracle Coherence 3.7.0.0 <D5> (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-override.xml" is not specified
2011-06-24 16:59:43.119/420.684 Oracle Coherence 3.7.0.0 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not specified

Oracle Coherence Version 3.7.0.0 Build 23397
 Grid Edition: Development mode
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

2011-06-24 16:59:43.333/420.898 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/co/coherence/lib/coherence.jar!/coherence-cache-config.xml"
2011-06-24 16:59:43.592/421.157 Oracle Coherence GE 3.7.0.0 <D4> (thread=main, member=n/a): TCMP bound to /192.168.0.192:8090 using SystemSocketProvider
2011-06-24 16:59:43.851/421.416 Oracle Coherence GE 3.7.0.0 <Info> (thread=Cluster, member=n/a): This Member(Id=2, Timestamp=2011-06-24 16:59:43.657, Address=192.168.0.192:8090, MachineId=26816, Location=process:10716, Role=TangosolCoherenceQueryPlus, Edition=Grid Edition, Mode=Development, CpuCount=8, SocketCount=2) joined cluster "cluster:0x96AB" with senior Member(Id=1, Timestamp=2011-06-24 16:49:41.469, Address=192.168.0.192:8088, MachineId=26816, Location=process:10630, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, CpuCount=8, SocketCount=2)
2011-06-24 16:59:43.863/421.428 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service Cluster with senior member 1
2011-06-24 16:59:43.863/421.428 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service Management with senior member 1
2011-06-24 16:59:43.863/421.428 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service DistributedCache with senior member 1
2011-06-24 16:59:43.864/421.429 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service ReplicatedCache with senior member 1
2011-06-24 16:59:43.864/421.429 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service OptimisticCache with senior member 1
2011-06-24 16:59:43.864/421.429 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service InvocationService with senior member 1
2011-06-24 16:59:43.866/421.434 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Started cluster Name=cluster:0x96AB

Group{Address=224.3.7.0, Port=37000, TTL=4}

MasterMemberSet
  (
  ThisMember=Member(Id=2, Timestamp=2011-06-24 16:59:43.657, Address=192.168.0.192:8090, MachineId=26816, Location=process:10716, Role=TangosolCoherenceQueryPlus)
  OldestMember=Member(Id=1, Timestamp=2011-06-24 16:49:41.469, Address=192.168.0.192:8088, MachineId=26816, Location=process:10630, Role=CoherenceServer)
  ActualMemberSet=MemberSet(Size=2, BitSetCount=2
    Member(Id=1, Timestamp=2011-06-24 16:49:41.469, Address=192.168.0.192:8088, MachineId=26816, Location=process:10630, Role=CoherenceServer)
    Member(Id=2, Timestamp=2011-06-24 16:59:43.657, Address=192.168.0.192:8090, MachineId=26816, Location=process:10716, Role=TangosolCoherenceQueryPlus)
    )
  RecycleMillis=1200000
  RecycleSet=MemberSet(Size=0, BitSetCount=0
    )
  )

TcpRing{Connections=[1]}
IpMonitor{AddressListSize=0}

2011-06-24 16:59:43.899/421.464 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:Management, member=2): Service Management joined the cluster with senior service member 1
2011-06-24 16:59:44.017/421.582 Oracle Coherence GE 3.7.0.0 <D5> (thread=DistributedCache, member=2): Service DistributedCache joined the cluster with senior service member 1

처음의 명령어로는 현재 Coherence 의 맴버로 참여(?) 하는군요..

잠깐 CoHQL 을 해봅시다. SQL 과 비슷합니다.

// 네임드 캐쉬 생성
CohQL> create cache "products"
// 캐쉬에 추가 (키와 값)
CohQL> insert into "products" key "television" value "ID-5070"
// 키 값이 "television" 인 데이터의 값을 "ID-5080" 으로 변경
CohQL> update "products" set value() = "ID-5080" where key() like "television"
Results
television: true
// 조회
CohQL> select * from "products"
Results
ID-5080
// 키 값이 "radio" 인 데이터의 key와 value 조회
CohQL> select key(), value() from "products" where key() is "radio"
Results
// 키 값이 "television" 인 데이터 삭제
CohQL> delete from "products" where key() = "television"
Results
// 네임드 캐쉬의 모든 데이터 삭제
CohQL> delete from "products"
Results
// 네임드 캐쉬 삭제
CohQL> drop cache "products"
// 네임드 캐쉬 다시 생성
CohQL> create cache "products"
// 4개의 데이터 삽입
CohQL> insert into "products" key "television" value "ID-5080"

CohQL> insert into "products" key "radio" value "ID-5090"

CohQL> insert into "products" key "MP3 Player" value "ID-5100"

CohQL> insert into "products" key "laptop" value "ID-5110"
// 조회
CohQL> select key(), value() from "products"
Results
"television", "ID-5080"
"radio", "ID-5090"
"MP3 Player", "ID-5100"
"laptop", "ID-5110"
// 백업?
CohQL> backup cache "products" to "products.bkup"
WARNING: The backup command should not be used on active data set,
as it makes no provisions that ensure data consistency during the backup.
Please see the documentation for more detailed information.
// 키값이 "television" 인 테이터 삭제
CohQL> delete from "products" where key() = 'television'
Results
// 조회 (텔레비젼 없음!)
CohQL> select key(), value() from "products"
Results
"radio", "ID-5090"
"MP3 Player", "ID-5100"
"laptop", "ID-5110"
// 네임드 캐쉬 삭제
CohQL> drop cache "products"
// 종료
CohQL> quit
2011-06-24 17:09:19.281/996.846 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:Management, member=2): Service Management left the cluster
2011-06-24 17:09:19.286/996.851 Oracle Coherence GE 3.7.0.0 <D5> (thread=DistributedCache, member=2): Service DistributedCache left the cluster
2011-06-24 17:09:19.307/996.872 Oracle Coherence GE 3.7.0.0 <D5> (thread=Cluster, member=2): Service Cluster left the cluster

다시 CohQL 을 실행하여 Coherence에 참여(?)하게 되면 Member=3 인 것을 확인할 수 있습니다.

2011-06-24 17:16:14.177/20.159 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:Management, member=3): Service Management joined the cluster with senior service member 1
2011-06-24 17:16:14.291/20.273 Oracle Coherence GE 3.7.0.0 <D5> (thread=DistributedCache, member=3): Service DistributedCache joined the cluster with senior service member 1

  1. 인메모리(in-memory): 디스크가 아닌 주 메모리에 모든 데이터를 보유. 상대적으로 인 메모리 자료 접근은 디스크 검색보다 훨씬 빠르다. [본문으로]
  2. Coherence Query Language: "CQL" 이라는 약자는 "Continuous Query Language"가 사용하고 있답니다. -_- [본문으로]
반응형
//