1
0
mirror of https://github.com/fluencelabs/redis synced 2025-07-08 21:31:32 +00:00
Files
client-libraries
deps
design-documents
doc
AppendCommand.html
AppendOnlyFileHowto.html
AuthCommand.html
Benchmarks.html
BgrewriteaofCommand.html
BgsaveCommand.html
BlpopCommand.html
BrpoplpushCommand.html
CommandReference.html
Comparisons.html
ConfigCommand.html
Configuration.html
ConnectionHandlingSidebar.html
ControlCommandsSidebar.html
Credits.html
DbsizeCommand.html
DelCommand.html
DesignPatterns.html
EventLibray.html
ExistsCommand.html
ExpireCommand.html
FAQ.html
Features.html
FlushallCommand.html
FlushdbCommand.html
FromSqlToDataStructures.html
GenericCommandsSidebar.html
GetCommand.html
GetbitCommand.html
GetsetCommand.html
HackingStrings.html
HashCommandsSidebar.html
Hashes.html
HdelCommand.html
HexistsCommand.html
HgetCommand.html
HgetallCommand.html
HincrbyCommand.html
HlenCommand.html
HmgetCommand.html
HmsetCommand.html
HsetCommand.html
HsetnxCommand.html
IncrCommand.html
InfoCommand.html
IntroductionToRedisDataTypes.html
KeysCommand.html
LastsaveCommand.html
LindexCommand.html
ListCommandsSidebar.html
Lists.html
LlenCommand.html
LpopCommand.html
LrangeCommand.html
LremCommand.html
LsetCommand.html
LtrimCommand.html
MgetCommand.html
MonitorCommand.html
MoveCommand.html
MsetCommand.html
MultiExecCommand.html
NonexistentCommands.html
ObjectHashMappers.html
Pipelining.html
ProgrammingExamples.html
ProtocolSpecification.html
PublishSubscribe.html
QuickStart.html
QuitCommand.html
README.html
RandomkeyCommand.html
Redis0100ChangeLog.html
Redis0900ChangeLog.html
RedisBigData.html
RedisCLI.html
RedisEventLibrary.html
RedisGuides.html
RedisInternals.html
RedisPipelining.html
RedisStatus.html
Redis_1_2_0_Changelog.html
Redis_2_0_0_Changelog.html
Redis_2_0_Whats_new.html
RenameCommand.html
RenamenxCommand.html
ReplicationHowto.html
ReplyTypes.html
RoadMap.html
RpoplpushCommand.html
RpushCommand.html
SaddCommand.html
SaveCommand.html
ScardCommand.html
SdiffCommand.html
SdiffstoreCommand.html
SelectCommand.html
SetCommand.html
SetCommandsSidebar.html
SetbitCommand.html
SetexCommand.html
SetnxCommand.html
SetrangeCommand.html
Sets.html
ShutdownCommand.html
SideBar.html
SinterCommand.html
SinterstoreCommand.html
SismemberCommand.html
SlaveofCommand.html
SmembersCommand.html
SmoveCommand.html
SortCommand.html
SortedSetCommandsSidebar.html
SortedSets.html
Speed.html
SponsorshipHistory.html
SpopCommand.html
SrandmemberCommand.html
SremCommand.html
StringCommandsSidebar.html
Strings.html
StrlenCommand.html
SubstrCommand.html
SunionCommand.html
SunionstoreCommand.html
SupportedLanguages.html
SupportedPlatforms.html
TemplateCommand.html
TtlCommand.html
TwitterAlikeExample.html
TypeCommand.html
UnstableSource.html
VirtualMemorySpecification.html
VirtualMemoryUserGuide.html
ZaddCommand.html
ZcardCommand.html
ZincrbyCommand.html
ZrangeCommand.html
ZrangebyscoreCommand.html
ZrankCommand.html
ZremCommand.html
ZremrangebyrankCommand.html
ZremrangebyscoreCommand.html
ZscoreCommand.html
ZunionCommand.html
ZunionstoreCommand.html
index.html
redis.png
style.css
src
tests
utils
.gitignore
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
Changelog
INSTALL
Makefile
README
TODO
redis.conf
redis/doc/AppendOnlyFileHowto.html

42 lines
6.4 KiB
HTML
Raw Normal View History

