提交 1311dfef authored 作者: noelgrandin's avatar noelgrandin

fix NPE when backing up and there is a ".mv.db" file lying around that we do not…

fix NPE when backing up and there is a ".mv.db" file lying around that we do not currently have open
上级 a628610c
...@@ -59,17 +59,19 @@ public class BackupCommand extends Prepared { ...@@ -59,17 +59,19 @@ public class BackupCommand extends Prepared {
throw DbException.get(ErrorCode.DATABASE_IS_NOT_PERSISTENT); throw DbException.get(ErrorCode.DATABASE_IS_NOT_PERSISTENT);
} }
try { try {
Store store = db.getMvStore(); Store mvStore = db.getMvStore();
if (store != null) { if (mvStore != null) {
store.flush(); mvStore.flush();
} }
String name = db.getName(); String name = db.getName();
name = FileUtils.getName(name); name = FileUtils.getName(name);
OutputStream zip = FileUtils.newOutputStream(fileName, false); OutputStream zip = FileUtils.newOutputStream(fileName, false);
ZipOutputStream out = new ZipOutputStream(zip); ZipOutputStream out = new ZipOutputStream(zip);
db.flush(); db.flush();
if (db.getPageStore() != null) {
String fn = db.getName() + Constants.SUFFIX_PAGE_FILE; String fn = db.getName() + Constants.SUFFIX_PAGE_FILE;
backupPageStore(out, fn, db.getPageStore()); backupPageStore(out, fn, db.getPageStore());
}
// synchronize on the database, to avoid concurrent temp file // synchronize on the database, to avoid concurrent temp file
// creation / deletion / backup // creation / deletion / backup
String base = FileUtils.getParent(db.getName()); String base = FileUtils.getParent(db.getName());
...@@ -82,12 +84,12 @@ public class BackupCommand extends Prepared { ...@@ -82,12 +84,12 @@ public class BackupCommand extends Prepared {
if (n.endsWith(Constants.SUFFIX_LOB_FILE)) { if (n.endsWith(Constants.SUFFIX_LOB_FILE)) {
backupFile(out, base, n); backupFile(out, base, n);
} }
if (n.endsWith(Constants.SUFFIX_MV_FILE)) { if (n.endsWith(Constants.SUFFIX_MV_FILE) && mvStore != null) {
MVStore s = store.getStore(); MVStore s = mvStore.getStore();
boolean before = s.getReuseSpace(); boolean before = s.getReuseSpace();
s.setReuseSpace(false); s.setReuseSpace(false);
try { try {
InputStream in = store.getInputStream(); InputStream in = mvStore.getInputStream();
backupFile(out, base, n, in); backupFile(out, base, n, in);
} finally { } finally {
s.setReuseSpace(before); s.setReuseSpace(before);
...@@ -104,9 +106,6 @@ public class BackupCommand extends Prepared { ...@@ -104,9 +106,6 @@ public class BackupCommand extends Prepared {
private void backupPageStore(ZipOutputStream out, String fileName, private void backupPageStore(ZipOutputStream out, String fileName,
PageStore store) throws IOException { PageStore store) throws IOException {
if (store == null) {
return;
}
Database db = session.getDatabase(); Database db = session.getDatabase();
fileName = FileUtils.getName(fileName); fileName = FileUtils.getName(fileName);
out.putNextEntry(new ZipEntry(fileName)); out.putNextEntry(new ZipEntry(fileName));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论