如何在少于3个节点的情况下使用Hazelcast的CPSubsystem? [英] How to use Hazelcast's CPSubsystem with fewer than 3 nodes?

查看:451
本文介绍了如何在少于3个节点的情况下使用Hazelcast的CPSubsystem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到Hazelcast 3.12为具有3-7个节点的系统引入了 CPSubsystem()。我了解原因。但是,如果我试图设计一种可以在1-n个节点之间的任何地方运行的解决方案,是否需要使用其他逻辑来验证是否启用了CPSubsystem?我什至怎么检查呢?

I see that Hazelcast 3.12 has introduced the CPSubsystem() for systems with 3-7 nodes. I understand the reasoning. However, if I am trying to design a solution that can run with anywhere between 1-n nodes, do I need to use different logic to validate if the CPSubsystem is enabled? How do I even check that?

我会想/希望那只是打电话

I would have thought/hoped that simply calling

hazelcastInstance.getCPSubsystem().getLock()

无论数量多少节点,但如果少于3个节点,则会引发异常。而且我找不到任何方法可以检查 CPSubsystem 是否已启用。

would work no matter the number of nodes, but if there are fewer than 3 nodes, it throws an exception. And I can't find any method that allows me to check if the CPSubsystem is enabled or not.

我的当前实现使用不推荐使用的方法 getLock()来获取分布式锁:

My current implementation uses the deprecated method getLock() to get a distributed lock:

   LOG.debug("Creating a distributed lock on username for a maximum of 5 minutes {}", username);
    ILock usernameLock = hazelcastInstance.getLock(this.getClass().getName() + ":" + username);
    try {
        if (usernameLock.tryLock (5, TimeUnit.MINUTES)) {
            clearUserData(cacheEntryEvent);
        }
    } catch (InterruptedException e) {
        LOG.warn("Exception locking on : {} ", username, e);
        LOG.warn("Invoking clearUserData without synchronization : {}", username);
        clearUserData(cacheEntryEvent);
    } finally {
        usernameLock.unlock();
    }

如何在不知情的情况下锁定Hazelcast? hazelcastInstance.getLock()被标记为已弃用,并已在HC4中删除。

How can I get a lock with Hazelcast without knowing this? The hazelcastInstance.getLock() is marked as deprecated and targeted for removal in HC4.

推荐答案

您已经知道,就而言, CPSubsystem CP 系统CAP 定理。必须明确启用它才能使用,因为它有一些限制和先决条件。其中之一是,群集中至少应存在3个Hazelcast成员。实际上,只有2个成员就足够了,但是Hazelcast的 CPSubsystem 拒绝与2个成员一起工作,因为2个成员中的大多数又是2个,一旦其中一个成员崩溃,它很可能不可用。

As you already know, CPSubsystem is a CP system in terms of CAP theorem. It has to be enabled explicitly to use, because it has some limitations and prerequisites. One of them is, at least 3 Hazelcast members should exist in the cluster. Actually, 2 members is sufficient but Hazelcast's CPSubsystem rejects to work with 2 members because majority of 2 members is 2 again, and it's prone to be unavailable once one of the members crashes.

HazelcastInstance.getLock()使用 Hazelcast的异步复制,并且无法提供 CP 失败时的保证。对于某些系统/应用程序,这很好,但对于所有系统/应用程序,则不是。因此,应该在尽力而为的锁定机制与基于CP的锁定机制之间进行选择,并根据此选择来设计依赖于锁定的应用程序。参见丹尼尔·阿巴迪(Daniel Abadi)的条件一致性的危险保证了
与该选择有关的帖子。这就是为什么 CPSubsystem()。getLock()不回退到最佳努力/不安全锁定机制。

HazelcastInstance.getLock() uses async replication of Hazelcast and cannot provide CP guarantees under failures. This is fine for some systems/applications but not for all. That's why choosing between a best-effort locking mechanism vs CP based locking mechanism should be explicit and applications relying on the lock should be designed depending on this choice. See Daniel Abadi's The dangers of conditional consistency guarantees post related to this choice. That's why, CPSubsystem().getLock() does not fallback to best-effort/unsafe locking mechanism when cluster size is below 3.

HazelcastInstance.getLock()在3.12中已弃用,在4.0中将被删除。但是Hazelcast将提供 不安全开发数据模式)),该模式可与任意数量的成员一起使用,并且基于类似于Hazelcast AP数据结构的异步复制。

HazelcastInstance.getLock() is deprecated in 3.12 and will be removed in 4.0. But Hazelcast will provide an unsafe (development) mode for CP data structures, which will work with any number of members and will be based on async replication similar to Hazelcast AP data structures.

这篇关于如何在少于3个节点的情况下使用Hazelcast的CPSubsystem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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