PersistItStorage.java revision 407bb81fb935e713a4a1ae1b9189b81488a944d5
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2014-2015 ForgeRock AS
*/
/** PersistIt database implementation of the {@link Storage} engine. */
public final class PersistItStorage implements Storage
{
/** The buffer / page size used by the PersistIt storage. */
/** PersistIt implementation of the {@link Cursor} interface. */
private final class CursorImpl implements Cursor
{
private ByteString currentKey;
private ByteString currentValue;
{
}
public void close()
{
// Release immediately because this exchange did not come from the txn cache
}
public ByteString getKey()
{
if (currentKey == null)
{
}
return currentKey;
}
public ByteString getValue()
{
if (currentValue == null)
{
}
return currentValue;
}
public boolean next()
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
public boolean positionToLastKey()
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
public boolean previous()
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
private void clearCurrentKeyAndValue()
{
currentKey = null;
currentValue = null;
}
}
/** PersistIt implementation of the {@link Importer} interface. */
private final class ImporterImpl implements Importer
{
public void close()
{
try
{
}
catch (final Exception e)
{
throw new StorageRuntimeException(e);
}
finally
{
PersistItStorage.this.close();
}
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
final ByteSequence value)
{
try
{
}
catch (final Exception e)
{
throw new StorageRuntimeException(e);
}
}
}
/** PersistIt implementation of the {@link WriteableStorage} interface. */
private final class StorageImpl implements WriteableStorage
{
final ByteSequence value)
{
try
{
}
catch (final Exception e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
ex.removeTree();
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
finally
{
}
}
{
}
{
try
{
/*
* Acquire a new exchange for the cursor rather than using a cached
* exchange in order to avoid reentrant accesses to the same tree
* interfering with the cursor position.
*/
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
finally
{
}
}
final ByteSequence value)
{
try
{
// There is no CAS (Compare And Swap) operation to do here :)
// Following code is fine because Persistit provides snapshot isolation.
// If another thread tries to update the same key, we'll get a RollbackException
// And the write operation will be retried (see write() method in this class)
{
return false;
}
return true;
}
catch (final Exception e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
final TreeName newTreeName)
{
throw new UnsupportedOperationException();
}
{
try
{
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
{
try
{
{
return true;
}
return false;
}
catch (final Exception e)
{
throw new StorageRuntimeException(e);
}
}
{
{
}
}
throws PersistitException
{
{
}
return exchange;
}
private void release()
{
{
}
}
}
{
{
{
}
}
else
{
}
}
private File backendDirectory;
private Configuration dbCfg;
private PersistitBackendCfg config;
/** {@inheritDoc} */
public void close()
{
{
try
{
}
catch (final PersistitException e)
{
throw new IllegalStateException(e);
}
}
}
/** {@inheritDoc} */
{
// nothing to do, in persistit you close the volume itself
}
/** {@inheritDoc} */
{
dbCfg = new Configuration();
{
}
else
{
}
}
private BufferPoolConfiguration getBufferPoolCfg()
{
}
/** {@inheritDoc} */
public boolean isValid()
{
}
/** {@inheritDoc} */
public void open()
{
try
{
db.initialize();
}
catch (final PersistitException e)
{
throw new StorageRuntimeException(e);
}
}
/** {@inheritDoc} */
{
for (;;)
{
try
{
try
{
return result;
}
catch (final StorageRuntimeException e)
{
{
}
throw e;
}
finally
{
}
}
catch (final RollbackException e)
{
// retry
}
catch (final Exception e)
{
throw e;
}
finally
{
}
}
}
/** {@inheritDoc} */
public Importer startImport()
{
open();
return new ImporterImpl();
}
/**
* Replace persistit reserved comma character with an underscore character.
*
* @param suffix
* the suffix name to convert
* @return a new String suitable for use as a suffix name
*/
{
}
/** {@inheritDoc} */
{
for (;;)
{
try
{
try
{
return;
}
catch (final StorageRuntimeException e)
{
{
}
throw e;
}
finally
{
}
}
catch (final RollbackException e)
{
// retry
}
catch (final Exception e)
{
throw e;
}
finally
{
}
}
}
/** {@inheritDoc} */
public FilenameFilter getFilesToBackupFilter()
{
return new FilenameFilter()
{
{
}
};
}
/*
* inefficient at the moment for simple byte arrays.
*/
{
}
{
return value;
}
throws PersistitException
{
}
{
}
{
{
}
return null;
}
}