Spicy-cream commented on code in PR #3535:
URL: https://github.com/apache/brpc/pull/3535#discussion_r4462827046


##########
src/brpc/ubshm/ub_ring.cpp:
##########
@@ -61,7 +61,44 @@ RETURN_CODE UBRing::UbrTrxMapShm(SHM *local_shm, SHM 
*remote_shm)
     return UBRING_OK;
 }
 
+RETURN_CODE UBRing::UbrTrxAbort() {
+    if (_trx == nullptr) {
+        return UBRING_OK;
+    }
+    if (ATOMIC_LOAD(_trx->close_state) != UBR_CLOSE_FIRST) {
+        return ReleaseTrx();
+    }
+    const RETURN_CODE close_rc = UbrTrxCloseCheck(_trx);
+    if (close_rc != UBRING_OK) {
+        return close_rc;
+    }
+    int expected = UBR_CLOSE_FIRST;
+    if (!ATOMIC_COMPARE_EXCHANGE_STRONG(
+            _trx->close_state, expected, UBR_CLOSE_SECOND)) {
+        return ReleaseTrx();
+    }
+    // Drain timer callbacks before unmapping the queues they access.
+    DeleteTimerSafe(_trx->timer_fd);
+    DeleteTimerSafe(_trx->hb_timer_fd);
+    DeleteTimerSafe(_trx->clear_timer_fd);
+    RETURN_CODE rc = UbrTrxFreeShm(_trx);
+    if (rc == UBRING_OK) {
+        rc = ReleaseTrx();
+    }

Review Comment:
   fixed



##########
src/brpc/ubshm/ub_ring.cpp:
##########
@@ -220,41 +221,9 @@ RETURN_CODE UBRing::UbrAddHBTimer() {
     return UBRING_OK;
 }
 
-RETURN_CODE UBRing::UbrPassiveClearTrx(UbrTrx *trx, int fd, PASSIVE_DISC_TYPE 
type) {
-    RETURN_CODE passive_close_check_rc = UbrTrxCloseCheck(trx);
-    if (UNLIKELY(passive_close_check_rc != UBRING_OK)) {
-        if (passive_close_check_rc == UBRING_REENTRY) {
-            LOG(INFO) << "Passive close skipped, active close in progress, 
name=" << trx->local_shm.name;
-            uint64_t start_time = GetCurNanoSeconds();
-            return ClearTrxResource(trx, start_time, UBR_CALL_BACK_CLOSE);
-        }
-        return UBRING_ERR;
-    }
-    trx->ubr_tx.trx_state = UBR_STATE_CLOSED;
-    trx->ubr_rx.trx_state = UBR_STATE_CLOSED;
-    DeleteTimerSafe((uint32_t)trx->timer_fd);
-    const char *type_name = nullptr;
-    if (type == UBR_HEARTBEAT) {
-        DeleteTimer((uint32_t)trx->hb_timer_fd);
-        type_name = "Trx heartbeat";
-    } else if (type == UBR_UB_EVENT) {
-        DeleteTimerSafe((uint32_t)trx->hb_timer_fd);
-        type_name = "Ub event callback";
-    }
-    constexpr int64_t kMicrosecondsPerSecond = 1000000LL;
-    bthread_usleep(FLAGS_ub_flying_io_timeout_s * kMicrosecondsPerSecond);
-
-    int rc = ShmLocalFree(&trx->remote_shm);
-    if (rc != UBRING_OK) {
-        LOG(ERROR) << type_name << ", delete remote shm failed. ret=" << rc;
-    }
-    rc = ShmLocalFree(&trx->local_shm);
-    if (rc != UBRING_OK) {
-        LOG(ERROR) << type_name << ", delete local shm failed. ret=" << rc;
-    }
-
-    UBRingManager::ReleaseUbrTrxFromMgr(trx);
-    return UBRING_OK;
+RETURN_CODE UBRing::UbrPassiveClearTrx(UbrTrx* trx) {
+    const RETURN_CODE rc = ClearTrxResource(trx, UBR_PASSIVE_CLOSE);
+    return rc == UBRING_REENTRY ? UBRING_OK : rc;

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to