pmeinfo使用引用计数,规避业务逻辑导致的无效pme问题。

This commit is contained in:
zhengchao
2019-06-05 16:46:56 +08:00
parent c899449a50
commit 963d780226

View File

@@ -36,6 +36,7 @@ struct http_project{
};
struct pme_info{
int ref_cnt;
int protocol;
int policy_id;
int maat_hit;
@@ -145,6 +146,7 @@ struct traceid2pme_search_cb_args{
static struct pme_info* pme_info_new(const struct streaminfo *stream, int thread_seq, void *logger){
struct pme_info* pmeinfo = ALLOC(struct pme_info, 1);
pmeinfo->ref_cnt=1;
pmeinfo->tfe_id = g_kni_handle->tfe_count > 0 ? thread_seq % g_kni_handle->tfe_count : -1;
uuid_t uu;
uuid_generate_random(uu);
@@ -274,7 +276,9 @@ error_out:
static void pme_info_destroy(struct pme_info *pmeinfo){
void *logger = pmeinfo->logger;
if(pmeinfo != NULL && pmeinfo->sapp_release == 1 && pmeinfo->tfe_release == 1){
assert(pmeinfo->ref_cnt<=2);
pmeinfo->ref_cnt--;
if(pmeinfo->ref_cnt == 0){
int ret = sendlog_to_kafka(pmeinfo, logger);
if(ret < 0){
KNI_LOG_ERROR(logger, "Failed at sendlog to kafka");
@@ -697,6 +701,7 @@ extern "C" char kni_tcpall_entry(const struct streaminfo *stream, void** pme, in
case OP_STATE_PENDING:
*pme = pmeinfo = pme_info_new(stream, thread_seq, logger);
key_size = strnlen(pmeinfo->stream_trace_id, sizeof(pmeinfo->stream_trace_id));
pmeinfo->ref_cnt++;
ret = MESA_htable_add(g_kni_handle->traceid2pme_htable, (const unsigned char *)(pmeinfo->stream_trace_id),
key_size, (const void*)pmeinfo);
if(ret < 0){