Github user pateljm commented on a diff in the pull request:
https://github.com/apache/incubator-quickstep/pull/6#discussion_r65805554
--- 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 --
@zuyu You make a good point. But, since this check happens rarely, would
you consider accommodating @hbdeshmukh note and making these DCHECKs. He does
make a good point, and such checks were really important in weeding out hard
bugs in the code in our recent benchmarking effort. I think at a later stage in
the project, when we have beat the code enough we could go back to only using
such checks in Debug mode. Thanks!
---
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.
---