You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2012/10/05 15:49:10 UTC
svn commit: r1394522 - in /db/derby/code/trunk/java/engine/org/apache/derby:
iapi/store/raw/data/DataFactory.java impl/store/raw/RawStore.java
impl/store/raw/data/BaseDataFileFactory.java
impl/store/raw/data/EncryptOrDecryptData.java
Author: kristwaa
Date: Fri Oct 5 13:49:10 2012
New Revision: 1394522
URL: http://svn.apache.org/viewvc?rev=1394522&view=rev
Log:
DERBY-5792: Make it possible to turn off encryption on an already encrypted database.
Simplified code removing old container files generated during encryption and
decryption of a database. There were two implementations, I removed one of them
and removed the parameter of EncryptOrDecryptData.removeOldVersionOfContainers
(and calling methods).
Patch file: derby-5792-5b-old_container_removal_cleanup.diff
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/data/DataFactory.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/EncryptOrDecryptData.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/data/DataFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/data/DataFactory.java?rev=1394522&r1=1394521&r2=1394522&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/data/DataFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/data/DataFactory.java Fri Oct 5 13:49:10 2012
@@ -32,7 +32,6 @@ import org.apache.derby.iapi.store.raw.C
import org.apache.derby.iapi.store.raw.Corruptable;
import org.apache.derby.iapi.store.raw.LockingPolicy;
import org.apache.derby.iapi.store.raw.RawStoreFactory;
-import org.apache.derby.iapi.store.raw.RecordHandle;
import org.apache.derby.iapi.store.raw.StreamContainerHandle;
import org.apache.derby.iapi.store.raw.xact.RawTransaction;
import org.apache.derby.iapi.store.raw.Transaction;
@@ -301,13 +300,10 @@ public interface DataFactory extends Cor
throws StandardException;
/**
- * Remove old versions of the containers after (re)encryption
- * of the database.
- * @param inRecovery <code> true </code>, if cleanup is
- * happening during recovery.
- * @exception StandardException Standard Derby Error Policy
+ * Removes old versions of the containers after a cryptographic operation
+ * on the database.
*/
- public void removeOldVersionOfContainers(boolean inRecovery)
+ public void removeOldVersionOfContainers()
throws StandardException;
/**
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=1394522&r1=1394521&r2=1394522&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Fri Oct 5 13:49:10 2012
@@ -1836,7 +1836,7 @@ public final class RawStore implements R
// database is (re)encrypted successfuly,
// remove the old version of the container files.
- dataFactory.removeOldVersionOfContainers(false);
+ dataFactory.removeOldVersionOfContainers();
if (decryptDatabase) {
// By now we can remove all cryptographic properties.
@@ -2047,7 +2047,7 @@ public final class RawStore implements R
if (dbEncryptionStatus == RawStoreFactory.DB_ENCRYPTION_IN_CLEANUP)
{
// remove all the old versions of the containers.
- dataFactory.removeOldVersionOfContainers(true);
+ dataFactory.removeOldVersionOfContainers();
}
if (SanityManager.DEBUG) {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java?rev=1394522&r1=1394521&r2=1394522&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java Fri Oct 5 13:49:10 2012
@@ -198,9 +198,6 @@ public class BaseDataFileFactory
private Hashtable postRecoveryRemovedFiles;
- private EncryptOrDecryptData containerEncrypter;
-
-
// PrivilegedAction actions
private int actionCode;
private static final int REMOVE_TEMP_DIRECTORY_ACTION = 2;
@@ -2102,39 +2099,23 @@ public class BaseDataFileFactory
/** {@inheritDoc} */
public void decryptAllContainers(RawTransaction t)
throws StandardException {
- containerEncrypter = new EncryptOrDecryptData(this);
- containerEncrypter.decryptAllContainers(t);
+ EncryptOrDecryptData containerDecrypter = new EncryptOrDecryptData(this);
+ containerDecrypter.decryptAllContainers(t);
}
-
+
/** {@inheritDoc} */
- public void encryptAllContainers(RawTransaction t) throws StandardException
- {
- containerEncrypter = new EncryptOrDecryptData(this);
- // encrypt all the containers in the database
+ public void encryptAllContainers(RawTransaction t)
+ throws StandardException {
+ EncryptOrDecryptData containerEncrypter = new EncryptOrDecryptData(this);
containerEncrypter.encryptAllContainers(t);
}
-
-
- /*
- * Remover old versions of the containers after (re)encryption
- * of the database.
- * @param inRecovery <code> true </code>, if cleanup is
- * happening during recovery.
- */
- public void removeOldVersionOfContainers(boolean inRecovery)
- throws StandardException
- {
- // check if old containers are being during recovery
- // because of a crash after successful completion of
- // (re)encryption of the dataabase, but before the
- // (re)encryption cleanup was complete.
- if (inRecovery) {
- containerEncrypter = new EncryptOrDecryptData(this);
- }
- containerEncrypter.removeOldVersionOfContainers(inRecovery);
- containerEncrypter = null;
- }
+ /** {@inheritDoc} */
+ public void removeOldVersionOfContainers()
+ throws StandardException {
+ EncryptOrDecryptData containerCryptoOp = new EncryptOrDecryptData(this);
+ containerCryptoOp.removeOldVersionOfContainers();
+ }
/**
* Return a jar file by asking the class's
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/EncryptOrDecryptData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/EncryptOrDecryptData.java?rev=1394522&r1=1394521&r2=1394522&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/EncryptOrDecryptData.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/EncryptOrDecryptData.java Fri Oct 5 13:49:10 2012
@@ -63,9 +63,6 @@ public class EncryptOrDecryptData implem
private BaseDataFileFactory dataFactory;
private StorageFactory storageFactory;
- private StorageFile[] oldFiles;
- private int noOldFiles = 0;
-
/* privileged actions */
private static final int STORAGE_FILE_EXISTS_ACTION = 1;
@@ -118,8 +115,6 @@ public class EncryptOrDecryptData implem
// simply reading the list of files in seg0.
String[] files = dataFactory.getContainerNames();
if (files != null) {
- oldFiles = new StorageFile[files.length];
- noOldFiles = 0;
long segmentId = 0;
// Loop through all the files in seg0 and
@@ -141,18 +136,18 @@ public class EncryptOrDecryptData implem
ContainerKey ckey = new ContainerKey(segmentId,
containerId);
- oldFiles[noOldFiles++] =
- encryptOrDecryptContainer(t, ckey, doEncrypt);
+ encryptOrDecryptContainer(t, ckey, doEncrypt);
}
// Old versions of the container files will
// be removed after the (re)encryption of database
// is completed.
- } else
- {
- if (SanityManager.DEBUG)
- SanityManager.THROWASSERT("encryption process is unable to" +
- "read container names in seg0");
+ } else {
+ if (SanityManager.DEBUG) {
+ SanityManager.THROWASSERT(
+ (doEncrypt ? "encryption" : "decryption") +
+ " process is unable to read container names in seg0");
+ }
}
}
@@ -164,12 +159,11 @@ public class EncryptOrDecryptData implem
* @param t transaction that used to perform the cryptographic operation
* @param ckey the key of the container that is being encrypted/decrypted
* @param doEncrypt tells whether to encrypt or decrypt
- * @return File handle to the old copy of the container.
* @exception StandardException Standard Derby error policy
*/
- private StorageFile encryptOrDecryptContainer(RawTransaction t,
- ContainerKey ckey,
- boolean doEncrypt)
+ private void encryptOrDecryptContainer(RawTransaction t,
+ ContainerKey ckey,
+ boolean doEncrypt)
throws StandardException
{
@@ -247,8 +241,6 @@ public class EncryptOrDecryptData implem
newFile, currentFile);
}
-
- return oldFile ;
}
@@ -275,14 +267,9 @@ public class EncryptOrDecryptData implem
return sb.toString();
}
- private boolean isOldContainerFile(String fileName)
- {
- // all old versions of the conatainer files
- // start with prefix "o" and ends with ".dat"
- if (fileName.startsWith("o") && fileName.endsWith(".dat"))
- return true;
- else
- return false;
+ private boolean isOldContainerFile(String fileName) {
+ // Old versions start with prefix "o" and ends with ".dat".
+ return (fileName.startsWith("o") && fileName.endsWith(".dat"));
}
private StorageFile getFile(String ctrFileName)
@@ -353,60 +340,30 @@ public class EncryptOrDecryptData implem
}
- /*
- * Remove all the old version (encrypted with old key or
- * un-encrypted) of the containers stored in the data directory .
- *
- * @param inRecovery <code> true </code>, if cleanup is
- * happening during recovery.
- * @exception StandardException Standard Derby Error Policy
+ /**
+ * Removes old versions of the containers after a cryptographic operation
+ * on the database.
*/
- public void removeOldVersionOfContainers(boolean inRecovery)
- throws StandardException
- {
-
- if (inRecovery)
- {
- // find the old version of the container files
- // and delete them
- String[] files = dataFactory.getContainerNames();
- if (files != null)
- {
- // loop through all the files in seg0 and
- // delete all old copies of the containers.
- for (int i = files.length-1; i >= 0 ; i--)
- {
- // if it is a old version of the container file
- // delete it.
- if (isOldContainerFile(files[i]))
- {
- StorageFile oldFile = getFile(files[i]);
- if (!privDelete(oldFile))
- {
- throw StandardException.newException(
- SQLState.FILE_CANNOT_REMOVE_FILE,
- oldFile);
- }
+ public void removeOldVersionOfContainers()
+ throws StandardException {
+ // Find the old version of the container files and delete them.
+ String[] files = dataFactory.getContainerNames();
+ if (files != null) {
+ // Loop through all the files in seg0 and
+ // delete all old copies of the containers.
+ for (int i = files.length-1; i >= 0 ; i--) {
+ if (isOldContainerFile(files[i])) {
+ StorageFile oldFile = getFile(files[i]);
+ if (!privDelete(oldFile)) {
+ throw StandardException.newException(
+ SQLState.FILE_CANNOT_REMOVE_FILE,
+ oldFile);
}
}
}
- }else
- {
- // delete all the old version of the containers.
- for (int i = 0 ; i < noOldFiles ; i++)
- {
- if (!privDelete(oldFiles[i]))
- {
- throw StandardException.newException(
- SQLState.FILE_CANNOT_REMOVE_FILE,
- oldFiles[i]);
- }
- }
}
}
-
-
private synchronized boolean privExists(StorageFile file)
{
actionCode = STORAGE_FILE_EXISTS_ACTION;