[asterisk-commits] juggie: branch juggie/NoLossCDR r84112 - in /team/juggie/NoLossCDR: cdr/ incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 28 16:03:47 CDT 2007


Author: juggie
Date: Fri Sep 28 16:03:46 2007
New Revision: 84112

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84112
Log:
Corydon wins, we allways retry and dont try to guess if the error is fatal or retryable

Modified:
    team/juggie/NoLossCDR/cdr/cdr_adaptive_odbc.c
    team/juggie/NoLossCDR/cdr/cdr_csv.c
    team/juggie/NoLossCDR/cdr/cdr_custom.c
    team/juggie/NoLossCDR/cdr/cdr_odbc.c
    team/juggie/NoLossCDR/cdr/cdr_pgsql.c
    team/juggie/NoLossCDR/include/asterisk/cdr.h
    team/juggie/NoLossCDR/main/cdr.c

Modified: team/juggie/NoLossCDR/cdr/cdr_adaptive_odbc.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/cdr/cdr_adaptive_odbc.c?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/cdr/cdr_adaptive_odbc.c (original)
+++ team/juggie/NoLossCDR/cdr/cdr_adaptive_odbc.c Fri Sep 28 16:03:46 2007
@@ -282,7 +282,7 @@
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
 						ast_free(sql);											\
 						ast_free(sql2);											\
-						return AST_CDR_POST_FATAL;								\
+						return AST_CDR_POST_FAILED;								\
 					}															\
 				}																\
 			} while (0)
@@ -297,7 +297,7 @@
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table);	\
 						ast_free(sql);											\
 						ast_free(sql2);											\
-						return AST_CDR_POST_FATAL;								\
+						return AST_CDR_POST_FAILED;								\
 					}															\
 				}																\
 			} while (0)
@@ -557,12 +557,12 @@
 		if (rows == 0) {
 			ast_log(LOG_WARNING, "Insert failed on '%s:%s'.  CDR failed: %s\n", tableptr->connection, tableptr->table, sql);
 			/* We have to assume SQL error here I think, so don't retry. */
-			res = AST_CDR_POST_FATAL;
+			res = AST_CDR_POST_FAILED;
 		}
 		ast_odbc_release_obj(obj);
 	} else {
 		ast_log(LOG_WARNING, "Unable to retrieve database handle for '%s:%s'.  CDR failed: %s\n", tableptr->connection, tableptr->table, sql);
-		res = AST_CDR_POST_RETRY;
+		res = AST_CDR_POST_FAILED;
 	}
 
 	/* Next time, just allocate buffers that are that big to start with. */

Modified: team/juggie/NoLossCDR/cdr/cdr_csv.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/cdr/cdr_csv.c?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/cdr/cdr_csv.c (original)
+++ team/juggie/NoLossCDR/cdr/cdr_csv.c Fri Sep 28 16:03:46 2007
@@ -295,7 +295,7 @@
 #endif
 	if (build_csv_record(buf, sizeof(buf), cdr)) {
 		ast_log(LOG_WARNING, "Unable to create CSV record in %d bytes.  CDR not recorded!\n", (int)sizeof(buf));
-		return AST_CDR_POST_FATAL;
+		return AST_CDR_POST_FAILED;
 	}
 	
 	/* because of the absolutely unconditional need for the
@@ -311,13 +311,13 @@
 	} else {
 		ast_mutex_unlock(&mf_lock);
 		ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", csvmaster, strerror(errno));
-		return AST_CDR_POST_RETRY;
+		return AST_CDR_POST_FAILED;
 	}
 	
 	if (!ast_strlen_zero(cdr->accountcode)) {
 		if (writefile(buf, cdr->accountcode))
 			ast_log(LOG_WARNING, "Unable to write CSV record to account file '%s' : %s\n", cdr->accountcode, strerror(errno));
-			return AST_CDR_POST_RETRY;
+			return AST_CDR_POST_FAILED;
 	}
 
 	return AST_CDR_POST_OK;

Modified: team/juggie/NoLossCDR/cdr/cdr_custom.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/cdr/cdr_custom.c?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/cdr/cdr_custom.c (original)
+++ team/juggie/NoLossCDR/cdr/cdr_custom.c Fri Sep 28 16:03:46 2007
@@ -168,7 +168,7 @@
 	sink->output = fopen(sink->filename, "a");
 	if (!sink->output) {
 		ast_log(LOG_ERROR, "Unable to re-open CDR custom file %s : %s\n", sink->filename, strerror(errno));
-		return AST_CDR_POST_RETRY;
+		return AST_CDR_POST_FAILED;
 	} else {
 		fputs(buf, sink->output);
 		fflush(sink->output); /* be particularly anal here */

Modified: team/juggie/NoLossCDR/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/cdr/cdr_odbc.c?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/cdr/cdr_odbc.c (original)
+++ team/juggie/NoLossCDR/cdr/cdr_odbc.c Fri Sep 28 16:03:46 2007
@@ -119,7 +119,7 @@
 		if (res < 0) {
 			odbc_disconnect();
 			ast_mutex_unlock(&odbc_lock);
-			return 0;
+			return AST_CDR_POST_FAILED;
 		}				
 	}
 
