提交 b9dab1da authored 作者: christian.peter.io's avatar christian.peter.io

Automatic upgrade: Fix "split:", rename old lobs dir, faster import via…

Automatic upgrade: Fix "split:", rename old lobs dir, faster import via UNDO_LOG=0, "analyze", "shutdown compact" after import
上级 060a64c7
...@@ -52,7 +52,7 @@ public class DbUpgrade { ...@@ -52,7 +52,7 @@ public class DbUpgrade {
try { try {
DbUpgradeNonPageStoreToCurrent instance = new DbUpgradeNonPageStoreToCurrent(url, info); DbUpgradeNonPageStoreToCurrent instance = new DbUpgradeNonPageStoreToCurrent(url, info);
runningConversions.put(url, instance); runningConversions.put(url, instance);
instance.upgrade(url, info); instance.upgrade();
} finally { } finally {
runningConversions.remove(url); runningConversions.remove(url);
} }
......
...@@ -14,6 +14,7 @@ import java.sql.Statement; ...@@ -14,6 +14,7 @@ import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FileSystem; import org.h2.store.fs.FileSystem;
import org.h2.store.fs.FileSystemDisk;
import org.h2.util.Utils; import org.h2.util.Utils;
/** /**
...@@ -30,12 +31,15 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -30,12 +31,15 @@ public class DbUpgradeNonPageStoreToCurrent {
private boolean mustBeConverted; private boolean mustBeConverted;
private String newName; private String newName;
private String newUrl;
private String oldUrl; private String oldUrl;
private File oldDataFile; private File oldDataFile;
private File oldIndexFile; private File oldIndexFile;
private File oldLobsDir;
private File newFile; private File newFile;
private File backupDataFile; private File backupDataFile;
private File backupIndexFile; private File backupIndexFile;
private File backupLobsDir;
private boolean successful; private boolean successful;
...@@ -55,6 +59,9 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -55,6 +59,9 @@ public class DbUpgradeNonPageStoreToCurrent {
private void init() throws SQLException { private void init() throws SQLException {
try { try {
newUrl = url;
newUrl = newUrl.replaceAll(";UNDO_LOG=\\d", "");
newUrl += ";UNDO_LOG=0";
String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL"); String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL");
oldUrl = url; oldUrl = url;
oldUrl = oldUrl.replaceAll(org.h2.engine.Constants.START_URL, oldStartUrlPrefix); oldUrl = oldUrl.replaceAll(org.h2.engine.Constants.START_URL, oldStartUrlPrefix);
...@@ -70,9 +77,9 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -70,9 +77,9 @@ public class DbUpgradeNonPageStoreToCurrent {
// remove stackable file systems // remove stackable file systems
int colon = dbName.indexOf(':'); int colon = dbName.indexOf(':');
while (colon != -1) { while (colon != -1) {
String fileSystemPrefix = dbName.substring(colon); String fileSystemPrefix = dbName.substring(0, colon+1);
FileSystem fs = FileSystem.getInstance(fileSystemPrefix); FileSystem fs = FileSystem.getInstance(fileSystemPrefix);
if (fs == null) { if (fs == null || fs instanceof FileSystemDisk) {
break; break;
} }
dbName = dbName.substring(colon+1); dbName = dbName.substring(colon+1);
...@@ -81,12 +88,15 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -81,12 +88,15 @@ public class DbUpgradeNonPageStoreToCurrent {
if (!isRemote && isPersistent) { if (!isRemote && isPersistent) {
String oldDataName = dbName + ".data.db"; String oldDataName = dbName + ".data.db";
String oldIndexName = dbName + ".index.db"; String oldIndexName = dbName + ".index.db";
String oldLobsName = dbName + ".lobs.db";
newName = dbName + ".h2.db"; newName = dbName + ".h2.db";
oldDataFile = new File(oldDataName).getAbsoluteFile(); oldDataFile = new File(oldDataName).getAbsoluteFile();
oldIndexFile = new File(oldIndexName).getAbsoluteFile(); oldIndexFile = new File(oldIndexName).getAbsoluteFile();
oldLobsDir = new File(oldLobsName).getAbsoluteFile();
newFile = new File(newName).getAbsoluteFile(); newFile = new File(newName).getAbsoluteFile();
backupDataFile = new File(oldDataFile.getAbsolutePath() + ".backup"); backupDataFile = new File(oldDataFile.getAbsolutePath() + ".backup");
backupIndexFile = new File(oldIndexFile.getAbsolutePath() + ".backup"); backupIndexFile = new File(oldIndexFile.getAbsolutePath() + ".backup");
backupLobsDir = new File(oldLobsDir.getAbsolutePath() + ".backup");
mustBeConverted = oldDataFile.exists() && !newFile.exists(); mustBeConverted = oldDataFile.exists() && !newFile.exists();
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -98,24 +108,20 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -98,24 +108,20 @@ public class DbUpgradeNonPageStoreToCurrent {
/** /**
* Returns if a database must be converted by this class. * Returns if a database must be converted by this class.
* *
* @param url The connection string
* @param info The connection properties
* @return if the conversion classes were found and the database must be * @return if the conversion classes were found and the database must be
* converted * converted
* @throws SQLException * @throws SQLException
*/ */
public boolean mustBeConverted(String url, Properties info) throws SQLException { public boolean mustBeConverted() throws SQLException {
return mustBeConverted; return mustBeConverted;
} }
/** /**
* Converts the database from 1.1 (non page store) to current (page store). * Converts the database from 1.1 (non page store) to current (page store).
* *
* @param url The connection string
* @param info The connection properties
* @throws SQLException * @throws SQLException
*/ */
public void upgrade(String url, Properties info) throws SQLException { public void upgrade() throws SQLException {
successful = true; successful = true;
if (!mustBeConverted) { if (!mustBeConverted) {
return; return;
...@@ -141,10 +147,13 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -141,10 +147,13 @@ public class DbUpgradeNonPageStoreToCurrent {
oldDataFile.renameTo(backupDataFile); oldDataFile.renameTo(backupDataFile);
oldIndexFile.renameTo(backupIndexFile); oldIndexFile.renameTo(backupIndexFile);
oldLobsDir.renameTo(backupLobsDir);
connection = DriverManager.getConnection(url, info); connection = DriverManager.getConnection(newUrl, info);
stmt = connection.createStatement(); stmt = connection.createStatement();
stmt.execute("runscript from '" + scriptFile + "'"); stmt.execute("runscript from '" + scriptFile + "'");
stmt.execute("analyze");
stmt.execute("shutdown compact");
stmt.close(); stmt.close();
connection.close(); connection.close();
...@@ -163,6 +172,9 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -163,6 +172,9 @@ public class DbUpgradeNonPageStoreToCurrent {
if (backupIndexFile.exists()) { if (backupIndexFile.exists()) {
backupIndexFile.renameTo(oldIndexFile); backupIndexFile.renameTo(oldIndexFile);
} }
if (backupLobsDir.exists()) {
backupLobsDir.renameTo(oldLobsDir);
}
newFile.delete(); newFile.delete();
// errorStream.println("H2 Migration of '" + oldFile.getPath() + // errorStream.println("H2 Migration of '" + oldFile.getPath() +
// "' finished with error: " + e.getMessage()); // "' finished with error: " + e.getMessage());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论