{"action":"created","comment":{"url":"https://api.github.com/repos/pmem/redis/pulls/comments/22645637","id":22645637,"diff_hunk":"@@ -1184,99 +1615,174 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {\n         latencyStartMonitor(latency);\n         snprintf(tmpfile,256,\"temp-rewriteaof-bg-%d.aof\",\n             (int)server.aof_child_pid);\n-        newfd = open(tmpfile,O_WRONLY|O_APPEND);\n-        if (newfd == -1) {\n-            redisLog(REDIS_WARNING,\n-                \"Unable to open the temporary AOF produced by the child: %s\", strerror(errno));\n-            goto cleanup;\n-        }\n \n-        if (aofRewriteBufferWrite(newfd) == -1) {\n-            redisLog(REDIS_WARNING,\n-                \"Error trying to flush the parent diff to the rewritten AOF: %s\", strerror(errno));\n-            close(newfd);\n-            goto cleanup;\n-        }\n-        latencyEndMonitor(latency);\n-        latencyAddSampleIfNeeded(\"aof-rewrite-diff-write\",latency);\n-\n-        redisLog(REDIS_NOTICE,\n-            \"Parent diff successfully flushed to the rewritten AOF (%lu bytes)\", aofRewriteBufferSize());\n-\n-        /* The only remaining thing to do is to rename the temporary file to\n-         * the configured file and switch the file descriptor used to do AOF\n-         * writes. We don't want close(2) or rename(2) calls to block the\n-         * server on old file deletion.\n-         *\n-         * There are two possible scenarios:\n-         *\n-         * 1) AOF is DISABLED and this was a one time rewrite. The temporary\n-         * file will be renamed to the configured file. When this file already\n-         * exists, it will be unlinked, which may block the server.\n-         *\n-         * 2) AOF is ENABLED and the rewritten AOF will immediately start\n-         * receiving writes. After the temporary file is renamed to the\n-         * configured file, the original AOF file descriptor will be closed.\n-         * Since this will be the last reference to that file, closing it\n-         * causes the underlying file to be unlinked, which may block the\n-         * server.\n-         *\n-         * To mitigate the blocking effect of the unlink operation (either\n-         * caused by rename(2) in scenario 1, or by close(2) in scenario 2), we\n-         * use a background thread to take care of this. First, we\n-         * make scenario 1 identical to scenario 2 by opening the target file\n-         * when it exists. The unlink operation after the rename(2) will then\n-         * be executed upon calling close(2) for its descriptor. Everything to\n-         * guarantee atomicity for this switch has already happened by then, so\n-         * we don't care what the outcome or duration of that close operation\n-         * is, as long as the file descriptor is released again. */\n-        if (server.aof_fd == -1) {\n-            /* AOF disabled */\n+#ifdef USE_NVML\n+        if (server.aof_use_nvml == 1) {\n+            /*size_t real_log_rewr_size; */\n+            if (server.aof_nvml_direct == 1) {\n+                pmemlog_walk(server.aof_plp, 0, copyDiffPMEMlog, NULL);\n+            } else {\n+                if (aofRewriteBufferWritePMEMlog(server.aof_plp_rewr) == -1) {\n+                    redisLog(REDIS_WARNING,\n+                        \"Error trying to flush the parent diff to the rewritten AOF: %s\", strerror(errno));\n+                    goto cleanup;\n+                }\n+            }\n+            latencyEndMonitor(latency);\n+            latencyAddSampleIfNeeded(\"aof-rewrite-diff-write\",latency);\n+\n+            redisLog(REDIS_NOTICE,\n+                \"Parent diff successfully flushed to the rewritten AOF (%lu bytes)\", aofRewriteBufferSize());\n+\n+            /* swap filenames, swap fd's  and plp's */\n+            latencyStartMonitor(latency);\n+            snprintf(tmpfile, 256, \"aof-rewrite-swap-%d.aof\", getpid());\n+            if (rename (server.aof_filename, tmpfile) == -1) {\n+                redisLog(REDIS_WARNING, \"Redis cannot rename AOF to temporary file: %s\",\n+                        strerror(errno));\n+                goto cleanup;\n+            }\n+            if (rename(server.aof_filename_rewr, server.aof_filename) == -1) {\n+                redisLog(REDIS_WARNING, \"Redis cannot rename AOF rewrite file to AOF: %s\",\n+                        strerror(errno));\n+                goto cleanup;\n+            }\n+            if (rename(tmpfile, server.aof_filename_rewr) == -1) {\n+                redisLog(REDIS_WARNING, \"Redis cannot rename temporary file to AOF rewrite: %s\",\n+                        strerror(errno));\n+                goto cleanup;\n+            }\n+            latencyEndMonitor(latency);\n+            latencyAddSampleIfNeeded(\"aof-rename\",latency);\n+\n+            if (server.aof_state != REDIS_AOF_OFF) {\n+\n+                PMEMlogpool *tmp_plp = server.aof_plp;\n+                server.aof_plp = server.aof_plp_rewr;\n+                server.aof_plp_rewr = tmp_plp;\n+\n+                /* compute real size of rewrite file, if it's different, than configured\n+                 * the reopen file */\n+                if ((pmemlog_tell(server.aof_plp) + pmemlog_nbyte(server.aof_plp)) !=","path":"src/aof.c","position":794,"original_position":794,"commit_id":"aa011ecad996f023fa1322feaf7d238d7d088a97","original_commit_id":"aa011ecad996f023fa1322feaf7d238d7d088a97","user":{"login":"lukasredynk","id":8236208,"avatar_url":"https://avatars.githubusercontent.com/u/8236208?v=3","gravatar_id":"","url":"https://api.github.com/users/lukasredynk","html_url":"https://github.com/lukasredynk","followers_url":"https://api.github.com/users/lukasredynk/followers","following_url":"https://api.github.com/users/lukasredynk/following{/other_user}","gists_url":"https://api.github.com/users/lukasredynk/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasredynk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasredynk/subscriptions","organizations_url":"https://api.github.com/users/lukasredynk/orgs","repos_url":"https://api.github.com/users/lukasredynk/repos","events_url":"https://api.github.com/users/lukasredynk/events{/privacy}","received_events_url":"https://api.github.com/users/lukasredynk/received_events","type":"User","site_admin":false},"body":"1) You're right, pmemlog_tell() shouldn't be here.\r\n2) Because configured pool size is different than usable space after pool creation.","created_at":"2015-01-08T10:59:02Z","updated_at":"2015-01-08T10:59:02Z","html_url":"https://github.com/pmem/redis/pull/1#discussion_r22645637","pull_request_url":"https://api.github.com/repos/pmem/redis/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/pmem/redis/pulls/comments/22645637"},"html":{"href":"https://github.com/pmem/redis/pull/1#discussion_r22645637"},"pull_request":{"href":"https://api.github.com/repos/pmem/redis/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/pmem/redis/pulls/1","id":26821899,"html_url":"https://github.com/pmem/redis/pull/1","diff_url":"https://github.com/pmem/redis/pull/1.diff","patch_url":"https://github.com/pmem/redis/pull/1.patch","issue_url":"https://api.github.com/repos/pmem/redis/issues/1","number":1,"state":"open","locked":false,"title":"2.8 aof nvml","user":{"login":"lukasredynk","id":8236208,"avatar_url":"https://avatars.githubusercontent.com/u/8236208?v=3","gravatar_id":"","url":"https://api.github.com/users/lukasredynk","html_url":"https://github.com/lukasredynk","followers_url":"https://api.github.com/users/lukasredynk/followers","following_url":"https://api.github.com/users/lukasredynk/following{/other_user}","gists_url":"https://api.github.com/users/lukasredynk/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasredynk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasredynk/subscriptions","organizations_url":"https://api.github.com/users/lukasredynk/orgs","repos_url":"https://api.github.com/users/lukasredynk/repos","events_url":"https://api.github.com/users/lukasredynk/events{/privacy}","received_events_url":"https://api.github.com/users/lukasredynk/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-05T12:53:43Z","updated_at":"2015-01-08T10:59:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e8e6c36d8ae058d83144295818845a2819d13677","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pmem/redis/pulls/1/commits","review_comments_url":"https://api.github.com/repos/pmem/redis/pulls/1/comments","review_comment_url":"https://api.github.com/repos/pmem/redis/pulls/comments/{number}","comments_url":"https://api.github.com/repos/pmem/redis/issues/1/comments","statuses_url":"https://api.github.com/repos/pmem/redis/statuses/aa011ecad996f023fa1322feaf7d238d7d088a97","head":{"label":"lukasredynk:2.8-aof-nvml","ref":"2.8-aof-nvml","sha":"aa011ecad996f023fa1322feaf7d238d7d088a97","user":{"login":"lukasredynk","id":8236208,"avatar_url":"https://avatars.githubusercontent.com/u/8236208?v=3","gravatar_id":"","url":"https://api.github.com/users/lukasredynk","html_url":"https://github.com/lukasredynk","followers_url":"https://api.github.com/users/lukasredynk/followers","following_url":"https://api.github.com/users/lukasredynk/following{/other_user}","gists_url":"https://api.github.com/users/lukasredynk/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasredynk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasredynk/subscriptions","organizations_url":"https://api.github.com/users/lukasredynk/orgs","repos_url":"https://api.github.com/users/lukasredynk/repos","events_url":"https://api.github.com/users/lukasredynk/events{/privacy}","received_events_url":"https://api.github.com/users/lukasredynk/received_events","type":"User","site_admin":false},"repo":{"id":28029903,"name":"redis","full_name":"lukasredynk/redis","owner":{"login":"lukasredynk","id":8236208,"avatar_url":"https://avatars.githubusercontent.com/u/8236208?v=3","gravatar_id":"","url":"https://api.github.com/users/lukasredynk","html_url":"https://github.com/lukasredynk","followers_url":"https://api.github.com/users/lukasredynk/followers","following_url":"https://api.github.com/users/lukasredynk/following{/other_user}","gists_url":"https://api.github.com/users/lukasredynk/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasredynk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasredynk/subscriptions","organizations_url":"https://api.github.com/users/lukasredynk/orgs","repos_url":"https://api.github.com/users/lukasredynk/repos","events_url":"https://api.github.com/users/lukasredynk/events{/privacy}","received_events_url":"https://api.github.com/users/lukasredynk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lukasredynk/redis","description":"Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, HyperLogLogs, Bitmaps.","fork":true,"url":"https://api.github.com/repos/lukasredynk/redis","forks_url":"https://api.github.com/repos/lukasredynk/redis/forks","keys_url":"https://api.github.com/repos/lukasredynk/redis/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lukasredynk/redis/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lukasredynk/redis/teams","hooks_url":"https://api.github.com/repos/lukasredynk/redis/hooks","issue_events_url":"https://api.github.com/repos/lukasredynk/redis/issues/events{/number}","events_url":"https://api.github.com/repos/lukasredynk/redis/events","assignees_url":"https://api.github.com/repos/lukasredynk/redis/assignees{/user}","branches_url":"https://api.github.com/repos/lukasredynk/redis/branches{/branch}","tags_url":"https://api.github.com/repos/lukasredynk/redis/tags","blobs_url":"https://api.github.com/repos/lukasredynk/redis/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lukasredynk/redis/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lukasredynk/redis/git/refs{/sha}","trees_url":"https://api.github.com/repos/lukasredynk/redis/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lukasredynk/redis/statuses/{sha}","languages_url":"https://api.github.com/repos/lukasredynk/redis/languages","stargazers_url":"https://api.github.com/repos/lukasredynk/redis/stargazers","contributors_url":"https://api.github.com/repos/lukasredynk/redis/contributors","subscribers_url":"https://api.github.com/repos/lukasredynk/redis/subscribers","subscription_url":"https://api.github.com/repos/lukasredynk/redis/subscription","commits_url":"https://api.github.com/repos/lukasredynk/redis/commits{/sha}","git_commits_url":"https://api.github.com/repos/lukasredynk/redis/git/commits{/sha}","comments_url":"https://api.github.com/repos/lukasredynk/redis/comments{/number}","issue_comment_url":"https://api.github.com/repos/lukasredynk/redis/issues/comments/{number}","contents_url":"https://api.github.com/repos/lukasredynk/redis/contents/{+path}","compare_url":"https://api.github.com/repos/lukasredynk/redis/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lukasredynk/redis/merges","archive_url":"https://api.github.com/repos/lukasredynk/redis/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lukasredynk/redis/downloads","issues_url":"https://api.github.com/repos/lukasredynk/redis/issues{/number}","pulls_url":"https://api.github.com/repos/lukasredynk/redis/pulls{/number}","milestones_url":"https://api.github.com/repos/lukasredynk/redis/milestones{/number}","notifications_url":"https://api.github.com/repos/lukasredynk/redis/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lukasredynk/redis/labels{/name}","releases_url":"https://api.github.com/repos/lukasredynk/redis/releases{/id}","created_at":"2014-12-15T09:36:44Z","updated_at":"2014-12-15T09:36:49Z","pushed_at":"2015-01-05T12:53:11Z","git_url":"git://github.com/lukasredynk/redis.git","ssh_url":"git@github.com:lukasredynk/redis.git","clone_url":"https://github.com/lukasredynk/redis.git","svn_url":"https://github.com/lukasredynk/redis","homepage":"http://redis.io","size":18439,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"unstable"}},"base":{"label":"pmem:2.8-nvml","ref":"2.8-nvml","sha":"22a0fe8de65124839d567f0d2f57f1dceced7e73","user":{"login":"pmem","id":4894933,"avatar_url":"https://avatars.githubusercontent.com/u/4894933?v=3","gravatar_id":"","url":"https://api.github.com/users/pmem","html_url":"https://github.com/pmem","followers_url":"https://api.github.com/users/pmem/followers","following_url":"https://api.github.com/users/pmem/following{/other_user}","gists_url":"https://api.github.com/users/pmem/gists{/gist_id}","starred_url":"https://api.github.com/users/pmem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmem/subscriptions","organizations_url":"https://api.github.com/users/pmem/orgs","repos_url":"https://api.github.com/users/pmem/repos","events_url":"https://api.github.com/users/pmem/events{/privacy}","received_events_url":"https://api.github.com/users/pmem/received_events","type":"Organization","site_admin":false},"repo":{"id":27923917,"name":"redis","full_name":"pmem/redis","owner":{"login":"pmem","id":4894933,"avatar_url":"https://avatars.githubusercontent.com/u/4894933?v=3","gravatar_id":"","url":"https://api.github.com/users/pmem","html_url":"https://github.com/pmem","followers_url":"https://api.github.com/users/pmem/followers","following_url":"https://api.github.com/users/pmem/following{/other_user}","gists_url":"https://api.github.com/users/pmem/gists{/gist_id}","starred_url":"https://api.github.com/users/pmem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmem/subscriptions","organizations_url":"https://api.github.com/users/pmem/orgs","repos_url":"https://api.github.com/users/pmem/repos","events_url":"https://api.github.com/users/pmem/events{/privacy}","received_events_url":"https://api.github.com/users/pmem/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pmem/redis","description":"Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, HyperLogLogs, Bitmaps.","fork":true,"url":"https://api.github.com/repos/pmem/redis","forks_url":"https://api.github.com/repos/pmem/redis/forks","keys_url":"https://api.github.com/repos/pmem/redis/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pmem/redis/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pmem/redis/teams","hooks_url":"https://api.github.com/repos/pmem/redis/hooks","issue_events_url":"https://api.github.com/repos/pmem/redis/issues/events{/number}","events_url":"https://api.github.com/repos/pmem/redis/events","assignees_url":"https://api.github.com/repos/pmem/redis/assignees{/user}","branches_url":"https://api.github.com/repos/pmem/redis/branches{/branch}","tags_url":"https://api.github.com/repos/pmem/redis/tags","blobs_url":"https://api.github.com/repos/pmem/redis/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pmem/redis/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pmem/redis/git/refs{/sha}","trees_url":"https://api.github.com/repos/pmem/redis/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pmem/redis/statuses/{sha}","languages_url":"https://api.github.com/repos/pmem/redis/languages","stargazers_url":"https://api.github.com/repos/pmem/redis/stargazers","contributors_url":"https://api.github.com/repos/pmem/redis/contributors","subscribers_url":"https://api.github.com/repos/pmem/redis/subscribers","subscription_url":"https://api.github.com/repos/pmem/redis/subscription","commits_url":"https://api.github.com/repos/pmem/redis/commits{/sha}","git_commits_url":"https://api.github.com/repos/pmem/redis/git/commits{/sha}","comments_url":"https://api.github.com/repos/pmem/redis/comments{/number}","issue_comment_url":"https://api.github.com/repos/pmem/redis/issues/comments/{number}","contents_url":"https://api.github.com/repos/pmem/redis/contents/{+path}","compare_url":"https://api.github.com/repos/pmem/redis/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pmem/redis/merges","archive_url":"https://api.github.com/repos/pmem/redis/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pmem/redis/downloads","issues_url":"https://api.github.com/repos/pmem/redis/issues{/number}","pulls_url":"https://api.github.com/repos/pmem/redis/pulls{/number}","milestones_url":"https://api.github.com/repos/pmem/redis/milestones{/number}","notifications_url":"https://api.github.com/repos/pmem/redis/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pmem/redis/labels{/name}","releases_url":"https://api.github.com/repos/pmem/redis/releases{/id}","created_at":"2014-12-12T14:36:15Z","updated_at":"2015-01-07T12:34:19Z","pushed_at":"2015-01-07T12:34:18Z","git_url":"git://github.com/pmem/redis.git","ssh_url":"git@github.com:pmem/redis.git","clone_url":"https://github.com/pmem/redis.git","svn_url":"https://github.com/pmem/redis","homepage":"http://redis.io","size":18436,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"2.8-nvml"}},"_links":{"self":{"href":"https://api.github.com/repos/pmem/redis/pulls/1"},"html":{"href":"https://github.com/pmem/redis/pull/1"},"issue":{"href":"https://api.github.com/repos/pmem/redis/issues/1"},"comments":{"href":"https://api.github.com/repos/pmem/redis/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/pmem/redis/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/pmem/redis/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/pmem/redis/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/pmem/redis/statuses/aa011ecad996f023fa1322feaf7d238d7d088a97"}}}}