{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/rocksdb/pulls/comments/39301135","id":39301135,"diff_hunk":"@@ -0,0 +1,154 @@\n+//  Copyright (c) 2013, Facebook, Inc.  All rights reserved.\n+//  This source code is licensed under the BSD-style license found in the\n+//  LICENSE file in the root directory of this source tree. An additional grant\n+//  of patent rights can be found in the PATENTS file in the same directory.\n+//\n+// Copyright (c) 2011 The LevelDB Authors. All rights reserved.\n+// Use of this source code is governed by a BSD-style license that can be\n+// found in the LICENSE file. See the AUTHORS file for names of contributors.\n+#pragma once\n+\n+#include <algorithm>\n+#include \"port/port.h\"\n+\n+namespace rocksdb {\n+\n+inline size_t TruncateToPageBoundary(size_t page_size, size_t s) {","path":"util/aligned_buffer.h","position":16,"original_position":16,"commit_id":"30e82d5c411d8d57c24fa98f955ab14f10e2a3d2","original_commit_id":"30e82d5c411d8d57c24fa98f955ab14f10e2a3d2","user":{"login":"yuslepukhin","id":11303988,"avatar_url":"https://avatars.githubusercontent.com/u/11303988?v=3","gravatar_id":"","url":"https://api.github.com/users/yuslepukhin","html_url":"https://github.com/yuslepukhin","followers_url":"https://api.github.com/users/yuslepukhin/followers","following_url":"https://api.github.com/users/yuslepukhin/following{/other_user}","gists_url":"https://api.github.com/users/yuslepukhin/gists{/gist_id}","starred_url":"https://api.github.com/users/yuslepukhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuslepukhin/subscriptions","organizations_url":"https://api.github.com/users/yuslepukhin/orgs","repos_url":"https://api.github.com/users/yuslepukhin/repos","events_url":"https://api.github.com/users/yuslepukhin/events{/privacy}","received_events_url":"https://api.github.com/users/yuslepukhin/received_events","type":"User","site_admin":false},"body":"@siying I do not mind but some compilers/linkers would produce a duplicate definition error.","created_at":"2015-09-11T18:24:04Z","updated_at":"2015-09-11T18:24:04Z","html_url":"https://github.com/facebook/rocksdb/pull/716#discussion_r39301135","pull_request_url":"https://api.github.com/repos/facebook/rocksdb/pulls/716","_links":{"self":{"href":"https://api.github.com/repos/facebook/rocksdb/pulls/comments/39301135"},"html":{"href":"https://github.com/facebook/rocksdb/pull/716#discussion_r39301135"},"pull_request":{"href":"https://api.github.com/repos/facebook/rocksdb/pulls/716"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/rocksdb/pulls/716","id":44806302,"html_url":"https://github.com/facebook/rocksdb/pull/716","diff_url":"https://github.com/facebook/rocksdb/pull/716.diff","patch_url":"https://github.com/facebook/rocksdb/pull/716.patch","issue_url":"https://api.github.com/repos/facebook/rocksdb/issues/716","number":716,"state":"open","locked":false,"title":"Refactor to support file_reader_writer on Windows.","user":{"login":"yuslepukhin","id":11303988,"avatar_url":"https://avatars.githubusercontent.com/u/11303988?v=3","gravatar_id":"","url":"https://api.github.com/users/yuslepukhin","html_url":"https://github.com/yuslepukhin","followers_url":"https://api.github.com/users/yuslepukhin/followers","following_url":"https://api.github.com/users/yuslepukhin/following{/other_user}","gists_url":"https://api.github.com/users/yuslepukhin/gists{/gist_id}","starred_url":"https://api.github.com/users/yuslepukhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuslepukhin/subscriptions","organizations_url":"https://api.github.com/users/yuslepukhin/orgs","repos_url":"https://api.github.com/users/yuslepukhin/repos","events_url":"https://api.github.com/users/yuslepukhin/events{/privacy}","received_events_url":"https://api.github.com/users/yuslepukhin/received_events","type":"User","site_admin":false},"body":"  Summary. A change https://reviews.facebook.net/differential/diff/224721/\r\n  Has attempted to move common functionality out of platform dependent\r\n  code to a new facility called file_reader_writer.\r\n  This includes:\r\n  - perf counters\r\n  - Buffering\r\n  - RateLimiting\r\n\r\n  However, the change did not attempt to refactor Windows code.\r\n  To mitigate, we introduce new quering interfaces such as UseOSBuffer(),\r\n  GetRequiredBufferAlignment() and ReaderWriterForward()\r\n  for pure forwarding where required.\r\n  Introduce WritableFile got a new method Truncate(). This is to communicate\r\n  to the file as to how much data it has on close.\r\n   - When space is pre-allocated on Linux it is filled with zeros implicitly,\r\n    no such thing exist on Windows so we must truncate file on close.\r\n   - When operating in unbuffered mode the last page is filled with\r\n   zeros but we still want to truncate.\r\n\r\n   Previously, Close() would take care of it but now buffer\r\n   management is shifted to the wrappers and the file has\r\n   no idea about the file true size.\r\n\r\n   This means that Close() on the wrapper level must always include\r\n   Truncate() as well as wrapper __dtor should call Close() and\r\n   against double Close().\r\n   Move buffered/unbuffered write logic to the wrapper.\r\n   Utilize Aligned buffer class.\r\n   Adjust tests and implement Truncate() where necessary.\r\n   Come up with reasonable defaults for new virtual interfaces.\r\n   Forward calls for RandomAccessReadAhead class to avoid double\r\n   buffering and locking (double locking in unbuffered mode on WIndows).\r\n\r\n There are two outstanding test failures\r\n  which I believe is due to the same Mock framework bug.\r\n Both flush_job_test and compaction_job_test fail with \r\n Assertion failed: result.size() == 4, file c:\\dev\\rocksdb\\rocksdb\\table\\mock_table.cc, line 110\r\n\r\n After some debugging it looks like the test opens a RandomAccessFile .sst which\r\n remains empty. Mocked TableBuilder which is responsible for flushing a Level-0 file\r\n never actually writes anything to disk. At the end of the test we attempt to read 4 bytes\r\n at the beginning of an empty file and fail.\r\n\r\nThere are two more failures after refreshing from master but seem to be\r\nof the more recent introduction.\r\n  * [ RUN      ] ColumnFamilyTest.ReadDroppedColumnFamily\r\n   `c:\\dev\\rocksdb\\rocksdb\\db\\column_family_test.cc`(1191): error: Value of: kKeysNum * ((i == 2) ?\r\n  * [ RUN      ] TransactionTest.TimeoutTest\r\n`c:\\dev\\rocksdb\\rocksdb\\utilities\\transactions\\transaction_test.cc`(1523): error: s\r\nOperation timed out: Timeout waiting to lock key","created_at":"2015-09-11T17:11:25Z","updated_at":"2015-09-11T18:24:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6fabfe8ae02b1638360907afc606782b7d6c1a81","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/facebook/rocksdb/pulls/716/commits","review_comments_url":"https://api.github.com/repos/facebook/rocksdb/pulls/716/comments","review_comment_url":"https://api.github.com/repos/facebook/rocksdb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/rocksdb/issues/716/comments","statuses_url":"https://api.github.com/repos/facebook/rocksdb/statuses/30e82d5c411d8d57c24fa98f955ab14f10e2a3d2","head":{"label":"yuslepukhin:refactor_file_reader_writer_win","ref":"refactor_file_reader_writer_win","sha":"30e82d5c411d8d57c24fa98f955ab14f10e2a3d2","user":{"login":"yuslepukhin","id":11303988,"avatar_url":"https://avatars.githubusercontent.com/u/11303988?v=3","gravatar_id":"","url":"https://api.github.com/users/yuslepukhin","html_url":"https://github.com/yuslepukhin","followers_url":"https://api.github.com/users/yuslepukhin/followers","following_url":"https://api.github.com/users/yuslepukhin/following{/other_user}","gists_url":"https://api.github.com/users/yuslepukhin/gists{/gist_id}","starred_url":"https://api.github.com/users/yuslepukhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuslepukhin/subscriptions","organizations_url":"https://api.github.com/users/yuslepukhin/orgs","repos_url":"https://api.github.com/users/yuslepukhin/repos","events_url":"https://api.github.com/users/yuslepukhin/events{/privacy}","received_events_url":"https://api.github.com/users/yuslepukhin/received_events","type":"User","site_admin":false},"repo":{"id":41066343,"name":"rocksdb","full_name":"yuslepukhin/rocksdb","owner":{"login":"yuslepukhin","id":11303988,"avatar_url":"https://avatars.githubusercontent.com/u/11303988?v=3","gravatar_id":"","url":"https://api.github.com/users/yuslepukhin","html_url":"https://github.com/yuslepukhin","followers_url":"https://api.github.com/users/yuslepukhin/followers","following_url":"https://api.github.com/users/yuslepukhin/following{/other_user}","gists_url":"https://api.github.com/users/yuslepukhin/gists{/gist_id}","starred_url":"https://api.github.com/users/yuslepukhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuslepukhin/subscriptions","organizations_url":"https://api.github.com/users/yuslepukhin/orgs","repos_url":"https://api.github.com/users/yuslepukhin/repos","events_url":"https://api.github.com/users/yuslepukhin/events{/privacy}","received_events_url":"https://api.github.com/users/yuslepukhin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yuslepukhin/rocksdb","description":"A library that provides an embeddable, persistent key-value store for fast storage.","fork":true,"url":"https://api.github.com/repos/yuslepukhin/rocksdb","forks_url":"https://api.github.com/repos/yuslepukhin/rocksdb/forks","keys_url":"https://api.github.com/repos/yuslepukhin/rocksdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yuslepukhin/rocksdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yuslepukhin/rocksdb/teams","hooks_url":"https://api.github.com/repos/yuslepukhin/rocksdb/hooks","issue_events_url":"https://api.github.com/repos/yuslepukhin/rocksdb/issues/events{/number}","events_url":"https://api.github.com/repos/yuslepukhin/rocksdb/events","assignees_url":"https://api.github.com/repos/yuslepukhin/rocksdb/assignees{/user}","branches_url":"https://api.github.com/repos/yuslepukhin/rocksdb/branches{/branch}","tags_url":"https://api.github.com/repos/yuslepukhin/rocksdb/tags","blobs_url":"https://api.github.com/repos/yuslepukhin/rocksdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yuslepukhin/rocksdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yuslepukhin/rocksdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/yuslepukhin/rocksdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yuslepukhin/rocksdb/statuses/{sha}","languages_url":"https://api.github.com/repos/yuslepukhin/rocksdb/languages","stargazers_url":"https://api.github.com/repos/yuslepukhin/rocksdb/stargazers","contributors_url":"https://api.github.com/repos/yuslepukhin/rocksdb/contributors","subscribers_url":"https://api.github.com/repos/yuslepukhin/rocksdb/subscribers","subscription_url":"https://api.github.com/repos/yuslepukhin/rocksdb/subscription","commits_url":"https://api.github.com/repos/yuslepukhin/rocksdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/yuslepukhin/rocksdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/yuslepukhin/rocksdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/yuslepukhin/rocksdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/yuslepukhin/rocksdb/contents/{+path}","compare_url":"https://api.github.com/repos/yuslepukhin/rocksdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yuslepukhin/rocksdb/merges","archive_url":"https://api.github.com/repos/yuslepukhin/rocksdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yuslepukhin/rocksdb/downloads","issues_url":"https://api.github.com/repos/yuslepukhin/rocksdb/issues{/number}","pulls_url":"https://api.github.com/repos/yuslepukhin/rocksdb/pulls{/number}","milestones_url":"https://api.github.com/repos/yuslepukhin/rocksdb/milestones{/number}","notifications_url":"https://api.github.com/repos/yuslepukhin/rocksdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yuslepukhin/rocksdb/labels{/name}","releases_url":"https://api.github.com/repos/yuslepukhin/rocksdb/releases{/id}","created_at":"2015-08-20T00:22:02Z","updated_at":"2015-08-20T00:22:05Z","pushed_at":"2015-09-11T17:02:53Z","git_url":"git://github.com/yuslepukhin/rocksdb.git","ssh_url":"git@github.com:yuslepukhin/rocksdb.git","clone_url":"https://github.com/yuslepukhin/rocksdb.git","svn_url":"https://github.com/yuslepukhin/rocksdb","homepage":"http://rocksdb.org","size":49286,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"af7cdbf6478f75b5b9ee26b6300f5fd35ca60393","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":6934395,"name":"rocksdb","full_name":"facebook/rocksdb","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/rocksdb","description":"A library that provides an embeddable, persistent key-value store for fast storage.","fork":false,"url":"https://api.github.com/repos/facebook/rocksdb","forks_url":"https://api.github.com/repos/facebook/rocksdb/forks","keys_url":"https://api.github.com/repos/facebook/rocksdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/rocksdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/rocksdb/teams","hooks_url":"https://api.github.com/repos/facebook/rocksdb/hooks","issue_events_url":"https://api.github.com/repos/facebook/rocksdb/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/rocksdb/events","assignees_url":"https://api.github.com/repos/facebook/rocksdb/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/rocksdb/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/rocksdb/tags","blobs_url":"https://api.github.com/repos/facebook/rocksdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/rocksdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/rocksdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/rocksdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/rocksdb/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/rocksdb/languages","stargazers_url":"https://api.github.com/repos/facebook/rocksdb/stargazers","contributors_url":"https://api.github.com/repos/facebook/rocksdb/contributors","subscribers_url":"https://api.github.com/repos/facebook/rocksdb/subscribers","subscription_url":"https://api.github.com/repos/facebook/rocksdb/subscription","commits_url":"https://api.github.com/repos/facebook/rocksdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/rocksdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/rocksdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/rocksdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/rocksdb/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/rocksdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/rocksdb/merges","archive_url":"https://api.github.com/repos/facebook/rocksdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/rocksdb/downloads","issues_url":"https://api.github.com/repos/facebook/rocksdb/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/rocksdb/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/rocksdb/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/rocksdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/rocksdb/labels{/name}","releases_url":"https://api.github.com/repos/facebook/rocksdb/releases{/id}","created_at":"2012-11-30T06:16:18Z","updated_at":"2015-09-11T04:33:33Z","pushed_at":"2015-09-11T17:13:51Z","git_url":"git://github.com/facebook/rocksdb.git","ssh_url":"git@github.com:facebook/rocksdb.git","clone_url":"https://github.com/facebook/rocksdb.git","svn_url":"https://github.com/facebook/rocksdb","homepage":"http://rocksdb.org","size":71158,"stargazers_count":4029,"watchers_count":4029,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":768,"mirror_url":null,"open_issues_count":106,"forks":768,"open_issues":106,"watchers":4029,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/rocksdb/pulls/716"},"html":{"href":"https://github.com/facebook/rocksdb/pull/716"},"issue":{"href":"https://api.github.com/repos/facebook/rocksdb/issues/716"},"comments":{"href":"https://api.github.com/repos/facebook/rocksdb/issues/716/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/rocksdb/pulls/716/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/rocksdb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/rocksdb/pulls/716/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/rocksdb/statuses/30e82d5c411d8d57c24fa98f955ab14f10e2a3d2"}}}}