Skip to content

Commit 8f1982c

Browse files
gtjosephgithub-actions[bot]
authored andcommitted
Alternate Channel Storage Backends
Full details: http://s.asterisk.net/dc679ec3 The previous proof-of-concept showed that the cpp_map_name_id alternate storage backed performed better than all the others so this final PR adds only that option. You still need to enable it in menuselect under the "Alternate Channel Storage Backends" category. To select which one is used at runtime, set the "channel_storage_backend" option in asterisk.conf to one of the values described in asterisk.conf.sample. The default remains "ao2_legacy". UpgradeNote: With this release, you can now select an alternate channel storage backend based on C++ Maps. Using the new backend may increase performance and reduce the chances of deadlocks on heavily loaded systems. For more information, see http://s.asterisk.net/dc679ec3
1 parent 2ced792 commit 8f1982c

16 files changed

+2013
-407
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,12 +1090,13 @@ menuselect/nmenuselect: menuselect/makeopts .lastclean
10901090
menuselect/makeopts: makeopts .lastclean
10911091
+$(MAKE_MENUSELECT) makeopts
10921092

1093-
menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc) $(wildcard $(dir)/*.xml)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml utils/utils.xml agi/agi.xml configure makeopts
1093+
menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc) $(wildcard $(dir)/*.xml)) main/channelstorage_makeopts.xml build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml utils/utils.xml agi/agi.xml configure makeopts
10941094
@echo "Generating input for menuselect ..."
10951095
@echo "<?xml version=\"1.0\"?>" > $@
10961096
@echo >> $@
10971097
@echo "<menu name=\"Asterisk Module and Build Option Selection\">" >> $@
10981098
+@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} moduleinfo >> $@; done
1099+
@cat main/channelstorage_makeopts.xml >> $@
10991100
@cat build_tools/cflags.xml >> $@
11001101
+@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} makeopts >> $@; done
11011102
@if [ "${AST_DEVMODE}" = "yes" ]; then \

configs/samples/asterisk.conf.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ documentation_language = en_US ; Set the language you want documentation
130130
; cause Asterisk to search for sounds files in
131131
; AST_DATA_DIR/sounds/custom before searching the
132132
; normal directories like AST_DATA_DIR/sounds/<lang>.
133+
;channel_storage_backend = ao2_legacy ; Select the channel storage backend
134+
; to use for live operation.
135+
; ao2_legacy: Original implementation (default)
136+
; Depending on compile options, the following may also be
137+
; available:
138+
; cpp_map_name_id: Use C++ Maps to index both
139+
; channel name and channel uniqueid.
140+
; See http://s.asterisk.net/dc679ec3 for more information.
133141

134142
; Changing the following lines may compromise your security.
135143
;[files]

include/asterisk/channel.h

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,15 +1455,17 @@ int ast_queue_answer(struct ast_channel *chan, const struct ast_stream_topology
14551455
/*!
14561456
* \brief Change channel name
14571457
*
1458-
* \pre Absolutely all channels _MUST_ be unlocked before calling this function.
1458+
* \pre Absolutely all channels and the channel storage backend _MUST_ be
1459+
* unlocked before calling this function.
14591460
*
14601461
* \param chan the channel to change the name of
14611462
* \param newname the name to change to
14621463
*
1463-
* \note this function must _NEVER_ be used when any channels are locked
1464-
* regardless if it is the channel who's name is being changed or not because
1465-
* it invalidates our channel container locking order... lock container first,
1466-
* then the individual channels, never the other way around.
1464+
* \note this function must _NEVER_ be used when any channels or the channel
1465+
* storage backend are locked regardless if it is the channel who's name is
1466+
* being changed or not because it invalidates our channel container locking
1467+
* order... lock container first, then the individual channels, never the
1468+
* other way around.
14671469
*/
14681470
void ast_change_name(struct ast_channel *chan, const char *newname);
14691471

@@ -3119,48 +3121,64 @@ struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
31193121

31203122
/*! @} End channel iterator definitions. */
31213123

3124+
/*! @{ Channel search functions */
3125+
3126+
/*!
3127+
* \warning Absolutely _NO_ channel locks should be held while calling any of
3128+
* these functions.
3129+
*/
3130+
31223131
/*!
31233132
* \brief Call a function with every active channel
31243133
*
31253134
* \details
31263135
* This function executes a callback one time for each active channel on the
31273136
* system. The channel is provided as an argument to the function.
31283137
*
3129-
* \note Absolutely _NO_ channel locks should be held before calling this function.
31303138
* \since 1.8
31313139
*/
31323140
struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
31333141
void *data, int ao2_flags);
31343142

3135-
/*! @{ Channel search functions */
3136-
31373143
/*!
3138-
* \brief Find a channel by name
3144+
* \brief Find a channel by name or uniqueid
31393145
*
3140-
* \param name the name or uniqueid of the channel to search for
3146+
* \param search the name or uniqueid of the channel to search for
31413147
*
31423148
* \details
3143-
* Find a channel that has the same name as the provided argument.
3149+
* First searches for a channel with a matching name. If not found
3150+
* a search for a channel with a matching uniqueid is done.
31443151
*
3145-
* \retval a channel with the name specified by the argument
3152+
* \retval a channel with a matching name or uniqueid
31463153
* \retval NULL if no channel was found
31473154
*
3155+
*\note The fallback search by uniqueid is a historical thing. If you
3156+
* know the search term is a uniqueid, use \ref ast_channel_get_by_uniqueid
3157+
* instead.
3158+
*
31483159
* \since 1.8
31493160
*/
3150-
struct ast_channel *ast_channel_get_by_name(const char *name);
3161+
struct ast_channel *ast_channel_get_by_name(const char *search);
31513162

