Issue #1926 consistently fast scan startup

Change-Id: If8d8cc4dd98a7c0b81bb2264a41d520895831b21

Former-commit-id: 10bd3ed35f766bdd61f130082a6917d6841f3351
This commit is contained in:
Nate Jensen 2013-04-26 14:46:19 -05:00
parent 159302cf8c
commit 3caf85558d
6 changed files with 51 additions and 63 deletions

View file

@ -111,6 +111,7 @@ import com.vividsolutions.jts.io.WKBReader;
* Jan 29, 2009 dhladky Initial creation
* Apr 18, 2013 1926 njensen Changed inner data maps to have Long key
* to avoid !TimeStamp.equals(Date) issue
* Apr 26, 2013 1926 njensen Optimized getAvailableUris()
* </pre>
*
* @author dhladky
@ -445,34 +446,6 @@ public class ScanMonitor extends ResourceMonitor implements IScanDialogListener
return scanRec;
}
/**
* Get list of records
*
* @param type
* @param interval
* @return
*/
public ScanRecord[] getScanRecords(ScanTables type, String icao)
throws VizException {
List<ScanRecord> recordList = new ArrayList<ScanRecord>();
String[] uriList = getAvailableUris(type, icao);
for (String uri : uriList) {
Map<String, Object> vals = new HashMap<String, Object>();
vals.put("pluginName", "scan");
vals.put("dataURI", uri);
ScanRecord scanRec = (ScanRecord) Loader.loadData(vals);
File loc = HDF5Util.findHDF5Location(scanRec);
IDataStore dataStore = DataStoreFactory.getDataStore(loc);
if (scanRec != null) {
scanRec.retrieveMapFromDataStore(dataStore);
recordList.add(scanRec);
}
}
return recordList.toArray(new ScanRecord[recordList.size()]);
}
/**
* Return the tilt angle at which the table is currently at
*
@ -1277,41 +1250,40 @@ public class ScanMonitor extends ResourceMonitor implements IScanDialogListener
return uri;
}
public String[] getAvailableUris(ScanTables type, String icao) {
List<String> uriList = new ArrayList<String>();
SimpleDateFormat datef = new SimpleDateFormat(datePattern);
datef.setTimeZone(TimeZone.getTimeZone("Zulu"));
String addedSQL = "";
public List<String> getAvailableUris(ScanTables type, String icao) {
List<String> uriList = null;
String sql = null;
if (type == ScanTables.DMD) {
addedSQL = "' and lastelevationangle = 't'";
} else {
addedSQL = "'";
}
String sql = "(select datauri from scan where type = '"
sql = "(select datauri from scan where type = '"
+ type.name()
+ "' and icao = '"
+ icao
+ addedSQL
+ " order by reftime desc) "
+ "' and lastelevationangle ='t')"
+ " union (select datauri from scan where type = '"
+ type.name()
+ "' and icao = '"
+ icao
+ "' and lastelevationangle = 'f' order by reftime desc, tilt desc limit 1)";
} else {
sql = "(select datauri from scan where type = '" + type.name()
+ "' and icao = '" + icao + "')";
}
try {
List<Object[]> results = DirectDbQuery.executeQuery(sql,
"metadata", QueryLanguage.SQL);
uriList = new ArrayList<String>(results.size());
if (results.size() > 0) {
for (Object[] ob : results) {
uriList.add((String) ob[0]);
}
}
} catch (VizException e) {
e.printStackTrace();
statusHandler.error("Error retrieving scan uris", e);
}
return uriList.toArray(new String[uriList.size()]);
return uriList;
}
/**

View file

@ -21,7 +21,6 @@ package com.raytheon.uf.viz.monitor.scan.resource;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
@ -177,16 +176,12 @@ public class ScanResource extends
PluginDataObject[] pdos = (PluginDataObject[]) object;
ScanRecord scan = null;
List<String> uris = Arrays.asList(getScan().getAvailableUris(
getTable(), resourceData.icao));
for (PluginDataObject pdo : pdos) {
try {
scan = (ScanRecord) pdo;
if (uris.contains(scan.getDataURI())) {
if (scan.getType().equals(getTable().name())) {
if (scan.getIcao().equals(resourceData.icao)
&& scan.getType().equals(getTable().name()))
addRecord(scan);
}
}
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error updating SCAN resource", e);

View file

@ -21,7 +21,6 @@ package com.raytheon.uf.viz.monitor.scan.resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
@ -97,8 +96,8 @@ public class ScanResourceData extends AbstractRequestableResourceData {
protected AbstractVizResource<?, ?> constructResource(
LoadProperties loadProperties, PluginDataObject[] objects)
throws VizException {
List<String> uris = Arrays.asList(getScan().getAvailableUris(
ScanTables.valueOf(tableType), icao));
List<String> uris = getScan().getAvailableUris(
ScanTables.valueOf(tableType), icao);
try {
long t0 = System.currentTimeMillis();
// Forces ScanMonitor to grab data back for one extra hour 1/2 past

View file

@ -133,15 +133,16 @@ public class LPIResource extends
"Label");
getCapability(LabelableCapability.class).setLabelField("Label");
File file = new File(resourceData.getFilename());
String filename = resourceData.getFilename();
File file = new File(filename);
if (!file.isAbsolute()) {
filename = FileUtil.join(VizApp.getMapsDir(), filename);
file = PathManagerFactory.getPathManager().getStaticFile(
FileUtil.join(VizApp.getMapsDir(),
resourceData.getFilename()));
filename);
}
if (file == null || file.exists() == false) {
throw new VizException("Could not find lpi file",
new FileNotFoundException(String.valueOf(file)));
new FileNotFoundException(filename));
}
points = new ArrayList<LPIPoint>();

View file

@ -0,0 +1,17 @@
#!/bin/bash
# DR #1926 - this update script will create a scan index
PSQL="/awips2/psql/bin/psql"
echo "INFO: Creating scan_icao_type_idx"
${PSQL} -U awips -d metadata -c "CREATE INDEX scan_icao_type_idx ON scan USING btree (icao COLLATE pg_catalog.\"default\", type COLLATE pg_catalog.\"default\");"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to create index."
echo "FATAL: The update has failed."
exit 1
fi
echo "INFO: Index created successfully!"
exit 0

View file

@ -0,0 +1,4 @@
CREATE INDEX scan_icao_type_idx
ON scan
USING btree
(icao COLLATE pg_catalog."default", type COLLATE pg_catalog."default");