Sort files correctly in Builder::SaveTo
Sort files correctly in Builder::SaveTo

Summary:
Previously, we used to sort all files by BySmallestFirst comparator and then re-sort level0 files in the Finalize() (recently moved to end of SaveTo).

In this diff, I chose the correct comparator at the beginning and sort the files correctly in Builder::SaveTo.

I also added a verification that all files are sorted correctly in CheckConsistency()

NOTE: This diff depends on D17037

Test Plan: make check. Will also run db_stress

Reviewers: dhruba, haobo, sdong, ljin

Reviewed By: ljin

CC: leveldb

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

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