开发者

Design advice for synchronize information

I am developing under Java, Ejb3.0, WebLogic.

I would like to have a system design suggestain from you about feature which I am going to develop. (not too complicated)

The main goal is to have a system which takes information from couple of databases and sync between them.

for example:

let's say I have database A, Database B and Database C.

if we compare B against C: ( B is master DB)

desired target:

scenario 1. A has a record which is missing in B. action we take = B add to its table the missing record.

scenario 2. A has a record and B has also that record. action we take = B is updating the record information exactly as it shown in A.

(The same goes with Database A against Database B).

The compare method suppose to compare between specifi开发者_如何学Cc table columns information.

Now I could take everything and drop it to objects and then compare. Other hand I can do manually sync.

Would like to hear some design advice (could be OOP design or any other pattern). Even if it's a bit overhead for some special design. I still Would like to do it so I can learn something new, and also use this mechanism to sync other systems.

Thanks in advance,

ray.


A good answer on this does depend on the amount of data.

If the amount is little, just get all objects from all databases and put it within a collection. Thats the most easy to maintain.

With a minor load of data coming from one database and major load of data from another, maybe its a good idead to take the minor data, pass it to the database with the major data and let the database do the work.

Mostly best practice is to keep the dataflow between your application and the database low.

Maybe you can explain details about your questions a bit more...

--- edit ---

Ok, so you want sync all to your B Master DB.

There are several approaches, depending on several environment parameters you have, the two main directions would be

  1. Make a full iteration every time (easy to program and maintain, very bad performance)
  2. Make a full sync once and delta updates after that (harder up to very hard to maintain, very good performance)

To 1.)

If all items from a table fit into your main memory without problem, take all of them into there, and do your stuff there. If not you have to do it bunch for bunch.

To 2.)

a) To allow to make deltas you have to identify changed items. For that you can use DB triggers, but this is very DB specific and very hard to maintain,

or

b) you can introduce table columns which have version numbers only for your sync purpose, which you count up, if a entity is done.

The version number could be introduced with Frameworks like Hibernate more easily, but still you have a bigger code base to do your things, since you have to check the version, etc. But the much better performance will make delta updates the most commonly used approach.


This just sounds like data replication, which is best handled by the database itself. Consult the documentation for your database technology, there should be a multitude of different ways to configure replication. Don't re-invent the wheel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