summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2010-06-10 00:54:48 +0000
committerBrian S. O'Neill <bronee@gmail.com>2010-06-10 00:54:48 +0000
commita8b0ca6059e125ebc34411b90768c672250392f3 (patch)
tree9c27b3a1ff390b449af2645fe26e7393de20a34a
parent41bc565cc82b87d1c1ef9f85705a1fc8fdd6f0f1 (diff)
Split data and log files during backup.
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java78
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/HotBackupCapability.java25
2 files changed, 89 insertions, 14 deletions
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<Txn> extends AbstractRepository<Txn>
* 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,15 +970,43 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
}
@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");
}
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<Txn> extends AbstractRepository<Txn>
}
}
}
-
+
@Override
public long getLastLogNumber() throws RepositoryException {
if (mFinalLogNumber < 0) {
@@ -987,7 +1026,9 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
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<Txn> extends AbstractRepository<Txn>
}
@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<Txn> extends AbstractRepository<Txn>
}
@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.
*
- * <p>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