Github user hbdeshmukh commented on a diff in the pull request:

    https://github.com/apache/incubator-quickstep/pull/6#discussion_r65725933
  
    --- Diff: storage/StorageBlock.cpp ---
    @@ -91,57 +91,30 @@ StorageBlock::StorageBlock(const CatalogRelationSchema 
&relation,
           all_indices_inconsistent_(false),
           relation_(relation) {
       if (new_block) {
    -    if (block_memory_size_ < layout.getBlockHeaderSize()) {
    -      throw BlockMemoryTooSmall("StorageBlock", block_memory_size_);
    -    }
    -
    -    layout.copyHeaderTo(block_memory_);
    -    DEBUG_ASSERT(*static_cast<const int*>(block_memory_) > 0);
    -
    -    if (!block_header_.ParseFromArray(static_cast<char*>(block_memory_) + 
sizeof(int),
    -                                      *static_cast<const 
int*>(block_memory_))) {
    -      FATAL_ERROR("A StorageBlockLayout created a malformed 
StorageBlockHeader.");
    -    }
    -
         // We mark a newly-created block as dirty, so that in the rare case 
that a
         // block is evicted before anything is inserted into it, we still 
write it
         // (and the header plus any sub-block specific fixed data structures) 
back
         // to disk.
         dirty_ = true;
     
    -    DEBUG_ASSERT(block_header_.IsInitialized());
    -    DEBUG_ASSERT(StorageBlockLayout::DescriptionIsValid(relation_, 
block_header_.layout()));
    -    DEBUG_ASSERT(block_header_.index_size_size() == 
block_header_.layout().index_description_size());
    -    DEBUG_ASSERT(block_header_.index_size_size() == 
block_header_.index_consistent_size());
    -  } else {
    -    if (block_memory_size < sizeof(int)) {
    -      throw MalformedBlock();
    -    }
    -    if (*static_cast<const int*>(block_memory_) <= 0) {
    -      throw MalformedBlock();
    -    }
    -    if (*static_cast<const int*>(block_memory_) + sizeof(int) > 
block_memory_size_) {
    -      throw MalformedBlock();
    -    }
    +    DCHECK_GE(block_memory_size_, layout.getBlockHeaderSize())
    +        << "BlockMemoryTooSmall: " << block_memory_size_ << " bytes is too 
small for StorageBlock";
     
    -    if (!block_header_.ParseFromArray(static_cast<char*>(block_memory_) + 
sizeof(int),
    -                                      *static_cast<const 
int*>(block_memory_))) {
    -      throw MalformedBlock();
    -    }
    -    if (!block_header_.IsInitialized()) {
    -      throw MalformedBlock();
    -    }
    -    if (!StorageBlockLayout::DescriptionIsValid(relation_, 
block_header_.layout())) {
    -      throw MalformedBlock();
    -    }
    -    if (block_header_.index_size_size() != 
block_header_.layout().index_description_size()) {
    -      throw MalformedBlock();
    -    }
    -    if (block_header_.index_size_size() != 
block_header_.index_consistent_size()) {
    -      throw MalformedBlock();
    -    }
    +    layout.copyHeaderTo(block_memory_);
    +  } else {
    +    DCHECK_GT(*static_cast<const int*>(block_memory_), 0);
    +    DCHECK_LE(*static_cast<const int*>(block_memory_) + sizeof(int), 
block_memory_size_);
       }
     
    +  CHECK(block_header_.ParseFromArray(static_cast<char*>(block_memory_) + 
sizeof(int),
    +                                     *static_cast<const 
int*>(block_memory_)))
    +      << "A StorageBlockLayout created a malformed StorageBlockHeader.";
    +
    +  DCHECK(block_header_.IsInitialized());
    +  DCHECK(StorageBlockLayout::DescriptionIsValid(relation_, 
block_header_.layout()));
    +  DCHECK_EQ(block_header_.index_size_size(), 
block_header_.layout().index_description_size());
    +  DCHECK_EQ(block_header_.index_size_size(), 
block_header_.index_consistent_size());
    --- End diff --
    
    Hi @zuyu 
    
    I feel somewhat nervous regarding converting the above checks in this class 
from release mode to debug mode. Unless they are substantially expensive (which 
they are not), I don't think they should be made debug-only. Such checks can be 
very helpful if something goes wrong. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to