redis-server 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +38 -0
- data/README.md +33 -0
- data/bin/redis +114 -0
- data/redis/Makefile +5 -0
- data/redis/extconf.rb +3 -0
- data/redis/redis-2.2.11/00-RELEASENOTES +199 -0
- data/redis/redis-2.2.11/BUGS +1 -0
- data/redis/redis-2.2.11/CONTRIBUTING +13 -0
- data/redis/redis-2.2.11/COPYING +10 -0
- data/redis/redis-2.2.11/Changelog +1032 -0
- data/redis/redis-2.2.11/INSTALL +30 -0
- data/redis/redis-2.2.11/Makefile +22 -0
- data/redis/redis-2.2.11/README +83 -0
- data/redis/redis-2.2.11/TODO +4 -0
- data/redis/redis-2.2.11/client-libraries/README +11 -0
- data/redis/redis-2.2.11/deps/hiredis/COPYING +10 -0
- data/redis/redis-2.2.11/deps/hiredis/Makefile +115 -0
- data/redis/redis-2.2.11/deps/hiredis/README.md +311 -0
- data/redis/redis-2.2.11/deps/hiredis/TODO +2 -0
- data/redis/redis-2.2.11/deps/hiredis/adapters/ae.h +95 -0
- data/redis/redis-2.2.11/deps/hiredis/adapters/libev.h +113 -0
- data/redis/redis-2.2.11/deps/hiredis/adapters/libevent.h +76 -0
- data/redis/redis-2.2.11/deps/hiredis/async.c +321 -0
- data/redis/redis-2.2.11/deps/hiredis/async.h +112 -0
- data/redis/redis-2.2.11/deps/hiredis/example-ae.c +53 -0
- data/redis/redis-2.2.11/deps/hiredis/example-libev.c +47 -0
- data/redis/redis-2.2.11/deps/hiredis/example-libevent.c +48 -0
- data/redis/redis-2.2.11/deps/hiredis/example.c +67 -0
- data/redis/redis-2.2.11/deps/hiredis/fmacros.h +15 -0
- data/redis/redis-2.2.11/deps/hiredis/hiredis.c +1058 -0
- data/redis/redis-2.2.11/deps/hiredis/hiredis.h +170 -0
- data/redis/redis-2.2.11/deps/hiredis/net.c +170 -0
- data/redis/redis-2.2.11/deps/hiredis/net.h +43 -0
- data/redis/redis-2.2.11/deps/hiredis/sds.c +479 -0
- data/redis/redis-2.2.11/deps/hiredis/sds.h +77 -0
- data/redis/redis-2.2.11/deps/hiredis/test.c +479 -0
- data/redis/redis-2.2.11/deps/hiredis/util.h +40 -0
- data/redis/redis-2.2.11/deps/linenoise/Makefile +10 -0
- data/redis/redis-2.2.11/deps/linenoise/README.markdown +45 -0
- data/redis/redis-2.2.11/deps/linenoise/example.c +27 -0
- data/redis/redis-2.2.11/deps/linenoise/linenoise.c +609 -0
- data/redis/redis-2.2.11/deps/linenoise/linenoise.h +55 -0
- data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER +214 -0
- data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER-2 +343 -0
- data/redis/redis-2.2.11/doc/AppendCommand.html +48 -0
- data/redis/redis-2.2.11/doc/AppendOnlyFileHowto.html +41 -0
- data/redis/redis-2.2.11/doc/AuthCommand.html +39 -0
- data/redis/redis-2.2.11/doc/Benchmarks.html +129 -0
- data/redis/redis-2.2.11/doc/BgrewriteaofCommand.html +41 -0
- data/redis/redis-2.2.11/doc/BgsaveCommand.html +39 -0
- data/redis/redis-2.2.11/doc/BlpopCommand.html +51 -0
- data/redis/redis-2.2.11/doc/BrpoplpushCommand.html +39 -0
- data/redis/redis-2.2.11/doc/CommandReference.html +47 -0
- data/redis/redis-2.2.11/doc/Comparisons.html +42 -0
- data/redis/redis-2.2.11/doc/ConfigCommand.html +76 -0
- data/redis/redis-2.2.11/doc/Configuration.html +38 -0
- data/redis/redis-2.2.11/doc/ConnectionHandlingSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/ControlCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Credits.html +38 -0
- data/redis/redis-2.2.11/doc/DbsizeCommand.html +38 -0
- data/redis/redis-2.2.11/doc/DelCommand.html +41 -0
- data/redis/redis-2.2.11/doc/DesignPatterns.html +37 -0
- data/redis/redis-2.2.11/doc/EventLibray.html +44 -0
- data/redis/redis-2.2.11/doc/ExistsCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ExpireCommand.html +96 -0
- data/redis/redis-2.2.11/doc/FAQ.html +70 -0
- data/redis/redis-2.2.11/doc/Features.html +38 -0
- data/redis/redis-2.2.11/doc/FlushallCommand.html +39 -0
- data/redis/redis-2.2.11/doc/FlushdbCommand.html +39 -0
- data/redis/redis-2.2.11/doc/FromSqlToDataStructures.html +37 -0
- data/redis/redis-2.2.11/doc/GenericCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/GetCommand.html +39 -0
- data/redis/redis-2.2.11/doc/GetbitCommand.html +39 -0
- data/redis/redis-2.2.11/doc/GetsetCommand.html +38 -0
- data/redis/redis-2.2.11/doc/HackingStrings.html +83 -0
- data/redis/redis-2.2.11/doc/HashCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Hashes.html +37 -0
- data/redis/redis-2.2.11/doc/HdelCommand.html +39 -0
- data/redis/redis-2.2.11/doc/HexistsCommand.html +39 -0
- data/redis/redis-2.2.11/doc/HgetCommand.html +39 -0
- data/redis/redis-2.2.11/doc/HgetallCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HincrbyCommand.html +45 -0
- data/redis/redis-2.2.11/doc/HlenCommand.html +38 -0
- data/redis/redis-2.2.11/doc/HmgetCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HmsetCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HsetCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HsetnxCommand.html +41 -0
- data/redis/redis-2.2.11/doc/IncrCommand.html +43 -0
- data/redis/redis-2.2.11/doc/InfoCommand.html +48 -0
- data/redis/redis-2.2.11/doc/IntroductionToRedisDataTypes.html +152 -0
- data/redis/redis-2.2.11/doc/KeysCommand.html +43 -0
- data/redis/redis-2.2.11/doc/LastsaveCommand.html +39 -0
- data/redis/redis-2.2.11/doc/LindexCommand.html +40 -0
- data/redis/redis-2.2.11/doc/ListCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Lists.html +42 -0
- data/redis/redis-2.2.11/doc/LlenCommand.html +41 -0
- data/redis/redis-2.2.11/doc/LpopCommand.html +41 -0
- data/redis/redis-2.2.11/doc/LrangeCommand.html +47 -0
- data/redis/redis-2.2.11/doc/LremCommand.html +41 -0
- data/redis/redis-2.2.11/doc/LsetCommand.html +38 -0
- data/redis/redis-2.2.11/doc/LtrimCommand.html +47 -0
- data/redis/redis-2.2.11/doc/MgetCommand.html +52 -0
- data/redis/redis-2.2.11/doc/MonitorCommand.html +63 -0
- data/redis/redis-2.2.11/doc/MoveCommand.html +42 -0
- data/redis/redis-2.2.11/doc/MsetCommand.html +44 -0
- data/redis/redis-2.2.11/doc/MultiExecCommand.html +166 -0
- data/redis/redis-2.2.11/doc/NonexistentCommands.html +51 -0
- data/redis/redis-2.2.11/doc/ObjectHashMappers.html +39 -0
- data/redis/redis-2.2.11/doc/Pipelining.html +36 -0
- data/redis/redis-2.2.11/doc/ProgrammingExamples.html +38 -0
- data/redis/redis-2.2.11/doc/ProtocolSpecification.html +137 -0
- data/redis/redis-2.2.11/doc/PublishSubscribe.html +115 -0
- data/redis/redis-2.2.11/doc/QuickStart.html +68 -0
- data/redis/redis-2.2.11/doc/QuitCommand.html +38 -0
- data/redis/redis-2.2.11/doc/README.html +119 -0
- data/redis/redis-2.2.11/doc/RandomkeyCommand.html +39 -0
- data/redis/redis-2.2.11/doc/Redis0100ChangeLog.html +67 -0
- data/redis/redis-2.2.11/doc/Redis0900ChangeLog.html +56 -0
- data/redis/redis-2.2.11/doc/RedisBigData.html +61 -0
- data/redis/redis-2.2.11/doc/RedisCLI.html +37 -0
- data/redis/redis-2.2.11/doc/RedisEventLibrary.html +70 -0
- data/redis/redis-2.2.11/doc/RedisGuides.html +37 -0
- data/redis/redis-2.2.11/doc/RedisInternals.html +38 -0
- data/redis/redis-2.2.11/doc/RedisPipelining.html +93 -0
- data/redis/redis-2.2.11/doc/RedisStatus.html +56 -0
- data/redis/redis-2.2.11/doc/Redis_1_2_0_Changelog.html +40 -0
- data/redis/redis-2.2.11/doc/Redis_2_0_0_Changelog.html +62 -0
- data/redis/redis-2.2.11/doc/Redis_2_0_Whats_new.html +59 -0
- data/redis/redis-2.2.11/doc/RenameCommand.html +39 -0
- data/redis/redis-2.2.11/doc/RenamenxCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ReplicationHowto.html +43 -0
- data/redis/redis-2.2.11/doc/ReplyTypes.html +42 -0
- data/redis/redis-2.2.11/doc/RoadMap.html +38 -0
- data/redis/redis-2.2.11/doc/RpoplpushCommand.html +44 -0
- data/redis/redis-2.2.11/doc/RpushCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SaddCommand.html +41 -0
- data/redis/redis-2.2.11/doc/SaveCommand.html +39 -0
- data/redis/redis-2.2.11/doc/ScardCommand.html +41 -0
- data/redis/redis-2.2.11/doc/SdiffCommand.html +45 -0
- data/redis/redis-2.2.11/doc/SdiffstoreCommand.html +38 -0
- data/redis/redis-2.2.11/doc/SelectCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SetCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SetCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/SetbitCommand.html +45 -0
- data/redis/redis-2.2.11/doc/SetexCommand.html +42 -0
- data/redis/redis-2.2.11/doc/SetnxCommand.html +51 -0
- data/redis/redis-2.2.11/doc/SetrangeCommand.html +58 -0
- data/redis/redis-2.2.11/doc/Sets.html +36 -0
- data/redis/redis-2.2.11/doc/ShutdownCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SideBar.html +36 -0
- data/redis/redis-2.2.11/doc/SinterCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SinterstoreCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SismemberCommand.html +42 -0
- data/redis/redis-2.2.11/doc/SlaveofCommand.html +41 -0
- data/redis/redis-2.2.11/doc/SmembersCommand.html +38 -0
- data/redis/redis-2.2.11/doc/SmoveCommand.html +44 -0
- data/redis/redis-2.2.11/doc/SortCommand.html +75 -0
- data/redis/redis-2.2.11/doc/SortedSetCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/SortedSets.html +36 -0
- data/redis/redis-2.2.11/doc/Speed.html +38 -0
- data/redis/redis-2.2.11/doc/SponsorshipHistory.html +38 -0
- data/redis/redis-2.2.11/doc/SpopCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SrandmemberCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SremCommand.html +42 -0
- data/redis/redis-2.2.11/doc/StringCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Strings.html +37 -0
- data/redis/redis-2.2.11/doc/StrlenCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SubstrCommand.html +52 -0
- data/redis/redis-2.2.11/doc/SunionCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SunionstoreCommand.html +38 -0
- data/redis/redis-2.2.11/doc/SupportedLanguages.html +60 -0
- data/redis/redis-2.2.11/doc/SupportedPlatforms.html +37 -0
- data/redis/redis-2.2.11/doc/TemplateCommand.html +38 -0
- data/redis/redis-2.2.11/doc/TtlCommand.html +38 -0
- data/redis/redis-2.2.11/doc/TwitterAlikeExample.html +250 -0
- data/redis/redis-2.2.11/doc/TypeCommand.html +46 -0
- data/redis/redis-2.2.11/doc/UnstableSource.html +39 -0
- data/redis/redis-2.2.11/doc/VirtualMemorySpecification.html +156 -0
- data/redis/redis-2.2.11/doc/VirtualMemoryUserGuide.html +66 -0
- data/redis/redis-2.2.11/doc/ZaddCommand.html +43 -0
- data/redis/redis-2.2.11/doc/ZcardCommand.html +41 -0
- data/redis/redis-2.2.11/doc/ZincrbyCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZrangeCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZrangebyscoreCommand.html +77 -0
- data/redis/redis-2.2.11/doc/ZrankCommand.html +43 -0
- data/redis/redis-2.2.11/doc/ZremCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZremrangebyrankCommand.html +39 -0
- data/redis/redis-2.2.11/doc/ZremrangebyscoreCommand.html +39 -0
- data/redis/redis-2.2.11/doc/ZscoreCommand.html +41 -0
- data/redis/redis-2.2.11/doc/ZunionCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZunionstoreCommand.html +43 -0
- data/redis/redis-2.2.11/doc/index.html +43 -0
- data/redis/redis-2.2.11/doc/redis.png +0 -0
- data/redis/redis-2.2.11/doc/style.css +25 -0
- data/redis/redis-2.2.11/redis.conf +417 -0
- data/redis/redis-2.2.11/src/Makefile +177 -0
- data/redis/redis-2.2.11/src/adlist.c +325 -0
- data/redis/redis-2.2.11/src/adlist.h +92 -0
- data/redis/redis-2.2.11/src/ae.c +390 -0
- data/redis/redis-2.2.11/src/ae.h +117 -0
- data/redis/redis-2.2.11/src/ae_epoll.c +91 -0
- data/redis/redis-2.2.11/src/ae_kqueue.c +93 -0
- data/redis/redis-2.2.11/src/ae_select.c +72 -0
- data/redis/redis-2.2.11/src/anet.c +347 -0
- data/redis/redis-2.2.11/src/anet.h +57 -0
- data/redis/redis-2.2.11/src/aof.c +675 -0
- data/redis/redis-2.2.11/src/config.c +627 -0
- data/redis/redis-2.2.11/src/config.h +64 -0
- data/redis/redis-2.2.11/src/db.c +543 -0
- data/redis/redis-2.2.11/src/debug.c +314 -0
- data/redis/redis-2.2.11/src/dict.c +721 -0
- data/redis/redis-2.2.11/src/dict.h +156 -0
- data/redis/redis-2.2.11/src/fmacros.h +15 -0
- data/redis/redis-2.2.11/src/help.h +638 -0
- data/redis/redis-2.2.11/src/intset.c +422 -0
- data/redis/redis-2.2.11/src/intset.h +19 -0
- data/redis/redis-2.2.11/src/lzf.h +100 -0
- data/redis/redis-2.2.11/src/lzfP.h +159 -0
- data/redis/redis-2.2.11/src/lzf_c.c +295 -0
- data/redis/redis-2.2.11/src/lzf_d.c +150 -0
- data/redis/redis-2.2.11/src/mkreleasehdr.sh +9 -0
- data/redis/redis-2.2.11/src/multi.c +268 -0
- data/redis/redis-2.2.11/src/networking.c +899 -0
- data/redis/redis-2.2.11/src/object.c +484 -0
- data/redis/redis-2.2.11/src/pqsort.c +197 -0
- data/redis/redis-2.2.11/src/pqsort.h +15 -0
- data/redis/redis-2.2.11/src/pubsub.c +267 -0
- data/redis/redis-2.2.11/src/rdb.c +1020 -0
- data/redis/redis-2.2.11/src/redis-benchmark.c +530 -0
- data/redis/redis-2.2.11/src/redis-check-aof.c +185 -0
- data/redis/redis-2.2.11/src/redis-check-dump.c +681 -0
- data/redis/redis-2.2.11/src/redis-cli.c +773 -0
- data/redis/redis-2.2.11/src/redis.c +1677 -0
- data/redis/redis-2.2.11/src/redis.h +1022 -0
- data/redis/redis-2.2.11/src/release.c +13 -0
- data/redis/redis-2.2.11/src/replication.c +557 -0
- data/redis/redis-2.2.11/src/sds.c +639 -0
- data/redis/redis-2.2.11/src/sds.h +78 -0
- data/redis/redis-2.2.11/src/sha1.c +276 -0
- data/redis/redis-2.2.11/src/sha1.h +17 -0
- data/redis/redis-2.2.11/src/solarisfixes.h +22 -0
- data/redis/redis-2.2.11/src/sort.c +389 -0
- data/redis/redis-2.2.11/src/syncio.c +154 -0
- data/redis/redis-2.2.11/src/t_hash.c +476 -0
- data/redis/redis-2.2.11/src/t_list.c +986 -0
- data/redis/redis-2.2.11/src/t_set.c +610 -0
- data/redis/redis-2.2.11/src/t_string.c +438 -0
- data/redis/redis-2.2.11/src/t_zset.c +1084 -0
- data/redis/redis-2.2.11/src/testhelp.h +54 -0
- data/redis/redis-2.2.11/src/util.c +243 -0
- data/redis/redis-2.2.11/src/valgrind.sup +5 -0
- data/redis/redis-2.2.11/src/version.h +1 -0
- data/redis/redis-2.2.11/src/vm.c +1149 -0
- data/redis/redis-2.2.11/src/ziplist.c +1323 -0
- data/redis/redis-2.2.11/src/ziplist.h +15 -0
- data/redis/redis-2.2.11/src/zipmap.c +455 -0
- data/redis/redis-2.2.11/src/zipmap.h +48 -0
- data/redis/redis-2.2.11/src/zmalloc.c +278 -0
- data/redis/redis-2.2.11/src/zmalloc.h +47 -0
- data/redis/redis-2.2.11/tests/assets/default.conf +308 -0
- data/redis/redis-2.2.11/tests/integration/aof.tcl +104 -0
- data/redis/redis-2.2.11/tests/integration/redis-cli.tcl +208 -0
- data/redis/redis-2.2.11/tests/integration/replication.tcl +98 -0
- data/redis/redis-2.2.11/tests/support/redis.tcl +241 -0
- data/redis/redis-2.2.11/tests/support/server.tcl +294 -0
- data/redis/redis-2.2.11/tests/support/test.tcl +190 -0
- data/redis/redis-2.2.11/tests/support/tmpfile.tcl +15 -0
- data/redis/redis-2.2.11/tests/support/util.tcl +296 -0
- data/redis/redis-2.2.11/tests/test_helper.tcl +221 -0
- data/redis/redis-2.2.11/tests/unit/auth.tcl +15 -0
- data/redis/redis-2.2.11/tests/unit/basic.tcl +616 -0
- data/redis/redis-2.2.11/tests/unit/cas.tcl +135 -0
- data/redis/redis-2.2.11/tests/unit/expire.tcl +74 -0
- data/redis/redis-2.2.11/tests/unit/other.tcl +240 -0
- data/redis/redis-2.2.11/tests/unit/printver.tcl +6 -0
- data/redis/redis-2.2.11/tests/unit/protocol.tcl +62 -0
- data/redis/redis-2.2.11/tests/unit/pubsub.tcl +195 -0
- data/redis/redis-2.2.11/tests/unit/quit.tcl +40 -0
- data/redis/redis-2.2.11/tests/unit/sort.tcl +189 -0
- data/redis/redis-2.2.11/tests/unit/type/hash.tcl +300 -0
- data/redis/redis-2.2.11/tests/unit/type/list.tcl +819 -0
- data/redis/redis-2.2.11/tests/unit/type/set.tcl +334 -0
- data/redis/redis-2.2.11/tests/unit/type/zset.tcl +587 -0
- data/redis/redis-2.2.11/utils/build-static-symbols.tcl +22 -0
- data/redis/redis-2.2.11/utils/generate-command-help.rb +112 -0
- data/redis/redis-2.2.11/utils/mktarball.sh +13 -0
- data/redis/redis-2.2.11/utils/redis-copy.rb +78 -0
- data/redis/redis-2.2.11/utils/redis-sha1.rb +52 -0
- data/redis/redis-2.2.11/utils/redis_init_script +42 -0
- metadata +362 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
/* This is a really minimal testing framework for C.
|
2
|
+
*
|
3
|
+
* Example:
|
4
|
+
*
|
5
|
+
* test_cond("Check if 1 == 1", 1==1)
|
6
|
+
* test_cond("Check if 5 > 10", 5 > 10)
|
7
|
+
* test_report()
|
8
|
+
*
|
9
|
+
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
|
10
|
+
* All rights reserved.
|
11
|
+
*
|
12
|
+
* Redistribution and use in source and binary forms, with or without
|
13
|
+
* modification, are permitted provided that the following conditions are met:
|
14
|
+
*
|
15
|
+
* * Redistributions of source code must retain the above copyright notice,
|
16
|
+
* this list of conditions and the following disclaimer.
|
17
|
+
* * Redistributions in binary form must reproduce the above copyright
|
18
|
+
* notice, this list of conditions and the following disclaimer in the
|
19
|
+
* documentation and/or other materials provided with the distribution.
|
20
|
+
* * Neither the name of Redis nor the names of its contributors may be used
|
21
|
+
* to endorse or promote products derived from this software without
|
22
|
+
* specific prior written permission.
|
23
|
+
*
|
24
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
27
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
28
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
29
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
30
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
32
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
33
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
*/
|
36
|
+
|
37
|
+
#ifndef __TESTHELP_H
|
38
|
+
#define __TESTHELP_H
|
39
|
+
|
40
|
+
int __failed_tests = 0;
|
41
|
+
int __test_num = 0;
|
42
|
+
#define test_cond(descr,_c) do { \
|
43
|
+
__test_num++; printf("%d - %s: ", __test_num, descr); \
|
44
|
+
if(_c) printf("PASSED\n"); else {printf("FAILED\n"); __failed_tests++;} \
|
45
|
+
} while(0);
|
46
|
+
#define test_report() do { \
|
47
|
+
printf("%d tests, %d passed, %d failed\n", __test_num, \
|
48
|
+
__test_num-__failed_tests, __failed_tests); \
|
49
|
+
if (__failed_tests) { \
|
50
|
+
printf("=== WARNING === We have failed tests here...\n"); \
|
51
|
+
} \
|
52
|
+
} while(0);
|
53
|
+
|
54
|
+
#endif
|
@@ -0,0 +1,243 @@
|
|
1
|
+
#include "redis.h"
|
2
|
+
#include <ctype.h>
|
3
|
+
#include <limits.h>
|
4
|
+
|
5
|
+
/* Glob-style pattern matching. */
|
6
|
+
int stringmatchlen(const char *pattern, int patternLen,
|
7
|
+
const char *string, int stringLen, int nocase)
|
8
|
+
{
|
9
|
+
while(patternLen) {
|
10
|
+
switch(pattern[0]) {
|
11
|
+
case '*':
|
12
|
+
while (pattern[1] == '*') {
|
13
|
+
pattern++;
|
14
|
+
patternLen--;
|
15
|
+
}
|
16
|
+
if (patternLen == 1)
|
17
|
+
return 1; /* match */
|
18
|
+
while(stringLen) {
|
19
|
+
if (stringmatchlen(pattern+1, patternLen-1,
|
20
|
+
string, stringLen, nocase))
|
21
|
+
return 1; /* match */
|
22
|
+
string++;
|
23
|
+
stringLen--;
|
24
|
+
}
|
25
|
+
return 0; /* no match */
|
26
|
+
break;
|
27
|
+
case '?':
|
28
|
+
if (stringLen == 0)
|
29
|
+
return 0; /* no match */
|
30
|
+
string++;
|
31
|
+
stringLen--;
|
32
|
+
break;
|
33
|
+
case '[':
|
34
|
+
{
|
35
|
+
int not, match;
|
36
|
+
|
37
|
+
pattern++;
|
38
|
+
patternLen--;
|
39
|
+
not = pattern[0] == '^';
|
40
|
+
if (not) {
|
41
|
+
pattern++;
|
42
|
+
patternLen--;
|
43
|
+
}
|
44
|
+
match = 0;
|
45
|
+
while(1) {
|
46
|
+
if (pattern[0] == '\\') {
|
47
|
+
pattern++;
|
48
|
+
patternLen--;
|
49
|
+
if (pattern[0] == string[0])
|
50
|
+
match = 1;
|
51
|
+
} else if (pattern[0] == ']') {
|
52
|
+
break;
|
53
|
+
} else if (patternLen == 0) {
|
54
|
+
pattern--;
|
55
|
+
patternLen++;
|
56
|
+
break;
|
57
|
+
} else if (pattern[1] == '-' && patternLen >= 3) {
|
58
|
+
int start = pattern[0];
|
59
|
+
int end = pattern[2];
|
60
|
+
int c = string[0];
|
61
|
+
if (start > end) {
|
62
|
+
int t = start;
|
63
|
+
start = end;
|
64
|
+
end = t;
|
65
|
+
}
|
66
|
+
if (nocase) {
|
67
|
+
start = tolower(start);
|
68
|
+
end = tolower(end);
|
69
|
+
c = tolower(c);
|
70
|
+
}
|
71
|
+
pattern += 2;
|
72
|
+
patternLen -= 2;
|
73
|
+
if (c >= start && c <= end)
|
74
|
+
match = 1;
|
75
|
+
} else {
|
76
|
+
if (!nocase) {
|
77
|
+
if (pattern[0] == string[0])
|
78
|
+
match = 1;
|
79
|
+
} else {
|
80
|
+
if (tolower((int)pattern[0]) == tolower((int)string[0]))
|
81
|
+
match = 1;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
pattern++;
|
85
|
+
patternLen--;
|
86
|
+
}
|
87
|
+
if (not)
|
88
|
+
match = !match;
|
89
|
+
if (!match)
|
90
|
+
return 0; /* no match */
|
91
|
+
string++;
|
92
|
+
stringLen--;
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
case '\\':
|
96
|
+
if (patternLen >= 2) {
|
97
|
+
pattern++;
|
98
|
+
patternLen--;
|
99
|
+
}
|
100
|
+
/* fall through */
|
101
|
+
default:
|
102
|
+
if (!nocase) {
|
103
|
+
if (pattern[0] != string[0])
|
104
|
+
return 0; /* no match */
|
105
|
+
} else {
|
106
|
+
if (tolower((int)pattern[0]) != tolower((int)string[0]))
|
107
|
+
return 0; /* no match */
|
108
|
+
}
|
109
|
+
string++;
|
110
|
+
stringLen--;
|
111
|
+
break;
|
112
|
+
}
|
113
|
+
pattern++;
|
114
|
+
patternLen--;
|
115
|
+
if (stringLen == 0) {
|
116
|
+
while(*pattern == '*') {
|
117
|
+
pattern++;
|
118
|
+
patternLen--;
|
119
|
+
}
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
if (patternLen == 0 && stringLen == 0)
|
124
|
+
return 1;
|
125
|
+
return 0;
|
126
|
+
}
|
127
|
+
|
128
|
+
int stringmatch(const char *pattern, const char *string, int nocase) {
|
129
|
+
return stringmatchlen(pattern,strlen(pattern),string,strlen(string),nocase);
|
130
|
+
}
|
131
|
+
|
132
|
+
/* Convert a string representing an amount of memory into the number of
|
133
|
+
* bytes, so for instance memtoll("1Gi") will return 1073741824 that is
|
134
|
+
* (1024*1024*1024).
|
135
|
+
*
|
136
|
+
* On parsing error, if *err is not NULL, it's set to 1, otherwise it's
|
137
|
+
* set to 0 */
|
138
|
+
long long memtoll(const char *p, int *err) {
|
139
|
+
const char *u;
|
140
|
+
char buf[128];
|
141
|
+
long mul; /* unit multiplier */
|
142
|
+
long long val;
|
143
|
+
unsigned int digits;
|
144
|
+
|
145
|
+
if (err) *err = 0;
|
146
|
+
/* Search the first non digit character. */
|
147
|
+
u = p;
|
148
|
+
if (*u == '-') u++;
|
149
|
+
while(*u && isdigit(*u)) u++;
|
150
|
+
if (*u == '\0' || !strcasecmp(u,"b")) {
|
151
|
+
mul = 1;
|
152
|
+
} else if (!strcasecmp(u,"k")) {
|
153
|
+
mul = 1000;
|
154
|
+
} else if (!strcasecmp(u,"kb")) {
|
155
|
+
mul = 1024;
|
156
|
+
} else if (!strcasecmp(u,"m")) {
|
157
|
+
mul = 1000*1000;
|
158
|
+
} else if (!strcasecmp(u,"mb")) {
|
159
|
+
mul = 1024*1024;
|
160
|
+
} else if (!strcasecmp(u,"g")) {
|
161
|
+
mul = 1000L*1000*1000;
|
162
|
+
} else if (!strcasecmp(u,"gb")) {
|
163
|
+
mul = 1024L*1024*1024;
|
164
|
+
} else {
|
165
|
+
if (err) *err = 1;
|
166
|
+
mul = 1;
|
167
|
+
}
|
168
|
+
digits = u-p;
|
169
|
+
if (digits >= sizeof(buf)) {
|
170
|
+
if (err) *err = 1;
|
171
|
+
return LLONG_MAX;
|
172
|
+
}
|
173
|
+
memcpy(buf,p,digits);
|
174
|
+
buf[digits] = '\0';
|
175
|
+
val = strtoll(buf,NULL,10);
|
176
|
+
return val*mul;
|
177
|
+
}
|
178
|
+
|
179
|
+
/* Convert a long long into a string. Returns the number of
|
180
|
+
* characters needed to represent the number, that can be shorter if passed
|
181
|
+
* buffer length is not enough to store the whole number. */
|
182
|
+
int ll2string(char *s, size_t len, long long value) {
|
183
|
+
char buf[32], *p;
|
184
|
+
unsigned long long v;
|
185
|
+
size_t l;
|
186
|
+
|
187
|
+
if (len == 0) return 0;
|
188
|
+
v = (value < 0) ? -value : value;
|
189
|
+
p = buf+31; /* point to the last character */
|
190
|
+
do {
|
191
|
+
*p-- = '0'+(v%10);
|
192
|
+
v /= 10;
|
193
|
+
} while(v);
|
194
|
+
if (value < 0) *p-- = '-';
|
195
|
+
p++;
|
196
|
+
l = 32-(p-buf);
|
197
|
+
if (l+1 > len) l = len-1; /* Make sure it fits, including the nul term */
|
198
|
+
memcpy(s,p,l);
|
199
|
+
s[l] = '\0';
|
200
|
+
return l;
|
201
|
+
}
|
202
|
+
|
203
|
+
/* Check if the sds string 's' can be represented by a long long
|
204
|
+
* (that is, is a number that fits into long without any other space or
|
205
|
+
* character before or after the digits, so that converting this number
|
206
|
+
* back to a string will result in the same bytes as the original string).
|
207
|
+
*
|
208
|
+
* If so, the function returns REDIS_OK and *llongval is set to the value
|
209
|
+
* of the number. Otherwise REDIS_ERR is returned */
|
210
|
+
int isStringRepresentableAsLongLong(sds s, long long *llongval) {
|
211
|
+
char buf[32], *endptr;
|
212
|
+
long long value;
|
213
|
+
int slen;
|
214
|
+
|
215
|
+
value = strtoll(s, &endptr, 10);
|
216
|
+
if (endptr[0] != '\0') return REDIS_ERR;
|
217
|
+
slen = ll2string(buf,32,value);
|
218
|
+
|
219
|
+
/* If the number converted back into a string is not identical
|
220
|
+
* then it's not possible to encode the string as integer */
|
221
|
+
if (sdslen(s) != (unsigned)slen || memcmp(buf,s,slen)) return REDIS_ERR;
|
222
|
+
if (llongval) *llongval = value;
|
223
|
+
return REDIS_OK;
|
224
|
+
}
|
225
|
+
|
226
|
+
int isStringRepresentableAsLong(sds s, long *longval) {
|
227
|
+
long long ll;
|
228
|
+
|
229
|
+
if (isStringRepresentableAsLongLong(s,&ll) == REDIS_ERR) return REDIS_ERR;
|
230
|
+
if (ll < LONG_MIN || ll > LONG_MAX) return REDIS_ERR;
|
231
|
+
*longval = (long)ll;
|
232
|
+
return REDIS_OK;
|
233
|
+
}
|
234
|
+
|
235
|
+
int isObjectRepresentableAsLongLong(robj *o, long long *llongval) {
|
236
|
+
redisAssert(o->type == REDIS_STRING);
|
237
|
+
if (o->encoding == REDIS_ENCODING_INT) {
|
238
|
+
if (llongval) *llongval = (long) o->ptr;
|
239
|
+
return REDIS_OK;
|
240
|
+
} else {
|
241
|
+
return isStringRepresentableAsLongLong(o->ptr,llongval);
|
242
|
+
}
|
243
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
#define REDIS_VERSION "2.2.11"
|
@@ -0,0 +1,1149 @@
|
|
1
|
+
#include "redis.h"
|
2
|
+
|
3
|
+
#include <fcntl.h>
|
4
|
+
#include <pthread.h>
|
5
|
+
#include <math.h>
|
6
|
+
#include <signal.h>
|
7
|
+
|
8
|
+
/* Virtual Memory is composed mainly of two subsystems:
|
9
|
+
* - Blocking Virutal Memory
|
10
|
+
* - Threaded Virtual Memory I/O
|
11
|
+
* The two parts are not fully decoupled, but functions are split among two
|
12
|
+
* different sections of the source code (delimited by comments) in order to
|
13
|
+
* make more clear what functionality is about the blocking VM and what about
|
14
|
+
* the threaded (not blocking) VM.
|
15
|
+
*
|
16
|
+
* Redis VM design:
|
17
|
+
*
|
18
|
+
* Redis VM is a blocking VM (one that blocks reading swapped values from
|
19
|
+
* disk into memory when a value swapped out is needed in memory) that is made
|
20
|
+
* unblocking by trying to examine the command argument vector in order to
|
21
|
+
* load in background values that will likely be needed in order to exec
|
22
|
+
* the command. The command is executed only once all the relevant keys
|
23
|
+
* are loaded into memory.
|
24
|
+
*
|
25
|
+
* This basically is almost as simple of a blocking VM, but almost as parallel
|
26
|
+
* as a fully non-blocking VM.
|
27
|
+
*/
|
28
|
+
|
29
|
+
/* =================== Virtual Memory - Blocking Side ====================== */
|
30
|
+
|
31
|
+
/* Create a VM pointer object. This kind of objects are used in place of
|
32
|
+
* values in the key -> value hash table, for swapped out objects. */
|
33
|
+
vmpointer *createVmPointer(int vtype) {
|
34
|
+
vmpointer *vp = zmalloc(sizeof(vmpointer));
|
35
|
+
|
36
|
+
vp->type = REDIS_VMPOINTER;
|
37
|
+
vp->storage = REDIS_VM_SWAPPED;
|
38
|
+
vp->vtype = vtype;
|
39
|
+
return vp;
|
40
|
+
}
|
41
|
+
|
42
|
+
void vmInit(void) {
|
43
|
+
off_t totsize;
|
44
|
+
int pipefds[2];
|
45
|
+
size_t stacksize;
|
46
|
+
struct flock fl;
|
47
|
+
|
48
|
+
if (server.vm_max_threads != 0)
|
49
|
+
zmalloc_enable_thread_safeness(); /* we need thread safe zmalloc() */
|
50
|
+
|
51
|
+
redisLog(REDIS_NOTICE,"Using '%s' as swap file",server.vm_swap_file);
|
52
|
+
/* Try to open the old swap file, otherwise create it */
|
53
|
+
if ((server.vm_fp = fopen(server.vm_swap_file,"r+b")) == NULL) {
|
54
|
+
server.vm_fp = fopen(server.vm_swap_file,"w+b");
|
55
|
+
}
|
56
|
+
if (server.vm_fp == NULL) {
|
57
|
+
redisLog(REDIS_WARNING,
|
58
|
+
"Can't open the swap file: %s. Exiting.",
|
59
|
+
strerror(errno));
|
60
|
+
exit(1);
|
61
|
+
}
|
62
|
+
server.vm_fd = fileno(server.vm_fp);
|
63
|
+
/* Lock the swap file for writing, this is useful in order to avoid
|
64
|
+
* another instance to use the same swap file for a config error. */
|
65
|
+
fl.l_type = F_WRLCK;
|
66
|
+
fl.l_whence = SEEK_SET;
|
67
|
+
fl.l_start = fl.l_len = 0;
|
68
|
+
if (fcntl(server.vm_fd,F_SETLK,&fl) == -1) {
|
69
|
+
redisLog(REDIS_WARNING,
|
70
|
+
"Can't lock the swap file at '%s': %s. Make sure it is not used by another Redis instance.", server.vm_swap_file, strerror(errno));
|
71
|
+
exit(1);
|
72
|
+
}
|
73
|
+
/* Initialize */
|
74
|
+
server.vm_next_page = 0;
|
75
|
+
server.vm_near_pages = 0;
|
76
|
+
server.vm_stats_used_pages = 0;
|
77
|
+
server.vm_stats_swapped_objects = 0;
|
78
|
+
server.vm_stats_swapouts = 0;
|
79
|
+
server.vm_stats_swapins = 0;
|
80
|
+
totsize = server.vm_pages*server.vm_page_size;
|
81
|
+
redisLog(REDIS_NOTICE,"Allocating %lld bytes of swap file",totsize);
|
82
|
+
if (ftruncate(server.vm_fd,totsize) == -1) {
|
83
|
+
redisLog(REDIS_WARNING,"Can't ftruncate swap file: %s. Exiting.",
|
84
|
+
strerror(errno));
|
85
|
+
exit(1);
|
86
|
+
} else {
|
87
|
+
redisLog(REDIS_NOTICE,"Swap file allocated with success");
|
88
|
+
}
|
89
|
+
server.vm_bitmap = zcalloc((server.vm_pages+7)/8);
|
90
|
+
redisLog(REDIS_VERBOSE,"Allocated %lld bytes page table for %lld pages",
|
91
|
+
(long long) (server.vm_pages+7)/8, server.vm_pages);
|
92
|
+
|
93
|
+
/* Initialize threaded I/O (used by Virtual Memory) */
|
94
|
+
server.io_newjobs = listCreate();
|
95
|
+
server.io_processing = listCreate();
|
96
|
+
server.io_processed = listCreate();
|
97
|
+
server.io_ready_clients = listCreate();
|
98
|
+
pthread_mutex_init(&server.io_mutex,NULL);
|
99
|
+
pthread_mutex_init(&server.io_swapfile_mutex,NULL);
|
100
|
+
server.io_active_threads = 0;
|
101
|
+
if (pipe(pipefds) == -1) {
|
102
|
+
redisLog(REDIS_WARNING,"Unable to intialized VM: pipe(2): %s. Exiting."
|
103
|
+
,strerror(errno));
|
104
|
+
exit(1);
|
105
|
+
}
|
106
|
+
server.io_ready_pipe_read = pipefds[0];
|
107
|
+
server.io_ready_pipe_write = pipefds[1];
|
108
|
+
redisAssert(anetNonBlock(NULL,server.io_ready_pipe_read) != ANET_ERR);
|
109
|
+
/* LZF requires a lot of stack */
|
110
|
+
pthread_attr_init(&server.io_threads_attr);
|
111
|
+
pthread_attr_getstacksize(&server.io_threads_attr, &stacksize);
|
112
|
+
|
113
|
+
/* Solaris may report a stacksize of 0, let's set it to 1 otherwise
|
114
|
+
* multiplying it by 2 in the while loop later will not really help ;) */
|
115
|
+
if (!stacksize) stacksize = 1;
|
116
|
+
|
117
|
+
while (stacksize < REDIS_THREAD_STACK_SIZE) stacksize *= 2;
|
118
|
+
pthread_attr_setstacksize(&server.io_threads_attr, stacksize);
|
119
|
+
/* Listen for events in the threaded I/O pipe */
|
120
|
+
if (aeCreateFileEvent(server.el, server.io_ready_pipe_read, AE_READABLE,
|
121
|
+
vmThreadedIOCompletedJob, NULL) == AE_ERR)
|
122
|
+
oom("creating file event");
|
123
|
+
}
|
124
|
+
|
125
|
+
/* Mark the page as used */
|
126
|
+
void vmMarkPageUsed(off_t page) {
|
127
|
+
off_t byte = page/8;
|
128
|
+
int bit = page&7;
|
129
|
+
redisAssert(vmFreePage(page) == 1);
|
130
|
+
server.vm_bitmap[byte] |= 1<<bit;
|
131
|
+
}
|
132
|
+
|
133
|
+
/* Mark N contiguous pages as used, with 'page' being the first. */
|
134
|
+
void vmMarkPagesUsed(off_t page, off_t count) {
|
135
|
+
off_t j;
|
136
|
+
|
137
|
+
for (j = 0; j < count; j++)
|
138
|
+
vmMarkPageUsed(page+j);
|
139
|
+
server.vm_stats_used_pages += count;
|
140
|
+
redisLog(REDIS_DEBUG,"Mark USED pages: %lld pages at %lld\n",
|
141
|
+
(long long)count, (long long)page);
|
142
|
+
}
|
143
|
+
|
144
|
+
/* Mark the page as free */
|
145
|
+
void vmMarkPageFree(off_t page) {
|
146
|
+
off_t byte = page/8;
|
147
|
+
int bit = page&7;
|
148
|
+
redisAssert(vmFreePage(page) == 0);
|
149
|
+
server.vm_bitmap[byte] &= ~(1<<bit);
|
150
|
+
}
|
151
|
+
|
152
|
+
/* Mark N contiguous pages as free, with 'page' being the first. */
|
153
|
+
void vmMarkPagesFree(off_t page, off_t count) {
|
154
|
+
off_t j;
|
155
|
+
|
156
|
+
for (j = 0; j < count; j++)
|
157
|
+
vmMarkPageFree(page+j);
|
158
|
+
server.vm_stats_used_pages -= count;
|
159
|
+
redisLog(REDIS_DEBUG,"Mark FREE pages: %lld pages at %lld\n",
|
160
|
+
(long long)count, (long long)page);
|
161
|
+
}
|
162
|
+
|
163
|
+
/* Test if the page is free */
|
164
|
+
int vmFreePage(off_t page) {
|
165
|
+
off_t byte = page/8;
|
166
|
+
int bit = page&7;
|
167
|
+
return (server.vm_bitmap[byte] & (1<<bit)) == 0;
|
168
|
+
}
|
169
|
+
|
170
|
+
/* Find N contiguous free pages storing the first page of the cluster in *first.
|
171
|
+
* Returns REDIS_OK if it was able to find N contiguous pages, otherwise
|
172
|
+
* REDIS_ERR is returned.
|
173
|
+
*
|
174
|
+
* This function uses a simple algorithm: we try to allocate
|
175
|
+
* REDIS_VM_MAX_NEAR_PAGES sequentially, when we reach this limit we start
|
176
|
+
* again from the start of the swap file searching for free spaces.
|
177
|
+
*
|
178
|
+
* If it looks pretty clear that there are no free pages near our offset
|
179
|
+
* we try to find less populated places doing a forward jump of
|
180
|
+
* REDIS_VM_MAX_RANDOM_JUMP, then we start scanning again a few pages
|
181
|
+
* without hurry, and then we jump again and so forth...
|
182
|
+
*
|
183
|
+
* This function can be improved using a free list to avoid to guess
|
184
|
+
* too much, since we could collect data about freed pages.
|
185
|
+
*
|
186
|
+
* note: I implemented this function just after watching an episode of
|
187
|
+
* Battlestar Galactica, where the hybrid was continuing to say "JUMP!"
|
188
|
+
*/
|
189
|
+
int vmFindContiguousPages(off_t *first, off_t n) {
|
190
|
+
off_t base, offset = 0, since_jump = 0, numfree = 0;
|
191
|
+
|
192
|
+
if (server.vm_near_pages == REDIS_VM_MAX_NEAR_PAGES) {
|
193
|
+
server.vm_near_pages = 0;
|
194
|
+
server.vm_next_page = 0;
|
195
|
+
}
|
196
|
+
server.vm_near_pages++; /* Yet another try for pages near to the old ones */
|
197
|
+
base = server.vm_next_page;
|
198
|
+
|
199
|
+
while(offset < server.vm_pages) {
|
200
|
+
off_t this = base+offset;
|
201
|
+
|
202
|
+
/* If we overflow, restart from page zero */
|
203
|
+
if (this >= server.vm_pages) {
|
204
|
+
this -= server.vm_pages;
|
205
|
+
if (this == 0) {
|
206
|
+
/* Just overflowed, what we found on tail is no longer
|
207
|
+
* interesting, as it's no longer contiguous. */
|
208
|
+
numfree = 0;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
if (vmFreePage(this)) {
|
212
|
+
/* This is a free page */
|
213
|
+
numfree++;
|
214
|
+
/* Already got N free pages? Return to the caller, with success */
|
215
|
+
if (numfree == n) {
|
216
|
+
*first = this-(n-1);
|
217
|
+
server.vm_next_page = this+1;
|
218
|
+
redisLog(REDIS_DEBUG, "FOUND CONTIGUOUS PAGES: %lld pages at %lld\n", (long long) n, (long long) *first);
|
219
|
+
return REDIS_OK;
|
220
|
+
}
|
221
|
+
} else {
|
222
|
+
/* The current one is not a free page */
|
223
|
+
numfree = 0;
|
224
|
+
}
|
225
|
+
|
226
|
+
/* Fast-forward if the current page is not free and we already
|
227
|
+
* searched enough near this place. */
|
228
|
+
since_jump++;
|
229
|
+
if (!numfree && since_jump >= REDIS_VM_MAX_RANDOM_JUMP/4) {
|
230
|
+
offset += random() % REDIS_VM_MAX_RANDOM_JUMP;
|
231
|
+
since_jump = 0;
|
232
|
+
/* Note that even if we rewind after the jump, we are don't need
|
233
|
+
* to make sure numfree is set to zero as we only jump *if* it
|
234
|
+
* is set to zero. */
|
235
|
+
} else {
|
236
|
+
/* Otherwise just check the next page */
|
237
|
+
offset++;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
return REDIS_ERR;
|
241
|
+
}
|
242
|
+
|
243
|
+
/* Write the specified object at the specified page of the swap file */
|
244
|
+
int vmWriteObjectOnSwap(robj *o, off_t page) {
|
245
|
+
if (server.vm_enabled) pthread_mutex_lock(&server.io_swapfile_mutex);
|
246
|
+
if (fseeko(server.vm_fp,page*server.vm_page_size,SEEK_SET) == -1) {
|
247
|
+
if (server.vm_enabled) pthread_mutex_unlock(&server.io_swapfile_mutex);
|
248
|
+
redisLog(REDIS_WARNING,
|
249
|
+
"Critical VM problem in vmWriteObjectOnSwap(): can't seek: %s",
|
250
|
+
strerror(errno));
|
251
|
+
return REDIS_ERR;
|
252
|
+
}
|
253
|
+
rdbSaveObject(server.vm_fp,o);
|
254
|
+
fflush(server.vm_fp);
|
255
|
+
if (server.vm_enabled) pthread_mutex_unlock(&server.io_swapfile_mutex);
|
256
|
+
return REDIS_OK;
|
257
|
+
}
|
258
|
+
|
259
|
+
/* Transfers the 'val' object to disk. Store all the information
|
260
|
+
* a 'vmpointer' object containing all the information needed to load the
|
261
|
+
* object back later is returned.
|
262
|
+
*
|
263
|
+
* If we can't find enough contiguous empty pages to swap the object on disk
|
264
|
+
* NULL is returned. */
|
265
|
+
vmpointer *vmSwapObjectBlocking(robj *val) {
|
266
|
+
off_t pages = rdbSavedObjectPages(val);
|
267
|
+
off_t page;
|
268
|
+
vmpointer *vp;
|
269
|
+
|
270
|
+
redisAssert(val->storage == REDIS_VM_MEMORY);
|
271
|
+
redisAssert(val->refcount == 1);
|
272
|
+
if (vmFindContiguousPages(&page,pages) == REDIS_ERR) return NULL;
|
273
|
+
if (vmWriteObjectOnSwap(val,page) == REDIS_ERR) return NULL;
|
274
|
+
|
275
|
+
vp = createVmPointer(val->type);
|
276
|
+
vp->page = page;
|
277
|
+
vp->usedpages = pages;
|
278
|
+
decrRefCount(val); /* Deallocate the object from memory. */
|
279
|
+
vmMarkPagesUsed(page,pages);
|
280
|
+
redisLog(REDIS_DEBUG,"VM: object %p swapped out at %lld (%lld pages)",
|
281
|
+
(void*) val,
|
282
|
+
(unsigned long long) page, (unsigned long long) pages);
|
283
|
+
server.vm_stats_swapped_objects++;
|
284
|
+
server.vm_stats_swapouts++;
|
285
|
+
return vp;
|
286
|
+
}
|
287
|
+
|
288
|
+
robj *vmReadObjectFromSwap(off_t page, int type) {
|
289
|
+
robj *o;
|
290
|
+
|
291
|
+
if (server.vm_enabled) pthread_mutex_lock(&server.io_swapfile_mutex);
|
292
|
+
if (fseeko(server.vm_fp,page*server.vm_page_size,SEEK_SET) == -1) {
|
293
|
+
redisLog(REDIS_WARNING,
|
294
|
+
"Unrecoverable VM problem in vmReadObjectFromSwap(): can't seek: %s",
|
295
|
+
strerror(errno));
|
296
|
+
_exit(1);
|
297
|
+
}
|
298
|
+
o = rdbLoadObject(type,server.vm_fp);
|
299
|
+
if (o == NULL) {
|
300
|
+
redisLog(REDIS_WARNING, "Unrecoverable VM problem in vmReadObjectFromSwap(): can't load object from swap file: %s", strerror(errno));
|
301
|
+
_exit(1);
|
302
|
+
}
|
303
|
+
if (server.vm_enabled) pthread_mutex_unlock(&server.io_swapfile_mutex);
|
304
|
+
return o;
|
305
|
+
}
|
306
|
+
|
307
|
+
/* Load the specified object from swap to memory.
|
308
|
+
* The newly allocated object is returned.
|
309
|
+
*
|
310
|
+
* If preview is true the unserialized object is returned to the caller but
|
311
|
+
* the pages are not marked as freed, nor the vp object is freed. */
|
312
|
+
robj *vmGenericLoadObject(vmpointer *vp, int preview) {
|
313
|
+
robj *val;
|
314
|
+
|
315
|
+
redisAssert(vp->type == REDIS_VMPOINTER &&
|
316
|
+
(vp->storage == REDIS_VM_SWAPPED || vp->storage == REDIS_VM_LOADING));
|
317
|
+
val = vmReadObjectFromSwap(vp->page,vp->vtype);
|
318
|
+
if (!preview) {
|
319
|
+
redisLog(REDIS_DEBUG, "VM: object %p loaded from disk", (void*)vp);
|
320
|
+
vmMarkPagesFree(vp->page,vp->usedpages);
|
321
|
+
zfree(vp);
|
322
|
+
server.vm_stats_swapped_objects--;
|
323
|
+
} else {
|
324
|
+
redisLog(REDIS_DEBUG, "VM: object %p previewed from disk", (void*)vp);
|
325
|
+
}
|
326
|
+
server.vm_stats_swapins++;
|
327
|
+
return val;
|
328
|
+
}
|
329
|
+
|
330
|
+
/* Plain object loading, from swap to memory.
|
331
|
+
*
|
332
|
+
* 'o' is actually a redisVmPointer structure that will be freed by the call.
|
333
|
+
* The return value is the loaded object. */
|
334
|
+
robj *vmLoadObject(robj *o) {
|
335
|
+
/* If we are loading the object in background, stop it, we
|
336
|
+
* need to load this object synchronously ASAP. */
|
337
|
+
if (o->storage == REDIS_VM_LOADING)
|
338
|
+
vmCancelThreadedIOJob(o);
|
339
|
+
return vmGenericLoadObject((vmpointer*)o,0);
|
340
|
+
}
|
341
|
+
|
342
|
+
/* Just load the value on disk, without to modify the key.
|
343
|
+
* This is useful when we want to perform some operation on the value
|
344
|
+
* without to really bring it from swap to memory, like while saving the
|
345
|
+
* dataset or rewriting the append only log. */
|
346
|
+
robj *vmPreviewObject(robj *o) {
|
347
|
+
return vmGenericLoadObject((vmpointer*)o,1);
|
348
|
+
}
|
349
|
+
|
350
|
+
/* How a good candidate is this object for swapping?
|
351
|
+
* The better candidate it is, the greater the returned value.
|
352
|
+
*
|
353
|
+
* Currently we try to perform a fast estimation of the object size in
|
354
|
+
* memory, and combine it with aging informations.
|
355
|
+
*
|
356
|
+
* Basically swappability = idle-time * log(estimated size)
|
357
|
+
*
|
358
|
+
* Bigger objects are preferred over smaller objects, but not
|
359
|
+
* proportionally, this is why we use the logarithm. This algorithm is
|
360
|
+
* just a first try and will probably be tuned later. */
|
361
|
+
double computeObjectSwappability(robj *o) {
|
362
|
+
/* actual age can be >= minage, but not < minage. As we use wrapping
|
363
|
+
* 21 bit clocks with minutes resolution for the LRU. */
|
364
|
+
time_t minage = estimateObjectIdleTime(o);
|
365
|
+
long asize = 0, elesize;
|
366
|
+
robj *ele;
|
367
|
+
list *l;
|
368
|
+
listNode *ln;
|
369
|
+
dict *d;
|
370
|
+
struct dictEntry *de;
|
371
|
+
int z;
|
372
|
+
|
373
|
+
if (minage <= 0) return 0;
|
374
|
+
switch(o->type) {
|
375
|
+
case REDIS_STRING:
|
376
|
+
if (o->encoding != REDIS_ENCODING_RAW) {
|
377
|
+
asize = sizeof(*o);
|
378
|
+
} else {
|
379
|
+
asize = sdslen(o->ptr)+sizeof(*o)+sizeof(long)*2;
|
380
|
+
}
|
381
|
+
break;
|
382
|
+
case REDIS_LIST:
|
383
|
+
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
|
384
|
+
asize = sizeof(*o)+ziplistSize(o->ptr);
|
385
|
+
} else {
|
386
|
+
l = o->ptr;
|
387
|
+
ln = listFirst(l);
|
388
|
+
asize = sizeof(list);
|
389
|
+
if (ln) {
|
390
|
+
ele = ln->value;
|
391
|
+
elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
|
392
|
+
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
|
393
|
+
asize += (sizeof(listNode)+elesize)*listLength(l);
|
394
|
+
}
|
395
|
+
}
|
396
|
+
break;
|
397
|
+
case REDIS_SET:
|
398
|
+
case REDIS_ZSET:
|
399
|
+
z = (o->type == REDIS_ZSET);
|
400
|
+
d = z ? ((zset*)o->ptr)->dict : o->ptr;
|
401
|
+
|
402
|
+
if (!z && o->encoding == REDIS_ENCODING_INTSET) {
|
403
|
+
intset *is = o->ptr;
|
404
|
+
asize = sizeof(*is)+is->encoding*is->length;
|
405
|
+
} else {
|
406
|
+
asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
|
407
|
+
if (z) asize += sizeof(zset)-sizeof(dict);
|
408
|
+
if (dictSize(d)) {
|
409
|
+
de = dictGetRandomKey(d);
|
410
|
+
ele = dictGetEntryKey(de);
|
411
|
+
elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
|
412
|
+
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
|
413
|
+
asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
|
414
|
+
if (z) asize += sizeof(zskiplistNode)*dictSize(d);
|
415
|
+
}
|
416
|
+
}
|
417
|
+
break;
|
418
|
+
case REDIS_HASH:
|
419
|
+
if (o->encoding == REDIS_ENCODING_ZIPMAP) {
|
420
|
+
unsigned char *p = zipmapRewind((unsigned char*)o->ptr);
|
421
|
+
unsigned int len = zipmapLen((unsigned char*)o->ptr);
|
422
|
+
unsigned int klen, vlen;
|
423
|
+
unsigned char *key, *val;
|
424
|
+
|
425
|
+
if ((p = zipmapNext(p,&key,&klen,&val,&vlen)) == NULL) {
|
426
|
+
klen = 0;
|
427
|
+
vlen = 0;
|
428
|
+
}
|
429
|
+
asize = len*(klen+vlen+3);
|
430
|
+
} else if (o->encoding == REDIS_ENCODING_HT) {
|
431
|
+
d = o->ptr;
|
432
|
+
asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
|
433
|
+
if (dictSize(d)) {
|
434
|
+
de = dictGetRandomKey(d);
|
435
|
+
ele = dictGetEntryKey(de);
|
436
|
+
elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
|
437
|
+
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
|
438
|
+
ele = dictGetEntryVal(de);
|
439
|
+
elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
|
440
|
+
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
|
441
|
+
asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
break;
|
445
|
+
}
|
446
|
+
return (double)minage*log(1+asize);
|
447
|
+
}
|
448
|
+
|
449
|
+
/* Try to swap an object that's a good candidate for swapping.
|
450
|
+
* Returns REDIS_OK if the object was swapped, REDIS_ERR if it's not possible
|
451
|
+
* to swap any object at all.
|
452
|
+
*
|
453
|
+
* If 'usethreaded' is true, Redis will try to swap the object in background
|
454
|
+
* using I/O threads. */
|
455
|
+
int vmSwapOneObject(int usethreads) {
|
456
|
+
int j, i;
|
457
|
+
struct dictEntry *best = NULL;
|
458
|
+
double best_swappability = 0;
|
459
|
+
redisDb *best_db = NULL;
|
460
|
+
robj *val;
|
461
|
+
sds key;
|
462
|
+
|
463
|
+
for (j = 0; j < server.dbnum; j++) {
|
464
|
+
redisDb *db = server.db+j;
|
465
|
+
/* Why maxtries is set to 100?
|
466
|
+
* Because this way (usually) we'll find 1 object even if just 1% - 2%
|
467
|
+
* are swappable objects */
|
468
|
+
int maxtries = 100;
|
469
|
+
|
470
|
+
if (dictSize(db->dict) == 0) continue;
|
471
|
+
for (i = 0; i < 5; i++) {
|
472
|
+
dictEntry *de;
|
473
|
+
double swappability;
|
474
|
+
|
475
|
+
if (maxtries) maxtries--;
|
476
|
+
de = dictGetRandomKey(db->dict);
|
477
|
+
val = dictGetEntryVal(de);
|
478
|
+
/* Only swap objects that are currently in memory.
|
479
|
+
*
|
480
|
+
* Also don't swap shared objects: not a good idea in general and
|
481
|
+
* we need to ensure that the main thread does not touch the
|
482
|
+
* object while the I/O thread is using it, but we can't
|
483
|
+
* control other keys without adding additional mutex. */
|
484
|
+
if (val->storage != REDIS_VM_MEMORY || val->refcount != 1) {
|
485
|
+
if (maxtries) i--; /* don't count this try */
|
486
|
+
continue;
|
487
|
+
}
|
488
|
+
swappability = computeObjectSwappability(val);
|
489
|
+
if (!best || swappability > best_swappability) {
|
490
|
+
best = de;
|
491
|
+
best_swappability = swappability;
|
492
|
+
best_db = db;
|
493
|
+
}
|
494
|
+
}
|
495
|
+
}
|
496
|
+
if (best == NULL) return REDIS_ERR;
|
497
|
+
key = dictGetEntryKey(best);
|
498
|
+
val = dictGetEntryVal(best);
|
499
|
+
|
500
|
+
redisLog(REDIS_DEBUG,"Key with best swappability: %s, %f",
|
501
|
+
key, best_swappability);
|
502
|
+
|
503
|
+
/* Swap it */
|
504
|
+
if (usethreads) {
|
505
|
+
robj *keyobj = createStringObject(key,sdslen(key));
|
506
|
+
vmSwapObjectThreaded(keyobj,val,best_db);
|
507
|
+
decrRefCount(keyobj);
|
508
|
+
return REDIS_OK;
|
509
|
+
} else {
|
510
|
+
vmpointer *vp;
|
511
|
+
|
512
|
+
if ((vp = vmSwapObjectBlocking(val)) != NULL) {
|
513
|
+
dictGetEntryVal(best) = vp;
|
514
|
+
return REDIS_OK;
|
515
|
+
} else {
|
516
|
+
return REDIS_ERR;
|
517
|
+
}
|
518
|
+
}
|
519
|
+
}
|
520
|
+
|
521
|
+
int vmSwapOneObjectBlocking() {
|
522
|
+
return vmSwapOneObject(0);
|
523
|
+
}
|
524
|
+
|
525
|
+
int vmSwapOneObjectThreaded() {
|
526
|
+
return vmSwapOneObject(1);
|
527
|
+
}
|
528
|
+
|
529
|
+
/* Return true if it's safe to swap out objects in a given moment.
|
530
|
+
* Basically we don't want to swap objects out while there is a BGSAVE
|
531
|
+
* or a BGAEOREWRITE running in backgroud. */
|
532
|
+
int vmCanSwapOut(void) {
|
533
|
+
return (server.bgsavechildpid == -1 && server.bgrewritechildpid == -1);
|
534
|
+
}
|
535
|
+
|
536
|
+
/* =================== Virtual Memory - Threaded I/O ======================= */
|
537
|
+
|
538
|
+
void freeIOJob(iojob *j) {
|
539
|
+
if ((j->type == REDIS_IOJOB_PREPARE_SWAP ||
|
540
|
+
j->type == REDIS_IOJOB_DO_SWAP ||
|
541
|
+
j->type == REDIS_IOJOB_LOAD) && j->val != NULL)
|
542
|
+
{
|
543
|
+
/* we fix the storage type, otherwise decrRefCount() will try to
|
544
|
+
* kill the I/O thread Job (that does no longer exists). */
|
545
|
+
if (j->val->storage == REDIS_VM_SWAPPING)
|
546
|
+
j->val->storage = REDIS_VM_MEMORY;
|
547
|
+
decrRefCount(j->val);
|
548
|
+
}
|
549
|
+
decrRefCount(j->key);
|
550
|
+
zfree(j);
|
551
|
+
}
|
552
|
+
|
553
|
+
/* Every time a thread finished a Job, it writes a byte into the write side
|
554
|
+
* of an unix pipe in order to "awake" the main thread, and this function
|
555
|
+
* is called.
|
556
|
+
*
|
557
|
+
* Note that this is called both by the event loop, when a I/O thread
|
558
|
+
* sends a byte in the notification pipe, and is also directly called from
|
559
|
+
* waitEmptyIOJobsQueue().
|
560
|
+
*
|
561
|
+
* In the latter case we don't want to swap more, so we use the
|
562
|
+
* "privdata" argument setting it to a not NULL value to signal this
|
563
|
+
* condition. */
|
564
|
+
void vmThreadedIOCompletedJob(aeEventLoop *el, int fd, void *privdata,
|
565
|
+
int mask)
|
566
|
+
{
|
567
|
+
char buf[1];
|
568
|
+
int retval, processed = 0, toprocess = -1, trytoswap = 1;
|
569
|
+
REDIS_NOTUSED(el);
|
570
|
+
REDIS_NOTUSED(mask);
|
571
|
+
REDIS_NOTUSED(privdata);
|
572
|
+
|
573
|
+
if (privdata != NULL) trytoswap = 0; /* check the comments above... */
|
574
|
+
|
575
|
+
/* For every byte we read in the read side of the pipe, there is one
|
576
|
+
* I/O job completed to process. */
|
577
|
+
while((retval = read(fd,buf,1)) == 1) {
|
578
|
+
iojob *j;
|
579
|
+
listNode *ln;
|
580
|
+
struct dictEntry *de;
|
581
|
+
|
582
|
+
redisLog(REDIS_DEBUG,"Processing I/O completed job");
|
583
|
+
|
584
|
+
/* Get the processed element (the oldest one) */
|
585
|
+
lockThreadedIO();
|
586
|
+
redisAssert(listLength(server.io_processed) != 0);
|
587
|
+
if (toprocess == -1) {
|
588
|
+
toprocess = (listLength(server.io_processed)*REDIS_MAX_COMPLETED_JOBS_PROCESSED)/100;
|
589
|
+
if (toprocess <= 0) toprocess = 1;
|
590
|
+
}
|
591
|
+
ln = listFirst(server.io_processed);
|
592
|
+
j = ln->value;
|
593
|
+
listDelNode(server.io_processed,ln);
|
594
|
+
unlockThreadedIO();
|
595
|
+
/* If this job is marked as canceled, just ignore it */
|
596
|
+
if (j->canceled) {
|
597
|
+
freeIOJob(j);
|
598
|
+
continue;
|
599
|
+
}
|
600
|
+
/* Post process it in the main thread, as there are things we
|
601
|
+
* can do just here to avoid race conditions and/or invasive locks */
|
602
|
+
redisLog(REDIS_DEBUG,"COMPLETED Job type: %d, ID %p, key: %s", j->type, (void*)j->id, (unsigned char*)j->key->ptr);
|
603
|
+
de = dictFind(j->db->dict,j->key->ptr);
|
604
|
+
redisAssert(de != NULL);
|
605
|
+
if (j->type == REDIS_IOJOB_LOAD) {
|
606
|
+
redisDb *db;
|
607
|
+
vmpointer *vp = dictGetEntryVal(de);
|
608
|
+
|
609
|
+
/* Key loaded, bring it at home */
|
610
|
+
vmMarkPagesFree(vp->page,vp->usedpages);
|
611
|
+
redisLog(REDIS_DEBUG, "VM: object %s loaded from disk (threaded)",
|
612
|
+
(unsigned char*) j->key->ptr);
|
613
|
+
server.vm_stats_swapped_objects--;
|
614
|
+
server.vm_stats_swapins++;
|
615
|
+
dictGetEntryVal(de) = j->val;
|
616
|
+
incrRefCount(j->val);
|
617
|
+
db = j->db;
|
618
|
+
/* Handle clients waiting for this key to be loaded. */
|
619
|
+
handleClientsBlockedOnSwappedKey(db,j->key);
|
620
|
+
freeIOJob(j);
|
621
|
+
zfree(vp);
|
622
|
+
} else if (j->type == REDIS_IOJOB_PREPARE_SWAP) {
|
623
|
+
/* Now we know the amount of pages required to swap this object.
|
624
|
+
* Let's find some space for it, and queue this task again
|
625
|
+
* rebranded as REDIS_IOJOB_DO_SWAP. */
|
626
|
+
if (!vmCanSwapOut() ||
|
627
|
+
vmFindContiguousPages(&j->page,j->pages) == REDIS_ERR)
|
628
|
+
{
|
629
|
+
/* Ooops... no space or we can't swap as there is
|
630
|
+
* a fork()ed Redis trying to save stuff on disk. */
|
631
|
+
j->val->storage = REDIS_VM_MEMORY; /* undo operation */
|
632
|
+
freeIOJob(j);
|
633
|
+
} else {
|
634
|
+
/* Note that we need to mark this pages as used now,
|
635
|
+
* if the job will be canceled, we'll mark them as freed
|
636
|
+
* again. */
|
637
|
+
vmMarkPagesUsed(j->page,j->pages);
|
638
|
+
j->type = REDIS_IOJOB_DO_SWAP;
|
639
|
+
lockThreadedIO();
|
640
|
+
queueIOJob(j);
|
641
|
+
unlockThreadedIO();
|
642
|
+
}
|
643
|
+
} else if (j->type == REDIS_IOJOB_DO_SWAP) {
|
644
|
+
vmpointer *vp;
|
645
|
+
|
646
|
+
/* Key swapped. We can finally free some memory. */
|
647
|
+
if (j->val->storage != REDIS_VM_SWAPPING) {
|
648
|
+
vmpointer *vp = (vmpointer*) j->id;
|
649
|
+
printf("storage: %d\n",vp->storage);
|
650
|
+
printf("key->name: %s\n",(char*)j->key->ptr);
|
651
|
+
printf("val: %p\n",(void*)j->val);
|
652
|
+
printf("val->type: %d\n",j->val->type);
|
653
|
+
printf("val->ptr: %s\n",(char*)j->val->ptr);
|
654
|
+
}
|
655
|
+
redisAssert(j->val->storage == REDIS_VM_SWAPPING);
|
656
|
+
vp = createVmPointer(j->val->type);
|
657
|
+
vp->page = j->page;
|
658
|
+
vp->usedpages = j->pages;
|
659
|
+
dictGetEntryVal(de) = vp;
|
660
|
+
/* Fix the storage otherwise decrRefCount will attempt to
|
661
|
+
* remove the associated I/O job */
|
662
|
+
j->val->storage = REDIS_VM_MEMORY;
|
663
|
+
decrRefCount(j->val);
|
664
|
+
redisLog(REDIS_DEBUG,
|
665
|
+
"VM: object %s swapped out at %lld (%lld pages) (threaded)",
|
666
|
+
(unsigned char*) j->key->ptr,
|
667
|
+
(unsigned long long) j->page, (unsigned long long) j->pages);
|
668
|
+
server.vm_stats_swapped_objects++;
|
669
|
+
server.vm_stats_swapouts++;
|
670
|
+
freeIOJob(j);
|
671
|
+
/* Put a few more swap requests in queue if we are still
|
672
|
+
* out of memory */
|
673
|
+
if (trytoswap && vmCanSwapOut() &&
|
674
|
+
zmalloc_used_memory() > server.vm_max_memory)
|
675
|
+
{
|
676
|
+
int more = 1;
|
677
|
+
while(more) {
|
678
|
+
lockThreadedIO();
|
679
|
+
more = listLength(server.io_newjobs) <
|
680
|
+
(unsigned) server.vm_max_threads;
|
681
|
+
unlockThreadedIO();
|
682
|
+
/* Don't waste CPU time if swappable objects are rare. */
|
683
|
+
if (vmSwapOneObjectThreaded() == REDIS_ERR) {
|
684
|
+
trytoswap = 0;
|
685
|
+
break;
|
686
|
+
}
|
687
|
+
}
|
688
|
+
}
|
689
|
+
}
|
690
|
+
processed++;
|
691
|
+
if (processed == toprocess) return;
|
692
|
+
}
|
693
|
+
if (retval < 0 && errno != EAGAIN) {
|
694
|
+
redisLog(REDIS_WARNING,
|
695
|
+
"WARNING: read(2) error in vmThreadedIOCompletedJob() %s",
|
696
|
+
strerror(errno));
|
697
|
+
}
|
698
|
+
}
|
699
|
+
|
700
|
+
void lockThreadedIO(void) {
|
701
|
+
pthread_mutex_lock(&server.io_mutex);
|
702
|
+
}
|
703
|
+
|
704
|
+
void unlockThreadedIO(void) {
|
705
|
+
pthread_mutex_unlock(&server.io_mutex);
|
706
|
+
}
|
707
|
+
|
708
|
+
/* Remove the specified object from the threaded I/O queue if still not
|
709
|
+
* processed, otherwise make sure to flag it as canceled. */
|
710
|
+
void vmCancelThreadedIOJob(robj *o) {
|
711
|
+
list *lists[3] = {
|
712
|
+
server.io_newjobs, /* 0 */
|
713
|
+
server.io_processing, /* 1 */
|
714
|
+
server.io_processed /* 2 */
|
715
|
+
};
|
716
|
+
int i;
|
717
|
+
|
718
|
+
redisAssert(o->storage == REDIS_VM_LOADING || o->storage == REDIS_VM_SWAPPING);
|
719
|
+
again:
|
720
|
+
lockThreadedIO();
|
721
|
+
/* Search for a matching object in one of the queues */
|
722
|
+
for (i = 0; i < 3; i++) {
|
723
|
+
listNode *ln;
|
724
|
+
listIter li;
|
725
|
+
|
726
|
+
listRewind(lists[i],&li);
|
727
|
+
while ((ln = listNext(&li)) != NULL) {
|
728
|
+
iojob *job = ln->value;
|
729
|
+
|
730
|
+
if (job->canceled) continue; /* Skip this, already canceled. */
|
731
|
+
if (job->id == o) {
|
732
|
+
redisLog(REDIS_DEBUG,"*** CANCELED %p (key %s) (type %d) (LIST ID %d)\n",
|
733
|
+
(void*)job, (char*)job->key->ptr, job->type, i);
|
734
|
+
/* Mark the pages as free since the swap didn't happened
|
735
|
+
* or happened but is now discarded. */
|
736
|
+
if (i != 1 && job->type == REDIS_IOJOB_DO_SWAP)
|
737
|
+
vmMarkPagesFree(job->page,job->pages);
|
738
|
+
/* Cancel the job. It depends on the list the job is
|
739
|
+
* living in. */
|
740
|
+
switch(i) {
|
741
|
+
case 0: /* io_newjobs */
|
742
|
+
/* If the job was yet not processed the best thing to do
|
743
|
+
* is to remove it from the queue at all */
|
744
|
+
freeIOJob(job);
|
745
|
+
listDelNode(lists[i],ln);
|
746
|
+
break;
|
747
|
+
case 1: /* io_processing */
|
748
|
+
/* Oh Shi- the thread is messing with the Job:
|
749
|
+
*
|
750
|
+
* Probably it's accessing the object if this is a
|
751
|
+
* PREPARE_SWAP or DO_SWAP job.
|
752
|
+
* If it's a LOAD job it may be reading from disk and
|
753
|
+
* if we don't wait for the job to terminate before to
|
754
|
+
* cancel it, maybe in a few microseconds data can be
|
755
|
+
* corrupted in this pages. So the short story is:
|
756
|
+
*
|
757
|
+
* Better to wait for the job to move into the
|
758
|
+
* next queue (processed)... */
|
759
|
+
|
760
|
+
/* We try again and again until the job is completed. */
|
761
|
+
unlockThreadedIO();
|
762
|
+
/* But let's wait some time for the I/O thread
|
763
|
+
* to finish with this job. After all this condition
|
764
|
+
* should be very rare. */
|
765
|
+
usleep(1);
|
766
|
+
goto again;
|
767
|
+
case 2: /* io_processed */
|
768
|
+
/* The job was already processed, that's easy...
|
769
|
+
* just mark it as canceled so that we'll ignore it
|
770
|
+
* when processing completed jobs. */
|
771
|
+
job->canceled = 1;
|
772
|
+
break;
|
773
|
+
}
|
774
|
+
/* Finally we have to adjust the storage type of the object
|
775
|
+
* in order to "UNDO" the operaiton. */
|
776
|
+
if (o->storage == REDIS_VM_LOADING)
|
777
|
+
o->storage = REDIS_VM_SWAPPED;
|
778
|
+
else if (o->storage == REDIS_VM_SWAPPING)
|
779
|
+
o->storage = REDIS_VM_MEMORY;
|
780
|
+
unlockThreadedIO();
|
781
|
+
redisLog(REDIS_DEBUG,"*** DONE");
|
782
|
+
return;
|
783
|
+
}
|
784
|
+
}
|
785
|
+
}
|
786
|
+
unlockThreadedIO();
|
787
|
+
printf("Not found: %p\n", (void*)o);
|
788
|
+
redisAssert(1 != 1); /* We should never reach this */
|
789
|
+
}
|
790
|
+
|
791
|
+
void *IOThreadEntryPoint(void *arg) {
|
792
|
+
iojob *j;
|
793
|
+
listNode *ln;
|
794
|
+
REDIS_NOTUSED(arg);
|
795
|
+
|
796
|
+
pthread_detach(pthread_self());
|
797
|
+
while(1) {
|
798
|
+
/* Get a new job to process */
|
799
|
+
lockThreadedIO();
|
800
|
+
if (listLength(server.io_newjobs) == 0) {
|
801
|
+
/* No new jobs in queue, exit. */
|
802
|
+
redisLog(REDIS_DEBUG,"Thread %ld exiting, nothing to do",
|
803
|
+
(long) pthread_self());
|
804
|
+
server.io_active_threads--;
|
805
|
+
unlockThreadedIO();
|
806
|
+
return NULL;
|
807
|
+
}
|
808
|
+
ln = listFirst(server.io_newjobs);
|
809
|
+
j = ln->value;
|
810
|
+
listDelNode(server.io_newjobs,ln);
|
811
|
+
/* Add the job in the processing queue */
|
812
|
+
j->thread = pthread_self();
|
813
|
+
listAddNodeTail(server.io_processing,j);
|
814
|
+
ln = listLast(server.io_processing); /* We use ln later to remove it */
|
815
|
+
unlockThreadedIO();
|
816
|
+
redisLog(REDIS_DEBUG,"Thread %ld got a new job (type %d): %p about key '%s'",
|
817
|
+
(long) pthread_self(), j->type, (void*)j, (char*)j->key->ptr);
|
818
|
+
|
819
|
+
/* Process the Job */
|
820
|
+
if (j->type == REDIS_IOJOB_LOAD) {
|
821
|
+
vmpointer *vp = (vmpointer*)j->id;
|
822
|
+
j->val = vmReadObjectFromSwap(j->page,vp->vtype);
|
823
|
+
} else if (j->type == REDIS_IOJOB_PREPARE_SWAP) {
|
824
|
+
j->pages = rdbSavedObjectPages(j->val);
|
825
|
+
} else if (j->type == REDIS_IOJOB_DO_SWAP) {
|
826
|
+
if (vmWriteObjectOnSwap(j->val,j->page) == REDIS_ERR)
|
827
|
+
j->canceled = 1;
|
828
|
+
}
|
829
|
+
|
830
|
+
/* Done: insert the job into the processed queue */
|
831
|
+
redisLog(REDIS_DEBUG,"Thread %ld completed the job: %p (key %s)",
|
832
|
+
(long) pthread_self(), (void*)j, (char*)j->key->ptr);
|
833
|
+
lockThreadedIO();
|
834
|
+
listDelNode(server.io_processing,ln);
|
835
|
+
listAddNodeTail(server.io_processed,j);
|
836
|
+
unlockThreadedIO();
|
837
|
+
|
838
|
+
/* Signal the main thread there is new stuff to process */
|
839
|
+
redisAssert(write(server.io_ready_pipe_write,"x",1) == 1);
|
840
|
+
}
|
841
|
+
return NULL; /* never reached */
|
842
|
+
}
|
843
|
+
|
844
|
+
void spawnIOThread(void) {
|
845
|
+
pthread_t thread;
|
846
|
+
sigset_t mask, omask;
|
847
|
+
int err;
|
848
|
+
|
849
|
+
sigemptyset(&mask);
|
850
|
+
sigaddset(&mask,SIGCHLD);
|
851
|
+
sigaddset(&mask,SIGHUP);
|
852
|
+
sigaddset(&mask,SIGPIPE);
|
853
|
+
pthread_sigmask(SIG_SETMASK, &mask, &omask);
|
854
|
+
while ((err = pthread_create(&thread,&server.io_threads_attr,IOThreadEntryPoint,NULL)) != 0) {
|
855
|
+
redisLog(REDIS_WARNING,"Unable to spawn an I/O thread: %s",
|
856
|
+
strerror(err));
|
857
|
+
usleep(1000000);
|
858
|
+
}
|
859
|
+
pthread_sigmask(SIG_SETMASK, &omask, NULL);
|
860
|
+
server.io_active_threads++;
|
861
|
+
}
|
862
|
+
|
863
|
+
/* We need to wait for the last thread to exit before we are able to
|
864
|
+
* fork() in order to BGSAVE or BGREWRITEAOF. */
|
865
|
+
void waitEmptyIOJobsQueue(void) {
|
866
|
+
while(1) {
|
867
|
+
int io_processed_len;
|
868
|
+
|
869
|
+
lockThreadedIO();
|
870
|
+
if (listLength(server.io_newjobs) == 0 &&
|
871
|
+
listLength(server.io_processing) == 0 &&
|
872
|
+
server.io_active_threads == 0)
|
873
|
+
{
|
874
|
+
unlockThreadedIO();
|
875
|
+
return;
|
876
|
+
}
|
877
|
+
/* While waiting for empty jobs queue condition we post-process some
|
878
|
+
* finshed job, as I/O threads may be hanging trying to write against
|
879
|
+
* the io_ready_pipe_write FD but there are so much pending jobs that
|
880
|
+
* it's blocking. */
|
881
|
+
io_processed_len = listLength(server.io_processed);
|
882
|
+
unlockThreadedIO();
|
883
|
+
if (io_processed_len) {
|
884
|
+
vmThreadedIOCompletedJob(NULL,server.io_ready_pipe_read,
|
885
|
+
(void*)0xdeadbeef,0);
|
886
|
+
usleep(1000); /* 1 millisecond */
|
887
|
+
} else {
|
888
|
+
usleep(10000); /* 10 milliseconds */
|
889
|
+
}
|
890
|
+
}
|
891
|
+
}
|
892
|
+
|
893
|
+
void vmReopenSwapFile(void) {
|
894
|
+
/* Note: we don't close the old one as we are in the child process
|
895
|
+
* and don't want to mess at all with the original file object. */
|
896
|
+
server.vm_fp = fopen(server.vm_swap_file,"r+b");
|
897
|
+
if (server.vm_fp == NULL) {
|
898
|
+
redisLog(REDIS_WARNING,"Can't re-open the VM swap file: %s. Exiting.",
|
899
|
+
server.vm_swap_file);
|
900
|
+
_exit(1);
|
901
|
+
}
|
902
|
+
server.vm_fd = fileno(server.vm_fp);
|
903
|
+
}
|
904
|
+
|
905
|
+
/* This function must be called while with threaded IO locked */
|
906
|
+
void queueIOJob(iojob *j) {
|
907
|
+
redisLog(REDIS_DEBUG,"Queued IO Job %p type %d about key '%s'\n",
|
908
|
+
(void*)j, j->type, (char*)j->key->ptr);
|
909
|
+
listAddNodeTail(server.io_newjobs,j);
|
910
|
+
if (server.io_active_threads < server.vm_max_threads)
|
911
|
+
spawnIOThread();
|
912
|
+
}
|
913
|
+
|
914
|
+
int vmSwapObjectThreaded(robj *key, robj *val, redisDb *db) {
|
915
|
+
iojob *j;
|
916
|
+
|
917
|
+
j = zmalloc(sizeof(*j));
|
918
|
+
j->type = REDIS_IOJOB_PREPARE_SWAP;
|
919
|
+
j->db = db;
|
920
|
+
j->key = key;
|
921
|
+
incrRefCount(key);
|
922
|
+
j->id = j->val = val;
|
923
|
+
incrRefCount(val);
|
924
|
+
j->canceled = 0;
|
925
|
+
j->thread = (pthread_t) -1;
|
926
|
+
val->storage = REDIS_VM_SWAPPING;
|
927
|
+
|
928
|
+
lockThreadedIO();
|
929
|
+
queueIOJob(j);
|
930
|
+
unlockThreadedIO();
|
931
|
+
return REDIS_OK;
|
932
|
+
}
|
933
|
+
|
934
|
+
/* ============ Virtual Memory - Blocking clients on missing keys =========== */
|
935
|
+
|
936
|
+
/* This function makes the clinet 'c' waiting for the key 'key' to be loaded.
|
937
|
+
* If there is not already a job loading the key, it is craeted.
|
938
|
+
* The key is added to the io_keys list in the client structure, and also
|
939
|
+
* in the hash table mapping swapped keys to waiting clients, that is,
|
940
|
+
* server.io_waited_keys. */
|
941
|
+
int waitForSwappedKey(redisClient *c, robj *key) {
|
942
|
+
struct dictEntry *de;
|
943
|
+
robj *o;
|
944
|
+
list *l;
|
945
|
+
|
946
|
+
/* If the key does not exist or is already in RAM we don't need to
|
947
|
+
* block the client at all. */
|
948
|
+
de = dictFind(c->db->dict,key->ptr);
|
949
|
+
if (de == NULL) return 0;
|
950
|
+
o = dictGetEntryVal(de);
|
951
|
+
if (o->storage == REDIS_VM_MEMORY) {
|
952
|
+
return 0;
|
953
|
+
} else if (o->storage == REDIS_VM_SWAPPING) {
|
954
|
+
/* We were swapping the key, undo it! */
|
955
|
+
vmCancelThreadedIOJob(o);
|
956
|
+
return 0;
|
957
|
+
}
|
958
|
+
|
959
|
+
/* OK: the key is either swapped, or being loaded just now. */
|
960
|
+
|
961
|
+
/* Add the key to the list of keys this client is waiting for.
|
962
|
+
* This maps clients to keys they are waiting for. */
|
963
|
+
listAddNodeTail(c->io_keys,key);
|
964
|
+
incrRefCount(key);
|
965
|
+
|
966
|
+
/* Add the client to the swapped keys => clients waiting map. */
|
967
|
+
de = dictFind(c->db->io_keys,key);
|
968
|
+
if (de == NULL) {
|
969
|
+
int retval;
|
970
|
+
|
971
|
+
/* For every key we take a list of clients blocked for it */
|
972
|
+
l = listCreate();
|
973
|
+
retval = dictAdd(c->db->io_keys,key,l);
|
974
|
+
incrRefCount(key);
|
975
|
+
redisAssert(retval == DICT_OK);
|
976
|
+
} else {
|
977
|
+
l = dictGetEntryVal(de);
|
978
|
+
}
|
979
|
+
listAddNodeTail(l,c);
|
980
|
+
|
981
|
+
/* Are we already loading the key from disk? If not create a job */
|
982
|
+
if (o->storage == REDIS_VM_SWAPPED) {
|
983
|
+
iojob *j;
|
984
|
+
vmpointer *vp = (vmpointer*)o;
|
985
|
+
|
986
|
+
o->storage = REDIS_VM_LOADING;
|
987
|
+
j = zmalloc(sizeof(*j));
|
988
|
+
j->type = REDIS_IOJOB_LOAD;
|
989
|
+
j->db = c->db;
|
990
|
+
j->id = (robj*)vp;
|
991
|
+
j->key = key;
|
992
|
+
incrRefCount(key);
|
993
|
+
j->page = vp->page;
|
994
|
+
j->val = NULL;
|
995
|
+
j->canceled = 0;
|
996
|
+
j->thread = (pthread_t) -1;
|
997
|
+
lockThreadedIO();
|
998
|
+
queueIOJob(j);
|
999
|
+
unlockThreadedIO();
|
1000
|
+
}
|
1001
|
+
return 1;
|
1002
|
+
}
|
1003
|
+
|
1004
|
+
/* Preload keys for any command with first, last and step values for
|
1005
|
+
* the command keys prototype, as defined in the command table. */
|
1006
|
+
void waitForMultipleSwappedKeys(redisClient *c, struct redisCommand *cmd, int argc, robj **argv) {
|
1007
|
+
int j, last;
|
1008
|
+
if (cmd->vm_firstkey == 0) return;
|
1009
|
+
last = cmd->vm_lastkey;
|
1010
|
+
if (last < 0) last = argc+last;
|
1011
|
+
for (j = cmd->vm_firstkey; j <= last; j += cmd->vm_keystep) {
|
1012
|
+
redisAssert(j < argc);
|
1013
|
+
waitForSwappedKey(c,argv[j]);
|
1014
|
+
}
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
/* Preload keys needed for the ZUNIONSTORE and ZINTERSTORE commands.
|
1018
|
+
* Note that the number of keys to preload is user-defined, so we need to
|
1019
|
+
* apply a sanity check against argc. */
|
1020
|
+
void zunionInterBlockClientOnSwappedKeys(redisClient *c, struct redisCommand *cmd, int argc, robj **argv) {
|
1021
|
+
int i, num;
|
1022
|
+
REDIS_NOTUSED(cmd);
|
1023
|
+
|
1024
|
+
num = atoi(argv[2]->ptr);
|
1025
|
+
if (num > (argc-3)) return;
|
1026
|
+
for (i = 0; i < num; i++) {
|
1027
|
+
waitForSwappedKey(c,argv[3+i]);
|
1028
|
+
}
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
/* Preload keys needed to execute the entire MULTI/EXEC block.
|
1032
|
+
*
|
1033
|
+
* This function is called by blockClientOnSwappedKeys when EXEC is issued,
|
1034
|
+
* and will block the client when any command requires a swapped out value. */
|
1035
|
+
void execBlockClientOnSwappedKeys(redisClient *c, struct redisCommand *cmd, int argc, robj **argv) {
|
1036
|
+
int i, margc;
|
1037
|
+
struct redisCommand *mcmd;
|
1038
|
+
robj **margv;
|
1039
|
+
REDIS_NOTUSED(cmd);
|
1040
|
+
REDIS_NOTUSED(argc);
|
1041
|
+
REDIS_NOTUSED(argv);
|
1042
|
+
|
1043
|
+
if (!(c->flags & REDIS_MULTI)) return;
|
1044
|
+
for (i = 0; i < c->mstate.count; i++) {
|
1045
|
+
mcmd = c->mstate.commands[i].cmd;
|
1046
|
+
margc = c->mstate.commands[i].argc;
|
1047
|
+
margv = c->mstate.commands[i].argv;
|
1048
|
+
|
1049
|
+
if (mcmd->vm_preload_proc != NULL) {
|
1050
|
+
mcmd->vm_preload_proc(c,mcmd,margc,margv);
|
1051
|
+
} else {
|
1052
|
+
waitForMultipleSwappedKeys(c,mcmd,margc,margv);
|
1053
|
+
}
|
1054
|
+
}
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
/* Is this client attempting to run a command against swapped keys?
|
1058
|
+
* If so, block it ASAP, load the keys in background, then resume it.
|
1059
|
+
*
|
1060
|
+
* The important idea about this function is that it can fail! If keys will
|
1061
|
+
* still be swapped when the client is resumed, this key lookups will
|
1062
|
+
* just block loading keys from disk. In practical terms this should only
|
1063
|
+
* happen with SORT BY command or if there is a bug in this function.
|
1064
|
+
*
|
1065
|
+
* Return 1 if the client is marked as blocked, 0 if the client can
|
1066
|
+
* continue as the keys it is going to access appear to be in memory. */
|
1067
|
+
int blockClientOnSwappedKeys(redisClient *c, struct redisCommand *cmd) {
|
1068
|
+
if (cmd->vm_preload_proc != NULL) {
|
1069
|
+
cmd->vm_preload_proc(c,cmd,c->argc,c->argv);
|
1070
|
+
} else {
|
1071
|
+
waitForMultipleSwappedKeys(c,cmd,c->argc,c->argv);
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
/* If the client was blocked for at least one key, mark it as blocked. */
|
1075
|
+
if (listLength(c->io_keys)) {
|
1076
|
+
c->flags |= REDIS_IO_WAIT;
|
1077
|
+
aeDeleteFileEvent(server.el,c->fd,AE_READABLE);
|
1078
|
+
server.vm_blocked_clients++;
|
1079
|
+
return 1;
|
1080
|
+
} else {
|
1081
|
+
return 0;
|
1082
|
+
}
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
/* Remove the 'key' from the list of blocked keys for a given client.
|
1086
|
+
*
|
1087
|
+
* The function returns 1 when there are no longer blocking keys after
|
1088
|
+
* the current one was removed (and the client can be unblocked). */
|
1089
|
+
int dontWaitForSwappedKey(redisClient *c, robj *key) {
|
1090
|
+
list *l;
|
1091
|
+
listNode *ln;
|
1092
|
+
listIter li;
|
1093
|
+
struct dictEntry *de;
|
1094
|
+
|
1095
|
+
/* The key object might be destroyed when deleted from the c->io_keys
|
1096
|
+
* list (and the "key" argument is physically the same object as the
|
1097
|
+
* object inside the list), so we need to protect it. */
|
1098
|
+
incrRefCount(key);
|
1099
|
+
|
1100
|
+
/* Remove the key from the list of keys this client is waiting for. */
|
1101
|
+
listRewind(c->io_keys,&li);
|
1102
|
+
while ((ln = listNext(&li)) != NULL) {
|
1103
|
+
if (equalStringObjects(ln->value,key)) {
|
1104
|
+
listDelNode(c->io_keys,ln);
|
1105
|
+
break;
|
1106
|
+
}
|
1107
|
+
}
|
1108
|
+
redisAssert(ln != NULL);
|
1109
|
+
|
1110
|
+
/* Remove the client form the key => waiting clients map. */
|
1111
|
+
de = dictFind(c->db->io_keys,key);
|
1112
|
+
redisAssert(de != NULL);
|
1113
|
+
l = dictGetEntryVal(de);
|
1114
|
+
ln = listSearchKey(l,c);
|
1115
|
+
redisAssert(ln != NULL);
|
1116
|
+
listDelNode(l,ln);
|
1117
|
+
if (listLength(l) == 0)
|
1118
|
+
dictDelete(c->db->io_keys,key);
|
1119
|
+
|
1120
|
+
decrRefCount(key);
|
1121
|
+
return listLength(c->io_keys) == 0;
|
1122
|
+
}
|
1123
|
+
|
1124
|
+
/* Every time we now a key was loaded back in memory, we handle clients
|
1125
|
+
* waiting for this key if any. */
|
1126
|
+
void handleClientsBlockedOnSwappedKey(redisDb *db, robj *key) {
|
1127
|
+
struct dictEntry *de;
|
1128
|
+
list *l;
|
1129
|
+
listNode *ln;
|
1130
|
+
int len;
|
1131
|
+
|
1132
|
+
de = dictFind(db->io_keys,key);
|
1133
|
+
if (!de) return;
|
1134
|
+
|
1135
|
+
l = dictGetEntryVal(de);
|
1136
|
+
len = listLength(l);
|
1137
|
+
/* Note: we can't use something like while(listLength(l)) as the list
|
1138
|
+
* can be freed by the calling function when we remove the last element. */
|
1139
|
+
while (len--) {
|
1140
|
+
ln = listFirst(l);
|
1141
|
+
redisClient *c = ln->value;
|
1142
|
+
|
1143
|
+
if (dontWaitForSwappedKey(c,key)) {
|
1144
|
+
/* Put the client in the list of clients ready to go as we
|
1145
|
+
* loaded all the keys about it. */
|
1146
|
+
listAddNodeTail(server.io_ready_clients,c);
|
1147
|
+
}
|
1148
|
+
}
|
1149
|
+
}
|