refactor: remove unused code (#418)
Clean the code and remove unused codes, or these unused codes would confuse our developers.
This commit is contained in:
parent
e9ea5d7f57
commit
afae65547b
1
deps/oblib/src/common/CMakeLists.txt
vendored
1
deps/oblib/src/common/CMakeLists.txt
vendored
@ -2,7 +2,6 @@ ob_set_subtarget(oblib_common common
|
||||
cell/ob_cell_reader.cpp
|
||||
cell/ob_cell_writer.cpp
|
||||
data_buffer.cpp
|
||||
lease/ob_lease_common.cpp
|
||||
log/ob_direct_log_reader.cpp
|
||||
log/ob_log_cursor.cpp
|
||||
log/ob_log_data_writer.cpp
|
||||
|
78
deps/oblib/src/common/lease/ob_lease_common.cpp
vendored
78
deps/oblib/src/common/lease/ob_lease_common.cpp
vendored
@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#include "common/lease/ob_lease_common.h"
|
||||
#include "lib/oblog/ob_log.h"
|
||||
|
||||
namespace oceanbase {
|
||||
using namespace lib;
|
||||
|
||||
namespace common {
|
||||
bool ObLease::is_lease_valid(int64_t redun_time)
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
timeval time_val;
|
||||
(void)gettimeofday(&time_val, NULL);
|
||||
int64_t cur_time_us = time_val.tv_sec * 1000 * 1000 + time_val.tv_usec;
|
||||
if (lease_time + lease_interval + redun_time < cur_time_us) {
|
||||
_OB_LOG(INFO,
|
||||
"Lease expired, lease_time=%ld, lease_interval=%ld, cur_time_us=%ld",
|
||||
lease_time,
|
||||
lease_interval,
|
||||
cur_time_us);
|
||||
ret = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEFINE_SERIALIZE(ObLease)
|
||||
{
|
||||
int err = OB_SUCCESS;
|
||||
if (NULL == buf || buf_len <= 0 || pos < 0) {
|
||||
_OB_LOG(WARN, "invalid param, buf=%p, buf_len=%ld, pos=%ld", buf, buf_len, pos);
|
||||
err = OB_INVALID_ARGUMENT;
|
||||
} else if (pos + (int64_t)sizeof(*this) > buf_len) {
|
||||
_OB_LOG(WARN, "buf is not enough, pos=%ld, buf_len=%ld", pos, buf_len);
|
||||
err = OB_INVALID_ARGUMENT;
|
||||
} else {
|
||||
*((ObLease*)(buf + pos)) = *this;
|
||||
pos += sizeof(*this);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
DEFINE_DESERIALIZE(ObLease)
|
||||
{
|
||||
int err = OB_SUCCESS;
|
||||
if (NULL == buf || data_len <= 0 || pos < 0) {
|
||||
_OB_LOG(WARN, "invalid param, buf=%p, data_len=%ld, pos=%ld", buf, data_len, pos);
|
||||
err = OB_INVALID_ARGUMENT;
|
||||
} else if (pos + (int64_t)sizeof(*this) > data_len) {
|
||||
_OB_LOG(WARN, "data_len is not enough, pos=%ld, data_len=%ld", pos, data_len);
|
||||
err = OB_INVALID_ARGUMENT;
|
||||
} else {
|
||||
*this = *((ObLease*)(buf + pos));
|
||||
pos += sizeof(*this);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
DEFINE_GET_SERIALIZE_SIZE(ObLease)
|
||||
{
|
||||
return sizeof(*this);
|
||||
}
|
||||
} // namespace common
|
||||
} // namespace oceanbase
|
34
deps/oblib/src/common/lease/ob_lease_common.h
vendored
34
deps/oblib/src/common/lease/ob_lease_common.h
vendored
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#ifndef __OCEANBASE_COMMON_OB_LEASE_COMMON_H__
|
||||
#define __OCEANBASE_COMMON_OB_LEASE_COMMON_H__
|
||||
#include "lib/ob_define.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace common {
|
||||
struct ObLease {
|
||||
int64_t lease_time; // lease start time
|
||||
int64_t lease_interval; // lease interval, lease valid time [lease_time, lease_time + lease_interval]
|
||||
int64_t renew_interval; // renew interval, slave will renew lease when lease expiration time is close
|
||||
|
||||
ObLease() : lease_time(0), lease_interval(0), renew_interval(0)
|
||||
{}
|
||||
|
||||
bool is_lease_valid(int64_t redun_time);
|
||||
|
||||
NEED_SERIALIZE_AND_DESERIALIZE;
|
||||
};
|
||||
} // namespace common
|
||||
} // namespace oceanbase
|
||||
|
||||
#endif //__OCEANBASE_COMMON_OB_LEASE_COMMON_H__
|
131
deps/oblib/src/lib/cbtree/btree_varchar_key.h
vendored
131
deps/oblib/src/lib/cbtree/btree_varchar_key.h
vendored
@ -1,131 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#ifndef __CBTREE_BTREE_VARCHAR_KEY_H__
|
||||
#define __CBTREE_BTREE_VARCHAR_KEY_H__
|
||||
|
||||
#include "lib/cbtree/btree.h"
|
||||
|
||||
namespace cbtree {
|
||||
inline int cbt_memcmp(const char* s1_, const char* s2_, int limit, int& offset)
|
||||
{
|
||||
int cmp = 0;
|
||||
unsigned char* s1 = (unsigned char*)s1_;
|
||||
unsigned char* s2 = (unsigned char*)s2_;
|
||||
while (offset < limit && (cmp = (*s1++ - *s2++)) == 0) {
|
||||
offset++;
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
||||
inline int cbt_memcmp_with_prefix(
|
||||
const char* s1, const char* s2, const char* prefix, int prefix_len, int limit, int& offset)
|
||||
{
|
||||
return cbt_memcmp(s1, prefix, prefix_len, offset) ?: cbt_memcmp(s1 + offset, s2 + offset, limit, offset);
|
||||
}
|
||||
|
||||
struct VarCharBuffer {
|
||||
VarCharBuffer() : len_(0)
|
||||
{}
|
||||
~VarCharBuffer()
|
||||
{}
|
||||
int get_total_len() const
|
||||
{
|
||||
return len_ + (int)sizeof(*this);
|
||||
}
|
||||
static uint16_t min(uint16_t x1, uint16_t x2)
|
||||
{
|
||||
return x1 < x2 ? x1 : x2;
|
||||
}
|
||||
uint16_t len_;
|
||||
char buf_[0];
|
||||
inline int compare(const VarCharBuffer& that, int& offset) const
|
||||
{
|
||||
return cbt_memcmp(this->buf_, that.buf_, min(this->len_, that.len_), offset) ?: this->len_ - that.len_;
|
||||
}
|
||||
};
|
||||
|
||||
struct VarCharKey {
|
||||
typedef VarCharKey key_t;
|
||||
enum { OFFSET_MASK = (1 << 13) - 1, SUFFIX_LEN_MASK = (1 << 3) - 1 };
|
||||
struct comp_helper_t {
|
||||
comp_helper_t() : last_decided_offset_(-1)
|
||||
{}
|
||||
void reset()
|
||||
{
|
||||
last_decided_offset_ = -1;
|
||||
}
|
||||
void reset_diff(key_t& key)
|
||||
{
|
||||
key.diff_offset_ = key.key_->len_ & OFFSET_MASK;
|
||||
key.diff_suffix_len_ = 0 & SUFFIX_LEN_MASK;
|
||||
}
|
||||
void calc_diff(key_t& thiskey, const key_t that)
|
||||
{
|
||||
int offset = 0;
|
||||
thiskey.key_->compare(*that.key_, offset);
|
||||
thiskey.diff_offset_ = offset & OFFSET_MASK;
|
||||
MEMCPY(thiskey.diff_suffix_,
|
||||
thiskey.key_->buf_ + offset,
|
||||
VarCharBuffer::min((uint16_t)sizeof(thiskey.diff_suffix_), (uint16_t)(thiskey.key_->len_ - offset)));
|
||||
}
|
||||
bool ideq(const key_t& key1, const key_t& key2) const
|
||||
{
|
||||
return key1.key_ == key2.key_;
|
||||
}
|
||||
bool veq(const key_t& key1, const key_t& key2) const
|
||||
{
|
||||
return key1.compare(key2) == 0;
|
||||
}
|
||||
int compare(const key_t& key1, const key_t& key2) const
|
||||
{
|
||||
return key1.compare(key2);
|
||||
}
|
||||
int linear_search_compare(const key_t search_key, const key_t idx_key)
|
||||
{
|
||||
int cmp = 0;
|
||||
int decided_offset = 0;
|
||||
if (last_decided_offset_ < 0) {
|
||||
if ((cmp = search_key.key_->compare(*idx_key.key_, decided_offset)) >= 0) {
|
||||
last_decided_offset_ = decided_offset;
|
||||
}
|
||||
} else if (idx_key.diff_offset_ > last_decided_offset_) {
|
||||
cmp = 1;
|
||||
} else if ((cmp = (cbt_memcmp_with_prefix(search_key.key_->buf_ + idx_key.diff_offset_,
|
||||
idx_key.key_->buf_ + idx_key.diff_offset_,
|
||||
idx_key.diff_suffix_,
|
||||
idx_key.diff_suffix_len_,
|
||||
VarCharBuffer::min(search_key.key_->len_, idx_key.key_->len_) - idx_key.diff_offset_,
|
||||
decided_offset)
|
||||
?: search_key.key_->len_ - idx_key.key_->len_)) >= 0) {
|
||||
last_decided_offset_ = idx_key.diff_offset_ + decided_offset;
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
int last_decided_offset_;
|
||||
};
|
||||
VarCharKey() : diff_offset_(0), diff_suffix_len_(0), key_(0)
|
||||
{}
|
||||
~VarCharKey()
|
||||
{}
|
||||
inline int compare(const VarCharKey& key) const
|
||||
{
|
||||
int offset = 0;
|
||||
return key_->compare(*key.key_, offset);
|
||||
}
|
||||
uint16_t diff_offset_ : 13;
|
||||
uint16_t diff_suffix_len_ : 3;
|
||||
char diff_suffix_[6];
|
||||
VarCharBuffer* key_;
|
||||
};
|
||||
}; // namespace cbtree
|
||||
#endif /* __CBTREE_BTREE_VARCHAR_KEY_H__ */
|
@ -1,187 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#include "ob_flashback_engine.h"
|
||||
#include "clog/ob_log_define.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace storage {
|
||||
|
||||
// 1000 -> 500, 1300 -> 700
|
||||
// data between 500 and 700 is visible
|
||||
bool ObFlashBackEngine::can_skip_version(
|
||||
const int64_t snapshot_version, const int64_t trans_version, ObFlashBackInfoArray* flashback_infos)
|
||||
{
|
||||
bool can_skip = false;
|
||||
if (NULL != flashback_infos) {
|
||||
for (int64_t i = flashback_infos->count() - 1; i >= 0; i--) {
|
||||
if (snapshot_version < flashback_infos->at(i).from_) {
|
||||
continue;
|
||||
} else {
|
||||
if (trans_version > flashback_infos->at(i).from_) {
|
||||
can_skip = false;
|
||||
break;
|
||||
} else if (trans_version > flashback_infos->at(i).to_) {
|
||||
can_skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return can_skip;
|
||||
}
|
||||
|
||||
int ObFlashBackEngine::push_flashback_info(ObFlashBackInfo& flashback_info)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(flashback_infos_.push_back(flashback_info))) {
|
||||
STORAGE_LOG(WARN, "failed to assign flashback infos", K(ret), K(flashback_info));
|
||||
}
|
||||
STORAGE_LOG(INFO, "push flashback infos", K(flashback_info), K(flashback_infos_));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFlashBackEngine::set_flashback_infos(ObFlashBackInfoArray& flashback_infos)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(flashback_infos_.assign(flashback_infos))) {
|
||||
STORAGE_LOG(WARN, "failed to assign flashback infos", K(ret), K(flashback_infos));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFlashBackEngine::get_flashback_infos(ObFlashBackInfoArray& flashback_infos)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(flashback_infos.assign(flashback_infos_))) {
|
||||
STORAGE_LOG(WARN, "failed to assign flashback infos", K(ret), K_(flashback_infos));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ObFlashBackPartitionCb::ObFlashBackPartitionCb()
|
||||
: guard_(), flashback_info_(), write_clog_state_(CB_INIT), is_locking_(false)
|
||||
{}
|
||||
|
||||
void ObFlashBackPartitionCb::reset()
|
||||
{
|
||||
guard_.reset();
|
||||
write_clog_state_ = CB_INIT;
|
||||
is_locking_ = false;
|
||||
}
|
||||
|
||||
int ObFlashBackPartitionCb::init(
|
||||
ObIPartitionGroup* partition_group, ObPartitionService& partition_service, const ObFlashBackInfo& flashback_info)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
guard_.set_partition_group(partition_service.get_pg_mgr(), *partition_group);
|
||||
flashback_info_ = flashback_info;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFlashBackPartitionCb::on_success(const common::ObPartitionKey& pkey, const clog::ObLogType log_type,
|
||||
const uint64_t log_id, const int64_t version, const bool batch_committed, const bool batch_last_succeed)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(pkey);
|
||||
UNUSED(log_type);
|
||||
UNUSED(version);
|
||||
UNUSED(batch_committed);
|
||||
UNUSED(batch_last_succeed);
|
||||
if (FALSE_IT(flashback_info_.log_id_ = log_id)) {
|
||||
} else if (OB_FAIL(guard_.get_partition_group()->update_flashback_info(flashback_info_))) {
|
||||
STORAGE_LOG(WARN, "failed to flashback", K(ret), K(pkey), K_(flashback_info));
|
||||
} else {
|
||||
bool need_release = false;
|
||||
while (true) {
|
||||
if (false == ATOMIC_TAS(&is_locking_, true)) {
|
||||
if (CB_END != write_clog_state_) {
|
||||
write_clog_state_ = CB_SUCCESS;
|
||||
} else {
|
||||
// rs wait thread has exited, can release memory
|
||||
need_release = true;
|
||||
}
|
||||
ATOMIC_STORE(&is_locking_, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (need_release) {
|
||||
op_free(this);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFlashBackPartitionCb::on_finished(const common::ObPartitionKey& pkey, const uint64_t log_id)
|
||||
{
|
||||
UNUSED(pkey);
|
||||
UNUSED(log_id);
|
||||
int ret = OB_SUCCESS;
|
||||
// lock
|
||||
bool need_release = false;
|
||||
while (true) {
|
||||
if (false == ATOMIC_TAS(&is_locking_, true)) {
|
||||
if (CB_END != write_clog_state_) {
|
||||
write_clog_state_ = CB_FAIL;
|
||||
} else {
|
||||
// index_builder wait thread has exited, can release memory
|
||||
need_release = true;
|
||||
}
|
||||
ATOMIC_STORE(&is_locking_, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (need_release) {
|
||||
op_free(this);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFlashBackPartitionCb::check_can_release(bool& can_release)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// lock
|
||||
while (true) {
|
||||
if (false == ATOMIC_TAS(&is_locking_, true)) {
|
||||
// clog is not callbacked
|
||||
if (CB_FAIL != write_clog_state_ && CB_SUCCESS != write_clog_state_) {
|
||||
write_clog_state_ = CB_END;
|
||||
can_release = false;
|
||||
} else {
|
||||
can_release = true;
|
||||
}
|
||||
ATOMIC_STORE(&is_locking_, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ObFlashBackPartitionCb* ObFlashBackPartitionCbFactory::alloc()
|
||||
{
|
||||
return op_reclaim_alloc(ObFlashBackPartitionCb);
|
||||
}
|
||||
|
||||
void ObFlashBackPartitionCbFactory::release(ObFlashBackPartitionCb* cb)
|
||||
{
|
||||
if (NULL != cb) {
|
||||
cb->reset();
|
||||
op_reclaim_free(cb);
|
||||
cb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace storage
|
||||
} // namespace oceanbase
|
Loading…
x
Reference in New Issue
Block a user