2016년 12월 18일 일요일

Collection

Tags

Collection

Collection은 Document의 집합으로, RDB의 Table과 유사한 개념이다.

Collection Method

생성

  • db._create("collection name", properties, type)
test database에서 test_collection이라는 이름의 collection을 생성했다.
id가 11983인 collection이 생성되었다.
이제 test_collection에 아래와 같이 접근할 수 있다.
  • db.test_collection.{some method}
properties는 아래 Collection 속성을 참고하도록 한다.
type은 document 이거나 edge 둘 중 하나이다.
type을 주지 않으면 default로 document이다. 아래와 같이 type이 필요없는 전용 method도 있다.
  • db._createDocumentCollection(collection-name, properties)
  • db._createEdgeCollection(collection-name, properties)

Document Collection 속성

collection에는 여러 옵션이 있는데 아래와 같다.
  • waitForSync : true일 경우, data가 disk에 쓰여진 후 return 된다.
  • journalSize : byte 단위.
  • isVolatile : memory에만 쓰고 persistence로 유지하지 않는다.
  • keyOptions : key 생성을 위한 추가 옵션. 아래 속성을 포함하는 JSON Array여야 한다.
    • type
    • allowUserKeys
    • increment
    • offset
  • indexBuckets
  • numberOfShards
  • shardKeys
위 속성 중, type, isVolatile, keyOptions는 생성된 후 바뀔 수 없다.
현재 속성은 아래와 같이 확인할 수 있으며

아래와 같이 수정할 수 있다.

Edge Collection Properties

  • waitForSync : default false
  • journalSize : default configuration value


Collection 상태 리포트

ArangoDB는 아래와 같은 명령을 통해 collection의 상태에 대한 리포트를 제공한다.
  • collection.figures()
arangosh> db.demo.figures()
{ 
  "indexes" : { 
    "count" : 1, 
    "size" : 32128 
  }, 
  "lastTick" : 97, 
  "uncollectedLogfileEntries" : 0, 
  "compactionStatus" : { 
    "message" : "skipped compaction because collection has no datafiles", 
    "time" : "2016-12-16T10:29:55Z" 
  }, 
  "readCache" : { 
    "count" : 1, 
    "size" : 48192 
  }, 
  "documentReferences" : 0, 
  "waitingFor" : "-", 
  "alive" : { 
    "count" : 1, 
    "size" : 184 
  }, 
  "dead" : { 
    "count" : 0, 
    "size" : 0, 
    "deletion" : 0 
  }, 
  "datafiles" : { 
    "count" : 0, 
    "fileSize" : 0 
  }, 
  "journals" : { 
    "count" : 1, 
    "fileSize" : 33554432 
  }, 
  "compactors" : { 
    "count" : 0, 
    "fileSize" : 0 
  }, 
  "revisions" : { 
    "count" : 1, 
    "size" : 48192 
  } 
}
주요 속성은 아래와 같다.
  • alive.count : 모든 data 파일과 collection의 journal에서 active인 document의 수
  • alive.size : active된 document의 size
  • dead.count : 삭제되거나 새로운 document로 대체된 document의 수
  • dead.size : dead document의 총 size
  • dead.deletion : 삭제 표시된 문서의 수
  • datafiles.count : data 파일 수
  • datafiles.fileSize : 총 data 파일 용량
  • journals.count
  • journals.fileSize
  • compactors.count
  • compactors.fileSize
  • shapefiles.count
  • shapefiles.fileSize
  • shapes.count
  • shapes.size
  • attributes.count
  • attributes.size
  • indexes.count
  • indexes.size
  • maxTick
  • uncollectedLogfileEntries
  • documentReferences
  • waitingFor
  • compactionStatus.time:
  • compactionStatus.message
위에서 size에 해당하는 속성들은 실제 파일시스템 상의 size와 약간의 오차가 있을 수 있다. figure에서 표시된 용량보다 실제 용량이 일반적으로 더 크다.


