用于 Java 的单文件、持久、排序的键值存储(替代 Berkeley DB)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5032581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:07:22  来源:igfitidea点击:

Single-file, persistent, sorted key-value store for Java (alternative to Berkeley DB)

javaberkeley-dbkey-value-store

提问by Jé Queue

Berkeley DB (JE) licensing may be a deal killer. I have a Java application going to a small set of customers but as it is a desktop application, my price cannot support individual instance licensing.

Berkeley DB (JE) 许可可能是交易杀手。我有一个面向一小部分客户的 Java 应用程序,但由于它是一个桌面应用程序,我的价格无法支持单个实例许可。

Is there a recommended Java alternative to Berkeley DB?Commercial or otherwise (good key-value store implementations can get non-trivial, I prefer to defer maintenance elsewhere). I need more than just a hash store as I'll need to iterate through subsequent key subsets and basic hash stores would O(m*n) that search and I expect the store to be ~50-60GiB on a desktop machine. Added benefit anyone that you can recommend that keeps its backing store in a single file?

Berkeley DB 有推荐的 Java 替代品吗?商业或其他方面(良好的键值存储实现可能变得非常重要,我更喜欢将维护推迟到其他地方)。我需要的不仅仅是一个散列存储,因为我需要遍历后续的关键子集和基本散列存储将 O(m*n) 搜索,我希望该存储在台式机上为 ~50-60GiB。您可以推荐将其后备存储保存在单个文件中的任何人都增加了好处?

回答by Andrejs

You should definitely try JDBM2, it does what you want:

您绝对应该尝试JDBCM2,它可以满足您的需求:

  • Disk backed HashMaps/TreeMaps thus you can iterate through keys.
  • Apache 2 license
  • 磁盘支持的 HashMaps/TreeMaps 因此您可以遍历键。
  • Apache 2 许可证

In addition:

此外:

  • Fast, very small footprint
  • Transactional
  • Standalone jar have only 145 KB.
  • Simple usage
  • Scales well up to 1e9 records
  • Uses Java serialization, no ORM mapping
  • 速度快,占用空间小
  • 事务性
  • 独立 jar 只有 145 KB。
  • 使用简单
  • 可扩展到 1e9 条记录
  • 使用Java序列化,无ORM映射

UPDATE

更新

The project has now evolved into MapDB http://www.mapdb.org

该项目现已发展为 MapDB http://www.mapdb.org

回答by JPelletier

I think SQLiteis exactly what you want: Free (Public Domain), Single File Database, Zero-Configuration, Small Footprint, Fast, cross-platform, etc.. Here is a list of wrappers, there is a section for Java. Take a look to sqlite4javaand read more on Java + SQLite here.

我认为SQLite正是您想要的:免费(公共域)、单文件数据库、零配置、占用空间小、速度快、跨平台等。这是一个包装器列表,有一个用于 Java 的部分。查看sqlite4java并在此处阅读有关 Java + SQLite 的更多信息

回答by mdrg

It won't be a single file, but if you want embedded database, I suggest Java DB(a rebranded version of Apache Derby, which I used in a previous job with wonderful results).

它不会是单个文件,但如果您想要嵌入式数据库,我建议使用Java DBApache Derby的更名版本,我在以前的工作中使用过,效果很好)。

Plus, both are completely free.

另外,两者都是完全免费的。

Edit: reading the other comments, another note: Java DB/Derby is 100% Java.

编辑:阅读其他评论,另一个注意事项:Java DB/Derby 是 100% Java。

回答by harschware

Consider ehcache. I show herea class for wrapping it as a java.util.Map. You can easily store Lists or other data structures as your values, avoiding the O(m*n) issue you are concerned with. ehcache is Apache 2.0 license, with an commercial enterprise version available by Terracotta. The open source version will allow you to spill your cache to disk, and if you choose not to evict cache entries it is effectively a persistent key-value store.

