#632 - ENH: Alter AutoTune such that it saves back to autotune.xml (rename any existing autotune file)

This commit is contained in:
Robin Bygrave
2016-04-01 14:56:35 +13:00
parent bdc81bf6f4
commit 27602c15b9
4 changed files with 25 additions and 9 deletions
@@ -41,10 +41,10 @@ public class AutoTuneAllCollection {
/**
* Write the document as an xml file.
*/
public void writeFile(String filePrefix) {
public void writeFile(String filePrefix, boolean withNow) {
AutoTuneXmlWriter writer = new AutoTuneXmlWriter();
writer.write(document, filePrefix);
writer.write(document, filePrefix, withNow);
}
/**
@@ -76,7 +76,7 @@ public class AutoTuneDiffCollection {
public void writeFile(String filePrefix) {
AutoTuneXmlWriter writer = new AutoTuneXmlWriter();
writer.write(document, filePrefix);
writer.write(document, filePrefix, true);
}
/**
@@ -15,19 +15,27 @@ import java.util.Date;
*/
public class AutoTuneXmlWriter {
/**
* Return 'now' as a string to second precision.
*/
public static String now() {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
return df.format(new Date());
}
/**
* Write the document as xml file with the given prefix.
*/
public void write(Autotune document, String filePrefix) {
public void write(Autotune document, String fileName, boolean withNow) {
SortAutoTuneDocument.sort(document);
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
String now = df.format(new Date());
if (withNow) {
fileName += "-" + now() + ".xml";
}
// write the file with serverName and now suffix as we can output the profiling many times
File file = new File(filePrefix + "-" + now + ".xml");
write(document, file);
write(document, new File(fileName));
}
/**
@@ -185,7 +185,15 @@ public class DefaultAutoTuneService implements AutoTuneService {
} else {
AutoTuneAllCollection event = new AutoTuneAllCollection(queryTuner);
int size = event.size();
event.writeFile(profilingFile + "-" + serverName + "-all");
File existingTuning = new File(tuningFile);
if (existingTuning.exists()) {
// rename the existing autotune.xml file (appending 'now')
if (!existingTuning.renameTo(new File(tuningFile+"."+AutoTuneXmlWriter.now()))) {
logger.warn("Failed to rename autotune file [{}]", tuningFile);
}
}
event.writeFile(tuningFile, false);
logger.info("query tuning detected [{}] changes, writing all [{}] tuning entries for server:{}", runtimeChangeCount, size, serverName);
}
}