@@ -130,7 +130,7 @@
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 		odbc_disconnect();
 		ast_mutex_unlock(&odbc_lock);
-		return 0;
+		return AST_CDR_POST_FAILED;
 	}
 
 	/* We really should only have to do this once.  But for some
@@ -144,7 +144,7 @@
 		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 		odbc_disconnect();
 		ast_mutex_unlock(&odbc_lock);
-		return 0;
+		return AST_CDR_POST_FAILED;
 	}
 
 	SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, &timestr, 0, NULL);
@@ -193,7 +193,10 @@
 	}
 	SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
 	ast_mutex_unlock(&odbc_lock);
-	return 0;
+	if (res < 0)
+		return AST_CDR_POST_FAILED;
+	else
+		return AST_CDR_POST_OK;
 }
 
 static int odbc_unload_module(void)

Modified: team/juggie/NoLossCDR/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/cdr/cdr_pgsql.c?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/cdr/cdr_pgsql.c (original)
+++ team/juggie/NoLossCDR/cdr/cdr_pgsql.c Fri Sep 28 16:03:46 2007
@@ -120,7 +120,7 @@
 		if ((!clid) || (!dcontext) || (!channel) || (!dstchannel) || (!lastapp) || (!lastdata) || (!uniqueid) || (!userfield)) {
 			ast_log(LOG_ERROR, "cdr_pgsql:  Out of memory error (insert fails)\n");
 			ast_mutex_unlock(&pgsql_lock);
-			return -1;
+			return AST_CDR_POST_FAILED;
 		}
 
 		ast_debug(2, "cdr_pgsql: inserting a CDR record.\n");
@@ -152,7 +152,7 @@
 				conn = NULL;
 				connected = 0;
 				ast_mutex_unlock(&pgsql_lock);
-				return -1;
+				return AST_CDR_POST_FAILED;
 			}
 		}
 		result = PQexec(conn, sqlcmd);
@@ -175,12 +175,12 @@
 			}
 			ast_mutex_unlock(&pgsql_lock);
 			PQclear(result);
-			return -1;
+			return AST_CDR_POST_FAILED;
 		}
 		PQclear(result);
 	}
 	ast_mutex_unlock(&pgsql_lock);
-	return 0;
+	return AST_CDR_POST_OK;
 }
 
 static int unload_module(void)

Modified: team/juggie/NoLossCDR/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/include/asterisk/cdr.h?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/include/asterisk/cdr.h (original)
+++ team/juggie/NoLossCDR/include/asterisk/cdr.h Fri Sep 28 16:03:46 2007
@@ -47,9 +47,8 @@
 
 /* CDR Return Flags */
 #define AST_CDR_POST_OK 0
-#define AST_CDR_POST_RETRY -1
-#define AST_CDR_POST_FATAL -2
-#define AST_CDR_POST_DISABLED -3
+#define AST_CDR_POST_FAILED -1
+#define AST_CDR_POST_DISABLED -2
 
 /* Include channel.h after relevant declarations it will need */
 #include "asterisk/channel.h"

Modified: team/juggie/NoLossCDR/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/main/cdr.c?view=diff&rev=84112&r1=84111&r2=84112
==============================================================================
--- team/juggie/NoLossCDR/main/cdr.c (original)
+++ team/juggie/NoLossCDR/main/cdr.c Fri Sep 28 16:03:46 2007
@@ -800,7 +800,7 @@
 
 	post_cdr(cdr);
 }
-/* todo, add a delay after a failure */
+
 static void *do_cdr(void *data)
 {
 	struct ast_cdr_beitem *i = data;
@@ -838,17 +838,14 @@
 				if (be_res == AST_CDR_POST_OK) {
 					ast_debug(1, "cdr insert into %s ok!\n", i->name);
 					break;
-				} else if (be_res == AST_CDR_POST_RETRY) {
-					ast_debug(1, "cdr insert into %s temporarily failed, retrying\n", i->name);
+				} else if (be_res == AST_CDR_POST_FAILED) {
+					ast_debug(1, "cdr insert into %s failed, retrying\n", i->name);
 					tv = ast_tvadd(ast_tvnow(), ast_samp2tv(retrydelay * 1000, 1000));
 					ts.tv_sec = tv.tv_sec;
 					ts.tv_nsec = tv.tv_usec * 1000;
 					ast_mutex_lock(&i->retry_poll_lock);
 					ast_cond_timedwait(&i->cdr_retry_cond, &i->retry_poll_lock, &ts);
 					ast_mutex_unlock(&i->retry_poll_lock);
-				} else if (be_res == AST_CDR_POST_FATAL){
-					ast_log(LOG_ERROR, "cdr insert *PERMENANTLY* failed in: %s, record lost\n",i->name);
-					break;
 				} else if (be_res == AST_CDR_POST_DISABLED) {
 					ast_debug(1, "cdr backend %s is registered, but disabled\n", i->name);
 					break;




More information about the asterisk-commits mailing list