forked from kamailio/kamailio
-
Notifications
You must be signed in to change notification settings - Fork 0
Rtpengine dmq sync #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vlad-korniiaka-idt
wants to merge
5
commits into
master
Choose a base branch
from
rtpengine-dmq-sync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0b82d2
rtpengine: add DMQ sync support for hash table replication
vlad-korniiaka-idt c5caf7e
RTPEngine DMQ SYNC. Changes after review.
vlad-korniiaka-idt 94f551f
use the "node" param of the rtpengine_dmq_replicate_action() function
vlad-korniiaka-idt 7b044cf
Merge branch 'master' into rtpengine-dmq-sync
vlad-korniiaka-idt d601d55
Error after conflicts resolving. Wrong merge
vlad-korniiaka-idt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
|
|
||
| #include "rtpengine.h" | ||
| #include "rtpengine_dmq.h" | ||
| #include "../../core/timer.h" | ||
|
|
||
| static str rtpengine_dmq_content_type = str_init("application/json"); | ||
| static str rtpengine_dmq_200_rpl = str_init("OK"); | ||
|
|
@@ -31,7 +32,8 @@ static str rtpengine_dmq_500_rpl = str_init("Server Internal Error"); | |
| dmq_api_t rtpengine_dmqb; | ||
| dmq_peer_t *rtpengine_dmq_peer = NULL; | ||
|
|
||
| int rtpengine_dmq_request_sync(dmq_node_t *node); | ||
| int rtpengine_dmq_request_sync(); | ||
| int rtpengine_dmq_send(str *body, dmq_node_t *node); | ||
|
|
||
| /** | ||
| * @brief add rtpengine notification peer | ||
|
|
@@ -64,9 +66,44 @@ int rtpengine_dmq_init() | |
| return 0; | ||
| } | ||
|
|
||
| int rtpengine_dmq_request_sync(dmq_node_t *node) | ||
| int rtpengine_dmq_request_sync() | ||
| { | ||
| srjson_doc_t jdoc; | ||
|
|
||
| LM_DBG("requesting sync from dmq peers\n"); | ||
|
|
||
| srjson_InitDoc(&jdoc, NULL); | ||
|
|
||
| jdoc.root = srjson_CreateObject(&jdoc); | ||
| if(jdoc.root == NULL) { | ||
| LM_ERR("cannot create json root\n"); | ||
| goto error; | ||
| } | ||
|
|
||
| srjson_AddNumberToObject(&jdoc, jdoc.root, "action", RTPENGINE_DMQ_SYNC); | ||
| jdoc.buf.s = srjson_PrintUnformatted(&jdoc, jdoc.root); | ||
| if(jdoc.buf.s == NULL) { | ||
| LM_ERR("unable to serialize data\n"); | ||
| goto error; | ||
| } | ||
| jdoc.buf.len = strlen(jdoc.buf.s); | ||
| LM_DBG("sending serialized data %.*s\n", jdoc.buf.len, jdoc.buf.s); | ||
| if(rtpengine_dmq_send(&jdoc.buf, 0) != 0) { | ||
| goto error; | ||
|
vlad-korniiaka-idt marked this conversation as resolved.
|
||
| } | ||
|
Comment on lines
+89
to
+93
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have checked:
|
||
|
|
||
| jdoc.free_fn(jdoc.buf.s); | ||
| jdoc.buf.s = NULL; | ||
| srjson_DestroyDoc(&jdoc); | ||
| return 0; | ||
|
|
||
| error: | ||
| if(jdoc.buf.s != NULL) { | ||
| jdoc.free_fn(jdoc.buf.s); | ||
| jdoc.buf.s = NULL; | ||
| } | ||
| srjson_DestroyDoc(&jdoc); | ||
| return -1; | ||
| } | ||
|
|
||
| int rtpengine_dmq_handle_msg( | ||
|
|
@@ -197,6 +234,10 @@ int rtpengine_dmq_handle_msg( | |
| goto error; | ||
| break; | ||
| case RTPENGINE_DMQ_SYNC: | ||
| if(rtpengine_dmq_replicate_sync(node) != 0) { | ||
| goto error; | ||
| } | ||
|
vlad-korniiaka-idt marked this conversation as resolved.
|
||
| break; | ||
| case RTPENGINE_DMQ_NONE: | ||
| break; | ||
| } | ||
|
|
@@ -276,7 +317,7 @@ int rtpengine_dmq_replicate_action(rtpengine_dmq_action_t action, str callid, | |
| if(jdoc.buf.s != NULL) { | ||
| jdoc.buf.len = strlen(jdoc.buf.s); | ||
| LM_DBG("sending serialized data %.*s\n", jdoc.buf.len, jdoc.buf.s); | ||
| if(rtpengine_dmq_send(&jdoc.buf, 0) != 0) { | ||
| if(rtpengine_dmq_send(&jdoc.buf, node) != 0) { | ||
| goto error; | ||
| } | ||
| jdoc.free_fn(jdoc.buf.s); | ||
|
|
@@ -310,3 +351,51 @@ int rtpengine_dmq_replicate_remove(str callid, str viabranch) | |
| return rtpengine_dmq_replicate_action( | ||
| RTPENGINE_DMQ_REMOVE, callid, viabranch, NULL, NULL); | ||
| } | ||
|
|
||
| int rtpengine_dmq_replicate_sync(dmq_node_t *node) | ||
| { | ||
| int i; | ||
| struct rtpengine_hash_entry *entry; | ||
| struct rtpengine_hash_table *hash_table; | ||
|
|
||
| LM_DBG("replicating all hash entries to dmq peers\n"); | ||
|
|
||
| if(!rtpengine_hash_table_sanity_checks()) { | ||
| LM_ERR("sanity checks failed\n"); | ||
| return -1; | ||
| } | ||
| hash_table = rtpengine_hash_table_get(); | ||
| if(!hash_table) { | ||
| LM_ERR("NULL rtpengine_hash_table\n"); | ||
| return -1; | ||
| } | ||
|
|
||
| for(i = 0; i < hash_table->size; i++) { | ||
| lock_get(&hash_table->row_locks[i]); | ||
|
|
||
| entry = hash_table->row_entry_list[i]; | ||
|
|
||
| while(entry) { | ||
| if(entry->tout >= get_ticks()) { | ||
| LM_DBG("replicating hash entry callid=%.*s viabranch=%.*s\n", | ||
| entry->callid.len, entry->callid.s, | ||
| entry->viabranch.len, entry->viabranch.s); | ||
|
|
||
| if(rtpengine_dmq_replicate_action(RTPENGINE_DMQ_INSERT, | ||
| entry->callid, entry->viabranch, entry, node) | ||
| != 0) { | ||
| LM_ERR("failed to replicate hash entry callid=%.*s " | ||
| "viabranch=%.*s\n", | ||
| entry->callid.len, entry->callid.s, | ||
| entry->viabranch.len, entry->viabranch.s); | ||
| } | ||
| } | ||
|
|
||
| entry = entry->next; | ||
| } | ||
|
|
||
| lock_release(&hash_table->row_locks[i]); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.