fix NULL in latch_hold

This commit is contained in:
nroskill
2023-05-04 14:08:24 +00:00
committed by ob-robot
parent c8f708f64d
commit cc9bf7e0d7
9 changed files with 33 additions and 50 deletions

View File

@ -32,9 +32,8 @@ public:
int64_t hold() const { return ATOMIC_LOAD(&hold_); }
void* alloc_block(int64_t size, ObMemAttr &attr) {
void *ret = NULL;
bool ignore_mem_limit = get_ignore_mem_limit();
int64_t used_after_alloc = ATOMIC_AAF(&hold_, size);
if (!ignore_mem_limit && used_after_alloc > limit_) {
if (used_after_alloc > limit_) {
ATOMIC_AAF(&hold_, -size);
if (REACH_TIME_INTERVAL(1000 * 1000)) {
_OB_LOG_RET(WARN, common::OB_ERR_UNEXPECTED, "block alloc over limit, limit=%ld alloc_size=%ld", limit_, size);

View File

@ -82,7 +82,7 @@ void ObBucketLock::destroy()
{
is_inited_ = false;
if (NULL != latches_) {
for (uint64_t i = 0; i < latch_cnt_; ++i) {
for (int64_t i = latch_cnt_ - 1; i >= 0; --i) {
latches_[i].~ObLatch();
}
ob_free(latches_);
@ -240,7 +240,7 @@ int ObBucketLock::wrlock_all()
}
if (OB_FAIL(ret)) {
for (int64_t i = 0; i <= last_succ_idx; ++i) {
for (int64_t i = last_succ_idx; i >= 0; --i) {
latches_[i].unlock();
}
}
@ -287,7 +287,7 @@ int ObBucketLock::try_lock_all(const bool is_write_lock)
}
if (OB_FAIL(ret)) {
for (int64_t i = 0; i <= last_succ_idx; ++i) {
for (int64_t i = last_succ_idx; i >= 0; --i) {
latches_[i].unlock();
}
}
@ -306,7 +306,7 @@ int ObBucketLock::unlock_all()
ret = OB_NOT_INIT;
COMMON_LOG(WARN, "The ObBucketLock has not been inited, ", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < latch_cnt_; ++i) {
for (int64_t i = latch_cnt_ - 1; OB_SUCC(ret) && i >= 0; --i) {
latches_[i].unlock();
}
}

View File

@ -73,7 +73,7 @@ int ObLatchMutex::try_lock(
if (!ATOMIC_BCAS(&lock_.val(), 0, (WRITE_MASK | uid))) {
ret = OB_EAGAIN;
} else {
IGNORE_RETURN ObLatch::unreg_lock((uint32_t*)&lock_.val());
IGNORE_RETURN ObLatch::reg_lock((uint32_t*)&lock_.val());
}
if (need_record_stat()) {
TRY_LOCK_RECORD_STAT(latch_id, 1, ret);
@ -610,7 +610,7 @@ int ObLatch::try_rdlock(const uint32_t latch_id)
++i;
if (ATOMIC_BCAS(&lock_, lock, lock + 1)) {
ret = OB_SUCCESS;
IGNORE_RETURN unreg_lock((uint32_t*)&lock_);
IGNORE_RETURN reg_lock((uint32_t*)&lock_);
break;
}
}
@ -640,7 +640,7 @@ int ObLatch::try_wrlock(const uint32_t latch_id, const uint32_t *puid)
if (!ATOMIC_BCAS(&lock_, 0, (WRITE_MASK | uid))) {
ret = OB_EAGAIN;
} else {
IGNORE_RETURN unreg_lock((uint32_t*)&lock_);
IGNORE_RETURN reg_lock((uint32_t*)&lock_);
}
if (need_record_stat()) {
TRY_LOCK_RECORD_STAT(latch_id, 1, ret);
@ -711,7 +711,6 @@ int ObLatch::wr2rdlock(const uint32_t *puid)
lock = lock_;
PAUSE();
}
IGNORE_RETURN unreg_lock((uint32_t*)&lock_);
bool only_rd_wait = true;
if (OB_FAIL(ObLatchWaitQueue::get_instance().wake_up(*this, only_rd_wait))) {
COMMON_LOG(ERROR, "Fail to wake up latch wait queue, ", K(this), K(ret));

View File

@ -233,33 +233,22 @@ public:
if (max_lock_slot_idx < sizeof(current_locks) / sizeof(uint32_t*)) {
ret = max_lock_slot_idx++;
current_locks[ret] = latch_addr;
} else {
for (auto i = 0; -1 == ret && i < sizeof(current_locks) / sizeof(uint32_t*); ++i) {
if (OB_ISNULL(current_locks[i]) || 0 == *current_locks[i]) {
ret = i;
current_locks[i] = latch_addr;
}
}
}
return ret;
}
OB_INLINE static int unreg_lock(uint32_t* latch_addr)
{
int ret = -1;
for (int8_t i = max_lock_slot_idx - 1; -1 == ret && i >= 0; --i) {
if (latch_addr == current_locks[i]) {
ret = i;
current_locks[i] = nullptr;
if (ret == max_lock_slot_idx - 1) {
--max_lock_slot_idx;
}
}
}
// for (int8_t i = max_lock_slot_idx - 1; -1 == ret && i >= 0; --i) {
// if (latch_addr == current_locks[i]) {
// ret = i;
// current_locks[i] = max_lock_slot_idx > 0 ? current_locks[--max_lock_slot_idx] : nullptr;
// }
// }
return ret;
}
OB_INLINE static void clear_lock()
{
MEMSET(current_locks, 0, max_lock_slot_idx * sizeof(current_locks[0]));
max_lock_slot_idx = 0;
}
static thread_local uint32_t* current_locks[16];
@ -495,7 +484,7 @@ OB_INLINE uint64_t ObLatchMutex::low_try_lock(const int64_t max_spin_cnt, const
for (; spin_cnt < max_spin_cnt; ++spin_cnt) {
if (0 == lock_.val()) {
if (ATOMIC_BCAS(&lock_.val(), 0, lock_value)) {
IGNORE_RETURN ObLatch::unreg_lock((uint32_t*)(&lock_.val()));
IGNORE_RETURN ObLatch::reg_lock((uint32_t*)(&lock_.val()));
break;
}
}
@ -557,7 +546,7 @@ inline int ObLatch::LowTryRDLock::operator()(volatile uint32_t *latch,
conflict = false;
if (ATOMIC_BCAS(latch, lock, lock + 1)) {
ret = OB_SUCCESS;
IGNORE_RETURN unreg_lock((uint32_t*)latch);
IGNORE_RETURN reg_lock((uint32_t*)latch);
}
} else {
conflict = true;
@ -580,7 +569,7 @@ inline int ObLatch::LowTryWRLock::operator()(volatile uint32_t *latch,
conflict = false;
if (ATOMIC_BCAS(latch, lock, (lock | (WRITE_MASK | uid)))) {
ret = OB_SUCCESS;
IGNORE_RETURN unreg_lock((uint32_t*)latch);
IGNORE_RETURN reg_lock((uint32_t*)latch);
}
} else {
conflict = true;

View File

@ -150,7 +150,7 @@ public:
}
if (OB_SUCC(ret)) {
// record in try_rdlock will be overwrited by latch_.rdlock, so record again.
IGNORE_RETURN ObLatch::unreg_lock((uint32_t*)&(latch_.lock_));
IGNORE_RETURN ObLatch::reg_lock((uint32_t*)&(latch_.lock_));
}
return ret;
}
@ -161,7 +161,7 @@ public:
get_tcref().inc_ref(&read_ref_);
if (OB_LIKELY(0 == ATOMIC_LOAD(&write_id_))) {
locked = true;
IGNORE_RETURN ObLatch::unreg_lock((uint32_t*)&(latch_.lock_));
IGNORE_RETURN ObLatch::reg_lock((uint32_t*)&(latch_.lock_));
} else {
get_tcref().dec_ref(&read_ref_);
lcond_.signal();
@ -260,7 +260,7 @@ public:
get_tcref().inc_ref(&read_ref_, slot_id);
if (OB_LIKELY(0 == ATOMIC_LOAD(&write_id_))) {
locked = true;
IGNORE_RETURN ObLatch::unreg_lock((uint32_t*)&(latch_.lock_));
IGNORE_RETURN ObLatch::reg_lock((uint32_t*)&(latch_.lock_));
} else {
get_tcref().dec_ref(&read_ref_, slot_id);
lcond_.signal();
@ -278,7 +278,7 @@ public:
}
if (OB_SUCC(ret)) {
// record in try_rdlock will be overwrited by latch_.rdlock, so record again.
IGNORE_RETURN ObLatch::unreg_lock((uint32_t*)&(latch_.lock_));
IGNORE_RETURN ObLatch::reg_lock((uint32_t*)&(latch_.lock_));
}
return ret;
}

View File

@ -2291,12 +2291,6 @@ OB_INLINE int64_t &get_tid_cache()
return (&tid)->v_;
}
OB_INLINE bool &get_ignore_mem_limit()
{
RLOCAL_INLINE(bool, ignore_mem_limit);
return ignore_mem_limit;
}
OB_INLINE int64_t &get_seq()
{
RLOCAL_INLINE(int64_t, seq);

View File

@ -1894,12 +1894,13 @@ int dump_thread_info(lua_State *L)
// latch_hold
{
GET_OTHER_TSI_ADDR(uint32_t**, locks_addr, &ObLatch::current_locks);
GET_OTHER_TSI_ADDR(int8_t, slot_cnt, &ObLatch::max_lock_slot_idx)
locks_addr = (uint32_t**)(thread_base + locks_addr_offset);
char addrs[256];
addrs[0] = 0;
for (auto i = 0, offset1 = 0; i < sizeof(ObLatch::current_locks) / sizeof(uint32_t*); ++i) {
if (OB_NOT_NULL(locks_addr[i])) {
offset1 = snprintf(addrs + offset1, 256 - offset1, "%p ", locks_addr[i]);
for (auto i = 0, offset1 = 0; i < slot_cnt; ++i) {
if (OB_NOT_NULL(locks_addr[i]) && offset1 < 256) {
offset1 += snprintf(addrs + offset1, 256 - offset1, "%p ", locks_addr[i]);
}
}
if (0 == addrs[0]) {

View File

@ -138,7 +138,7 @@ int ObAllVirtualThread::inner_get_next_row(common::ObNewRow *&row)
ObCharset::get_default_collation(ObCharset::get_default_charset()));
break;
}
case LATCH_WAIT_ADDR: {
case LATCH_WAIT: {
if (OB_ISNULL(wait_addr)) {
cells[i].set_varchar("");
} else {
@ -149,19 +149,20 @@ int ObAllVirtualThread::inner_get_next_row(common::ObNewRow *&row)
ObCharset::get_default_collation(ObCharset::get_default_charset()));
break;
}
case LATCH_HOLD_ADDR: {
case LATCH_HOLD: {
GET_OTHER_TSI_ADDR(uint32_t**, locks_addr, &ObLatch::current_locks);
GET_OTHER_TSI_ADDR(int8_t, slot_cnt, &ObLatch::max_lock_slot_idx)
locks_addr = (uint32_t**)(thread_base + locks_addr_offset);
locks_addr_[0] = 0;
for (auto i = 0, j = 0; i < sizeof(ObLatch::current_locks) / sizeof(uint32_t*); ++i) {
for (auto i = 0, j = 0; i < slot_cnt; ++i) {
if (OB_NOT_NULL(locks_addr[i])) {
bool has_segv = false;
uint32_t val = 0;
do_with_crash_restore([&] {
val = *locks_addr[i];
}, has_segv);
if (!has_segv && 0 != val) {
j = snprintf(locks_addr_ + j, 256 - j, "%p ", locks_addr[i]);
if (!has_segv && 0 != val && j < 256) {
j += snprintf(locks_addr_ + j, 256 - j, "%p ", locks_addr[i]);
}
}
}

View File

@ -30,8 +30,8 @@ class ObAllVirtualThread : public common::ObVirtualTableScannerIterator
TNAME,
STATUS,
WAIT_EVENT,
LATCH_WAIT_ADDR,
LATCH_HOLD_ADDR,
LATCH_WAIT,
LATCH_HOLD,
TRACE_ID,
LOOP_TS
};