[asterisk-commits] snuffy: branch snuffy/func_memcache r230765 - in /team/snuffy/func_memcache: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 20 18:59:33 CST 2009


Author: snuffy
Date: Fri Nov 20 18:59:31 2009
New Revision: 230765

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=230765
Log:
More updates, some spelling, make sample more clean.
Testers welcome, also autoconf person would be nice.

Modified:
    team/snuffy/func_memcache/configs/func_memcache.conf.sample
    team/snuffy/func_memcache/funcs/func_memcache.c

Modified: team/snuffy/func_memcache/configs/func_memcache.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/snuffy/func_memcache/configs/func_memcache.conf.sample?view=diff&rev=230765&r1=230764&r2=230765
==============================================================================
--- team/snuffy/func_memcache/configs/func_memcache.conf.sample (original)
+++ team/snuffy/func_memcache/configs/func_memcache.conf.sample Fri Nov 20 18:59:31 2009
@@ -1,33 +1,33 @@
 [general]
-; Default Transport Protocol, either tcp or udp
-; If you choose to use udp, some features may not be available
-;transportprotocol=tcp
+; Default Transport Protocol, either TCP or UDP
+; If you choose to use udp, you can ONLY SET VALUES.
+; transportprotocol=tcp
 ;
-; Doing multiple gets, or high usage you may see improvement using binary protocol.
+; Under high usage you may see improvement using binary protocol.
 ; memcacheprotocol=text
 ;
-; Hash Method, only consistent for now
-; distrubitehash=consistent
+; For mirrored memcache set type to 'mirror'
+; type=normal
 ;
+; Hash Method, only consistant for now
+; distributehash=consistant
 ;
+; If server port not specified it defaults to 11211 
 ;
 ; Mirrored Cache
-; Allows for copying values to two servers.
-; Replicas are only of use if you use the mirror option.
-; replicas=2
-;[mirror]
+; Allows for copying values to X servers.
+;
+;[mymirror]
+;type=mirror
 ;server=localhost:11211
-;mirrorserver=localhost:11212
+;server=localhost:11212
 ;memcacheprotocol=binary
-;replicas=2
 ;
+;[testmem]
+;server=127.0.0.1:21000
+;memcacheprotocol=binary
 ;
-
-[testmem]
-server=127.0.0.1:21000
-memcacheprotocol=binary
-
-[manycaches]
-server=abc.123.com:13333
-server=def.456.com
-server=ghi.789.com
+;[manycaches]
+;server=abc.123.com:13333
+;server=def.123.com:11311
+;server=ghi.123.com

Modified: team/snuffy/func_memcache/funcs/func_memcache.c
URL: http://svnview.digium.com/svn/asterisk/team/snuffy/func_memcache/funcs/func_memcache.c?view=diff&rev=230765&r1=230764&r2=230765
==============================================================================
--- team/snuffy/func_memcache/funcs/func_memcache.c (original)
+++ team/snuffy/func_memcache/funcs/func_memcache.c Fri Nov 20 18:59:31 2009
@@ -109,13 +109,21 @@
 	int trans_protocol;
 	/*! Memcache Protocol either TEXT/BINARY */
 	int memc_protocol;
+	/*! Mirror connection */
 	int mirror;
-	unsigned int flags; /* bitmasking instead? */
-	char hash; /* consistent (cluster) or other */
+	/*! Unsed ATM */
+	unsigned int flags; 
+	/*! Memcache key hash */
+	char hash; 
+	/*! Memcache connection */
 	memcached_st *conn;
+	/*! Memcache list of servers */
 	memcached_server_st *servers;
+	/*! Memcache error code return */
 	memcached_return rc;
+	/*! Link to next entry */
 	AST_RWLIST_ENTRY(memcache_con) list;
+	/*! Internal list of servers */
 	AST_LIST_HEAD(_serv_list, memc_servers) serv_list;
 };	
 