2009-12-23 11:15:07 -05:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page">
<div id='header'>
<a href="index.html">
<img style="border:none" alt="Redis Documentation" src="redis.png">
</a>
</div>
<div id="pagecontent">
<div class="index">
<!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
2010-12-15 15:49:29 +01:00
<b>AppendOnlyFileHowto: Contents</b><br>&nbsp;&nbsp;<a href="#Append Only File HOWTO">Append Only File HOWTO</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#General Information">General Information</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Log rewriting">Log rewriting</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Wait... but how does this work?">Wait... but how does this work?</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#How durable is the append only file?">How durable is the append only file?</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#What should I do if my Append Only File gets corrupted?">What should I do if my Append Only File gets corrupted?</a>
2009-12-23 11:15:07 -05:00
</div>
<h1 class="wikiname">AppendOnlyFileHowto</h1>
<div class="summary">
</div>
<div class="narrow">
&iuml;&raquo;&iquest;#sidebar <a href="RedisGuides.html">RedisGuides</a>
<h1><a name="Append Only File HOWTO">Append Only File HOWTO</a></h1><h2><a name="General Information">General Information</a></h2>Append only file is an alternative durability option for Redis. What this mean? Let's start with some fact:<br/><br/><ul><li> For default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb (by default at least). For instance you can configure Redis to save the dataset every 60 seconds if there are at least 100 changes in the dataset, or every 1000 seconds if there is at least a single change in the dataset. This is known as &quot;Snapshotting&quot;.</li><li> Snapshotting is not very durable. If your computer running Redis stops, your power line fails, or you write killall -9 redis-server for a mistake, the latest data written on Redis will get lost. There are applications where this is not a big deal. There are applications where this is not acceptable and Redis <b>was</b> not an option for this applications.</li></ul>
2009-12-23 11:15:07 -05:00
What is the solution? To use append only file as alternative to snapshotting. How it works?<br/><br/><ul><li> It is an 1.1 only feature.</li><li> You have to turn it on editing the configuration file. Just make sure you have &quot;appendonly yes&quot; somewhere.</li><li> Append only files work this way: every time Redis receive a command that changes the dataset (for instance a SET or LPUSH command) it appends this command in the append only file. When you restart Redis it will first <b>re-play</b> the append only file to rebuild the state.</li></ul>
<h2><a name="Log rewriting">Log rewriting</a></h2>As you can guess... the append log file gets bigger and bigger, every time there is a new operation changing the dataset. Even if you set always the same key &quot;mykey&quot; to the values of &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, ... up to 10000000000 in the end you'll have just a single key in the dataset, just a few bytes! but how big will be the append log file? Very very big.<br/><br/>So Redis supports an interesting feature: it is able to rebuild the append log file, in background, without to stop processing client commands. The key is the command <a href="BGREWRITEAOF.html">BGREWRITEAOF</a>. This command basically is able to use the dataset in memory in order to rewrite the shortest sequence of commands able to rebuild the exact dataset that is currently in memory.<br/><br/>So from time to time when the log gets too big, try this command. It's safe as if it fails you will not lost your old log (but you can make a backup copy given that currently 1.1 is still in beta!).<h2><a name="Wait... but how does this work?">Wait... but how does this work?</a></h2>Basically it uses the same fork() copy-on-write trick that snapshotting already uses. This is how the algorithm works:<br/><br/><ul><li> Redis forks, so now we have a child and a parent.</li><li> The child starts writing the new append log file in a temporary file.</li><li> The parent accumulates all the new changes in an in-memory buffer (but at the same time it writes the new changes in the <b>old</b> append only file, so if the rewriting fails, we are safe).</li><li> When the child finished to rewrite the file, the parent gets a signal, and append the in-memory buffer at the end of the file generated by the child.</li><li> Profit! Now Redis atomically renames the old file into the new one, and starts appending new data into the new file.</li></ul>
2009-12-23 11:15:07 -05:00
<h2><a name="How durable is the append only file?">How durable is the append only file?</a></h2>Check redis.conf, you can configure how many times Redis will fsync() data on disk. There are three options:<br/><br/><ul><li> Fsync() every time a new command is appended to the append log file. Very very slow, very safe.</li><li> Fsync() one time every second. Fast enough, and you can lose 1 second of data if there is a disaster.</li><li> Never fsync(), just put your data in the hands of the Operating System. The faster and unsafer method.</li></ul>
2010-12-15 15:49:29 +01:00
The suggested (and default) policy is &quot;everysec&quot;. It is both very fast and pretty safe. The &quot;always&quot; policy is very slow in practice, even if it was improved in Redis 2.0.0 there is no way to make fsync() faster than it is.<h2><a name="What should I do if my Append Only File gets corrupted?">What should I do if my Append Only File gets corrupted?</a></h2>It is possible that the server crashes while writing the AOF file (this still should never lead to inconsistencies) corrupting the file in a way that is no longer loadable by Redis. When this happens you can fix this problem using the following procedure:<br/><br/><ul><li> Make a backup copy of your AOF file.</li><li> Fix the original file with: ./redis-check-aof --fix <code name="code" class="python">&lt;filename&gt;</code></li><li> Optionally use diff -u to check what is the difference between two files.</li><li> Restart the server with the fixed file.</li></ul>
2009-12-23 11:15:07 -05:00
</div>
</div>
</div>
</body>
</html>