@ -5,9 +5,10 @@
# include "db/table_cache.h"
# include "db/filename.h"
# include "db/db_statistics.h"
# include "leveldb/env.h"
# include "leveldb/table.h"
# include "leveldb/statistics.h"
# include "util/coding.h"
namespace leveldb {
@ -17,13 +18,11 @@ struct TableAndFile {
unique_ptr < Table > table ;
} ;
static class DB Statistics* dbstatistics ;
static class Statistics * dbstatistics ;
static void DeleteEntry ( const Slice & key , void * value ) {
TableAndFile * tf = reinterpret_cast < TableAndFile * > ( value ) ;
if ( dbstatistics ) {
dbstatistics - > incNumFileCloses ( ) ;
}
RecordTick ( dbstatistics , NO_FILE_CLOSES ) ;
delete tf ;
}
@ -40,7 +39,7 @@ TableCache::TableCache(const std::string& dbname,
dbname_ ( dbname ) ,
options_ ( options ) ,
cache_ ( NewLRUCache ( entries , options - > table_cache_numshardbits ) ) {
dbstatistics = ( DBStatistics * ) options - > statistics ;
dbstatistics = options - > statistics ;
}
TableCache : : ~ TableCache ( ) {
@ -52,24 +51,23 @@ Status TableCache::FindTable(uint64_t file_number, uint64_t file_size,
char buf [ sizeof ( file_number ) ] ;
EncodeFixed64 ( buf , file_number ) ;
Slice key ( buf , sizeof ( buf ) ) ;
DBStatistics * stats = ( DBStatistics * ) options_ - > statistics ;
* handle = cache_ - > Lookup ( key ) ;
if ( * handle = = NULL ) {
if ( tableIO ! = NULL ) {
if ( * handle = = nullptr ) {
if ( tableIO ! = nullptr ) {
* tableIO = true ; // we had to do IO from storage
}
std : : string fname = TableFileName ( dbname_ , file_number ) ;
unique_ptr < RandomAccessFile > file ;
unique_ptr < Table > table ;
s = env_ - > NewRandomAccessFile ( fname , & file ) ;
stats ? stats - > incNumFileOpens ( ) : ( void ) 0 ;
RecordTick ( options_ - > statistics , NO_FILE_OPENS ) ;
if ( s . ok ( ) ) {
s = Table : : Open ( * options_ , std : : move ( file ) , file_size , & table ) ;
}
if ( ! s . ok ( ) ) {
assert ( table = = NULL ) ;
stats ? stats - > incNumFileErrors ( ) : ( void ) 0 ;
assert ( table = = nullptr ) ;
RecordTick ( options_ - > statistics , NO_FILE_ERRORS ) ;
// We do not cache error results so that if the error is transient,
// or somebody repairs the file, we recover automatically.
} else {
@ -86,11 +84,11 @@ Iterator* TableCache::NewIterator(const ReadOptions& options,
uint64_t file_number ,
uint64_t file_size ,
Table * * tableptr ) {
if ( tableptr ! = NULL ) {
* tableptr = NULL ;
if ( tableptr ! = nullptr ) {
* tableptr = nullptr ;
}
Cache : : Handle * handle = NULL ;
Cache : : Handle * handle = nullptr ;
Status s = FindTable ( file_number , file_size , & handle ) ;
if ( ! s . ok ( ) ) {
return NewErrorIterator ( s ) ;
@ -100,7 +98,7 @@ Iterator* TableCache::NewIterator(const ReadOptions& options,
reinterpret_cast < TableAndFile * > ( cache_ - > Value ( handle ) ) - > table . get ( ) ;
Iterator * result = table - > NewIterator ( options ) ;
result - > RegisterCleanup ( & UnrefEntry , cache_ . get ( ) , handle ) ;
if ( tableptr ! = NULL ) {
if ( tableptr ! = nullptr ) {
* tableptr = table ;
}
return result ;
@ -113,7 +111,7 @@ Status TableCache::Get(const ReadOptions& options,
void * arg ,
void ( * saver ) ( void * , const Slice & , const Slice & , bool ) ,
bool * tableIO ) {
Cache : : Handle * handle = NULL ;
Cache : : Handle * handle = nullptr ;
Status s = FindTable ( file_number , file_size , & handle , tableIO ) ;
if ( s . ok ( ) ) {
Table * t =