@@ -139,10 +147,14 @@
 	AST_RWLIST_RDLOCK(&memcaches);
 	AST_RWLIST_TRAVERSE(&memcaches, memc, list) {
 		if (!strcmp(memc->name, server)) {
-			value = memcached_get(memc->conn, key, strlen(key), &value_len, &flags, &memc->rc);
-			if (memc->rc != 0) {
-				ast_log(LOG_ERROR, "Memcache Error: %s\n", 
-					memcached_strerror(memc->conn, memc->rc));
+			if (client->trans_protocol == 0) {
+				value = memcached_get(memc->conn, key, strlen(key), &value_len, &flags, &memc->rc);
+				if (memc->rc != 0) {
+					ast_log(LOG_ERROR, "Memcache Error: %s\n", 
+						memcached_strerror(memc->conn, memc->rc));
+				}
+			} else {
+				ast_log(LOG_ERROR, "Memcache 'READ' is unavailable under UDP\n");
 			}
 		}
 	}
@@ -287,7 +299,7 @@
 		return -1;
 	}	
 	if (fn_memcache_put(args.key, args.server, args.expiry, value)) {
-		ast_log(LOG_WARNING, "MEMCACHE: Error writing key:%s & Value:%s to server.\n", args.key, value);
+		ast_log(LOG_WARNING, "MEMCACHE error writing key:%s to server\n", args.key);
 		return -1;
 	}
 
@@ -355,8 +367,7 @@
 	}	
 
 	if (fn_memcache_get(args.key, args.server, buf, len)) {
-		ast_debug(1, "MEMCACHE_DELETE: %s/%s not found in database.\n", 
-				args.server, args.key);
+		ast_debug(1, "MEMCACHE_DELETE: %s/%s not found in database\n", args.server, args.key);
 		pbx_builtin_setvar_helper(chan, "MEMCACHE_RESULT", "");
 		strcpy(buf, "0");
 	} else {
@@ -399,17 +410,20 @@
 		return 1;
 	}
 
+	/* Set defaults of connection */
 	client->trans_protocol = 0;
 	client->memc_protocol = 0;
+	client->mirror = 0;
 
 	ast_copy_string(client->name, cat, sizeof(client->name));
 
 	while (var) {
 		if (!strcasecmp(var->name, "server")) {
 			/* Split server string name:port */
+			struct memc_servers *serv;
 			char *server = ast_strdupa(var->value);
 			char *cport = strchr(server, ':');
-			struct memc_servers *serv;
+
 			serv = ast_calloc(1, sizeof(*serv));
 			
 			if (cport) {
@@ -434,8 +448,7 @@
 				client->memc_protocol = 1;
 			}
 		} else if (!strcasecmp(var->name, "distributehash")) {
-			client->hash=1;/* Fixed HASH ATM */
-			/*ast_copy_string(client->hash, var->value, sizeof(client->hash));*/
+			client->hash = 1;
 		} else if (!strcasecmp(var->name, "type")) {
 			if (!strcmp(var->value, "mirror")) { 
 				client->mirror = 1;
@@ -451,7 +464,7 @@
 
 	if (client->trans_protocol) {
 		memcached_behavior_set(client->conn, MEMCACHED_BEHAVIOR_USE_UDP, 1);
-		ast_debug(3, "UDP Transport Active\n");
+		ast_debug(3, "UDP Transport Active, Remember: No READS allowed\n");
 	}
 
 	if (client->memc_protocol) {
@@ -557,11 +570,11 @@
 
 static int load_module(void)
 {
-	int res = 0;
 	struct ast_config *cfg = NULL;
 	struct ast_variable *var = NULL;
+	struct ast_flags config_flags = { 0 };
+	int res = 0;
 	char *cat;
-	struct ast_flags config_flags = { 0 };
 
 	res |= ast_custom_function_register(&memcache_function);
 	res |= ast_custom_function_register(&memcache_delete_function);
@@ -593,8 +606,8 @@
 
 static int unload_module(void)
 {
+	struct memcache_con *client;
 	int res = 0;
-	struct memcache_con *client;
 
 	AST_RWLIST_WRLOCK(&memcaches);
 
@@ -625,8 +638,8 @@
 	struct ast_config *cfg;
 	struct ast_variable *var = NULL;
 	struct memcache_con *oldmem;
+	struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
 	char *cat;
-	struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
 
 	cfg = ast_config_load(config, config_flags);
 	if (cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)




More information about the asterisk-commits mailing list