考虑ehcache。我在这里展示一个用于将其包装为 java.util.Map 的类。您可以轻松地将列表或其他数据结构存储为您的值,从而避免您关心的 O(m*n) 问题。ehcache 是 Apache 2.0 许可证,Terracotta 提供商业企业版。开源版本将允许您将缓存溢出到磁盘,如果您选择不驱逐缓存条目,它实际上是一个持久的键值存储。

回答by Edwin Buck

--- Edited after seeing the size of the file ---

--- 看到文件大小后编辑---

50 to 60 GiB files! It seems that you would have to know that your DB engine didn't load all of that in memory at once, and was very efficient in handling / scavenging off-loaded data backing blocks.

50 到 60 GiB 文件!似乎您必须知道您的数据库引擎并没有一次将所有这些加载到内存中,并且在处理/清除卸载的数据支持块方面非常有效。

I don't know if Cloudscape is up to the task, and I wouldn't be surprised if it wasn't.

我不知道 Cloudscape 是否能胜任这项任务,如果不能,我也不会感到惊讶。

--- original post follows ---

--- 原帖如下---

Cloudscape often fits the bill. It's a bit more than Berkeley DB, but it gained enough traction to be distributed even with some JDK offerings.

Cloudscape 经常符合要求。它比 Berkeley DB 多一点,但它获得了足够的吸引力,即使有一些 JDK 产品也可以分发。

回答by Tom Anderson

JavaDBaka Derby aka Cloudscape would be a decent choice; it's a pure Java SQL database, and it's included in the JRE, so you don't have to ship it with your code or require users to install it separately.

JavaDBaka Derby aka Cloudscape 将是一个不错的选择;它是一个纯 Java SQL 数据库,并且包含在 JRE 中,因此您不必随代码一起提供它或要求用户单独安装它。

(It's actually not included in the JRE provided by some Linux package managers, but there it will be a separate package that is trivial to install)

(它实际上没有包含在一些 Linux 包管理器提供的 JRE 中,但它会有一个单独的包,安装起来很简单)

However, Derby has fairly poor performance. An alternative would be H2- again, a pure Java SQL database that stores a database in a single file, with a ~1MB jar under a redistributable license, but one that is considerably faster and lighter than Derby.

然而,德比的表现相当糟糕。另一种选择是H2——同样是一个纯 Java SQL 数据库,它将数据库存储在单个文件中,在可再发行许可证下有一个约 1MB 的 jar ,但它比 Derby 更快、更轻

I've happily used H2 for a number of small projects. JBoss liked it enough that they bundled it in AS7. It's trivial to set up, and definitely worth a try.

我很高兴将 H2 用于许多小项目。JBoss 非常喜欢它,以至于他们将它捆绑在 AS7 中。设置起来很简单,绝对值得一试。

回答by Simon Brandhof - SonarSource

Persistit is the new challenger. It's a fast, persistent and transactional Java B+Tree library.

Persistit 是新的挑战者。它是一个快速、持久和事务性的 Java B+Tree 库。

I'm afraid that there's no guarantee that it will still be maintained. Akiban, the company supporting Persistit, was recently acquired by FoundationDB. The latter did not provide any information on the future.

恐怕不能保证它仍然会得到维护。支持 Persistit 的公司 Akiban 最近被 FoundationDB 收购。后者没有提供任何有关未来的信息。

https://github.com/akiban/persistit

https://github.com/akiban/persistit

回答by mbelow

I just would like to point out that the storage backend of H2 can also be used as a key-value storage engine if you do not need sql / jdbc:

我只想指出,如果不需要sql/jdbc,H2的存储后端也可以作为key-value存储引擎:

http://www.h2database.com/html/mvstore.html

http://www.h2database.com/html/mvstore.html

回答by leventov

Take a look at LMDBJava, Java bindings to LMDB, the fastest sorted ACID key-value store out there.

看看LMDBJava,Java 与LMDB 的绑定,这是目前最快的排序 ACID 键值存储。

回答by Maurice Perry

H2 http://www.h2database.com/

H2 http://www.h2database.com/

It's a full-blown SQL/JDBC database, but it's lightweight and fast

它是一个成熟的 SQL/JDBC 数据库,但它轻量级和快速