arangosh> db.demo.figures()
{ 
  "indexes" : { 
    "count" : 1, 
    "size" : 32128 
  }, 
  "lastTick" : 97, 
  "uncollectedLogfileEntries" : 0, 
  "compactionStatus" : { 
    "message" : "skipped compaction because collection has no datafiles", 
    "time" : "2016-12-16T10:29:55Z" 
  }, 
  "readCache" : { 
    "count" : 1, 
    "size" : 48192 
  }, 
  "documentReferences" : 0, 
  "waitingFor" : "-", 
  "alive" : { 
    "count" : 1, 
    "size" : 184 
  }, 
  "dead" : { 
    "count" : 0, 
    "size" : 0, 
    "deletion" : 0 
  }, 
  "datafiles" : { 
    "count" : 0, 
    "fileSize" : 0 
  }, 
  "journals" : { 
    "count" : 1, 
    "fileSize" : 33554432 
  }, 
  "compactors" : { 
    "count" : 0, 
    "fileSize" : 0 
  }, 
  "revisions" : { 
    "count" : 1, 
    "size" : 48192 
  } 
}

Load

Collection을 메모리로 올린다.
arangosh> col = db.example;
[ArangoCollection 14508, "example" (type document, status loaded)]
arangosh> col.load();
arangosh> col;
[ArangoCollection 14508, "example" (type document, status loaded)]

Unload

Collection을 메모리에서 내린다. 그러나 query가 모두 끝날 때까지 유예되고, 이후 실행된다.
arangosh> col = db.example;
[ArangoCollection 7351, "example" (type document, status loaded)]
arangosh> col.unload();
arangosh> col;
[ArangoCollection 7351, "example" (type document, status unloaded)]

Rename

  • collection.rename(new-name)

삭제

  • collection.drop(options)
collection의 data와 index 모두 제거한다. system collection을 제거하기 위해서는 option에서 isSystem을 true 값을 주어야 한다.

 

collection의 모든 데이터는 삭제하되, index는 남기는 것은 아래와 같이 truncate를 이용한다.
  • collection.truncate()

 

Revision

Collection은 document의 data가 변경될때 revision id가 바뀐다. revision을 통해 collection의 data가 바뀌었는지 안바뀌었는지 check할 수 있다. revision은 string값을 return한다.

Reserve

  • collection.reserve(number)
collection에 index들의 resize시 미리 잡을 용량을 지정한다. 이는, collection에 bulk insert가 되기 전 reserve를 통해 memory re-allocation과 re-location을 방지할 수 있다.

Checksum

  • collection.checksum(withRevisions, withData)
withRevision은 true일 경우 document의 revision id가 hash 계산에 포함된다.
withData는 true일 경우 모든 document의 속성값이 checksum 대상에 포함된다. 이 경우 느리지만 정확한 checksum이 될 수 있다.

Rotate(TODO)

  • collection.rotate()
현재 collection의 journal이 read-only data파일로 되며 GC 대상이 된다. 만약 현재 collection의 journal이 없다면 에러가 발생한다.


Database Method

단일 Collection 가져오기

  • db._collection(collection identifier like id or name)

만약 없는 collection을 찾고자 한다면 null을 반환한다.

모든 Collection 가져오기

  • db._collections()

Collection 삭제

  • db._drop(collection-name, options)
 Collectio drop이 아닌 truncate는 아래와 같다
  • db._truncate(collection-name)

Collection type

collection.type()
collection의 타입을 리턴하는데, 가능한 타입은 아래 두 개 뿐이다.
  • 2: document collection
  • 3: edge collection

Collection Name Convention

  • 영어 대소문자
  • 숫자
  • underscore(_), dash(-)
  • system collection만 underscore로 시작할 수 있으며 사용자 정의 collection은 항상 영어 대소문자로 시작해야 함
  • 대소문자 구분
  • 64바이트 이하 길이

ArangoDB 3.x부터 제공되는 Collection의 Replication 동기화 관련

TODO


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)