# mongo-connector 관련
## 기본 동작 과정
- OplogThread 생성
- main Connector thread 에서 MongoDB node의 type을 isdbgrid 명령으로 확인
- isdbgrid 메서드 없으면 mongod (replica set), 있으면 mongos node (shard cluster)
- 이 정보를 기반으로 Connector thread 가 OplogThread 생성
- replica set -> replica set의 primary를 위한 OplogThread 생성
- shard cluster -> 각 shard의 primary node를 위한 OplogThread 생성
- 각 replication endpoint 마다 하나 이상의 DocManager 초기화한 후 OplogThread에 전달
- mongod Cursor 생성
- OplogThread 는 mongod 에서 oplog.rs collection 의 tailable cursor 를 생성
- OplogThread 에서 "collection dump"
- OplogThread 는 DocManagers 의 namespace에 있는 collection 의 모든 doc을 "collection dump"
- 처음 mongo-connector 시작할 때만 "collection dump". 이후에는 mongo-connector last oplog timestamp를 이용
- OplogThread 동작
- OplogThread는 loop 돌면서 oplog에 새로운 doc이 생길 때마다 가져와서 확인
- oplog operation 정보를 확인해서 각 DocManager에 적혀있는 적절한 메서드 호출
- insert: doc 을 MongoDB에서 가져와서 DocManager의 upsert method 호출
- update: DocManager가 remote system(ex)solr)의 doc 버전을 확인 후 update 수행 및 remote system에 re-saving
- delete: 주어진 id로 remove system의 doc 제거
- dropDatabase, dropCollection 등 다른 database commands 들도 DocManager에 handle_command 메서드로 정의
- OplogThread timestamp
- OplogThread 가 oplog의 각 doc 를 읽은 후에 읽어온 doc의 정보를 "checkpoint" 형태로 기록
- 주기적으로 'oplog.timestamp' 파일에 기록. mongo-connector 꺼졌다가 다시 켜져도 oplog.timestamp 시점부터 시작
## Oplog Progress File ("oplog.timestamp")
- mongo-connector 가 가장 최근 작업한 oplog 기록
- mongo-connector 시작시 oplog를 어디서부터 읽어와야 할지 결정
- oplog progress file 이 없으면 namespace의 collection dump 후에 dump 가 발생하기 직전 가장 최근의 oplog timestamp를 oplog progress file에 기록 후 oplog 변동사항 적용
- format
["oplog name", timestamp]
[["oplog 1 name", timestamp 1], ["oplog 2 name", timestamp 2], ...]
## Resyncing the Connector
- Stop Solr, mongo-connector
- Solr Remove all data
$ rm -rf ./solr-5.4.1/server/solr/notes/data
or
http://<hostname>:<port>/solr/<core name>/update?commit=true&stream.body=<delete><query>*:*</query></delete>
ex) http://localhost:8983/solr/notes/update?commit=true&stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E - Start Solr
- Remove oplog.timestamp
- Start mongo-connector
## 참고
댓글
댓글 쓰기