225c0d55992aefae478461bba278644bdfdda3c5
max
  Wed Jan 15 08:33:57 2014 -0800
library changes for the browser box: This changes mostly hdb and jksql,plus - to a smaller extent - various other places in the code that deal
with /gbdb/ files.  The overall aim is to make it possible to have the
data remote at UCSC while having the CGIs on a machine far away. At up to
180msecs distance from UCSC (Europe,Japan), each query can get slow. So
I tried to reduce the number of queries sent to UCSC while allowing to
keep some mysql tables on localhost.

I changed four things:
- extend larry's table cache to include field names. The code uses
"describe" very often, which is slow from remote. With a table name
cache these queries can be handled locally. This is configured in
hg.conf
- mysql "failover" connections: a mysql connection can have a 2nd
connection that is used if a query fails, configured in hg.conf
(I didn't call it "remote" connections, because we use that term already
in the code)
- mysql lazy connects: don't connect a sqlConnection right away, but
only when needed. a mysql connect takes >500msecs from across the
atlantic.
- move gbdb: patch various places that use absolute "/gbdb/" pathnames
to go through a central function that can change the filename of
gbdb files to something else, as configured in hg.conf

Plus patch 1 or 2 lines for more speed + update the hgMirror script

diff --git src/hg/hgVai/hgVai.c src/hg/hgVai/hgVai.c
index eb12344..aa23fe7 100644
--- src/hg/hgVai/hgVai.c
+++ src/hg/hgVai/hgVai.c
@@ -543,46 +543,49 @@
 if (table != NULL)
     tableName = cloneString(table->name);
 slNameFreeList(&snpNNNTables);
 return tableName;
 }
 
 boolean findSnpBed4(char *suffix, char **retFileName, struct trackDb **retTdb)
 /* If we can find the latest snpNNNsuffix table, or better yet a bigBed file for it (faster),
  * set the appropriate ret* and return TRUE, otherwise return FALSE. */
 {
 char *table = findLatestSnpTable(suffix);
 if (table == NULL)
     return FALSE;
 boolean foundIt = FALSE;
 // Do we happen to have a bigBed version?  Better yet, bed4 only for current uses:
-char fileName[HDB_MAX_PATH_STRING];
-safef(fileName, sizeof(fileName), "/gbdb/%s/vai/%s.bed4.bb", database, table);
+char origFileName[HDB_MAX_PATH_STRING];
+safef(origFileName, sizeof(origFileName), "/gbdb/%s/vai/%s.bed4.bb", database, table);
+char* fileName = hCloneRewriteFileName(origFileName);
 if (fileExists(fileName))
     {
     if (retFileName != NULL)
-	*retFileName = cloneString(fileName);
+	*retFileName = fileName;
     foundIt = TRUE;
     }
 else
     {
     // Not bed4; try just .bb:
-    safef(fileName, sizeof(fileName), "/gbdb/%s/vai/%s.bb", database, table);
+    freez(&fileName);
+    safef(origFileName, sizeof(origFileName), "/gbdb/%s/vai/%s.bb", database, table);
+    fileName = hCloneRewriteFileName(origFileName);
     if (fileExists(fileName))
 	{
 	if (retFileName != NULL)
-	    *retFileName = cloneString(fileName);
+	    *retFileName = fileName;
 	foundIt = TRUE;
 	}
     }
 if (foundIt && retTdb == NULL)
     return TRUE;
 struct trackDb *tdb = tdbForTrack(database, table, &fullTrackList);
 if (tdb != NULL)
     {
     if (retTdb != NULL)
 	*retTdb = tdb;
     return TRUE;
     }
 return foundIt;
 }
 
@@ -897,31 +900,33 @@
     ! sameString(tdb->type, "vcfTabix"))
     {
     errAbort("Expected variant track '%s' to be either pgSnp or vcfTabix, but it's '%s'",
 	     tdb->track, tdb->type);
     }
 }
 
 char *fileNameFromTable(char *table)
 /* Get fileName from a bigData table (for when we don't have a trackDb, just table). */
 {
 struct sqlConnection *conn = hAllocConn(database);
 char query[512];
 sqlSafef(query, sizeof(query), "select fileName from %s", table);
 char *fileName = sqlQuickString(conn, query);
 hFreeConn(&conn);
-return fileName;
+char *fileNameRewrite = hCloneRewriteFileName(fileName);
+freez(&fileName);
+return fileNameRewrite;
 }
 
 void textOpen()
 /* Start serving up plain text, possibly via a pipeline to gzip. */
 {
 char *fileName = cartUsualString(cart, "hgva_outFile", "");
 char *compressType = cartUsualString(cart, "hgva_compressType", textOutCompressGzip);
 compressPipeline = textOutInit(fileName, compressType);
 }
 
 void setGpVarFuncFilter(struct annoGrator *gpVarGrator)
 /* Use cart variables to configure gpVarGrator's filtering by functional category. */
 {
 struct annoGratorGpVarFuncFilter aggvFuncFilter;
 ZeroVar(&aggvFuncFilter);