Flush before Fsync()/Sync()
Flush before Fsync()/Sync()

Summary: Calling Fsync()/Sync() on a file should give the guarantee that whatever you written to the file is now persisted. This is currently not the case, since we might have some data left in application cache as we do Fsync()/Sync(). For example, BuildTable() calls Fsync() without the flush, assuming all sst data is now persisted, but it's actually not. This may result in big inconsistencies.

Test Plan: no test

Reviewers: sdong, dhruba, haobo, ljin, yhchiang

Reviewed By: sdong

CC: leveldb

Differential Revision: https://reviews.facebook.net/D18159

wat-ze-hex/rocksdb,skunkwerks/rocksdb,wlqGit/rocksdb,JoeWoo/rocksdb,luckywhu/rocksdb,rDSN-Projects/rocksdb.replicated,anagav/rocksdb,Vaisman/rocksdb,JackLian/rocksdb,alihalabyah/rocksdb,geraldoandradee/rocksdb,hobinyoon/rocksdb,Vaisman/rocksdb,wenduo/rocksdb,OverlordQ/rocksdb,JackLian/rocksdb,wlqGit/rocksdb,geraldoandradee/rocksdb,tsheasha/rocksdb,tschottdorf/rocksdb,bbiao/rocksdb,facebook/rocksdb,bbiao/rocksdb,caijieming-baidu/rocksdb,amyvmiwei/rocksdb,vmx/rocksdb,amyvmiwei/rocksdb,flabby/rocksdb,Applied-Duality/rocksdb,wat-ze-hex/rocksdb,IMCG/RcoksDB,norton/rocksdb,wenduo/rocksdb,lgscofield/rocksdb,makelivedotnet/rocksdb,rDSN-Projects/rocksdb.replicated,vmx/rocksdb,kaschaeffer/rocksdb,zhangpng/rocksdb,virtdb/rocksdb,SunguckLee/RocksDB,makelivedotnet/rocksdb,IMCG/RcoksDB,JackLian/rocksdb,vashstorm/rocksdb,dkorolev/rocksdb,wenduo/rocksdb,facebook/rocksdb,vmx/rocksdb,OverlordQ/rocksdb,makelivedotnet/rocksdb,temicai/rocksdb,Andymic/rocksdb,tschottdorf/rocksdb,RyanTech/rocksdb,NickCis/rocksdb,tizzybec/rocksdb,fengshao0907/rocksdb,mbarbon/rocksdb,ylong/rocksdb,Andymic/rocksdb,Applied-Duality/rocksdb,tizzybec/rocksdb,jalexanderqed/rocksdb,luckywhu/rocksdb,JackLian/rocksdb,vmx/rocksdb,ylong/rocksdb,tsheasha/rocksdb,ryneli/rocksdb,flabby/rocksdb,OverlordQ/rocksdb,biddyweb/rocksdb,mbarbon/rocksdb,IMCG/RcoksDB,kaschaeffer/rocksdb,dkorolev/rocksdb,wskplho/rocksdb,wskplho/rocksdb,NickCis/rocksdb,mbarbon/rocksdb,norton/rocksdb,IMCG/RcoksDB,jalexanderqed/rocksdb,sorphi/rocksdb,anagav/rocksdb,siddhartharay007/rocksdb,msb-at-yahoo/rocksdb,amyvmiwei/rocksdb,Applied-Duality/rocksdb,makelivedotnet/rocksdb,wat-ze-hex/rocksdb,siddhartharay007/rocksdb,JohnPJenkins/rocksdb,mbarbon/rocksdb,ryneli/rocksdb,skunkwerks/rocksdb,flabby/rocksdb,RyanTech/rocksdb,fengshao0907/rocksdb,jalexanderqed/rocksdb,JohnPJenkins/rocksdb,norton/rocksdb,Applied-Duality/rocksdb,hobinyoon/rocksdb,JoeWoo/rocksdb,vashstorm/rocksdb,biddyweb/rocksdb,norton/rocksdb,temicai/rocksdb,tschottdorf/rocksdb,zhangpng/rocksdb,wlqGit/rocksdb,caijieming-baidu/rocksdb,msb-at-yahoo/rocksdb,alihalabyah/rocksdb,mbarbon/rocksdb,geraldoandradee/rocksdb,Andymic/rocksdb,sorphi/rocksdb,makelivedotnet/rocksdb,lgscofield/rocksdb,wenduo/rocksdb,sorphi/rocksdb,wskplho/rocksdb,SunguckLee/RocksDB,luckywhu/rocksdb,JackLian/rocksdb,wlqGit/rocksdb,IMCG/RcoksDB,vashstorm/rocksdb,vashstorm/rocksdb,OverlordQ/rocksdb,flabby/rocksdb,biddyweb/rocksdb,kaschaeffer/rocksdb,skunkwerks/rocksdb,rDSN-Projects/rocksdb.replicated,biddyweb/rocksdb,wlqGit/rocksdb,RyanTech/rocksdb,ylong/rocksdb,ylong/rocksdb,virtdb/rocksdb,tsheasha/rocksdb,msb-at-yahoo/rocksdb,Vaisman/rocksdb,wskplho/rocksdb,vmx/rocksdb,caijieming-baidu/rocksdb,makelivedotnet/rocksdb,luckywhu/rocksdb,siddhartharay007/rocksdb,fengshao0907/rocksdb,siddhartharay007/rocksdb,IMCG/RcoksDB,mbarbon/rocksdb,vashstorm/rocksdb,OverlordQ/rocksdb,wskplho/rocksdb,wskplho/rocksdb,anagav/rocksdb,vmx/rocksdb,sorphi/rocksdb,flabby/rocksdb,wat-ze-hex/rocksdb,SunguckLee/RocksDB,zhangpng/rocksdb,norton/rocksdb,JoeWoo/rocksdb,wlqGit/rocksdb,lgscofield/rocksdb,amyvmiwei/rocksdb,SunguckLee/RocksDB,tsheasha/rocksdb,skunkwerks/rocksdb,hobinyoon/rocksdb,rDSN-Projects/rocksdb.replicated,lgscofield/rocksdb,NickCis/rocksdb,facebook/rocksdb,flabby/rocksdb,zhangpng/rocksdb,ryneli/rocksdb,wenduo/rocksdb,jalexanderqed/rocksdb,bbiao/rocksdb,alihalabyah/rocksdb,Andymic/rocksdb,msb-at-yahoo/rocksdb,SunguckLee/RocksDB,virtdb/rocksdb,wskplho/rocksdb,NickCis/rocksdb,zhangpng/rocksdb,Vaisman/rocksdb,fengshao0907/rocksdb,ryneli/rocksdb,wenduo/rocksdb,Applied-Duality/rocksdb,ylong/rocksdb,wenduo/rocksdb,JohnPJenkins/rocksdb,Andymic/rocksdb,caijieming-baidu/rocksdb,vashstorm/rocksdb,bbiao/rocksdb,JoeWoo/rocksdb,JohnPJenkins/rocksdb,wat-ze-hex/rocksdb,makelivedotnet/rocksdb,Andymic/rocksdb,dkorolev/rocksdb,JohnPJenkins/rocksdb,flabby/rocksdb,NickCis/rocksdb,facebook/rocksdb,tschottdorf/rocksdb,wat-ze-hex/rocksdb,temicai/rocksdb,wlqGit/rocksdb,hobinyoon/rocksdb,ylong/rocksdb,facebook/rocksdb,ryneli/rocksdb,SunguckLee/RocksDB,virtdb/rocksdb,ryneli/rocksdb,NickCis/rocksdb,kaschaeffer/rocksdb,lgscofield/rocksdb,msb-at-yahoo/rocksdb,rDSN-Projects/rocksdb.replicated,zhangpng/rocksdb,Vaisman/rocksdb,msb-at-yahoo/rocksdb,hobinyoon/rocksdb,temicai/rocksdb,hobinyoon/rocksdb,tschottdorf/rocksdb,OverlordQ/rocksdb,kaschaeffer/rocksdb,biddyweb/rocksdb,tizzybec/rocksdb,sorphi/rocksdb,RyanTech/rocksdb,amyvmiwei/rocksdb,luckywhu/rocksdb,IMCG/RcoksDB,JohnPJenkins/rocksdb,wenduo/rocksdb,virtdb/rocksdb,rDSN-Projects/rocksdb.replicated,dkorolev/rocksdb,mbarbon/rocksdb,siddhartharay007/rocksdb,tsheasha/rocksdb,sorphi/rocksdb,geraldoandradee/rocksdb,Andymic/rocksdb,RyanTech/rocksdb,JoeWoo/rocksdb,temicai/rocksdb,vmx/rocksdb,anagav/rocksdb,hobinyoon/rocksdb,biddyweb/rocksdb,jalexanderqed/rocksdb,bbiao/rocksdb,temicai/rocksdb,JoeWoo/rocksdb,bbiao/rocksdb,alihalabyah/rocksdb,geraldoandradee/rocksdb,tizzybec/rocksdb,wat-ze-hex/rocksdb,RyanTech/rocksdb,JoeWoo/rocksdb,tsheasha/rocksdb,fengshao0907/rocksdb,vashstorm/rocksdb,geraldoandradee/rocksdb,geraldoandradee/rocksdb,norton/rocksdb,jalexanderqed/rocksdb,lgscofield/rocksdb,fengshao0907/rocksdb,rDSN-Projects/rocksdb.replicated,amyvmiwei/rocksdb,norton/rocksdb,lgscofield/rocksdb,Vaisman/rocksdb,alihalabyah/rocksdb,tizzybec/rocksdb,alihalabyah/rocksdb,ylong/rocksdb,siddhartharay007/rocksdb,tizzybec/rocksdb,SunguckLee/RocksDB,Andymic/rocksdb,anagav/rocksdb,fengshao0907/rocksdb,virtdb/rocksdb,ryneli/rocksdb,amyvmiwei/rocksdb,norton/rocksdb,alihalabyah/rocksdb,facebook/rocksdb,tschottdorf/rocksdb,sorphi/rocksdb,SunguckLee/RocksDB,anagav/rocksdb,skunkwerks/rocksdb,caijieming-baidu/rocksdb,facebook/rocksdb,siddhartharay007/rocksdb,luckywhu/rocksdb,skunkwerks/rocksdb,dkorolev/rocksdb,JohnPJenkins/rocksdb,luckywhu/rocksdb,tizzybec/rocksdb,RyanTech/rocksdb,Applied-Duality/rocksdb,temicai/rocksdb,Applied-Duality/rocksdb,anagav/rocksdb,tsheasha/rocksdb,skunkwerks/rocksdb,OverlordQ/rocksdb,caijieming-baidu/rocksdb,kaschaeffer/rocksdb,facebook/rocksdb,virtdb/rocksdb,dkorolev/rocksdb,JackLian/rocksdb,vmx/rocksdb,zhangpng/rocksdb,wat-ze-hex/rocksdb,tsheasha/rocksdb,JackLian/rocksdb,hobinyoon/rocksdb,NickCis/rocksdb,bbiao/rocksdb,biddyweb/rocksdb,dkorolev/rocksdb,Vaisman/rocksdb,bbiao/rocksdb,caijieming-baidu/rocksdb,kaschaeffer/rocksdb,jalexanderqed/rocksdb