Skip to content

Commit

Permalink
feat(tianmu): mv func from public to protected(stoneatom#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzz-vincent committed Apr 3, 2023
1 parent 7484c58 commit 8b317a5
Show file tree
Hide file tree
Showing 3 changed files with 783 additions and 142 deletions.
21 changes: 12 additions & 9 deletions storage/tianmu/core/pack.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* Copyright (c) 2022 StoneAtom, Inc. All rights reserved.
Use is subject to license terms
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
Expand Down Expand Up @@ -41,6 +38,11 @@ Pack::Pack(DPN *dpn, PackCoordinate pc, ColumnShare *col_share) : col_share_(col
m_coord.co.pack = pc;
}

// Number of bits in bytes
const int kBitsInBytes = 8;
// Fill in values to prevent boundary errors
const int kPadding = kBitsInBytes - 1;

Pack::Pack(const Pack &ap, const PackCoordinate &pc)
: mm::TraceableObject(ap), col_share_(ap.col_share_), dpn_(ap.dpn_) {
m_coord.ID = COORD_TYPE::PACK;
Expand Down Expand Up @@ -79,12 +81,8 @@ bool Pack::ShouldNotCompress() const {

bool Pack::CompressedBitMap(mm::MMGuard<uchar> &comp_buf, uint &comp_buf_size, std::unique_ptr<uint32_t[]> &ptr_buf,
uint32_t &dpn_num1) {
// Number of bits in bytes
int bitsInBytes = 8;
// Fill in values to prevent boundary errors
int padding = bitsInBytes - 1;
// Because the maximum size of dpn_->numofrecords is 65536, the buffer used by bitmaps is also limited
comp_buf_size = ((dpn_->numOfRecords + padding) / bitsInBytes);
comp_buf_size = ((dpn_->numOfRecords + kPadding) / kBitsInBytes);

comp_buf = mm::MMGuard<uchar>(
static_cast<uchar *>(alloc((comp_buf_size + sizeof(ushort)) * sizeof(char), mm::BLOCK_TYPE::BLOCK_TEMPORARY)),
Expand All @@ -98,11 +96,16 @@ bool Pack::CompressedBitMap(mm::MMGuard<uchar> &comp_buf, uint &comp_buf_size, s
TIANMU_LOG(LogCtl_Level::ERROR, "buffer overrun by BitstreamCompressor (N f).");
ASSERT(0, "ERROR: buffer overrun by BitstreamCompressor (N f).");
}
return CheckCompressRes(comp_buf, comp_buf_size, ptr_buf, res);
}

bool Pack::CheckCompressRes(mm::MMGuard<uchar> &comp_buf, uint &comp_buf_size, std::unique_ptr<uint32_t[]> &ptr_buf,
CprsErr res) {
if (res == CprsErr::CPRS_SUCCESS)
return true;
else if (res == CprsErr::CPRS_ERR_BUF) {
comp_buf = mm::MMGuard<uchar>(reinterpret_cast<uchar *>(ptr_buf.get()), *this, false);
comp_buf_size = ((dpn_->numOfRecords + padding) / bitsInBytes);
comp_buf_size = ((dpn_->numOfRecords + kPadding) / kBitsInBytes);
return false;
} else {
throw common::DatabaseException("Compression of nulls or deletes failed for column " +
Expand Down
11 changes: 4 additions & 7 deletions storage/tianmu/core/pack.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* Copyright (c) 2022 StoneAtom, Inc. All rights reserved.
Use is subject to license terms
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
Expand Down Expand Up @@ -103,16 +100,16 @@ class Pack : public mm::TraceableObject {
PackCoordinate GetPackCoordinate() const { return m_coord.co.pack; }
void SetDPN(DPN *new_dpn) { dpn_ = new_dpn; }

// Compress bitmap
bool CompressedBitMap(mm::MMGuard<uchar> &comp_buf, uint &comp_buf_size, std::unique_ptr<uint32_t[]> &ptr_buf,
uint32_t &dpn_num1);

protected:
Pack(DPN *dpn, PackCoordinate pc, ColumnShare *col_share);
Pack(const Pack &ap, const PackCoordinate &pc);
virtual std::pair<UniquePtr, size_t> Compress() = 0;
virtual void Destroy() = 0;

bool CompressedBitMap(mm::MMGuard<uchar> &comp_buf, uint &comp_buf_size, std::unique_ptr<uint32_t[]> &ptr_buf,
uint32_t &dpn_num1);
bool CheckCompressRes(mm::MMGuard<uchar> &comp_buf, uint &comp_buf_size, std::unique_ptr<uint32_t[]> &ptr_buf,
CprsErr res);
bool ShouldNotCompress() const;
bool IsModeNullsCompressed() const { return dpn_->null_compressed; }
bool IsModeDeletesCompressed() const { return dpn_->delete_compressed; }
Expand Down
Loading

0 comments on commit 8b317a5

Please sign in to comment.