Skip to content

Commit 1ee0214

Browse files
committed
b2b_entities: add support for locked_by per entities
1 parent 04ab2c8 commit 1ee0214

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

modules/b2b_entities/b2b_entities.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "../../dprint.h"
3636
#include "../../error.h"
3737
#include "../../ut.h"
38+
#include "../../pt.h"
3839
#include "../../script_cb.h"
3940
#include "../../parser/parse_from.h"
4041
#include "../dialog/dlg_load.h"
@@ -416,6 +417,7 @@ int b2b_update_b2bl_param(enum b2b_entity_type type, str* key,
416417
b2b_dlg_t* dlg;
417418
b2b_table table;
418419
unsigned int hash_index, local_index;
420+
int unlock = 1;
419421

420422
if(!param)
421423
{
@@ -442,17 +444,23 @@ int b2b_update_b2bl_param(enum b2b_entity_type type, str* key,
442444
LM_ERR("Wrong format for b2b key [%.*s]\n", key->len, key->s);
443445
return -1;
444446
}
445-
lock_get(&table[hash_index].lock);
447+
if (table[hash_index].locked_by != process_no)
448+
lock_get(&table[hash_index].lock);
449+
else
450+
unlock = 0;
451+
446452
dlg = b2b_search_htable(table, hash_index, local_index);
447453
if(dlg == NULL)
448454
{
449455
LM_ERR("No dialog found\n");
450-
lock_release(&table[hash_index].lock);
456+
if (unlock)
457+
lock_release(&table[hash_index].lock);
451458
return -1;
452459
}
453460
memcpy(dlg->param.s, param->s, param->len);
454461
dlg->param.len = param->len;
455-
lock_release(&table[hash_index].lock);
462+
if (unlock)
463+
lock_release(&table[hash_index].lock);
456464

457465
if (b2be_cluster)
458466
replicate_entity_update(dlg, type, hash_index, param, NULL);

modules/b2b_entities/b2be_clustering.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "b2be_clustering.h"
3838
#include "b2b_entities.h"
3939
#include "b2be_db.h"
40+
#include "../../pt.h"
4041

4142
#define NO_REPL_CONSTANT_STRS 10
4243

@@ -453,9 +454,12 @@ int receive_entity_create(bin_packet_t *packet, b2b_dlg_t *dlg, int type,
453454
new_dlg->legs = new_leg;
454455

455456
lock_get(&htable[h_idx].lock);
457+
htable[h_idx].locked_by = process_no;
456458

457459
b2b_run_cb(new_dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_CREATE, packet);
458460

461+
htable[h_idx].locked_by = -1;
462+
459463
new_key = b2b_htable_insert(htable, new_dlg, hash_index, type, 1, 1);
460464
if (new_key == NULL) {
461465
LM_ERR("Failed to insert new record\n");
@@ -547,7 +551,9 @@ int receive_entity_update(bin_packet_t *packet)
547551
if (packet->type == REPL_ENTITY_UPDATE) {
548552
unpack_update_fields(packet, dlg);
549553

554+
htable[hash_index].locked_by = process_no;
550555
b2b_run_cb(dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_UPDATE, packet);
556+
htable[hash_index].locked_by = -1;
551557
} else {
552558
rc = recv_b2bl_param_update(packet, dlg);
553559
}
@@ -601,7 +607,9 @@ int receive_entity_delete(bin_packet_t *packet)
601607
return 0;
602608
}
603609

610+
htable[hash_index].locked_by = process_no;
604611
b2b_run_cb(dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_DELETE, packet);
612+
htable[hash_index].locked_by = -1;
605613

606614
b2b_entity_db_delete(type, dlg);
607615
b2b_delete_record(dlg, htable, hash_index);

modules/b2b_entities/dlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct b2b_entry
117117
{
118118
b2b_dlg_t* first;
119119
gen_lock_t lock;
120+
int locked_by;
120121
int checked;
121122
}b2b_entry_t;
122123

0 commit comments

Comments
 (0)