dongqindan4406 2010-09-03 17:01
浏览 41
已采纳

以原子方式调用Web服务?

I have a MySQL database with product prices and from now on I want to synchronize another database with these values, but this other database is not in my server, and I can only update it through web services...

Is there a way to make these two operations (updating my database and calling the web service for the other database to be updated too) atomic? I don't want to find out one day that the second databse was down when the server tried to call the web service to update it, and so, it doesn't have the same values as my current database.

I'm using PHP, by the way.

Thank you very much.

  • 写回答

1条回答 默认 最新

  • douzhen5158 2010-09-03 19:55
    关注

    Your answers to these questions may help in thinking about the best solution -

    • Is the price updation a bulk process? I mean once in a week or something all the prices of your site are edited and bulk changes have to be done on the other server (where 2nd database is hosted)?
    • Or is it like individual prices can be edited and the same change has to either take effect on both or not at all (in case the 2nd server was down)?

    • What would you like to do in case the 2nd server was down, rollback changes on first server?

    If the web service gives back a response - whether it successfully updated its product prices things are pretty easy. Here is one way of making it appear atomic -

    • Have two fields - price_backup and lock_item in the table where all the item prices are stored.
    • Before starting the updation process, set lock_item = true, so that the item cannot be purchased during that time (to prevent inconsistensies).
    • Update price field on first database keeping the price in the price_backup field, then call web service to update and check for the response.
    • If response is false, revert the price of the item with the price_backup value and reset lock_item, or else simply reset the lock.

    This method ensures same values across the servers. However, there may be better methods

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度