얼마 전에 Cache도 Replication 기능이 있느냐는 질문을 받았다. 찾아보니, Cache에도 유사한 기능이 있는데 그 이름이 달랐다. "Object Synchronization" 기능이 바로 그것이다. Cache2007에서 처음 써봤는데, 매우 잘 동작했다. 여기에 그 기능과 적용 대상을 간략히 소개한다.
Cache 5.1에서 부터 추가된 Object Synchronization 기능을 사용하여 여러 분산된 Cache DB 간에 일정 간격을 두고 서로 동기(sync)를 맞추는 기능 구현이 가능하다.
참고로, 이 기능은 SQL 서버 등에서, 구독/게시 혹은 Replication이라 불리우기도 한다.
예를 들어, 영업 담당자들이 각기 PC에 Cache를 설치하고 동기를 맞춘 후에 각자 나가서 해당 DB를 업데이트 한 후에 다시 돌아와 그 내용을 Master 서버와 동기를 맞출 필요가 있을 때 사용할 수 있는 기능이다.
다음 문서에서는 Cache Object Synchronization 기능에 대한 설명 및 사용법을 소개하고 있다. 자, 도전해 봅시다!
Object synchronization is a feature of Caché objects that allows “occasionally connected”
systems to synchronize databases. By this process, each database updates its objects. Object synchronization offers complementary functionality to Caché system tools that provide high availability and shadowing. Object synchronization is not designed to provide support for real-time updates; rather, it is most useful for a system that needs updates at discrete intervals.
For example, a typical object synchronization application would be in an environment where there is a master copy of a database on a central server and secondary copies on client machines. Consider the case of a sales database, where each sales representative has a copy of the database on a laptop computer. When Mary, a sales representative, is off site, she makes updates to her copy of the database. When she connects her machine to the network, the central and remote copies of the database are synchronized. This can occur hourly, daily, or at any interval.
This chapter includes the following sections:
Object synchronization between two databases involves updating each of them with data from the other. However, Caché does not support bidirectional synchronization as such. Rather, updates from one database are posted to the other; then updates are posted in the opposite direction. For a typical application, if there is a main database and one or more local databases (as in the previous sales database example), it is recommended that updates are from the local to the main database first, and then from the main database to the local one.
For object synchronization, the idea of client and server is by convention only. For any two databases, you can perform bidirectional updates; if there are more than two databases, you can choose what scheme you use to update all of them (such as local databases synchronizing with a main database independently).
This section addresses the following topics:
To ensure that updates work properly, each object in a database should be uniquely distinguishable. To provide this functionality, Caché gives each individual object instance a GUID
— a Globally Unique ID. The GUID makes each object universally unique.
The GUID is optionally created, based on the value of the GUIDENABLED
parameter. If GUIDENABLED
has a value of 1, then a GUID is assigned to each new object instance.
Consider the following example. Two databases are synchronized and each has the same set of objects in it. After synchronization, each database has a new object added to it. If the two objects share a common GUID, object synchronization considers them the same object in two different states; if each has its own GUID, object synchronization considers them to be different objects.
How Updates Work
Each update from one database to another is sent as a set of transactions. This ensures that all interdependent objects are updated together. The content of each transaction depends on the contents of the journal for the “source”
database. The update can include one or more transactions, up to all transactions that have occurred since the last synchronization.
Resolution of the following conditions is the responsibility of the application:
If two instances that share a unique key have different GUIDs. This requires determining if the two records describe a single object or two unique objects.
If two changes require reconciliation. This requires determining if the two changes were to a common property or to non-intersecting sets of properties.