分布式并发控制 [英] Distributed Concurrency Control

查看:288
本文介绍了分布式并发控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个工作了几天了,我找到了几个解决方案,但没有一个是令人难以置信的简单或轻量级。问题基本上是这样的:我们有一个10台机器的集群,每台机器在多线程ESB平台上运行相同的软件。我可以很容易地处理在同一台机器上的线程之间的并发问题,但是在不同的机器上的同一数据上的并发问题呢?

I've been working on this for a few days now, and I've found several solutions but none of them incredibly simple or lightweight. The problem is basically this: We have a cluster of 10 machines, each of which is running the same software on a multithreaded ESB platform. I can deal with concurrency issues between threads on the same machine fairly easily, but what about concurrency on the same data on different machines?

本质上,软件接收通过网络服务将客户的数据从一个企业馈送到另一个企业的请求。然而,客户可能存在或可能不存在于另一个系统上。如果没有,我们通过Web服务方法创建它。所以它需要一种测试和设置,但我需要某种信号量锁定其他机器导致竞争条件。我有一个情况,一个远程客户是为一个本地客户创建两次,这是不太可取的。

Essentially the software receives requests to feed a customer's data from one business to another via web services. However, the customer may or may not exist yet on the other system. If it does not, we create it via a web service method. So it requires a sort of test-and-set, but I need a semaphore of some sort to lock out the other machines from causing race conditions. I've had situations before where a remote customer was created twice for a single local customer, which isn't really desirable.

我在概念上玩弄的解决方案是:

Solutions I've toyed with conceptually are:


  1. 使用我们的容错共享文件系统来创建锁定文件,这些文件将由每台机器根据客户

  1. Using our fault-tolerant shared file system to create "lock" files which will be checked for by each machine depending on the customer

在我们的数据库中使用一个特殊的表,并锁定整个表,以便对锁记录进行测试和设置。

Using a special table in our database, and locking the whole table in order to do a "test-and-set" for a lock record.

使用Terracotta,这是一个开放源代码服务器软件,有助于扩展,但使用中心辐射模型。

Using Terracotta, an open source server software which assists in scaling, but uses a hub-and-spoke model.

使用EHCache同步复制我的内存中的锁。

Using EHCache for synchronous replication of my in-memory "locks."

不能想象我是唯一一个有过这种问题的人。你是如何解决的?

I can't imagine that I'm the only person who's ever had this kind of problem. How did you solve it? Did you cook something up in-house or do you have a favorite 3rd-party product?

推荐答案

您可能需要考虑使用第三方产品 Hazelcast 分布式锁。超轻松和容易。

you might want to consider using Hazelcast distributed locks. Super lite and easy.

java.util.concurrent.locks.Lock lock = Hazelcast.getLock ("mymonitor");
lock.lock ();
try {
// do your stuff
}finally {
   lock.unlock();
}

Hazelcast - 分布式队列,地图,集合,列表,锁定

Hazelcast - Distributed Queue, Map, Set, List, Lock

这篇关于分布式并发控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