Skip to content

Commit

Permalink
Merge pull request #1892 from wdoekes/feature/clustering-publish-to-any
Browse files Browse the repository at this point in the history
presence/clustering: Keep presence state on all nodes without shared DB
  • Loading branch information
rvlad-patrascu committed Jan 22, 2020
2 parents 0278b07 + 1c88f8f commit d680f15
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
21 changes: 17 additions & 4 deletions modules/presence/README
Expand Up @@ -228,10 +228,23 @@ modparam("presence", "cluster_id", 2)
1.4.4. cluster_federation_mode (int)

When enabling the federation mode, the node inside the presence
cluster will start partitioning the data (each node will keep
its own data set) and exchange the minimimum of needed
information via the clustering support. A non-zero value means
enabled.
cluster will start broadcasting the data to other nodes in the
cluster via the clustering support. Each node will keep its own
data set. A non-zero value means enabled.

Possible values for mode:
* 0 (default) - no federation/partitioning.
* 1 - the minimum needed information is broadcast/kept.
* 2 - published state is kept on all presence nodes on all
presence nodes, even when there aren't any subscribers.

If you don't want to use a shared database using fallback2db,
but still want a complete data set everywhere, you may choose
mode 2.

This mode allows you to switch PUBLISH endpoints, even for
already published Event States, thus allowing you to add and
remove presence servers without losing state.

For more on presence clustering see the Section 1.2, “Presence
clustering” chapter.
Expand Down
7 changes: 5 additions & 2 deletions modules/presence/clustering.c
Expand Up @@ -383,7 +383,9 @@ static void handle_replicated_publish(bin_packet_t *packet)
delete_cluster_query( &s, ev.parsed, hash_code);
lock_release( &pres_htable[hash_code].lock );

if (presentity_has_subscribers( &s, pres.event)==0) {
if (!discard_unused_cluster_federation_data()) {
LM_DBG("Keeping presentity regardless of subscriber existence\n");
} else if (presentity_has_subscribers(&s, pres.event) == 0) {
LM_DBG("Presentity has NO local subscribers\n");
/* no subscribers for this presentity, discard the publish */
if (p==NULL)
Expand All @@ -392,8 +394,9 @@ static void handle_replicated_publish(bin_packet_t *packet)
LM_DBG("Forcing expires 0\n");
/* force an expire of the presentity */
pres.expires = 0;
} else
} else {
LM_DBG("Presentity has some local subscribers\n");
}
pkg_free(s.s); // allocated by uandd_to_uri()

/* the publish is worthy to be handle, carry on */
Expand Down
5 changes: 5 additions & 0 deletions modules/presence/clustering.h
Expand Up @@ -31,6 +31,11 @@
#define is_cluster_federation_enabled() \
(is_presence_cluster_enabled() && cluster_federation>0)

/* Discard broadcast presentity state when there are no local
* subscribers */
#define discard_unused_cluster_federation_data() \
(cluster_federation == 1)

/* The ID of the presence cluster */
extern int pres_cluster_id;

Expand Down
46 changes: 42 additions & 4 deletions modules/presence/doc/presence_admin.xml
Expand Up @@ -159,10 +159,48 @@ modparam("presence", "cluster_id", 2)
<section id="param_cluster_federation_mode" xreflabel="cluster_federation_mode">
<title><varname>cluster_federation_mode</varname> (int)</title>
<para>
When enabling the federation mode, the node inside the presence cluster
will start partitioning the data (each node will keep its own data
set) and exchange the minimimum of needed information via the
clustering support. A non-zero value means enabled.
When enabling the federation mode, the node inside the presence
cluster will start broadcasting the data to other nodes in the
cluster via the clustering support. Each node will keep its own
data set. A non-zero value means enabled.
</para>
<para>
<emphasis>Possible values for mode:</emphasis>
<itemizedlist>
<listitem>
<para>
<emphasis>0 (default) - no federation/partitioning.</emphasis>
</para>
</listitem>
<listitem>
<para>
<emphasis>1 - the minimum needed information is
broadcast/kept.</emphasis>
</para>
</listitem>
<listitem>
<para>
<emphasis>2 - published state is kept on all
presence nodes on all presence nodes, even when
there aren't any subscribers.</emphasis>
</para>
</listitem>
</itemizedlist>
</para>
<para>
<emphasis>
If you don't want to use a shared database using
<xref linkend="param_fallback2db"/>, but still want a
complete data set everywhere, you may choose mode 2.
</emphasis>
</para>
<para>
<emphasis>
This mode allows you to switch PUBLISH endpoints,
even for already published Event States, thus allowing
you to add and remove presence servers without losing
state.
</emphasis>
</para>
<para>
For more on presence clustering see the
Expand Down

0 comments on commit d680f15

Please sign in to comment.