Aerospike 读写过程中对partition tree的引用计数的处理

as_tsvc_process_transaction:
    as_partition_reserve_write or as_partition_reserve_read
	    pthread_mutex_lock(&p->lock);
        ...
        partition_reserve_lockfree(p, ns, rsv);
        |--cf_rc_reserve(p->vp);
		pthread_mutex_unlock(&p->lock);
        ...
    if (is_write) {
        if (as_transaction_is_delete(tr)) {
            status = as_delete_start(tr);
        }else if (tr->origin == FROM_IUDF || as_transaction_is_udf(tr)) {
            status = as_udf_start(tr);
        }else {
            status = as_write_start(tr);
        }
    }else {
        status = as_read_start(tr);
    }
    switch (status) {
    case TRANS_DONE_ERROR:
    case TRANS_DONE_SUCCESS:
    // Done, response already sent - free msg & release reservation.
        as_partition_release(&tr->rsv);
        break;
    case TRANS_IN_PROGRESS:
    // Don't free msg or release reservation - both owned by rw_request.
        free_msgp = false;
        break;
    case TRANS_WAITING:
    // Will be re-queued - don't free msg, but release reservation.
        free_msgp = false;
        as_partition_release(&tr->rsv);
        break;
    default:
        cf_crash(AS_TSVC, "invalid transaction status %d", status);
        break;
    }

1、事务处理流程一

thr_demarshal:
    as_tsvc_process_transaction(&tr);
2、事务处理流程二
thr_demarshal:
    as_batch_queue_task(&tr)->as_tsvc_process_transaction(&tr);
                            ->as_tsvc_enqueue(&tr);
3、事务处理流程三
thr_demarshal:
    as_tsvc_enqueue(&tr);
run_tsvc:
    cf_queue *q = g_transaction_queues[qid];
    while (true) {
        cf_queue_pop(q, &tr, CF_QUEUE_FOREVER);
        as_tsvc_process_transaction(&tr);
    }
1、partition_reserve_lockfree该函数会对partition tree引用计数加1
2、事务处理的几个流程最终都会调用as_tsvc_process_transaction进行事务处理
   先对partition的tree引用计数加1。操作结束后根据as_delete_start | as_write_start
   | as_read_start | as_udf_start的返回值对引用计数减一:
   1)TRANS_DONE_ERROR | TRANS_DONE_SUCCESS :对引用计数减一
   2)TRANS_IN_PROGRESS:引用计数不减一
   3)TRANS_WAITING:引用计数减一
   4)else:也不减一
3、as_write_start返回TRANS_DONE_ERROR
   1)dupl写失败,将rw从g_rw_request_hash表删除
4、as_write_start返回TRANS_IN_PROGRESS
   1)dupl写成功

3和4都需要写dupl情况,最后直接返回。5之后都是不需要dupl情况:


5、as_write_start返回TRANS_IN_PROGRESS:write_master写成功,之后开始写replica
6、write_master写成功返回TRANS_IN_PROGRESS,否则返回TRANS_DONE_ERROR
   1)当返回TRANS_DONE_ERROR时,会将rw从g_rw_request_hash表删除并返回TRANS_DONE_ERROR
   2)write_master写成功返回TRANS_IN_PROGRESS时,如果不需要写replica,返回TRANS_DONE_SUCCESS
   3)否则初始化写replica的rw失败返回TRANS_DONE_ERROR


总结:
1、as_write_start函数只有写成功后,并需要写replica时才会对partition tree 的引用计数不减一。
2、目标节点write_replica过程中会对partition tree引用计数加一,结束后减一
3、repl_write_handle_ack接收到replica写完成的ACK后调用rw_request_release(rw)->rw_request_destroy(rw)
   ->as_partition_release(&rw->rsv);将partition tree的引用计数减一  

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值