31523163
/*!
31533164
* \brief Find a channel by a name prefix
31543165
*
3155-
* \param name The channel name or uniqueid prefix to search for
3156-
* \param name_len Only search for up to this many characters from the name
3166+
* \param search The channel name or uniqueid prefix to search for
3167+
* \param len Only search for up to this many characters from the search term
31573168
*
31583169
* \details
3159-
* Find a channel that has the same name prefix as specified by the arguments.
3170+
* Search for a channel that has the same name prefix as specified by the
3171+
* search term. If not found, search for an exact match on the uniqueid.
3172+
* Searching by partial uniqueid doesn't make any sense as it's usually
3173+
* a system-name plus a timestamp and is not supported.
31603174
*
3161-
* \retval a channel with the name prefix specified by the arguments
3175+
* \retval a channel with a matching name or uniqueid
31623176
* \retval NULL if no channel was found
31633177
*
3178+
*\note The fallback search by uniqueid is a historical thing. If you
3179+
* know the search term is a uniqueid, use \ref ast_channel_get_by_uniqueid
3180+
* instead.
3181+
*
31643182
* \since 1.8
31653183
*/
31663184
struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
@@ -3181,6 +3199,16 @@ struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name
31813199
*/
31823200
struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
31833201

3202+
/*!
3203+
* \brief Find a channel by a uniqueid
3204+
*
3205+
* \param uniqueid The uniqueid to search for
3206+
*
3207+
* \retval a channel with the uniqueid specified by the arguments
3208+
* \retval NULL if no channel was found
3209+
*/
3210+
struct ast_channel *ast_channel_get_by_uniqueid(const char *uniqueid);
3211+
31843212
/*! @} End channel search functions. */
31853213

31863214
/*!
@@ -4998,5 +5026,27 @@ void *ast_channel_get_stream_topology_change_source(struct ast_channel *chan);
49985026
#define ast_channel_has_tech_function(chan, function) \
49995027
(ast_channel_tech(chan) ? ast_channel_tech(chan)->function != NULL : 0)
50005028

5029+
/*!
5030+
* \brief Get the name of the current channel storage driver
5031+
*
5032+
* \return The name of the current channel storage driver
5033+
*/
5034+
const char *ast_channel_get_current_storage_driver_name(void);
5035+
5036+
/*!
5037+
* \internal
5038+
* \brief Set the current channel storage driver
5039+
*
5040+
* \param driver_name The name of the driver to set as the current driver
5041+
*
5042+
* \return 0 on success, -1 on failure
5043+
*
5044+
* \warning Changing the channel storage driver while Asterisk is running is
5045+
* not supported. This function will return an error if called while
5046+
* the ast_fully_booted flag is set. The function is exposed only
5047+
* because options.c needs it to set the driver when reading
5048+
* asterisk.conf.
5049+
*/
5050+
int internal_channel_set_current_storage_driver(const char *driver_name);
50015051

50025052
#endif /* _ASTERISK_CHANNEL_H */

include/asterisk/channel_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ void ast_channel_internal_set_stream_topology_change_source(
3939
void ast_channel_internal_swap_stream_topology(struct ast_channel *chan1,
4040
struct ast_channel *chan2);
4141

42+
/*! \brief The current channel storage driver */
43+
extern const struct ast_channelstorage_driver *current_channel_storage_driver;
44+
extern struct ast_channelstorage_instance *current_channel_storage_instance;
45+
46+
void ast_channel_close_storage(void);
47+
int ast_channel_open_storage(void);
48+
4249
#endif /* ASTERISK_CHANNEL_INTERNAL_H */

include/asterisk/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern "C" {
3232
#define AST_CACHE_DIR_LEN 512
3333
#define AST_FILENAME_MAX 80
3434
#define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
35+
#define AST_CHANNEL_STORAGE_BACKEND_NAME_LEN 80 /*!< Max length of storage backend name */
3536

3637

3738
/*! \ingroup main_options */

main/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ ifeq ($(PJPROJECT_BUNDLED),yes)
3131
SRC:=$(filter-out libasteriskpj.c,$(SRC))
3232
endif
3333
OBJSFILTER:=$(MOD_OBJS) fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
34-
SRC_CC:=$(wildcard *.cc)
34+
35+
SRC_CC:=$(filter-out $(addsuffix .cc,$(MENUSELECT_CHANNELSTORAGE)),$(wildcard *.cc))
36+
SRC:=$(filter-out $(addsuffix .c,$(MENUSELECT_CHANNELSTORAGE)),$(SRC))
37+
3538
OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o) $(SRC_CC:.cc=.oo))
3639

3740
# we need to link in the objects statically, not as a library, because

main/asterisk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ int daemon(int, int); /* defined in libresolv of all places */
245245
#include "asterisk/utf8.h"
246246

247247
#include "../defaults.h"
248+
#include "channelstorage.h"
248249

249250
/*** DOCUMENTATION
250251
<managerEvent language="en_US" name="FullyBooted">
@@ -578,6 +579,8 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c
578579
ast_cli(a->fd, " RTP dynamic payload types: %u-%u\n",
579580
AST_RTP_PT_FIRST_DYNAMIC, AST_RTP_MAX_PT - 1);
580581
}
582+
ast_cli(a->fd, " Channel storage backend: %s\n",
583+
ast_channel_get_current_storage_driver_name());
581584

582585
ast_cli(a->fd, "\n* Subsystems\n");
583586
ast_cli(a->fd, " -------------\n");

0 commit comments

Comments
 (0)