| 570 | } |
| 571 | |
| 572 | static void receive_entity_delete(enum b2b_entity_type entity_type, |
| 573 | str *entity_key, str *b2bl_key, bin_packet_t *storage) |
| 574 | { |
| 575 | unsigned int hash_index, local_index; |
| 576 | b2bl_tuple_t* tuple = NULL; |
| 577 | int tuple_repl_type; |
| 578 | int lifetime; |
| 579 | b2bl_entity_id_t *entity = NULL, **entity_head = NULL; |
| 580 | int i; |
| 581 | |
| 582 | LM_DBG("Received DELETE event for entity [%.*s]\n", |
| 583 | entity_key->len, entity_key->s); |
| 584 | |
| 585 | if (b2bl_parse_key(b2bl_key, &hash_index, &local_index) < 0) { |
| 586 | LM_ERR("Bad tuple key: %.*s\n", b2bl_key->len, b2bl_key->s); |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | B2BL_LOCK_GET(hash_index); |
| 591 | |
| 592 | tuple = b2bl_search_tuple_safe(hash_index, local_index); |
| 593 | if (!tuple) { |
| 594 | /* tuple might have already expired locally */ |
| 595 | LM_DBG("Tuple [%.*s] not found, discarding entity [%.*s] delete\n", |
| 596 | b2bl_key->len, b2bl_key->s, entity_key->len, entity_key->s); |
| 597 | B2BL_LOCK_RELEASE(hash_index); |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | bin_pop_int(storage, &tuple_repl_type); |
| 602 | |
| 603 | switch (tuple_repl_type) { |
| 604 | case REPL_TUPLE_UPDATE: |
| 605 | bin_pop_int(storage, &tuple->state); |
| 606 | bin_pop_int(storage, &lifetime); |
| 607 | |
| 608 | tuple->lifetime = lifetime ? get_ticks() + lifetime : 0; |
| 609 | |
| 610 | if (unpack_context_vals(tuple, storage) < 0) { |
| 611 | LM_ERR("Failed to unpack context values\n"); |
| 612 | B2BL_LOCK_RELEASE(hash_index); |
| 613 | return; |
| 614 | } |
| 615 | break; |
| 616 | case REPL_TUPLE_NO_INFO: |
| 617 | /* tuple already deleted on sender, no info to pop */ |
| 618 | break; |
| 619 | default: |
| 620 | LM_ERR("Bad tuple replication type: %d\n", tuple_repl_type); |
| 621 | B2BL_LOCK_RELEASE(hash_index); |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | entity = b2bl_search_entity(tuple, entity_key, entity_type, &entity_head); |
| 626 | if (entity) |
| 627 | b2bl_delete_entity(entity, tuple, hash_index, 0); |
| 628 | else |
| 629 | LM_DBG("Entity [%.*s] does not exist\n", entity_key->len, entity_key->s); |
no test coverage detected