@ -24,10 +24,9 @@ Reader::Reader(unique_ptr<RandomAccessFileReader>&& file_reader, Env* env,
buffer_ ( ) ,
buffer_ ( ) ,
next_byte_ ( 0 ) { }
next_byte_ ( 0 ) { }
Status Reader : : ReadSlice ( uint64_t size , Slice * slice , std : : string * buf ) {
Status Reader : : ReadSlice ( uint64_t size , Slice * slice , char * buf ) {
StopWatch read_sw ( env_ , statistics_ , BLOB_DB_BLOB_FILE_READ_MICROS ) ;
StopWatch read_sw ( env_ , statistics_ , BLOB_DB_BLOB_FILE_READ_MICROS ) ;
buf - > reserve ( static_cast < size_t > ( size ) ) ;
Status s = file_ - > Read ( next_byte_ , static_cast < size_t > ( size ) , slice , buf ) ;
Status s = file_ - > Read ( next_byte_ , static_cast < size_t > ( size ) , slice , & ( * buf ) [ 0 ] ) ;
next_byte_ + = size ;
next_byte_ + = size ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
return s ;
return s ;
@ -42,7 +41,7 @@ Status Reader::ReadSlice(uint64_t size, Slice* slice, std::string* buf) {
Status Reader : : ReadHeader ( BlobLogHeader * header ) {
Status Reader : : ReadHeader ( BlobLogHeader * header ) {
assert ( file_ . get ( ) ! = nullptr ) ;
assert ( file_ . get ( ) ! = nullptr ) ;
assert ( next_byte_ = = 0 ) ;
assert ( next_byte_ = = 0 ) ;
Status s = ReadSlice ( BlobLogHeader : : kSize , & buffer_ , & backing_store _) ;
Status s = ReadSlice ( BlobLogHeader : : kSize , & buffer_ , header_buf _) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
return s ;
return s ;
}
}
@ -56,7 +55,7 @@ Status Reader::ReadHeader(BlobLogHeader* header) {
Status Reader : : ReadRecord ( BlobLogRecord * record , ReadLevel level ,
Status Reader : : ReadRecord ( BlobLogRecord * record , ReadLevel level ,
uint64_t * blob_offset ) {
uint64_t * blob_offset ) {
Status s = ReadSlice ( BlobLogRecord : : kHeaderSize , & buffer_ , & backing_store _) ;
Status s = ReadSlice ( BlobLogRecord : : kHeaderSize , & buffer_ , header_buf _) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
return s ;
return s ;
}
}
@ -80,14 +79,18 @@ Status Reader::ReadRecord(BlobLogRecord* record, ReadLevel level,
break ;
break ;
case kReadHeaderKey :
case kReadHeaderKey :
s = ReadSlice ( record - > key_size , & record - > key , & record - > key_buf ) ;
record - > key_buf . reset ( new char [ record - > key_size ] ) ;
s = ReadSlice ( record - > key_size , & record - > key , record - > key_buf . get ( ) ) ;
next_byte_ + = record - > value_size ;
next_byte_ + = record - > value_size ;
break ;
break ;
case kReadHeaderKeyBlob :
case kReadHeaderKeyBlob :
s = ReadSlice ( record - > key_size , & record - > key , & record - > key_buf ) ;
record - > key_buf . reset ( new char [ record - > key_size ] ) ;
s = ReadSlice ( record - > key_size , & record - > key , record - > key_buf . get ( ) ) ;
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
s = ReadSlice ( record - > value_size , & record - > value , & record - > value_buf ) ;
record - > value_buf . reset ( new char [ record - > value_size ] ) ;
s = ReadSlice ( record - > value_size , & record - > value ,
record - > value_buf . get ( ) ) ;
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
s = record - > CheckBlobCRC ( ) ;
s = record - > CheckBlobCRC ( ) ;