简体   繁体   English

内存数据库如何提供持久性?

[英]How do in-memory databases provide durability?

More specifically, are there any databases that don't require secondary storage (eg HDD) to provide durability? 更具体地说,是否有不需要辅助存储(例如HDD)的数据库来提供持久性?

Note:This is a follow up of my earlier question . 注意:这是我先前的问题跟进

If you want persistence of transations writing to persistent storage is only real option (you perhaps do not want to build many clusters with independent power supplies in independent data centers and still pray that they never fail simultaneously). 如果您希望持久化写入持久存储的操作是唯一的选择(您可能不想在独立的数据中心中构建具有独立电源的许多集群,而仍然祈祷它们永远不会同时发生故障)。 On the other hand it depends on how valuable your data is. 另一方面,这取决于您的数据的价值。 If it is dispensable then pure in-memory DB with sufficient replication may be appropriate. 如果有必要,那么具有足够复制能力的纯内存数据库可能是合适的。 BTW even HDD may fail after you stored your data on it so here is no ideal solution. 顺便说一句,即使将硬盘存储在硬盘上,硬盘也可能会失败,因此这不是理想的解决方案。 You may look at http://www.julianbrowne.com/article/viewer/brewers-cap-theorem to choose replication tradeoffs. 您可以查看http://www.julianbrowne.com/article/viewer/brewers-cap-theorem选择复制权衡。

Prevayler http://prevayler.org/ is an example of in-memory system backed up with persistent storage (and the code is extremely simple BTW). Prevayler http://prevayler.org/是使用持久性存储备份的内存系统示例(代码非常简单,顺便说一句)。 Durability is provided via transaction logs that are persisted on appropriate device (eg HDD or SSD). 持久性是通过保存在适当设备(例如HDD或SSD)上的事务日志提供的。 Each transaction that modifies data is written into log and the log is used to restore DB state after power failure or database/system restart. 修改数据的每个事务都会写入日志,该日志用于在断电或数据库/系统重新启动后恢复数据库状态。 Aside from Prevayler I have seen similar scheme used to persist message queues. 除了Prevayler,我还看到了用于持久化消息队列的类似方案。 This is indeed similar to how "classic" RDBMS works except that logs are only data written to underlying storage. 实际上,这与“经典” RDBMS的工作方式类似,不同之处在于日志仅是写入底层存储的数据。 The logs can be used for replication also so you may send one copy of log to a live replica other one to HDD. 日志还可以用于复制,因此您可以将日志的一个副本发送到活动副本,将另一个副本发送到HDD。 Various combinations are possible of course. 当然,各种组合都是可能的。

All databases require non-volatile storage to ensure durability. 所有数据库都需要非易失性存储以确保持久性。 The memory image does not provide a durable storage medium. 内存映像不提供耐用的存储介质。 Very shortly after you loose power your memory image becomes invalid. 释放电源后不久,您的内存映像将失效。 Likewise, as soon as the database process terminates, the operating system will release the memory containing the in-memory image. 同样,一旦数据库进程终止,操作系统将释放包含内存映像的内存。 In either case, you loose your database contents. 无论哪种情况,都将丢失数据库内容。

Until any changes have been written to non-volatile memory, they are not truely durable. 在将任何更改写入非易失性存储器之前,它们并不是真正的持久性。 This may consist of either writing all the data changes to disk, or writing a journal of the change being done. 这可以包括将所有数据更改写入磁盘,也可以写入所做更改的日志。

In space or size critical instances non-volatile memory such as flash could be substituted for a HDD. 在空间或大小至关重要的情况下,非易失性存储器(例如闪存)可以代替HDD。 However, flash is reported to have issues with the number of write cycles that can be written. 但是,据报告闪存存在可写入的写入周期数问题。

Having reviewed your previous post, multi-server replication would work as long as you can keep that last server running. 在回顾了您以前的文章之后,只要您可以使最后一台服务器保持运行状态,多服务器复制就可以工作。 As soon as it goes down, you loose your queue. 一旦出现问题,您就可以放松队列。 However, there are a number of alternatives to Oracle which could be considered. 但是,可以考虑使用许多替代Oracle的方法。

PDAs often use battery backed up memory to store their databases. PDA通常使用电池备份的内存来存储其数据库。 These databases are non-durable once the battery runs down. 电池耗尽后,这些数据库将无法使用。 Backups are important. 备份很重要。

In-memory means all the data is stored in memory for it to be accessed. 内存中是指所有数据都存储在内存中以便访问。 When data is read, it can either be read from the disk or from memory. 读取数据后,可以从磁盘或内存中读取数据。 In case of in-memory databases, it's always retrieved from memory. 对于内存数据库,总是从内存中检索它。 However, if the server is turned off suddenly, the data will be lost. 但是,如果服务器突然关闭,数据将丢失。 Hence, in-memory databases are said to lack support for the durability part of ACID. 因此,据说内存数据库缺乏对ACID持久性部分的支持。 However, many databases implement different techniques to achieve durability. 但是,许多数据库采用不同的技术来实现持久性。 This techniques are listed below. 下面列出了此技术。

  • Snapshotting - Record the state of the database at a given moment in time. 快照-在给定的时间记录数据库的状态。 In case of Redis the data is persisted to the disk after every two seconds for durability. 如果是Redis,则每两秒钟将数据持久保存到磁盘中,以实现持久性。
  • Transaction Logging - Changes to the database are recorded in a journal file, which facilitates automatic recovery. 事务记录-对数据库的更改记录在日志文件中,这有助于自动恢复。
  • Use of NVRAM usually in the form of static RAM backed up by battery power. 通常以静态RAM的形式使用NVRAM,并由电池电源支持。 In this case data can be recovered after reboot from its last consistent state. 在这种情况下,可以在重启后从其最后的一致状态恢复数据。

classic in memory database can't provide classic durability, but depending on what your requirements are you can: 内存数据库中的classic不能提供经典的持久性,但是根据您的要求,您可以:

  • use memcached (or similar) to storing in memory across enough nodes that it's unlikely that the data is lost 使用memcached(或类似方法)跨足够多的节点存储在内存中,这样就不太可能丢失数据
  • store your oracle database on a SAN based filesystem, you can give it enough RAM (say 3GB) that the whole database is in RAM, and so disk seek access never stores your application down. 将oracle数据库存储在基于SAN的文件系统上,您可以为其提供足够的RAM(例如3GB),整个数据库都位于RAM中,因此磁盘搜索访问永远不会将应用程序存储下来。 The SAN then takes care of delayed writeback of the cache contents to disk. 然后,SAN负责将缓存内容延迟回写到磁盘。 This is a very expensive option, but it is common in places where high performance and high availability are needed and they can afford it. 这是一个非常昂贵的选择,但是在需要高性能和高可用性且他们负担得起的地方很常见。
  • if you can't afford a SAN, mount a ram disk and install your database on there, then use DB level replication (like logshipping) to provide failover. 如果您负担不起SAN,请安装ram磁盘并在其中安装数据库,然后使用数据库级复制(如日志传送)提供故障转移。

Any reason why you don't want to use persistent storage? 您为什么不想使用永久性存储?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM