use of org.apache.derby.iapi.store.raw.ContainerKey in project derby by apache.
the class EncryptOrDecryptData method encryptOrDecryptAllContainers.
/**
* Encrypts or decrypts all containers in the database data directory.
*
* @param t transaction used for the cryptographic operation
* @param doEncrypt tells whether to encrypt or decrypt
* @exception StandardException Standard Derby error policy
*/
private void encryptOrDecryptAllContainers(RawTransaction t, boolean doEncrypt) throws StandardException {
// List of containers that need to be transformed are identified by
// simply reading the list of files in seg0.
String[] files = dataFactory.getContainerNames();
if (files != null) {
long segmentId = 0;
// encrypt/decrypt all valid containers.
for (int f = files.length - 1; f >= 0; f--) {
long containerId;
try {
containerId = Long.parseLong(files[f].substring(1, (files[f].length() - 4)), 16);
} catch (Throwable th) {
// didn't expect. Continue with the next one.
continue;
}
ContainerKey ckey = new ContainerKey(segmentId, containerId);
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((doEncrypt ? "encryption" : "decryption") + " process is unable to read container names in seg0");
}
}
}
use of org.apache.derby.iapi.store.raw.ContainerKey in project derby by apache.
the class BaseDataFileFactory method backupDataFiles.
/*
* Find all the all the containers stored in the seg0 directory and
* backup each container to the specified backup location.
*/
public void backupDataFiles(Transaction rt, File backupDir) throws StandardException {
/*
* List of containers that needs to be backed up are identified by
* simply reading the list of files in seg0.
* All container that are created after the container list is created
* when backup is in progress are recreated on restore using the
* transaction log.
*/
String[] files = getContainerNames();
if (files != null) {
// No user visible locks are acquired to backup the database. A stable backup
// is made by latching the pages and internal synchronization
// mechanisms.
LockingPolicy lockPolicy = rt.newLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false);
long segmentId = 0;
// loop through all the files in seg0 and backup all valid containers.
for (int f = files.length - 1; f >= 0; f--) {
long containerId;
try {
containerId = Long.parseLong(files[f].substring(1, (files[f].length() - 4)), 16);
} catch (Throwable t) {
// next one.
continue;
}
ContainerKey identity = new ContainerKey(segmentId, containerId);
/* Not necessary to get the container thru the transaction.
* Backup opens in container in read only mode , No need to
* transition the transaction to active state.
*
* dropped container stubs also has to be backed up
* for restore to work correctly. That is
* why we are using a open call that let us
* open dropped containers.
*/
ContainerHandle containerHdl = openDroppedContainer((RawTransaction) rt, identity, lockPolicy, ContainerHandle.MODE_READONLY);
if (containerHdl != null) {
containerHdl.backupContainer(backupDir.getPath());
containerHdl.close();
}
}
} else {
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("backup process is unable to read container names in seg0");
}
}
use of org.apache.derby.iapi.store.raw.ContainerKey in project derby by apache.
the class BaseDataFileFactory method reCreateContainerForRedoRecovery.
/**
* re-Create a container during redo recovery.
*
* called ONLY during recovery load tran.
*
* @exception StandardException Standard Derby Error policy
*/
public void reCreateContainerForRedoRecovery(RawTransaction t, long segmentId, long containerId, ByteArray containerInfo) throws StandardException {
if (SanityManager.DEBUG)
SanityManager.ASSERT(segmentId != ContainerHandle.TEMPORARY_SEGMENT, "Cannot recreate temp container during load tran");
ContainerKey identity = new ContainerKey(segmentId, containerId);
// no need to lock container during load tran
// no need to create any page for the container, they will be created
// as their log records are encountered later in load tran
FileContainer container = (FileContainer) containerCache.create(identity, containerInfo);
containerCache.release(container);
}
use of org.apache.derby.iapi.store.raw.ContainerKey in project derby by apache.
the class BaseDataFileFactory method addContainer.
/**
* Add a container with a specified page size to a segment.
* @exception StandardException Standard Derby error policy
*/
public long addContainer(RawTransaction t, long segmentId, long input_containerid, int mode, Properties tableProperties, int temporaryFlag) throws StandardException {
if (SanityManager.DEBUG) {
if ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) != 0)
SanityManager.ASSERT((mode & ContainerHandle.MODE_UNLOGGED) != 0, "cannot have CREATE_UNLOGGED set but UNLOGGED not set");
}
// If client has provided a containerid then use it, else use the
// internally generated one from getNextId().
long containerId = ((input_containerid != ContainerHandle.DEFAULT_ASSIGN_ID) ? input_containerid : getNextId());
ContainerKey identity = new ContainerKey(segmentId, containerId);
boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT);
ContainerHandle ch = null;
LockingPolicy cl = null;
if (!tmpContainer) {
if (isReadOnly()) {
throw StandardException.newException(SQLState.DATA_CONTAINER_READ_ONLY);
}
cl = t.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true);
if (SanityManager.DEBUG)
SanityManager.ASSERT(cl != null);
ch = t.openContainer(identity, cl, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY));
}
FileContainer container = (FileContainer) containerCache.create(identity, tableProperties);
// create the first alloc page and the first user page,
// if this fails for any reason the transaction
// will roll back and the container will be dropped (removed)
ContainerHandle containerHdl = null;
Page firstPage = null;
try {
// make sure to open it with IS_KEPT too.
if (tmpContainer && ((temporaryFlag & TransactionController.IS_KEPT) == TransactionController.IS_KEPT)) {
mode |= ContainerHandle.MODE_TEMP_IS_KEPT;
}
// open no-locking as we already have the container locked
containerHdl = t.openContainer(identity, null, (ContainerHandle.MODE_FORUPDATE | mode));
// we just added it, containerHdl should not be null
if (SanityManager.DEBUG)
SanityManager.ASSERT(containerHdl != null);
if (!tmpContainer) {
// make it persistent (in concept if not in reality)
RawContainerHandle rch = (RawContainerHandle) containerHdl;
ContainerOperation lop = new ContainerOperation(rch, ContainerOperation.CREATE);
// mark the container as pre-dirtied so that if a checkpoint
// happens after the log record is sent to the log stream, the
// cache cleaning will wait for this change.
rch.preDirty(true);
try {
t.logAndDo(lop);
// flush the log to reduce the window between where
// the container is created & synced and the log record
// for it makes it to disk. If we fail in this
// window we will leave a stranded container file.
flush(t.getLastLogInstant());
} finally {
// in case logAndDo fail, make sure the container is not
// stuck in preDirty state.
rch.preDirty(false);
}
}
firstPage = containerHdl.addPage();
} finally {
if (firstPage != null) {
firstPage.unlatch();
firstPage = null;
}
containerCache.release(container);
if (containerHdl != null) {
containerHdl.close();
containerHdl = null;
}
if (!tmpContainer) {
// this should do nothing, since we requested isolation 3
// but we can't assume that, so call the policy correctly.
cl.unlockContainer(t, ch);
}
}
return containerId;
}
use of org.apache.derby.iapi.store.raw.ContainerKey in project derby by apache.
the class BaseDataFileFactory method openStreamContainer.
/**
* open an exsisting streamContainer
*
* @see DataFactory#openStreamContainer
* @exception StandardException Standard Derby error policy
*/
public StreamContainerHandle openStreamContainer(RawTransaction t, long segmentId, long containerId, boolean hold) throws StandardException {
ContainerKey identity = new ContainerKey(segmentId, containerId);
StreamFileContainerHandle c;
// open the container with the identity
StreamFileContainer container = new StreamFileContainer(identity, this);
container = container.open(false);
if (container == null)
return null;
c = new StreamFileContainerHandle(getIdentifier(), t, container, hold);
// see if we can use the container
if (c.useContainer())
return c;
else
return null;
}
Aggregations