处理键值存储中的集合(列表或集合)的最佳方法是什么?
我想知道当您的存储类似于 memcached 时,从非常大的列表中添加/删除项目的有效方法是什么? 也许有一些带有Java接口的分布式存储可以很好地处理这个问题?
有人可能会推荐兵马俑。 我知道,但这并不是我所需要的。 ;)
I wonder what can be an effective way to add/remove items from a really large list when your storage is memcached-like? Maybe there is some distributed storage with Java interface that deals with this problem well?
Someone may recommend Terracotta. I know about it, but that's not exactly what I need. ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Hazelcast 1.6 将具有分布式实现 MultiMap,其中一个键可以与一组值关联。
Hazelcast 是队列、主题、映射、集合、列表、锁定和执行人服务。 它非常容易使用; 只需将 hazelcast.jar 添加到类路径中并开始编码即可。 几乎不需要任何配置。
Hazelcast 在 Apache 许可下发布,并且还提供企业级支持。 代码托管于 Google 代码。
Hazelcast 1.6 will have distributed implementation MultiMap, where a key can be associated with a set of values.
Hazelcast is an open source transactional, distributed/partitioned implementation of queue, topic, map, set, list, lock and executor service. It is super easy to work with; just add hazelcast.jar into your classpath and start coding. Almost no configuration is required.
Hazelcast is released under Apache license and enterprise grade support is also available. Code is hosted at Google Code.
也许您还应该看看 Scalaris!
Maybe you should also have a look at Scalaris!
如果忽略并发问题,您可以使用键值存储对大多数数据结构进行建模。 您的要求并不完全清楚,因此我将对您的用例做出一些假设。 希望如果他们不正确,您可以概括该方法。
您可以通过拥有一个已知的根(我们称之为“node_root”)节点来轻松地在存储中创建一个链表,该节点指向 {data, prev_key, next_key} 的值元组。 prev_key 和 next_key 元素是键名称,应遵循约定“node_foo”,其中 foo 是 UUID(理想情况下您可以按顺序生成这些元素,如果不是,您可以使用其他类型的 UUID)。 这提供了对您的数据的有序访问。
现在,如果您需要 O(1) 删除某个键,则可以在结构上添加第二个索引,其中键为“data”,值“node_foo”用于右侧 foo。 然后您可以像处理内存中的链表一样执行删除操作。 完成后删除索引节点。
现在,请记住,并发修改此列表与并发修改任何共享数据结构一样糟糕。 如果您使用的是 BDB 之类的东西,您可以使用它们(出色的)事务支持来避免这种情况。 对于没有事务或并发控制的情况,您需要提供外部锁定或对单个线程的序列化访问。
You can use a key-value store to model most data structures if you ignore concurrency issues. Your requirements aren't entirely clear, so I'm going to make some assumptions about your use case. Hopefully if they are incorrect you can generalize the approach.
You can trivially create a linked list in the storage by having a known root (let's call it 'node_root') node which points to a value tuple of {data, prev_key, next_key}. The prev_key and next_key elements are key names which should follow the convention 'node_foo' where foo is a UUID (ideally you can generate these sequentially, if not you can use some other type of UUID). This provides ordered access to your data.
Now if you need O(1) removal of a key, you can add a second index on the structure with key 'data' and value 'node_foo' for the right foo. Then you can perform the removal just as you would a linked list in memory. Remove the index node when you're done.
Now, keep in mind that concurrent modification of this list is just as bad as concurrent modification of any shared data structure. If you're using something like BDBs, you can use their (excellent) transaction support to avoid this. For something without transactions or concurrency control, you'll want to provide external locking or serialize accesses to a single thread.