From a8b0ca6059e125ebc34411b90768c672250392f3 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 10 Jun 2010 00:54:48 +0000 Subject: Split data and log files during backup. --- .../carbonado/repo/sleepycat/BDBRepository.java | 78 +++++++++++++++++++--- .../repo/sleepycat/HotBackupCapability.java | 25 +++++-- 2 files changed, 89 insertions(+), 14 deletions(-) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java index 27b4109..baaddf3 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -705,16 +705,27 @@ abstract class BDBRepository extends AbstractRepository * Called only if in backup mode. Old API is kept for backwards * compatibility. */ + @Deprecated File[] backupFiles() throws Exception { return backupFiles(new long[1]); } + @Deprecated + File[] backupFiles(long[] newLastLogNum) throws Exception { + throw new UnsupportedOperationException(); + } + + /** + * Called only if in backup mode. + */ + abstract File[] backupDataFiles() throws Exception; + /** * Called only if in backup mode. * * @param newLastLogNum reference to last log number at [0] */ - abstract File[] backupFiles(long[] newLastLogNum) throws Exception; + abstract File[] backupLogFiles(long[] newLastLogNum) throws Exception; /** * Called only if in incremental backup mode. @@ -959,7 +970,35 @@ abstract class BDBRepository extends AbstractRepository } @Override + @Deprecated public File[] getFiles() throws RepositoryException { + synchronized (mBackupLock) { + File[] data = getDataFiles(); + File[] logs = getLogFiles(); + File[] all = new File[data.length + logs.length]; + System.arraycopy(data, 0, all, 0, data.length); + System.arraycopy(logs, 0, all, data.length, logs.length); + return all; + } + } + + @Override + public File[] getDataFiles() throws RepositoryException { + synchronized (mBackupLock) { + if (mDone) { + throw new IllegalStateException("Backup has ended"); + } + + try { + return getDataBackupFiles(); + } catch (Exception e) { + throw mExTransformer.toRepositoryException(e); + } + } + } + + @Override + public File[] getLogFiles() throws RepositoryException { synchronized (mBackupLock) { if (mDone) { throw new IllegalStateException("Backup has ended"); @@ -967,7 +1006,7 @@ abstract class BDBRepository extends AbstractRepository try { long[] newLastLogNum = {-1}; - File[] toReturn = getBackupFiles(newLastLogNum); + File[] toReturn = getLogBackupFiles(newLastLogNum); mFinalLogNumber = newLastLogNum[0]; return toReturn; } catch (Exception e) { @@ -975,7 +1014,7 @@ abstract class BDBRepository extends AbstractRepository } } } - + @Override public long getLastLogNumber() throws RepositoryException { if (mFinalLogNumber < 0) { @@ -987,7 +1026,9 @@ abstract class BDBRepository extends AbstractRepository abstract void finishBackup() throws RepositoryException; - abstract File[] getBackupFiles(long[] newLastLogNum) throws Exception; + abstract File[] getDataBackupFiles() throws Exception; + + abstract File[] getLogBackupFiles(long[] newLastLogNum) throws Exception; } class IncrementalBackup extends AbstractBackup { @@ -1010,7 +1051,12 @@ abstract class BDBRepository extends AbstractRepository } @Override - File[] getBackupFiles(long[] newLastLogNum) throws Exception { + File[] getDataBackupFiles() throws Exception { + return new File[0]; + } + + @Override + File[] getLogBackupFiles(long[] newLastLogNum) throws Exception { return incrementalBackup(mLastLogNumber, newLastLogNum); } } @@ -1033,12 +1079,28 @@ abstract class BDBRepository extends AbstractRepository } @Override - File[] getBackupFiles(long[] newLastLogNum) throws Exception { + File[] getDataBackupFiles() throws Exception { try { - return backupFiles(newLastLogNum); + return backupDataFiles(); + } catch (AbstractMethodError e) { + // Old API will be called for backwards compatibility in the + // getLogBackupFiles method. + return new File[0]; + } + } + + @Override + File[] getLogBackupFiles(long[] newLastLogNum) throws Exception { + try { + return backupLogFiles(newLastLogNum); } catch (AbstractMethodError e) { // Call old API for backwards compatibility. - return backupFiles(); + try { + return backupFiles(newLastLogNum); + } catch (AbstractMethodError e2) { + // Call even older API for backwards compatibility. + return backupFiles(); + } } } } diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/HotBackupCapability.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/HotBackupCapability.java index 05d8a6d..cbf379f 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/HotBackupCapability.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/HotBackupCapability.java @@ -99,15 +99,28 @@ public interface HotBackupCapability extends Capability { void endBackup() throws RepositoryException; /** - * Returns all the files to be copied, in the exact order in which they - * must be copied. + * @deprecated use getDataFiles and getLogFiles + */ + @Deprecated + File[] getFiles() throws RepositoryException; + + /** + * Returns all the data files to be copied. After these files are + * durably copied, call {@link #getLogFiles()} and copy the log files + * which were created while the data files were copied. * - *

These files must be durably copied prior to calling {@link #endBackup()}. + * @return array of data files, which might be empty + */ + File[] getDataFiles() throws RepositoryException; + + /** + * Returns all the transaction log files to be copied, in the exact + * order in which they must be copied. After these files are durably + * copied, call {@link #endBackup()}. * - * @return ordered array of absolute files - * @throws IllegalStateException if backup has ended + * @return array of transaction log files, never empty */ - File[] getFiles() throws RepositoryException; + File[] getLogFiles() throws RepositoryException; /** * Can be called after a backup has been performed to find the last log file -- cgit v1.2.3