如何从Gemfire获得独特的长度? [英] How can I get a unique long from Gemfire?

查看:144
本文介绍了如何从Gemfire获得独特的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个直接与Gemfire对话的分层Java应用程序。

We are working on a layered Java application that talks directly to Gemfire.

我们需要能够生成唯一的长序列号,保证所有序列号都是唯一的应用程序的节点。 (并非所有节点都是集群的)

We need to be able to generate unique "long" sequence numbers, guaranteed unique across all nodes of the application. (Not all nodes are clustered)

通常我会在Oracle中创建一个序列,但在这种情况下,即使我们的Gemfire配置与关系数据库有连接以进行写入在持久性背后,我们的应用程序没有其他数据库知识。

Normally I would create a sequence in Oracle, but in this case, even though our Gemfire configuration has a connection to the relational database for write behind persistence, our application has no other knowledge of the database.

生成那些保证的唯一长值的最佳方法是什么,而无需进入数据库?

What would be the best way to generate those guaranteed unique long values, without going to the database?

推荐答案

第一个问自己的问题是你真的需要一个长序列号(单调增加长整数)或者你只需​​要一个全局唯一标识符(如UUID)。

The first question to ask yourself is do you really need a long sequence number (monotonically increasing long integer) or do you just need a globally unique identifier (like a UUID).

最高性能的解决方案是全局唯一ID,我建议使用GUID。

The most performant solution is going to be a globally unique id and I would just suggest using a GUID.

如果你需要一个全局唯一的单调递增长值(长序列),那么你将不得不使用一些分布式锁定并在该区域中增加一个值。此方法和性能取决于您使用的区域类型。

If you need a globally unique monotonically increasing long value (long sequence) then you will have to use some distributed locking and increment a value in the region. The method for this and performance depends on the type of region you are using.

查看Region.replace(K,V,V)。它可以对特定区域定义下的值执行全局原子更新。如果您当前的区域类型没有充分定义,您可能需要考虑一个只包含序列的区域。

Look at Region.replace(K, V, V). It can perform globally atomic updates to values under specific region definitions. You may need to consider a region that just has your sequences if your current region type is not sufficiently defined.

这篇关于如何从Gemfire获得独特的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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