You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2018/03/08 21:53:59 UTC
[directory-server] branch master updated: o Added support for
operation transaction
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-server.git
The following commit(s) were added to refs/heads/master by this push:
new 2ea9990 o Added support for operation transaction
2ea9990 is described below
commit 2ea9990e888306ff51af1c60cdb54bb6279c49c5
Author: Emmanuel Lécharny <el...@symas.com>
AuthorDate: Thu Mar 8 22:53:27 2018 +0100
o Added support for operation transaction
---
.../directory/server/core/api/AbstractLayout.java | 2 +-
.../server/core/api/LdapCoreSessionConnection.java | 3 +-
.../api/filtering/EntryFilteringCursorImpl.java | 2 +-
.../context/AbstractOperationContext.java | 26 +
.../api/interceptor/context/OperationContext.java | 29 +
.../core/api/partition/AbstractPartition.java | 28 +-
.../server/core/api/partition/Partition.java | 23 +-
.../server/core/api/partition/PartitionNexus.java | 11 -
.../core/api/partition/PartitionReadTxn.java | 62 +-
.../server/core/api/partition/PartitionTxn.java | 30 +
.../core/api/partition/PartitionWriteTxn.java | 62 +-
.../server/core/api/schema/SchemaPartition.java | 50 +-
.../directory/server/core/api/MockCoreSession.java | 5 +-
.../directory/server/core/api/MockOperation.java | 32 +
.../FilterNormalizingVisitorTest.java | 1 -
.../server/core/avltree/ArrayTreeCursor.java | 18 +-
.../avltree/AvlSingletonOrOrderedSetCursor.java | 18 +-
.../server/core/avltree/AvlTreeCursor.java | 18 +-
.../server/core/avltree/KeyTupleAvlCursor.java | 18 +-
.../server/core/integ/IntegrationUtils.java | 2 +-
.../configuration/PartitionConfigurationIT.java | 19 +-
.../server/core/jndi/ObjStateFactoryIT.java | 2 -
.../server/core/operations/add/AddIT.java | 1 -
.../core/operations/hasEntry/hasEntryPerfIT.java | 4 +-
.../core/operations/search/SearchPerfIT.java | 2 -
.../directory/server/core/jndi/ServerContext.java | 16 +-
.../server/core/shared/DefaultCoreSession.java | 23 +-
.../server/core/shared/ReferralManagerImpl.java | 95 +--
.../server/core/shared/SchemaService.java | 130 ++--
.../shared/partition/DefaultPartitionNexus.java | 96 ++-
.../core/shared/partition/RootPartition.java | 188 ++++++
.../server/core/DefaultDirectoryService.java | 557 +++++++++++------
.../server/core/DefaultOperationManager.java | 414 +++++++++++-
.../org/apache/directory/server/i18n/I18n.java | 4 +-
.../apache/directory/server/i18n/errors.properties | 4 +-
.../server/installers/MojoHelperUtils.java | 2 +-
.../archive/ArchiveInstallerCommand.java | 2 +-
.../server/installers/bin/BinInstallerCommand.java | 6 +-
.../server/installers/deb/DebInstallerCommand.java | 6 +-
.../macosxpkg/MacOsXPkgInstallerCommand.java | 30 +-
.../installers/nsis/NsisInstallerCommand.java | 2 +-
.../server/installers/rpm/RpmInstallerCommand.java | 12 +-
.../core/kerberos/KeyDerivationInterceptor.java | 2 +
.../core/admin/AdministrativePointInterceptor.java | 36 +-
.../server/core/authn/AbstractAuthenticator.java | 54 +-
.../core/authn/AuthenticationInterceptor.java | 66 +-
.../server/core/authn/SimpleAuthenticator.java | 3 +
.../core/authz/AciAuthorizationInterceptor.java | 57 +-
.../authz/DefaultAuthorizationInterceptor.java | 19 +-
.../directory/server/core/authz/GroupCache.java | 5 +
.../directory/server/core/authz/TupleCache.java | 6 +-
.../server/core/authz/support/ACDFEngine.java | 3 +
.../server/core/authz/support/MaxImmSubFilter.java | 2 +
.../core/changelog/ChangeLogInterceptor.java | 3 +
.../collective/CollectiveAttributeInterceptor.java | 3 +
.../server/core/event/EventInterceptor.java | 4 +
.../core/exception/ExceptionInterceptor.java | 8 +-
.../core/number/NumberIncrementingInterceptor.java | 60 +-
.../OperationalAttributeInterceptor.java | 14 +-
.../server/core/referral/ReferralInterceptor.java | 4 +
.../schema/SchemaLdifToPartitionExtractor.java | 67 +-
.../server/core/schema/SchemaSubentryModifier.java | 33 +
.../server/core/subtree/SubentryInterceptor.java | 79 ++-
.../AbstractStoredProcedureParameterInjector.java | 2 +
.../DeleteStoredProcedureParameterInjector.java | 4 +-
.../ModifyStoredProcedureParameterInjector.java | 4 +-
.../server/core/trigger/TriggerInterceptor.java | 7 +-
.../server/core/trigger/TriggerSpecCache.java | 4 +
.../impl/btree/jdbm/DupsContainerCursor.java | 16 +-
.../core/partition/impl/btree/jdbm/DupsCursor.java | 18 +-
.../partition/impl/btree/jdbm/JdbmDnIndex.java | 25 +-
.../core/partition/impl/btree/jdbm/JdbmIndex.java | 233 +++----
.../partition/impl/btree/jdbm/JdbmMasterTable.java | 7 +-
.../partition/impl/btree/jdbm/JdbmPartition.java | 424 ++++++++-----
.../impl/btree/jdbm/JdbmPartitionWriteTxn.java | 87 +++
.../partition/impl/btree/jdbm/JdbmRdnIndex.java | 27 +-
.../core/partition/impl/btree/jdbm/JdbmTable.java | 128 +---
.../partition/impl/btree/jdbm/KeyBTreeCursor.java | 14 +-
.../impl/btree/jdbm/KeyTupleBTreeCursor.java | 16 +-
.../partition/impl/btree/jdbm/NoDupsCursor.java | 15 +-
.../impl/btree/jdbm/DupsContainerCursorTest.java | 10 +-
.../partition/impl/btree/jdbm/DupsCursorTest.java | 96 +--
.../impl/btree/jdbm/JdbmBrowserBugTest.java | 4 +-
.../partition/impl/btree/jdbm/JdbmIndexTest.java | 304 ++++-----
.../impl/btree/jdbm/JdbmMasterTableTest.java | 15 +-
.../impl/btree/jdbm/JdbmRdnIndexTest.java | 139 +++--
.../partition/impl/btree/jdbm/JdbmStoreTest.java | 403 +++++++-----
.../impl/btree/jdbm/JdbmTableNoDuplicatesTest.java | 135 ++--
.../btree/jdbm/JdbmTableWithDuplicatesTest.java | 367 +++++------
.../impl/btree/jdbm/KeyTupleArrayCursorTest.java | 6 +-
.../impl/btree/jdbm/KeyTupleBTreeCursorTest.java | 24 +-
.../impl/btree/jdbm/NoDupsCursorTest.java | 13 +-
.../directory/kerberos/client/KdcConnection.java | 2 -
.../shared/client/api/LdapConnectionTest.java | 1 -
.../api/LightweightLdapConnectionPoolTest.java | 2 -
.../api/operations/bind/SimpleBindRequestTest.java | 1 -
.../shared/client/api/operations/bind/Test.java | 15 -
.../operations/search/ClientSearchRequestTest.java | 12 +-
.../server/core/partition/ldif/LdifPartition.java | 154 ++++-
.../partition/ldif/SingleFileLdifPartition.java | 154 +++--
.../core/partition/ldif/LdifPartitionTest.java | 123 +++-
...SingleFileLdifPartitionSingeValueAttribute.java | 267 ++++++--
.../ldif/SingleFileLdifPartitionTest.java | 270 ++++++--
.../impl/btree/mavibot/KeyTupleValueCursor.java | 6 +-
.../impl/btree/mavibot/MavibotCursor.java | 14 +-
.../impl/btree/mavibot/MavibotDnIndex.java | 15 +-
.../partition/impl/btree/mavibot/MavibotIndex.java | 167 ++---
.../impl/btree/mavibot/MavibotMasterTable.java | 2 +-
.../impl/btree/mavibot/MavibotPartition.java | 84 +--
.../impl/btree/mavibot/MavibotRdnIndex.java | 13 +-
.../partition/impl/btree/mavibot/MavibotTable.java | 53 +-
.../impl/btree/mavibot/MavibotIndexTest.java | 195 +++---
.../impl/btree/mavibot/MavibotMasterTableTest.java | 12 +-
.../impl/btree/mavibot/MavibotRdnIndexTest.java | 75 +--
.../impl/btree/mavibot/MavibotStoreTest.java | 109 ++--
.../impl/btree/mavibot/MavibotCursor.java | 14 +-
.../partition/impl/btree/mavibot/MavibotIndex.java | 23 +-
.../impl/btree/mavibot/MavibotPartition.java | 2 +-
.../apache/directory/server/ldap/LdapSession.java | 81 ++-
.../directory/server/ldap/LdapSessionManager.java | 21 +-
.../ldap/handlers/extended/PwdModifyHandler.java | 1 -
.../ldap/handlers/extended/StartTlsHandler.java | 2 +-
.../ldap/handlers/request/BindRequestHandler.java | 1 -
.../handlers/request/SearchRequestHandler.java | 2 +-
.../ldap/handlers/sasl/SimpleMechanismHandler.java | 1 -
.../ldap/handlers/sasl/ntlm/NtlmSaslServer.java | 1 -
.../ldap/handlers/sasl/plain/PlainSaslServer.java | 1 -
.../consumer/ReplicationConsumerImpl.java | 18 +-
.../replication/provider/ReplConsumerManager.java | 21 +-
.../ldap/replication/provider/ReplicaEventLog.java | 24 +-
.../replication/provider/ReplicaJournalCursor.java | 12 +-
.../provider/SyncReplRequestHandler.java | 31 +-
.../apache/directory/server/ldap/JournalTest.java | 30 +-
.../directory/server/ldap/MockPartitionTxn.java | 62 +-
.../factory/DirectoryServiceAnnotationTest.java | 1 -
.../server/config/ConfigPartitionInitializer.java | 19 +-
.../server/config/ConfigPartitionReader.java | 83 +--
.../directory/server/config/ConfigWriter.java | 1 -
.../server/config/LdifConfigExtractor.java | 10 +-
.../config/ReadOnlyConfigurationPartition.java | 82 +--
.../config/ChangePasswordConfigReaderTest.java | 2 +-
.../server/config/ConfigPartitionReaderTest.java | 2 +-
.../directory/server/config/ConfigWriterTest.java | 2 +-
.../server/config/HttpServerConfigReaderTest.java | 2 +-
.../config/KerberosServerConfigReaderTest.java | 2 +-
.../server/config/LdapServerConfigReaderTest.java | 2 +-
.../test/java/org/apache/directory/IndexIT.java | 57 +-
.../org/apache/directory/MockPartitionReadTxn.java | 62 +-
.../server/replication/MockSyncReplConsumer.java | 6 +-
.../server/config/builder/ServiceBuilder.java | 21 +-
.../apache/directory/server/ApacheDsService.java | 2 +-
.../core/partition/impl/avl/AvlPartition.java | 37 +-
.../impl/btree/AbstractBTreePartition.java | 693 +++++++++++----------
.../partition/impl/btree/EntryCursorAdaptor.java | 9 +-
.../partition/impl/btree/IndexCursorAdaptor.java | 6 +-
.../directory/server/xdbm/AbstractIndex.java | 2 +-
.../directory/server/xdbm/AbstractIndexCursor.java | 19 +
.../directory/server/xdbm/AbstractTable.java | 1 -
.../directory/server/xdbm/EmptyIndexCursor.java | 29 +-
.../org/apache/directory/server/xdbm/Index.java | 52 +-
.../directory/server/xdbm/KeyTupleArrayCursor.java | 18 +-
.../apache/directory/server/xdbm/MasterTable.java | 3 +-
.../server/xdbm/SingletonIndexCursor.java | 35 +-
.../org/apache/directory/server/xdbm/Store.java | 34 +-
.../org/apache/directory/server/xdbm/Table.java | 13 +-
.../directory/server/xdbm/impl/avl/AvlIndex.java | 153 ++---
.../server/xdbm/impl/avl/AvlMasterTable.java | 2 +-
.../server/xdbm/impl/avl/AvlRdnIndex.java | 6 +-
.../directory/server/xdbm/impl/avl/AvlTable.java | 11 +-
.../server/xdbm/impl/avl/AvlTableDupsCursor.java | 18 +-
.../directory/server/xdbm/search/Evaluator.java | 5 +-
.../directory/server/xdbm/search/Optimizer.java | 4 +-
.../directory/server/xdbm/search/SearchEngine.java | 8 +-
.../xdbm/search/cursor/AllEntriesCursor.java | 33 +-
.../server/xdbm/search/cursor/AndCursor.java | 33 +-
.../xdbm/search/cursor/ApproximateCursor.java | 33 +-
.../server/xdbm/search/cursor/ChildrenCursor.java | 16 +-
.../xdbm/search/cursor/DescendantCursor.java | 32 +-
.../server/xdbm/search/cursor/EqualityCursor.java | 34 +-
.../server/xdbm/search/cursor/GreaterEqCursor.java | 41 +-
.../server/xdbm/search/cursor/LessEqCursor.java | 42 +-
.../server/xdbm/search/cursor/NotCursor.java | 27 +-
.../server/xdbm/search/cursor/OrCursor.java | 43 +-
.../server/xdbm/search/cursor/PresenceCursor.java | 43 +-
.../server/xdbm/search/cursor/SubstringCursor.java | 41 +-
.../server/xdbm/search/evaluator/AndEvaluator.java | 11 +-
.../search/evaluator/ApproximateEvaluator.java | 20 +-
.../search/evaluator/BaseLevelScopeEvaluator.java | 9 +-
.../xdbm/search/evaluator/EmptyEvaluator.java | 5 +-
.../xdbm/search/evaluator/EqualityEvaluator.java | 20 +-
.../xdbm/search/evaluator/GreaterEqEvaluator.java | 20 +-
.../xdbm/search/evaluator/LeafEvaluator.java | 2 -
.../xdbm/search/evaluator/LessEqEvaluator.java | 21 +-
.../server/xdbm/search/evaluator/NotEvaluator.java | 7 +-
.../search/evaluator/OneLevelScopeEvaluator.java | 15 +-
.../server/xdbm/search/evaluator/OrEvaluator.java | 11 +-
.../search/evaluator/PassThroughEvaluator.java | 7 +-
.../xdbm/search/evaluator/PresenceEvaluator.java | 19 +-
.../xdbm/search/evaluator/SubstringEvaluator.java | 24 +-
.../search/evaluator/SubtreeScopeEvaluator.java | 61 +-
.../server/xdbm/search/impl/CursorBuilder.java | 197 +++---
.../server/xdbm/search/impl/DefaultOptimizer.java | 151 ++---
.../xdbm/search/impl/DefaultSearchEngine.java | 59 +-
.../server/xdbm/search/impl/EvaluatorBuilder.java | 37 +-
.../server/xdbm/search/impl/NoOpOptimizer.java | 8 +-
.../server/xdbm/AbstractIndexCursorTest.java | 8 +-
.../server/xdbm/EmptyIndexCursorTest.java | 4 +-
.../server/xdbm/MockPartitionReadTxn.java} | 60 +-
.../server/xdbm/MockPartitionWriteTxn.java} | 60 +-
.../directory/server/xdbm/PartitionTest.java | 121 ++--
.../server/xdbm/SingletonIndexCursorTest.java | 4 +-
.../apache/directory/server/xdbm/StoreUtils.java | 1 +
.../server/xdbm/impl/avl/AvlPartitionTest.java | 81 ++-
.../server/xdbm/impl/avl/AvlRdnIndexTest.java | 62 +-
.../server/xdbm/impl/avl/AvlTableTest.java | 52 +-
.../directory/server/xdbm/impl/avl/TableData.java | 41 +-
.../xdbm/search/impl/AbstractCursorTest.java | 12 +-
.../server/xdbm/search/impl/AndCursorTest.java | 14 +-
.../server/xdbm/search/impl/EqualityTest.java | 56 +-
.../xdbm/search/impl/GreaterEqNotIndexedTest.java | 42 +-
.../server/xdbm/search/impl/GreaterEqTest.java | 80 +--
.../server/xdbm/search/impl/LessEqTest.java | 80 +--
.../server/xdbm/search/impl/NestedFilterTest.java | 23 +-
.../server/xdbm/search/impl/NotCursorTest.java | 11 +-
.../server/xdbm/search/impl/OrCursorTest.java | 14 +-
.../server/xdbm/search/impl/PresenceTest.java | 55 +-
.../server/xdbm/search/impl/SubstringTest.java | 100 +--
227 files changed, 6815 insertions(+), 4026 deletions(-)
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/AbstractLayout.java b/core-api/src/main/java/org/apache/directory/server/core/api/AbstractLayout.java
index 39d42b9..487fed3 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/AbstractLayout.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/AbstractLayout.java
@@ -115,7 +115,7 @@ public abstract class AbstractLayout
{
if ( !requiredDirectory.mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, requiredDirectory ) );
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, requiredDirectory ) );
}
}
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java b/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
index 9d7f5a9..1ce3cb7 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
@@ -1122,6 +1122,7 @@ public class LdapCoreSessionConnection extends AbstractLdapConnection
SearchRequest searchRequest = new SearchRequestImpl();
searchRequest.setBase( baseDn );
+
searchRequest.setFilter( filter );
searchRequest.setScope( scope );
searchRequest.addAttributes( attributes );
@@ -1294,7 +1295,7 @@ public class LdapCoreSessionConnection extends AbstractLdapConnection
int newId = messageId.incrementAndGet();
- BindOperationContext bindContext = new BindOperationContext( directoryService, null );
+ BindOperationContext bindContext = new BindOperationContext( null );
bindContext.setCredentials( bindRequest.getCredentials() );
Dn bindDn = bindRequest.getDn();
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursorImpl.java b/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursorImpl.java
index 2be74f5..3172ee9 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursorImpl.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursorImpl.java
@@ -116,7 +116,7 @@ public class EntryFilteringCursorImpl extends AbstractCursor<Entry> implements E
this.wrapped = wrapped;
this.operationContext = operationContext;
- this.filters = new ArrayList<EntryFilter>();
+ this.filters = new ArrayList<>();
this.schemaManager = schemaManager;
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/AbstractOperationContext.java b/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/AbstractOperationContext.java
index 0fba0bc..358ccc6 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/AbstractOperationContext.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/AbstractOperationContext.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionTxn;
@@ -78,6 +79,9 @@ public abstract class AbstractOperationContext implements OperationContext
/** The transaction this operation is ran into */
protected PartitionTxn transaction;
+
+ /** The partition this operation will be applied on */
+ protected Partition partition;
/**
@@ -481,6 +485,7 @@ public abstract class AbstractOperationContext implements OperationContext
/**
* @return the transaction
*/
+ @Override
public PartitionTxn getTransaction()
{
return transaction;
@@ -490,8 +495,29 @@ public abstract class AbstractOperationContext implements OperationContext
/**
* @param transaction the transaction to set
*/
+ @Override
public void setTransaction( PartitionTxn transaction )
{
this.transaction = transaction;
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Partition getPartition()
+ {
+ return partition;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setPartition( Partition partition )
+ {
+ this.partition = partition;
+ }
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/OperationContext.java b/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/OperationContext.java
index 9bf0a87..69986b2 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/OperationContext.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/OperationContext.java
@@ -28,6 +28,8 @@ import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
/**
@@ -279,4 +281,31 @@ public interface OperationContext
* @return <code>true</code> if the referrals are ignored
*/
boolean isReferralIgnored();
+
+
+ /**
+ * @return the transaction
+ */
+ PartitionTxn getTransaction();
+
+
+ /**
+ * @param transaction the transaction to set
+ */
+ void setTransaction( PartitionTxn transaction );
+
+
+ /**
+ * @return The Partition this operation will be applied on
+ * @return
+ */
+ Partition getPartition();
+
+
+ /**
+ * @return The Partition this operation will be applied on
+ * @return
+ */
+ void setPartition( Partition partition );
+
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java b/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
index 4b49a49..a93358d 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
@@ -100,7 +100,7 @@ public abstract class AbstractPartition implements Partition
{
try
{
- destroy();
+ destroy( null );
}
catch ( Exception e )
{
@@ -115,7 +115,7 @@ public abstract class AbstractPartition implements Partition
* {@inheritDoc}
*/
@Override
- public void repair() throws Exception
+ public void repair() throws LdapException
{
// Do nothing. It will be handled by the implementation classes
}
@@ -124,7 +124,7 @@ public abstract class AbstractPartition implements Partition
/**
* Override this method to put your initialization code.
*/
- protected abstract void doDestroy() throws Exception;
+ protected abstract void doDestroy( PartitionTxn partitionTxn ) throws LdapException;
/**
@@ -132,7 +132,7 @@ public abstract class AbstractPartition implements Partition
*
* @throws Exception If teh init failed
*/
- protected abstract void doInit() throws InvalidNameException, Exception;
+ protected abstract void doInit() throws InvalidNameException, LdapException;
/**
@@ -140,7 +140,7 @@ public abstract class AbstractPartition implements Partition
*
* @throws Exception If the repair failed
*/
- protected abstract void doRepair() throws InvalidNameException, Exception;
+ protected abstract void doRepair() throws LdapException;
/**
@@ -149,11 +149,11 @@ public abstract class AbstractPartition implements Partition
* will return <tt>false</tt>.
*/
@Override
- public final void destroy() throws Exception
+ public final void destroy( PartitionTxn partitionTxn ) throws LdapException
{
try
{
- doDestroy();
+ doDestroy( partitionTxn );
}
finally
{
@@ -246,7 +246,7 @@ public abstract class AbstractPartition implements Partition
* {@inheritDoc}
*/
@Override
- public void dumpIndex( OutputStream stream, String name ) throws IOException
+ public void dumpIndex( PartitionTxn partitionTxn, OutputStream stream, String name ) throws IOException
{
stream.write( Strings.getBytesUtf8( "Nothing to dump for index " + name ) );
}
@@ -297,7 +297,7 @@ public abstract class AbstractPartition implements Partition
* {@inheritDoc}
*/
@Override
- public String getContextCsn()
+ public String getContextCsn( PartitionTxn partitionTxn )
{
return contextCsn;
}
@@ -317,4 +317,14 @@ public abstract class AbstractPartition implements Partition
ctxCsnChanged = true;
}
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void sync() throws LdapException
+ {
+ // Do nothing by default
+ }
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/partition/Partition.java b/core-api/src/main/java/org/apache/directory/server/core/api/partition/Partition.java
index 9bf435b..ad126fe 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/partition/Partition.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/partition/Partition.java
@@ -58,6 +58,17 @@ public interface Partition
/** Default id used for context entry if context entry doesn't exists */
String DEFAULT_ID = new UUID( 0L, 1L ).toString();
+ /**
+ * Start a read transaction
+ */
+ PartitionReadTxn beginReadTransaction();
+
+
+ /**
+ * Start a write transaction
+ */
+ PartitionWriteTxn beginWriteTransaction();
+
// -----------------------------------------------------------------------
// C O N F I G U R A T I O N M E T H O D S
@@ -139,7 +150,7 @@ public interface Partition
* Instructs this Partition to synchronize with it's persistent store, and
* destroy all held resources, in preparation for a shutdown event.
*/
- void destroy() throws Exception;
+ void destroy( PartitionTxn partitionTxn ) throws LdapException;
/**
@@ -153,7 +164,7 @@ public interface Partition
* Flushes any changes made to this partition now.
* @throws Exception if buffers cannot be flushed to disk
*/
- void sync() throws Exception;
+ void sync() throws LdapException;
/**
@@ -287,7 +298,7 @@ public interface Partition
* @param name The index to dump to stdout
* @throws IOException if we can't write the data
*/
- void dumpIndex( OutputStream stream, String name ) throws IOException;
+ void dumpIndex( PartitionTxn partitionTxn, OutputStream stream, String name ) throws IOException;
/**
@@ -301,14 +312,14 @@ public interface Partition
/**
* @return the current highest committed CSN value
*/
- String getContextCsn();
+ String getContextCsn( PartitionTxn partitionTxn );
/**
* saves the context CSN value in the context entry of the partition
* @throws Exception
*/
- void saveContextCsn() throws Exception;
+ void saveContextCsn( PartitionTxn partitionTxn ) throws LdapException;
/**
@@ -318,5 +329,5 @@ public interface Partition
* @return The Subordinate instance that contains the values.
* @throws LdapException If we had an issue while processing the request
*/
- Subordinates getSubordinates( Entry entry ) throws LdapException;
+ Subordinates getSubordinates( PartitionTxn partitionTxn, Entry entry ) throws LdapException;
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionNexus.java b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionNexus.java
index 43e3c8a..39935e6 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionNexus.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionNexus.java
@@ -49,18 +49,7 @@ public interface PartitionNexus extends Partition
String ADMIN_PASSWORD_STRING = "secret";
byte[] ADMIN_PASSWORD_BYTES = Strings.getBytesUtf8( ADMIN_PASSWORD_STRING );
-
- /**
- * Start a read transaction
- */
- PartitionReadTxn beginReadTransaction();
-
-
- /**
- * Start a write transaction
- */
- PartitionWriteTxn beginWriteTransaction();
/**
* Get's the RootDSE entry for the DSA.
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionReadTxn.java b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionReadTxn.java
index d74c53f..62e7797 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionReadTxn.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionReadTxn.java
@@ -1,6 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.directory.server.core.api.partition;
-public interface PartitionReadTxn extends PartitionTxn
+import java.io.IOException;
+
+/**
+ * The Read Transaction interface
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PartitionReadTxn implements PartitionTxn
{
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void commit() throws IOException
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void abort() throws IOException
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isClosed()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws IOException
+ {
+ }
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionTxn.java b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionTxn.java
index 88841f9..7173321 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionTxn.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionTxn.java
@@ -1,8 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.directory.server.core.api.partition;
import java.io.Closeable;
import java.io.IOException;
+/**
+ * The Transaction interface that partitions have to implement.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public interface PartitionTxn extends Closeable
{
/**
@@ -27,4 +51,10 @@ public interface PartitionTxn extends Closeable
* @return <tt>true</tt> if the transaction has been completed.
*/
boolean isClosed();
+
+
+ /**
+ * Commit the transaction. It's called when we get out of a try-with-resource.
+ */
+ void close() throws IOException;
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionWriteTxn.java b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionWriteTxn.java
index effcd3d..2c1f7f0 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionWriteTxn.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/partition/PartitionWriteTxn.java
@@ -1,6 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.directory.server.core.api.partition;
-public interface PartitionWriteTxn extends PartitionTxn
+import java.io.IOException;
+
+/**
+ * The Write Transaction interface
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PartitionWriteTxn implements PartitionTxn
{
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void commit() throws IOException
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void abort() throws IOException
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isClosed()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws IOException
+ {
+ }
}
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java b/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
index 185e480..9835d4b 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
@@ -60,6 +60,9 @@ import org.apache.directory.server.core.api.interceptor.context.SearchOperationC
import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
import org.apache.directory.server.core.api.partition.AbstractPartition;
import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionReadTxn;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.core.api.partition.PartitionWriteTxn;
import org.apache.directory.server.core.api.partition.Subordinates;
import org.apache.directory.server.core.api.schema.registries.synchronizers.RegistrySynchronizerAdaptor;
import org.apache.directory.server.i18n.I18n;
@@ -194,7 +197,7 @@ public final class SchemaPartition extends AbstractPartition
/**
* {@inheritDoc}
*/
- public void sync() throws Exception
+ public void sync() throws LdapException
{
wrapped.sync();
}
@@ -204,7 +207,7 @@ public final class SchemaPartition extends AbstractPartition
* {@inheritDoc}
*/
@Override
- protected void doRepair() throws Exception
+ protected void doRepair() throws LdapException
{
// Nothing to do
}
@@ -214,7 +217,7 @@ public final class SchemaPartition extends AbstractPartition
* {@inheritDoc}
*/
@Override
- protected void doInit() throws Exception
+ protected void doInit() throws LdapException
{
if ( !initialized )
{
@@ -247,11 +250,11 @@ public final class SchemaPartition extends AbstractPartition
* {@inheritDoc}
*/
@Override
- protected void doDestroy()
+ protected void doDestroy( PartitionTxn partitionTxn )
{
try
{
- wrapped.destroy();
+ wrapped.destroy( partitionTxn );
}
catch ( Exception e )
{
@@ -311,6 +314,8 @@ public final class SchemaPartition extends AbstractPartition
SearchOperationContext searchContext = new SearchOperationContext( deleteContext.getSession(),
searchRequest );
+ searchContext.setPartition( this );
+ searchContext.setTransaction( deleteContext.getTransaction() );
EntryFilteringCursor cursor = wrapped.search( searchContext );
@@ -389,6 +394,8 @@ public final class SchemaPartition extends AbstractPartition
{
LookupOperationContext lookupCtx = new LookupOperationContext( modifyContext.getSession(),
modifyContext.getDn() );
+ lookupCtx.setPartition( this );
+ lookupCtx.setTransaction( modifyContext.getTransaction() );
entry = wrapped.lookup( lookupCtx );
modifyContext.setEntry( entry );
}
@@ -421,6 +428,9 @@ public final class SchemaPartition extends AbstractPartition
CoreSession session = moveContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, moveContext.getDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( this );
+ lookupContext.setTransaction( moveContext.getTransaction() );
+
Entry entry = session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
synchronizer.move( moveContext, entry, cascade );
wrapped.move( moveContext );
@@ -437,6 +447,9 @@ public final class SchemaPartition extends AbstractPartition
CoreSession session = moveAndRenameContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, moveAndRenameContext.getDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( this );
+ lookupContext.setTransaction( moveAndRenameContext.getTransaction() );
+
Entry entry = session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
synchronizer.moveAndRename( moveAndRenameContext, entry, cascade );
wrapped.moveAndRename( moveAndRenameContext );
@@ -520,21 +533,24 @@ public final class SchemaPartition extends AbstractPartition
// without using a a bypass list
CoreSession session = opContext.getSession();
ModifyOperationContext modifyContext = new ModifyOperationContext( session, schemaModificationDN, mods );
+ modifyContext.setPartition( this );
+ modifyContext.setTransaction( opContext.getTransaction() );
+
session.getDirectoryService().getPartitionNexus().modify( modifyContext );
}
@Override
- public String getContextCsn()
+ public String getContextCsn( PartitionTxn partitionTxn )
{
- return wrapped.getContextCsn();
+ return wrapped.getContextCsn( partitionTxn );
}
@Override
- public void saveContextCsn() throws Exception
+ public void saveContextCsn( PartitionTxn partitionTxn ) throws LdapException
{
- wrapped.saveContextCsn();
+ wrapped.saveContextCsn( partitionTxn );
}
@@ -562,10 +578,24 @@ public final class SchemaPartition extends AbstractPartition
* @return The Subordinate instance that contains the values.
* @throws LdapException If we had an issue while processing the request
*/
- public Subordinates getSubordinates( Entry entry ) throws LdapException
+ public Subordinates getSubordinates( PartitionTxn partitionTxn, Entry entry ) throws LdapException
{
Subordinates subordinates = new Subordinates();
return subordinates;
}
+
+
+ @Override
+ public PartitionReadTxn beginReadTransaction()
+ {
+ return new PartitionReadTxn();
+ }
+
+
+ @Override
+ public PartitionWriteTxn beginWriteTransaction()
+ {
+ return new PartitionWriteTxn();
+ }
}
diff --git a/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java b/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java
index fdeb3f0..35c207b 100644
--- a/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java
+++ b/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java
@@ -480,7 +480,10 @@ public class MockCoreSession implements CoreSession
public Entry lookup( Dn dn, String... attrIds ) throws LdapException
{
OperationManager operationManager = directoryService.getOperationManager();
- return operationManager.lookup( new LookupOperationContext( this, dn, attrIds ) );
+
+ LookupOperationContext lookupContext = new LookupOperationContext( this, dn, attrIds );
+
+ return operationManager.lookup( lookupContext );
}
diff --git a/core-api/src/test/java/org/apache/directory/server/core/api/MockOperation.java b/core-api/src/test/java/org/apache/directory/server/core/api/MockOperation.java
index 48240e6..f80030a 100644
--- a/core-api/src/test/java/org/apache/directory/server/core/api/MockOperation.java
+++ b/core-api/src/test/java/org/apache/directory/server/core/api/MockOperation.java
@@ -36,6 +36,8 @@ import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
public class MockOperation implements OperationContext
@@ -43,6 +45,7 @@ public class MockOperation implements OperationContext
final int count;
final CoreSession session;
final SchemaManager schemaManager;
+ private Partition partition;
public MockOperation( SchemaManager schemaManager, int count ) throws Exception
@@ -239,4 +242,33 @@ public class MockOperation implements OperationContext
public void setCurrentInterceptor( int currentInterceptor )
{
}
+
+
+ @Override
+ public PartitionTxn getTransaction()
+ {
+ return null;
+ }
+
+
+ @Override
+ public void setTransaction( PartitionTxn transaction )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public Partition getPartition()
+ {
+ return partition;
+ }
+
+
+ @Override
+ public void setPartition( Partition partition )
+ {
+ this.partition = partition;
+ }
}
diff --git a/core-api/src/test/java/org/apache/directory/server/core/api/normalization/FilterNormalizingVisitorTest.java b/core-api/src/test/java/org/apache/directory/server/core/api/normalization/FilterNormalizingVisitorTest.java
index db77f29..f24772e 100644
--- a/core-api/src/test/java/org/apache/directory/server/core/api/normalization/FilterNormalizingVisitorTest.java
+++ b/core-api/src/test/java/org/apache/directory/server/core/api/normalization/FilterNormalizingVisitorTest.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.util.List;
-import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer;
diff --git a/core-avl/src/main/java/org/apache/directory/server/core/avltree/ArrayTreeCursor.java b/core-avl/src/main/java/org/apache/directory/server/core/avltree/ArrayTreeCursor.java
index 28722f7..a982e82 100644
--- a/core-avl/src/main/java/org/apache/directory/server/core/avltree/ArrayTreeCursor.java
+++ b/core-avl/src/main/java/org/apache/directory/server/core/avltree/ArrayTreeCursor.java
@@ -75,7 +75,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public void after( E element ) throws LdapException, CursorException
{
- checkNotClosed( "after" );
+ checkNotClosed();
if ( element == null )
{
@@ -105,7 +105,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast" );
+ checkNotClosed();
current = -1;
position = Position.AFTER_LAST;
@@ -126,7 +126,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public void before( E element ) throws LdapException, CursorException
{
- checkNotClosed( "before" );
+ checkNotClosed();
if ( element == null )
{
@@ -156,7 +156,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst" );
+ checkNotClosed();
current = -1;
position = Position.BEFORE_FIRST;
@@ -168,7 +168,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public boolean first() throws LdapException, CursorException
{
- checkNotClosed( "first" );
+ checkNotClosed();
if ( array.isEmpty() )
{
@@ -190,7 +190,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public E get() throws CursorException
{
- checkNotClosed( "get" );
+ checkNotClosed();
if ( position == Position.ON_NODE )
{
@@ -206,7 +206,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public boolean last() throws LdapException, CursorException
{
- checkNotClosed( "last" );
+ checkNotClosed();
if ( array.isEmpty() )
{
@@ -228,7 +228,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next" );
+ checkNotClosed();
// If the array is empty, return false
if ( array.size() == 0 )
@@ -273,7 +273,7 @@ public class ArrayTreeCursor<E> extends AbstractCursor<E>
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous" );
+ checkNotClosed();
if ( array.size() == 0 )
{
diff --git a/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java b/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java
index df74cdd..1c0c625 100644
--- a/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java
+++ b/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java
@@ -95,7 +95,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast" );
+ checkNotClosed();
node = null;
position = Position.AFTER_LAST;
}
@@ -118,7 +118,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst" );
+ checkNotClosed();
node = null;
position = Position.BEFORE_FIRST;
}
@@ -129,7 +129,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public boolean first() throws LdapException, CursorException
{
- checkNotClosed( "first" );
+ checkNotClosed();
node = tree.getFirst();
@@ -151,7 +151,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public Tuple<K, SingletonOrOrderedSet<V>> get() throws CursorException
{
- checkNotClosed( "get" );
+ checkNotClosed();
if ( position == Position.ON_NODE )
{
@@ -169,7 +169,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public boolean last() throws LdapException, CursorException
{
- checkNotClosed( "last" );
+ checkNotClosed();
node = tree.getLast();
@@ -191,7 +191,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next" );
+ checkNotClosed();
switch ( position )
{
@@ -232,7 +232,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous" );
+ checkNotClosed();
switch ( position )
{
@@ -271,7 +271,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
*/
public void afterKey( K key ) throws LdapException, CursorException
{
- checkNotClosed( "afterKey" );
+ checkNotClosed();
if ( key == null )
{
@@ -303,7 +303,7 @@ public class AvlSingletonOrOrderedSetCursor<K, V> extends AbstractCursor<Tuple<K
public void beforeKey( K key ) throws LdapException, CursorException
{
- checkNotClosed( "beforeKey" );
+ checkNotClosed();
if ( key == null )
{
diff --git a/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java b/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
index 32c0fc8..421add6 100644
--- a/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
+++ b/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeCursor.java
@@ -70,7 +70,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public void after( E element ) throws LdapException, CursorException
{
- checkNotClosed( "after" );
+ checkNotClosed();
if ( element == null )
{
@@ -99,7 +99,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast" );
+ checkNotClosed();
node = null;
position = Position.AFTER_LAST;
}
@@ -116,7 +116,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public void before( E element ) throws LdapException, CursorException
{
- checkNotClosed( "before" );
+ checkNotClosed();
if ( element == null )
{
@@ -145,7 +145,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst" );
+ checkNotClosed();
node = null;
position = Position.BEFORE_FIRST;
}
@@ -156,7 +156,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public boolean first() throws LdapException, CursorException
{
- checkNotClosed( "first" );
+ checkNotClosed();
node = tree.getFirst();
@@ -178,7 +178,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public E get() throws CursorException
{
- checkNotClosed( "get" );
+ checkNotClosed();
if ( position == Position.ON_NODE )
{
@@ -194,7 +194,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public boolean last() throws LdapException, CursorException
{
- checkNotClosed( "last" );
+ checkNotClosed();
node = tree.getLast();
@@ -216,7 +216,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next" );
+ checkNotClosed();
switch ( position )
{
@@ -255,7 +255,7 @@ public class AvlTreeCursor<E> extends AbstractCursor<E>
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous" );
+ checkNotClosed();
switch ( position )
{
diff --git a/core-avl/src/main/java/org/apache/directory/server/core/avltree/KeyTupleAvlCursor.java b/core-avl/src/main/java/org/apache/directory/server/core/avltree/KeyTupleAvlCursor.java
index 42047c8..0aa421d 100644
--- a/core-avl/src/main/java/org/apache/directory/server/core/avltree/KeyTupleAvlCursor.java
+++ b/core-avl/src/main/java/org/apache/directory/server/core/avltree/KeyTupleAvlCursor.java
@@ -100,7 +100,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
public void beforeValue( K key, V value ) throws Exception
{
- checkNotClosed( "beforeValue()" );
+ checkNotClosed();
if ( key != null && !key.equals( this.key ) )
{
throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
@@ -113,7 +113,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
public void afterValue( K key, V value ) throws Exception
{
- checkNotClosed( "afterValue()" );
+ checkNotClosed();
if ( key != null && !key.equals( this.key ) )
{
throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
@@ -134,7 +134,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void before( Tuple<K, V> element ) throws LdapException, CursorException
{
- checkNotClosed( "before()" );
+ checkNotClosed();
wrapped.before( element.getValue() );
clearValue();
}
@@ -145,7 +145,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void after( Tuple<K, V> element ) throws LdapException, CursorException
{
- checkNotClosed( "after()" );
+ checkNotClosed();
wrapped.after( element.getValue() );
clearValue();
}
@@ -156,7 +156,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst()" );
+ checkNotClosed();
wrapped.beforeFirst();
clearValue();
}
@@ -167,7 +167,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast()" );
+ checkNotClosed();
wrapped.afterLast();
clearValue();
}
@@ -198,7 +198,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
if ( wrapped.previous() )
{
returnedTuple.setKey( key );
@@ -219,7 +219,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next()" );
+ checkNotClosed();
if ( wrapped.next() )
{
@@ -241,7 +241,7 @@ public class KeyTupleAvlCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public Tuple<K, V> get() throws CursorException
{
- checkNotClosed( "get()" );
+ checkNotClosed();
if ( valueAvailable )
{
return returnedTuple;
diff --git a/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java b/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
index d406011..042b9a7 100644
--- a/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
+++ b/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
@@ -477,7 +477,7 @@ public class IntegrationUtils
{
LdapConnection connection = new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME, ldapServer.getPort() );
- connection.setTimeOut( 0 );
+ connection.setTimeOut( 30000L );
connection.bind( ServerDNConstants.ADMIN_SYSTEM_DN, "secret" );
OPEN_CONNECTIONS.add( connection );
diff --git a/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java b/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java
index 1a349ba..a366f42 100644
--- a/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java
+++ b/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java
@@ -23,6 +23,7 @@ package org.apache.directory.server.core.configuration;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.io.IOException;
import java.util.UUID;
import org.apache.directory.api.ldap.model.csn.CsnFactory;
@@ -33,6 +34,8 @@ import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionReadTxn;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
import org.apache.directory.server.core.factory.DirectoryServiceFactory;
import org.apache.directory.server.core.factory.PartitionFactory;
@@ -77,7 +80,21 @@ public class PartitionConfigurationIT extends AbstractLdapTestUnit
"entryCSN", new CsnFactory( 1 ).newInstance().toString(),
"entryUUID", UUID.randomUUID().toString() );
- partition.add( new AddOperationContext( getService().getAdminSession(), ctxEntry ) );
+ AddOperationContext addContext = new AddOperationContext( getService().getAdminSession(), ctxEntry );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( IOException ioe )
+ {
+ partitionTxn.abort();
+ }
LdapConnection connection = IntegrationUtils.getAdminConnection( getService() );
diff --git a/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java b/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java
index e8ae01b..413e98c 100644
--- a/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java
+++ b/core-integ/src/test/java/org/apache/directory/server/core/jndi/ObjStateFactoryIT.java
@@ -24,7 +24,6 @@ import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemC
import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import java.util.Hashtable;
@@ -40,7 +39,6 @@ import javax.naming.ldap.LdapContext;
import javax.naming.spi.DirObjectFactory;
import javax.naming.spi.DirStateFactory;
-import org.apache.commons.lang.ArrayUtils;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.util.Strings;
diff --git a/core-integ/src/test/java/org/apache/directory/server/core/operations/add/AddIT.java b/core-integ/src/test/java/org/apache/directory/server/core/operations/add/AddIT.java
index 2cadf46..e126e68 100644
--- a/core-integ/src/test/java/org/apache/directory/server/core/operations/add/AddIT.java
+++ b/core-integ/src/test/java/org/apache/directory/server/core/operations/add/AddIT.java
@@ -35,7 +35,6 @@ import org.apache.directory.server.core.annotations.CreatePartition;
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
import org.apache.directory.server.core.integ.FrameworkRunner;
import org.apache.directory.server.core.integ.IntegrationUtils;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/core-integ/src/test/java/org/apache/directory/server/core/operations/hasEntry/hasEntryPerfIT.java b/core-integ/src/test/java/org/apache/directory/server/core/operations/hasEntry/hasEntryPerfIT.java
index d7498cf..0fd7793 100644
--- a/core-integ/src/test/java/org/apache/directory/server/core/operations/hasEntry/hasEntryPerfIT.java
+++ b/core-integ/src/test/java/org/apache/directory/server/core/operations/hasEntry/hasEntryPerfIT.java
@@ -50,7 +50,7 @@ public class hasEntryPerfIT extends AbstractLdapTestUnit
boolean hasEntry = getService().getOperationManager().hasEntry( hasEntryContext );
assertTrue( hasEntry );
- int nbIterations = 150000;
+ int nbIterations = 1500000;
long t0 = System.currentTimeMillis();
long t00 = 0L;
@@ -60,7 +60,7 @@ public class hasEntryPerfIT extends AbstractLdapTestUnit
{
hasEntryContext.setCurrentInterceptor( 0 );
- if ( i % 1000 == 0 )
+ if ( i % 100000 == 0 )
{
long tt1 = System.currentTimeMillis();
diff --git a/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchPerfIT.java b/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchPerfIT.java
index 50103bc..79d8ddd 100644
--- a/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchPerfIT.java
+++ b/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchPerfIT.java
@@ -41,11 +41,9 @@ import org.apache.directory.server.core.annotations.ContextEntry;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.annotations.CreateIndex;
import org.apache.directory.server.core.annotations.CreatePartition;
-import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
import org.apache.directory.server.core.integ.FrameworkRunner;
import org.apache.directory.server.core.integ.IntegrationUtils;
-import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotPartition;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java b/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
index 1f7a27b..5aa4b44 100644
--- a/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
+++ b/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
@@ -59,13 +59,12 @@ import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyImpl;
import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyResponseImpl;
import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator;
import org.apache.directory.api.ldap.extras.controls.syncrepl.syncDone.SyncDoneValue;
-import org.apache.directory.api.ldap.extras.controls.syncrepl.syncInfoValue.SyncInfoValue;
-import org.apache.directory.api.ldap.extras.controls.syncrepl.syncInfoValue.SyncRequestValue;
+import org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue;
import org.apache.directory.api.ldap.extras.controls.syncrepl.syncState.SyncStateValue;
import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueDecorator;
-import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncInfoValueDecorator;
import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueDecorator;
import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncStateValueDecorator;
+import org.apache.directory.api.ldap.extras.intermediate.syncrepl.syncInfoValue.SyncInfoValue;
import org.apache.directory.api.ldap.model.constants.JndiPropertyConstants;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.EmptyCursor;
@@ -436,11 +435,6 @@ public abstract class ServerContext implements EventContext
break;
- case SYNC_INFO_VALUE_CONTROL:
- control = new SyncInfoValueDecorator( getDirectoryService().getLdapCodecService() );
-
- break;
-
case SYNC_REQUEST_VALUE_CONTROL:
control = new SyncRequestValueDecorator( getDirectoryService().getLdapCodecService() );
@@ -540,8 +534,7 @@ public abstract class ServerContext implements EventContext
boolean result = operationManager.compare( compareContext );
// setup the op context and populate with request controls
- searchContext = new SearchOperationContext( session, dn, filter,
- searchControls );
+ searchContext = new SearchOperationContext( session, dn, filter, searchControls );
searchContext.setAliasDerefMode( aliasDerefMode );
searchContext.addRequestControls( convertControls( true, requestControls ) );
@@ -630,12 +623,14 @@ public abstract class ServerContext implements EventContext
LookupOperationContext lookupContext = new LookupOperationContext( session, target );
lookupContext.addRequestControls( convertControls( true, requestControls ) );
OperationManager operationManager = service.getOperationManager();
+
Entry serverEntry = operationManager.lookup( lookupContext );
// clear the request controls and set the response controls
requestControls = EMPTY_CONTROLS;
responseControls = JndiUtils.toJndiControls( getDirectoryService().getLdapCodecService(),
lookupContext.getResponseControls() );
+
return serverEntry;
}
@@ -679,7 +674,6 @@ public abstract class ServerContext implements EventContext
{
// setup the op context and populate with request controls
BindOperationContext bindContext = new BindOperationContext( null );
- bindContext.setTransaction( getDirectoryService().getPartitionNexus().beginReadTransaction() );
bindContext.setDn( bindDn );
bindContext.setCredentials( credentials );
bindContext.setSaslMechanism( saslMechanism );
diff --git a/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java b/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java
index b2633c4..41f311b 100644
--- a/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java
+++ b/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java
@@ -31,7 +31,7 @@ import java.util.Set;
import jdbm.recman.BaseRecordManager;
-import org.apache.directory.api.ldap.extras.controls.syncrepl.syncInfoValue.SyncRequestValue;
+import org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue;
import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.Cursor;
@@ -255,6 +255,7 @@ public class DefaultCoreSession implements CoreSession
addContext.setLogChange( log );
OperationManager operationManager = directoryService.getOperationManager();
+
try
{
operationManager.add( addContext );
@@ -264,6 +265,7 @@ public class DefaultCoreSession implements CoreSession
addRequest.getResultResponse().addAllControls( addContext.getResponseControls() );
throw e;
}
+
addRequest.getResultResponse().addAllControls( addContext.getResponseControls() );
}
@@ -652,6 +654,7 @@ public class DefaultCoreSession implements CoreSession
modifyContext.setLogChange( log );
OperationManager operationManager = directoryService.getOperationManager();
+
operationManager.modify( modifyContext );
}
@@ -1217,10 +1220,26 @@ public class DefaultCoreSession implements CoreSession
}
catch ( Exception e )
{
- e.printStackTrace();
done.addAllControls( searchContext.getResponseControls() );
throw new LdapException( e );
}
+ finally
+ {
+ // Don't close the transaction !!!
+ LOG.debug( "Search done, the transaction is still opened" );
+ /*
+ try
+ {
+ ( ( EntryFilteringCursor ) cursor ).getOperationContext().getTransaction().close();
+ }
+ catch ( IOException ioe )
+ {
+ done.addAllControls( searchContext.getResponseControls() );
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ */
+ }
if ( sortRespCtrl != null )
{
diff --git a/core-shared/src/main/java/org/apache/directory/server/core/shared/ReferralManagerImpl.java b/core-shared/src/main/java/org/apache/directory/server/core/shared/ReferralManagerImpl.java
index 2de726f..8341799 100644
--- a/core-shared/src/main/java/org/apache/directory/server/core/shared/ReferralManagerImpl.java
+++ b/core-shared/src/main/java/org/apache/directory/server/core/shared/ReferralManagerImpl.java
@@ -20,6 +20,7 @@
package org.apache.directory.server.core.shared;
+import java.io.IOException;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -30,6 +31,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.filter.EqualityNode;
import org.apache.directory.api.ldap.model.filter.ExprNode;
import org.apache.directory.api.ldap.model.message.AliasDerefMode;
@@ -41,7 +43,9 @@ import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.ReferralManager;
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
/**
@@ -179,38 +183,50 @@ public class ReferralManagerImpl implements ReferralManager
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, suffixDn,
referralFilter, searchControl );
- searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
- EntryFilteringCursor cursor = nexus.search( searchOperationContext );
-
- try
+
+ Partition partition = nexus.getPartition( suffixDn );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- // Move to the first entry in the cursor
- cursor.beforeFirst();
-
- while ( cursor.next() )
+ searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
+ searchOperationContext.setTransaction( partitionTxn );
+ searchOperationContext.setPartition( partition );
+ EntryFilteringCursor cursor = nexus.search( searchOperationContext );
+
+ try
{
- Entry entry = cursor.get();
-
- // Lock the referralManager
- lockWrite();
-
- try
+ // Move to the first entry in the cursor
+ cursor.beforeFirst();
+
+ while ( cursor.next() )
{
- // Add it at the right place
- addReferral( entry );
- }
- finally
- {
- // Unlock the referralManager
- unlock();
+ Entry entry = cursor.get();
+
+ // Lock the referralManager
+ lockWrite();
+
+ try
+ {
+ // Add it at the right place
+ addReferral( entry );
+ }
+ finally
+ {
+ // Unlock the referralManager
+ unlock();
+ }
}
+
+ cursor.close();
+ }
+ catch ( Exception e )
+ {
+ throw new LdapOperationException( e.getMessage(), e );
}
-
- cursor.close();
}
- catch ( Exception e )
+ catch ( IOException ioe )
{
- throw new LdapOperationException( e.getMessage(), e );
+ throw new LdapOtherException( ioe.getMessage(), ioe );
}
}
}
@@ -236,19 +252,26 @@ public class ReferralManagerImpl implements ReferralManager
// We will store each entry's Dn into the Referral tree
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, suffix,
referralFilter, searchControl );
+ Partition partition = nexus.getPartition( suffix );
+ searchOperationContext.setPartition( partition );
searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
- EntryFilteringCursor cursor = nexus.search( searchOperationContext );
-
- // Move to the first entry in the cursor
- cursor.beforeFirst();
-
- while ( cursor.next() )
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- Entry entry = cursor.get();
-
- // Add it at the right place
- removeReferral( entry );
- }
+ searchOperationContext.setTransaction( partitionTxn );
+ EntryFilteringCursor cursor = nexus.search( searchOperationContext );
+
+ // Move to the first entry in the cursor
+ cursor.beforeFirst();
+
+ while ( cursor.next() )
+ {
+ Entry entry = cursor.get();
+
+ // Add it at the right place
+ removeReferral( entry );
+ }
+ }
}
diff --git a/core-shared/src/main/java/org/apache/directory/server/core/shared/SchemaService.java b/core-shared/src/main/java/org/apache/directory/server/core/shared/SchemaService.java
index a5c8172..f7a4a86 100644
--- a/core-shared/src/main/java/org/apache/directory/server/core/shared/SchemaService.java
+++ b/core-shared/src/main/java/org/apache/directory/server/core/shared/SchemaService.java
@@ -19,12 +19,15 @@
package org.apache.directory.server.core.shared;
+import java.io.IOException;
+
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.DitContentRule;
@@ -47,6 +50,8 @@ import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.entry.ClonedServerEntry;
import org.apache.directory.server.core.api.interceptor.context.FilteringOperationContext;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
/**
@@ -309,11 +314,23 @@ public final class SchemaService
{
Dn schemaModificationAttributesDn = new Dn( directoryService.getSchemaManager(),
SchemaConstants.SCHEMA_MODIFICATIONS_DN );
-
- generateSchemaSubentry(
- directoryService.getSchemaManager(),
- directoryService.getSchemaPartition().lookup(
- new LookupOperationContext( null, schemaModificationAttributesDn ) ) );
+
+ Partition partition = directoryService.getSchemaPartition();
+
+ LookupOperationContext lookupContext = new LookupOperationContext( null, schemaModificationAttributesDn );
+ lookupContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+
+ generateSchemaSubentry( directoryService.getSchemaManager(),
+ directoryService.getSchemaPartition().lookup( lookupContext ) );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
return schemaSubentry.clone();
@@ -331,10 +348,23 @@ public final class SchemaService
Dn schemaModificationAttributesDn = new Dn( directoryService.getSchemaManager(),
SchemaConstants.SCHEMA_MODIFICATIONS_DN );
- generateSchemaSubentry(
- directoryService.getSchemaManager(),
- directoryService.getSchemaPartition().lookup(
- new LookupOperationContext( null, schemaModificationAttributesDn ) ) );
+ Partition partition = directoryService.getSchemaPartition();
+
+ LookupOperationContext lookupContext = new LookupOperationContext( null, schemaModificationAttributesDn );
+ lookupContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+
+ generateSchemaSubentry(
+ directoryService.getSchemaManager(),
+ directoryService.getSchemaPartition().lookup( lookupContext ) );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
return schemaSubentry.clone();
@@ -359,41 +389,53 @@ public final class SchemaService
Dn schemaModificationAttributesDn = new Dn( directoryService.getSchemaManager(),
SchemaConstants.SCHEMA_MODIFICATIONS_DN );
- Entry mods =
- directoryService.getSchemaPartition().lookup(
- new LookupOperationContext( null, schemaModificationAttributesDn,
- SchemaConstants.ALL_ATTRIBUTES_ARRAY ) );
-
- // @todo enable this optimization at some point but for now it
- // is causing some problems so I will just turn it off
- // Attribute modifyTimeDisk = mods.get( SchemaConstants.MODIFY_TIMESTAMP_AT );
- //
- // Attribute modifyTimeMemory = null;
- //
- // if ( schemaSubentry != null )
- // {
- // modifyTimeMemory = schemaSubentry.get( SchemaConstants.MODIFY_TIMESTAMP_AT );
- // if ( modifyTimeDisk == null && modifyTimeMemory == null )
- // {
- // // do nothing!
- // }
- // else if ( modifyTimeDisk != null && modifyTimeMemory != null )
- // {
- // Date disk = DateUtils.getDate( ( String ) modifyTimeDisk.get() );
- // Date mem = DateUtils.getDate( ( String ) modifyTimeMemory.get() );
- // if ( disk.after( mem ) )
- // {
- // generateSchemaSubentry( mods );
- // }
- // }
- // else
- // {
- // generateSchemaSubentry( mods );
- // }
- // }
- // else
- // {
- generateSchemaSubentry( schemaManager, mods );
+ Partition partition = directoryService.getSchemaPartition();
+
+ LookupOperationContext lookupContext = new LookupOperationContext( null, schemaModificationAttributesDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+
+ Entry mods =
+ directoryService.getSchemaPartition().lookup( lookupContext );
+ // @todo enable this optimization at some point but for now it
+ // is causing some problems so I will just turn it off
+ // Attribute modifyTimeDisk = mods.get( SchemaConstants.MODIFY_TIMESTAMP_AT );
+ //
+ // Attribute modifyTimeMemory = null;
+ //
+ // if ( schemaSubentry != null )
+ // {
+ // modifyTimeMemory = schemaSubentry.get( SchemaConstants.MODIFY_TIMESTAMP_AT );
+ // if ( modifyTimeDisk == null && modifyTimeMemory == null )
+ // {
+ // // do nothing!
+ // }
+ // else if ( modifyTimeDisk != null && modifyTimeMemory != null )
+ // {
+ // Date disk = DateUtils.getDate( ( String ) modifyTimeDisk.get() );
+ // Date mem = DateUtils.getDate( ( String ) modifyTimeMemory.get() );
+ // if ( disk.after( mem ) )
+ // {
+ // generateSchemaSubentry( mods );
+ // }
+ // }
+ // else
+ // {
+ // generateSchemaSubentry( mods );
+ // }
+ // }
+ // else
+ // {
+ generateSchemaSubentry( schemaManager, mods );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
// }
// ---------------------------------------------------------------
diff --git a/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java b/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java
index ee7a81f..f179f48 100644
--- a/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java
+++ b/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java
@@ -80,6 +80,9 @@ import org.apache.directory.server.core.api.interceptor.context.UnbindOperationC
import org.apache.directory.server.core.api.partition.AbstractPartition;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.partition.PartitionReadTxn;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.core.api.partition.PartitionWriteTxn;
import org.apache.directory.server.core.api.partition.Subordinates;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
@@ -123,7 +126,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
private final List<Modification> mods = new ArrayList<>( 2 );
/** The cn=schema Dn */
- private Dn subschemSubentryDn;
+ private Dn subschemaSubentryDn;
/**
@@ -178,7 +181,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* {@inheritDoc}
*/
@Override
- public void repair() throws Exception
+ public void repair() throws LdapException
{
// Nothing to do
}
@@ -188,7 +191,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* {@inheritDoc}
*/
@Override
- protected void doRepair() throws Exception
+ protected void doRepair() throws LdapException
{
// Nothing to do
}
@@ -198,7 +201,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* {@inheritDoc}
*/
@Override
- protected void doInit() throws Exception
+ protected void doInit() throws LdapException
{
// NOTE: We ignore ContextPartitionConfiguration parameter here.
if ( !initialized )
@@ -214,7 +217,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
schemaManager = directoryService.getSchemaManager();
Value attr = rootDse.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
- subschemSubentryDn = directoryService.getDnFactory().create( attr.getValue() );
+ subschemaSubentryDn = directoryService.getDnFactory().create( attr.getValue() );
List<Partition> initializedPartitions = new ArrayList<>();
@@ -246,7 +249,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
try
{
- partition.destroy();
+ partition.destroy( partition.beginReadTransaction() );
}
catch ( Exception e )
{
@@ -267,7 +270,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* {@inheritDoc}
*/
@Override
- protected synchronized void doDestroy()
+ protected synchronized void doDestroy( PartitionTxn partitionTxn )
{
if ( !initialized )
{
@@ -316,34 +319,35 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* {@inheritDoc}
*/
@Override
- public void sync() throws Exception
+ public void sync() throws LdapException
{
- MultiException error = null;
+ MultiException errors = null;
for ( Partition partition : this.partitions.values() )
{
try
{
- partition.saveContextCsn();
+ partition.saveContextCsn( partition.beginReadTransaction() );
partition.sync();
}
catch ( Exception e )
{
LOG.warn( "Failed to flush partition data out.", e );
- if ( error == null )
+
+ if ( errors == null )
{
//noinspection ThrowableInstanceNeverThrown
- error = new MultiException( I18n.err( I18n.ERR_265 ) );
+ errors = new MultiException( I18n.err( I18n.ERR_265 ) );
}
// @todo really need to send this info to a monitor
- error.addThrowable( e );
+ errors.addThrowable( e );
}
}
- if ( error != null )
+ if ( errors != null )
{
- throw error;
+ throw new LdapOtherException( errors.getMessage(), errors );
}
}
@@ -357,7 +361,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
@Override
public void add( AddOperationContext addContext ) throws LdapException
{
- Partition partition = getPartition( addContext.getDn() );
+ Partition partition = addContext.getPartition();
partition.add( addContext );
}
@@ -446,7 +450,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
{
Dn dn = lookupContext.getDn();
- if ( dn.getNormName().equals( subschemSubentryDn.getNormName() ) )
+ if ( dn.getNormName().equals( subschemaSubentryDn.getNormName() ) )
{
return new ClonedServerEntry( rootDse.clone() );
}
@@ -581,8 +585,11 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
}
Entry serverEntry = new DefaultEntry( schemaManager, Dn.ROOT_DSE );
-
- Entry foundRootDse = getRootDse( new GetRootDseOperationContext( searchContext.getSession() ) );
+ GetRootDseOperationContext getRootDseContext = new GetRootDseOperationContext( searchContext.getSession() );
+ getRootDseContext.setPartition( searchContext.getPartition() );
+ getRootDseContext.setTransaction( searchContext.getTransaction() );
+
+ Entry foundRootDse = getRootDse( getRootDseContext );
for ( Attribute attribute : foundRootDse )
{
@@ -630,7 +637,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
}
// Normal case : do a search on the specific partition
- Partition backend = getPartition( baseDn );
+ Partition backend = searchContext.getPartition();
return backend.search( searchContext );
}
@@ -696,8 +703,13 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
for ( Partition partition : partitions.values() )
{
Dn contextDn = partition.getSuffixDn();
+ PartitionTxn partitionTxn = partition.beginReadTransaction();
HasEntryOperationContext hasEntryContext = new HasEntryOperationContext(
searchContext.getSession(), contextDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+ searchContext.setPartition( partition );
+ searchContext.setTransaction( partitionTxn );
// search only if the context entry exists
if ( partition.hasEntry( hasEntryContext ) )
@@ -718,9 +730,14 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
for ( Partition partition : partitions.values() )
{
+ PartitionTxn partitionTxn = partition.beginReadTransaction();
Dn contextDn = partition.getSuffixDn();
HasEntryOperationContext hasEntryContext = new HasEntryOperationContext(
searchContext.getSession(), contextDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+ searchContext.setPartition( partition );
+ searchContext.setTransaction( partitionTxn );
if ( partition.hasEntry( hasEntryContext ) )
{
@@ -901,7 +918,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
try
{
- partition.destroy();
+ partition.destroy( partition.beginReadTransaction() );
}
catch ( Exception e )
{
@@ -917,12 +934,22 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
public Partition getPartition( Dn dn ) throws LdapException
{
Partition parent;
+
+ if ( dn == null )
+ {
+ dn = Dn.ROOT_DSE;
+ }
if ( !dn.isSchemaAware() )
{
dn = new Dn( schemaManager, dn );
}
-
+
+ if ( dn.isRootDse() || dn.getNormName().equals( subschemaSubentryDn.getNormName() ) )
+ {
+ return new RootPartition( schemaManager );
+ }
+
synchronized ( partitionLookupTree )
{
parent = partitionLookupTree.getElement( dn );
@@ -1014,7 +1041,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* BackendNexus.
* @throws Exception if there are problems unregistering the partition
*/
- private void unregister( Partition partition ) throws Exception
+ private void unregister( Partition partition ) throws LdapException
{
Attribute namingContexts = rootDse.get( SchemaConstants.NAMING_CONTEXTS_AT );
@@ -1065,8 +1092,11 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public String getContextCsn()
+ public String getContextCsn( PartitionTxn partitionTxn )
{
// nexus doesn't contain a contextCSN
return null;
@@ -1074,7 +1104,7 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
@Override
- public void saveContextCsn() throws Exception
+ public void saveContextCsn( PartitionTxn partitionTxn ) throws LdapException
{
}
@@ -1087,8 +1117,22 @@ public class DefaultPartitionNexus extends AbstractPartition implements Partitio
* @throws LdapException If we had an issue while processing the request
*/
@Override
- public Subordinates getSubordinates( Entry entry ) throws LdapException
+ public Subordinates getSubordinates( PartitionTxn partitionTxn, Entry entry ) throws LdapException
{
return new Subordinates();
}
+
+
+ @Override
+ public PartitionReadTxn beginReadTransaction()
+ {
+ return new PartitionReadTxn();
+ }
+
+
+ @Override
+ public PartitionWriteTxn beginWriteTransaction()
+ {
+ return new PartitionWriteTxn();
+ }
}
diff --git a/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/RootPartition.java b/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/RootPartition.java
new file mode 100644
index 0000000..e2a1ae5
--- /dev/null
+++ b/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/RootPartition.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.core.shared.partition;
+
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.api.partition.AbstractPartition;
+import org.apache.directory.server.core.api.partition.PartitionReadTxn;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.core.api.partition.PartitionWriteTxn;
+import org.apache.directory.server.core.api.partition.Subordinates;
+
+/**
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class RootPartition extends AbstractPartition
+{
+
+ protected RootPartition( SchemaManager schemaManager )
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+
+ @Override
+ public PartitionReadTxn beginReadTransaction()
+ {
+ return new PartitionReadTxn();
+ }
+
+
+ @Override
+ public PartitionWriteTxn beginWriteTransaction()
+ {
+ return new PartitionWriteTxn();
+ }
+
+ @Override
+ protected void doRepair() throws LdapException
+ {
+ }
+
+
+ @Override
+ public Entry delete( DeleteOperationContext deleteContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ @Override
+ public void add( AddOperationContext addContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public void modify( ModifyOperationContext modifyContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ @Override
+ public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ @Override
+ public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ @Override
+ public void rename( RenameOperationContext renameContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public void move( MoveOperationContext moveContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public void unbind( UnbindOperationContext unbindContext ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public void saveContextCsn( PartitionTxn partitionTxn ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public Subordinates getSubordinates( PartitionTxn partitionTxn, Entry entry ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ @Override
+ protected void doDestroy( PartitionTxn partitionTxn ) throws LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ protected void doInit() throws InvalidNameException, LdapException
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java b/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
index 845715b..d45ba60 100644
--- a/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
+++ b/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
@@ -56,6 +56,7 @@ import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.ldif.ChangeType;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
@@ -101,6 +102,7 @@ import org.apache.directory.server.core.api.interceptor.context.OperationContext
import org.apache.directory.server.core.api.journal.Journal;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.core.api.schema.SchemaPartition;
import org.apache.directory.server.core.api.subtree.SubentryCache;
import org.apache.directory.server.core.api.subtree.SubtreeEvaluator;
@@ -252,10 +254,10 @@ public class DefaultDirectoryService implements DirectoryService
private Partition systemPartition;
/** The set of all declared partitions */
- private Set<Partition> partitions = new HashSet<Partition>();
+ private Set<Partition> partitions = new HashSet<>();
/** A list of LDIF entries to inject at startup */
- private List<? extends LdifEntry> testEntries = new ArrayList<LdifEntry>(); // List<Attributes>
+ private List<? extends LdifEntry> testEntries = new ArrayList<>(); // List<Attributes>
/** The event service */
private EventService eventService;
@@ -340,7 +342,7 @@ public class DefaultDirectoryService implements DirectoryService
*/
public Set<? extends Partition> getPartitions()
{
- Set<Partition> cloned = new HashSet<Partition>();
+ Set<Partition> cloned = new HashSet<>();
cloned.addAll( partitions );
return cloned;
}
@@ -353,9 +355,9 @@ public class DefaultDirectoryService implements DirectoryService
*/
public void setPartitions( Set<? extends Partition> partitions )
{
- Set<Partition> cloned = new HashSet<Partition>();
+ Set<Partition> cloned = new HashSet<>();
cloned.addAll( partitions );
- Set<String> names = new HashSet<String>();
+ Set<String> names = new HashSet<>();
for ( Partition partition : cloned )
{
@@ -429,7 +431,7 @@ public class DefaultDirectoryService implements DirectoryService
*/
public List<Interceptor> getInterceptors()
{
- List<Interceptor> cloned = new ArrayList<Interceptor>();
+ List<Interceptor> cloned = new ArrayList<>();
readLock.lock();
@@ -453,7 +455,7 @@ public class DefaultDirectoryService implements DirectoryService
*/
public List<String> getInterceptors( OperationEnum operation )
{
- List<String> cloned = new ArrayList<String>();
+ List<String> cloned = new ArrayList<>();
readLock.lock();
@@ -480,11 +482,11 @@ public class DefaultDirectoryService implements DirectoryService
try
{
- operationInterceptors = new ConcurrentHashMap<OperationEnum, List<String>>();
+ operationInterceptors = new ConcurrentHashMap<>();
for ( OperationEnum operation : OperationEnum.getOperations() )
{
- List<String> operationList = new ArrayList<String>();
+ List<String> operationList = new ArrayList<>();
for ( Interceptor interceptor : interceptors )
{
@@ -701,7 +703,7 @@ public class DefaultDirectoryService implements DirectoryService
*/
public List<LdifEntry> getTestEntries()
{
- List<LdifEntry> cloned = new ArrayList<LdifEntry>();
+ List<LdifEntry> cloned = new ArrayList<>();
cloned.addAll( testEntries );
return cloned;
@@ -717,7 +719,7 @@ public class DefaultDirectoryService implements DirectoryService
public void setTestEntries( List<? extends LdifEntry> testEntries )
{
//noinspection MismatchedQueryAndUpdateOfCollection
- List<LdifEntry> cloned = new ArrayList<LdifEntry>();
+ List<LdifEntry> cloned = new ArrayList<>();
cloned.addAll( testEntries );
this.testEntries = testEntries;
}
@@ -744,7 +746,7 @@ public class DefaultDirectoryService implements DirectoryService
{
if ( !instanceLayout.getInstanceDirectory().mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
instanceLayout.getInstanceDirectory() ) );
}
}
@@ -753,7 +755,7 @@ public class DefaultDirectoryService implements DirectoryService
{
if ( !instanceLayout.getLogDirectory().mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
instanceLayout.getLogDirectory() ) );
}
}
@@ -762,7 +764,7 @@ public class DefaultDirectoryService implements DirectoryService
{
if ( !instanceLayout.getRunDirectory().mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
instanceLayout.getRunDirectory() ) );
}
}
@@ -771,7 +773,7 @@ public class DefaultDirectoryService implements DirectoryService
{
if ( !instanceLayout.getPartitionsDirectory().mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
instanceLayout.getPartitionsDirectory() ) );
}
}
@@ -780,7 +782,7 @@ public class DefaultDirectoryService implements DirectoryService
{
if ( !instanceLayout.getConfDirectory().mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
instanceLayout.getConfDirectory() ) );
}
}
@@ -933,7 +935,7 @@ public class DefaultDirectoryService implements DirectoryService
private void setDefaultInterceptorConfigurations()
{
// Set default interceptor chains
- List<Interceptor> list = new ArrayList<Interceptor>();
+ List<Interceptor> list = new ArrayList<>();
list.add( new NormalizationInterceptor() );
list.add( new AuthenticationInterceptor() );
@@ -993,7 +995,6 @@ public class DefaultDirectoryService implements DirectoryService
}
BindOperationContext bindContext = new BindOperationContext( null );
- bindContext.setTransaction( partitionNexus.beginReadTransaction() );
bindContext.setCredentials( credentials );
if ( principalDn.isSchemaAware() )
@@ -1305,9 +1306,9 @@ public class DefaultDirectoryService implements DirectoryService
// --------------------------------------------------------------------
LOG.debug( "--- Syncing the nexus " );
LOG.debug( "--- Flushing everything before quitting" );
- getOperationManager().lockWrite();
+ operationManager.lockWrite();
partitionNexus.sync();
- getOperationManager().unlockWrite();
+ operationManager.unlockWrite();
// --------------------------------------------------------------------
// Shutdown the changelog
@@ -1331,7 +1332,7 @@ public class DefaultDirectoryService implements DirectoryService
// --------------------------------------------------------------------
LOG.debug( "--- Destroying the nexus" );
- partitionNexus.destroy();
+ partitionNexus.destroy( null );
// --------------------------------------------------------------------
// Shutdown the interceptors
@@ -1455,6 +1456,52 @@ public class DefaultDirectoryService implements DirectoryService
{
return new DefaultEntry( schemaManager, dn );
}
+
+
+ /**
+ * Add a new entry into the server
+ */
+ private void addEntry( Entry serverEntry ) throws LdapException
+ {
+ Partition partition = partitionNexus.getPartition( serverEntry.getDn() );
+ AddOperationContext addContext = new AddOperationContext( adminSession, serverEntry );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+ addContext.setPartition( partition );
+ partitionNexus.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
/**
@@ -1476,31 +1523,41 @@ public class DefaultDirectoryService implements DirectoryService
/*
* If the admin entry is there, then the database was already created
*/
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, adminDn ) ) )
+ Partition partition = partitionNexus.getPartition( adminDn );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, adminDn );
-
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.PERSON_OC,
- SchemaConstants.ORGANIZATIONAL_PERSON_OC,
- SchemaConstants.INET_ORG_PERSON_OC );
-
- serverEntry.put( SchemaConstants.UID_AT, PartitionNexus.ADMIN_UID );
- serverEntry.put( SchemaConstants.USER_PASSWORD_AT, PartitionNexus.ADMIN_PASSWORD_BYTES );
- serverEntry.put( SchemaConstants.DISPLAY_NAME_AT, "Directory Superuser" );
- serverEntry.put( SchemaConstants.CN_AT, "system administrator" );
- serverEntry.put( SchemaConstants.SN_AT, "administrator" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.put( SchemaConstants.DISPLAY_NAME_AT, "Directory Superuser" );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- TlsKeyGenerator.addKeyPair( serverEntry );
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, adminDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, adminDn );
+
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ SchemaConstants.PERSON_OC,
+ SchemaConstants.ORGANIZATIONAL_PERSON_OC,
+ SchemaConstants.INET_ORG_PERSON_OC );
+
+ serverEntry.put( SchemaConstants.UID_AT, PartitionNexus.ADMIN_UID );
+ serverEntry.put( SchemaConstants.USER_PASSWORD_AT, PartitionNexus.ADMIN_PASSWORD_BYTES );
+ serverEntry.put( SchemaConstants.DISPLAY_NAME_AT, "Directory Superuser" );
+ serverEntry.put( SchemaConstants.CN_AT, "system administrator" );
+ serverEntry.put( SchemaConstants.SN_AT, "administrator" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.put( SchemaConstants.DISPLAY_NAME_AT, "Directory Superuser" );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ TlsKeyGenerator.addKeyPair( serverEntry );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1508,24 +1565,32 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn userDn = getDnFactory().create( ServerDNConstants.USERS_SYSTEM_DN );
+ partition = partitionNexus.getPartition( userDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, userDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, userDn );
-
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-
- serverEntry.put( SchemaConstants.OU_AT, "users" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, userDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, userDn );
+
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+
+ serverEntry.put( SchemaConstants.OU_AT, "users" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1533,50 +1598,66 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn groupDn = getDnFactory().create( ServerDNConstants.GROUPS_SYSTEM_DN );
+ partition = partitionNexus.getPartition( groupDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, groupDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, groupDn );
-
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-
- serverEntry.put( SchemaConstants.OU_AT, "groups" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, groupDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, groupDn );
+
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+
+ serverEntry.put( SchemaConstants.OU_AT, "groups" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
-
+
// -------------------------------------------------------------------
// create administrator group
// -------------------------------------------------------------------
Dn name = getDnFactory().create( ServerDNConstants.ADMINISTRATORS_GROUP_DN );
+ partition = partitionNexus.getPartition( name );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, name ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, name );
-
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC );
-
- serverEntry.put( SchemaConstants.CN_AT, "Administrators" );
- serverEntry.put( SchemaConstants.UNIQUE_MEMBER_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, name );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, name );
+
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC );
+
+ serverEntry.put( SchemaConstants.CN_AT, "Administrators" );
+ serverEntry.put( SchemaConstants.UNIQUE_MEMBER_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1584,22 +1665,30 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn configurationDn = getDnFactory().create( "ou=configuration,ou=system" );
+ partition = partitionNexus.getPartition( configurationDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, configurationDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, configurationDn );
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-
- serverEntry.put( SchemaConstants.OU_AT, "configuration" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, configurationDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, configurationDn );
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+
+ serverEntry.put( SchemaConstants.OU_AT, "configuration" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1607,21 +1696,29 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn partitionsDn = getDnFactory().create( "ou=partitions,ou=configuration,ou=system" );
+ partition = partitionNexus.getPartition( partitionsDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, partitionsDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, partitionsDn );
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
- serverEntry.put( SchemaConstants.OU_AT, "partitions" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, partitionsDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, partitionsDn );
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+ serverEntry.put( SchemaConstants.OU_AT, "partitions" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1629,22 +1726,30 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn servicesDn = getDnFactory().create( "ou=services,ou=configuration,ou=system" );
+ partition = partitionNexus.getPartition( servicesDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, servicesDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, servicesDn );
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-
- serverEntry.put( SchemaConstants.OU_AT, "services" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, servicesDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, servicesDn );
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+
+ serverEntry.put( SchemaConstants.OU_AT, "services" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1652,22 +1757,30 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn interceptorsDn = getDnFactory().create( "ou=interceptors,ou=configuration,ou=system" );
+ partition = partitionNexus.getPartition( interceptorsDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, interceptorsDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, interceptorsDn );
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-
- serverEntry.put( SchemaConstants.OU_AT, "interceptors" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, interceptorsDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, interceptorsDn );
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+
+ serverEntry.put( SchemaConstants.OU_AT, "interceptors" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
// -------------------------------------------------------------------
@@ -1675,24 +1788,32 @@ public class DefaultDirectoryService implements DirectoryService
// -------------------------------------------------------------------
Dn sysPrefRootDn = getDnFactory().create( ServerDNConstants.SYSPREFROOT_SYSTEM_DN );
+ partition = partitionNexus.getPartition( sysPrefRootDn );
- if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, sysPrefRootDn ) ) )
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- firstStart = true;
-
- Entry serverEntry = new DefaultEntry( schemaManager, sysPrefRootDn );
- serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC,
- SchemaConstants.EXTENSIBLE_OBJECT_OC );
-
- serverEntry.put( "prefNodeName", "sysPrefRoot" );
- serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
- serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- partitionNexus.add( new AddOperationContext( adminSession, serverEntry ) );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, sysPrefRootDn );
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !partitionNexus.hasEntry( hasEntryContext ) )
+ {
+ firstStart = true;
+
+ Entry serverEntry = new DefaultEntry( schemaManager, sysPrefRootDn );
+ serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC,
+ SchemaConstants.EXTENSIBLE_OBJECT_OC );
+
+ serverEntry.put( "prefNodeName", "sysPrefRoot" );
+ serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ serverEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ serverEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ serverEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+
+ addEntry( serverEntry );
+ }
}
return firstStart;
@@ -1710,8 +1831,22 @@ public class DefaultDirectoryService implements DirectoryService
boolean needToChangeAdminPassword;
Dn adminDn = getDnFactory().create( ServerDNConstants.ADMIN_SYSTEM_DN );
+ Partition partition = partitionNexus.getPartition( adminDn );
+ LookupOperationContext lookupContext = new LookupOperationContext( adminSession, adminDn );
+ lookupContext.setPartition( partition );
+
+ Entry adminEntry;
- Entry adminEntry = partitionNexus.lookup( new LookupOperationContext( adminSession, adminDn ) );
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+ adminEntry = partitionNexus.lookup( lookupContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
Value userPassword = adminEntry.get( SchemaConstants.USER_PASSWORD_AT ).get();
needToChangeAdminPassword = Arrays.equals( PartitionNexus.ADMIN_PASSWORD_BYTES, userPassword.getBytes() );
@@ -1765,24 +1900,70 @@ public class DefaultDirectoryService implements DirectoryService
Dn systemSuffixDn = getDnFactory().create( ServerDNConstants.SYSTEM_DN );
CoreSession adminSession = getAdminSession();
- if ( !system.hasEntry( new HasEntryOperationContext( adminSession, systemSuffixDn ) ) )
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( adminSession, systemSuffixDn );
+ Partition partition = getPartitionNexus().getPartition( systemSuffixDn );
+ hasEntryContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- Entry systemEntry = new DefaultEntry( schemaManager, systemSuffixDn );
-
- // Add the ObjectClasses
- systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );
-
- // Add some operational attributes
- systemEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN );
- systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
- systemEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
- systemEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
- systemEntry.put( DnUtils.getRdnAttributeType( ServerDNConstants.SYSTEM_DN ), DnUtils
- .getRdnValue( ServerDNConstants.SYSTEM_DN ) );
-
- AddOperationContext addOperationContext = new AddOperationContext( adminSession, systemEntry );
- system.add( addOperationContext );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( !system.hasEntry( hasEntryContext ) )
+ {
+ Entry systemEntry = new DefaultEntry( schemaManager, systemSuffixDn );
+
+ // Add the ObjectClasses
+ systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );
+
+ // Add some operational attributes
+ systemEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN );
+ systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ systemEntry.add( SchemaConstants.ENTRY_CSN_AT, getCSN().toString() );
+ systemEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+ systemEntry.put( DnUtils.getRdnAttributeType( ServerDNConstants.SYSTEM_DN ), DnUtils
+ .getRdnValue( ServerDNConstants.SYSTEM_DN ) );
+
+ AddOperationContext addOperationContext = new AddOperationContext( adminSession, systemEntry );
+ addOperationContext.setPartition( partition );
+
+ PartitionTxn writeTxn = null;
+
+ try
+ {
+ writeTxn = partition.beginWriteTransaction();
+ addOperationContext.setTransaction( writeTxn );
+ system.add( addOperationContext );
+
+ writeTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ writeTxn.abort();
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ writeTxn.abort();
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
}
}
@@ -1816,10 +1997,10 @@ public class DefaultDirectoryService implements DirectoryService
cacheService.initialize( instanceLayout, instanceId );
// Initialize the AP caches
- accessControlAPCache = new DnNode<AccessControlAdministrativePoint>();
- collectiveAttributeAPCache = new DnNode<CollectiveAttributeAdministrativePoint>();
- subschemaAPCache = new DnNode<SubschemaAdministrativePoint>();
- triggerExecutionAPCache = new DnNode<TriggerExecutionAdministrativePoint>();
+ accessControlAPCache = new DnNode<>();
+ collectiveAttributeAPCache = new DnNode<>();
+ subschemaAPCache = new DnNode<>();
+ triggerExecutionAPCache = new DnNode<>();
if ( dnFactory == null )
{
diff --git a/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java b/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
index de57705..d1393d4 100644
--- a/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
+++ b/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
@@ -20,6 +20,7 @@
package org.apache.directory.server.core;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;
@@ -34,6 +35,7 @@ import org.apache.directory.api.ldap.model.exception.LdapAffectMultipleDsaExcept
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException;
import org.apache.directory.api.ldap.model.exception.LdapOperationErrorException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.exception.LdapPartialResultException;
import org.apache.directory.api.ldap.model.exception.LdapReferralException;
import org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException;
@@ -63,6 +65,8 @@ import org.apache.directory.server.core.api.interceptor.context.OperationContext
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -168,6 +172,8 @@ public class DefaultOperationManager implements OperationManager
LookupOperationContext lookupContext = new LookupOperationContext( adminSession, opContext.getDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
Entry foundEntry = opContext.getSession().getDirectoryService().getPartitionNexus().lookup( lookupContext );
if ( foundEntry != null )
@@ -362,7 +368,11 @@ public class DefaultOperationManager implements OperationManager
dn = new Dn( directoryService.getSchemaManager(), dn );
addContext.setDn( dn );
}
-
+
+ // Find the working partition
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ addContext.setPartition( partition );
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
@@ -398,9 +408,45 @@ public class DefaultOperationManager implements OperationManager
lockWrite();
+ // Start a Write transaction right away
+ PartitionTxn transaction = null;
+
try
{
+ transaction = partition.beginWriteTransaction();
+ addContext.setTransaction( transaction );
+
head.add( addContext );
+ transaction.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ transaction.abort();
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
}
finally
{
@@ -454,7 +500,19 @@ public class DefaultOperationManager implements OperationManager
try
{
- head.bind( bindContext );
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ bindContext.setPartition( partition );
+ bindContext.setTransaction( partitionTxn );
+
+ head.bind( bindContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
finally
{
@@ -560,7 +618,19 @@ public class DefaultOperationManager implements OperationManager
try
{
- result = head.compare( compareContext );
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ compareContext.setPartition( partition );
+ compareContext.setTransaction( partitionTxn );
+
+ result = head.compare( compareContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
finally
{
@@ -602,6 +672,8 @@ public class DefaultOperationManager implements OperationManager
// Normalize the deleteContext Dn
Dn dn = deleteContext.getDn();
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ deleteContext.setPartition( partition );
if ( !dn.isSchemaAware() )
{
@@ -660,14 +732,54 @@ public class DefaultOperationManager implements OperationManager
// populate the context with the old entry
lockWrite();
+ // Start a Write transaction right away
+ PartitionTxn transaction = null;
+
try
{
+ transaction = partition.beginWriteTransaction();
+ deleteContext.setTransaction( transaction );
+
eagerlyPopulateFields( deleteContext );
// Call the Delete method
Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() );
head.delete( deleteContext );
+
+ transaction.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
}
finally
{
@@ -706,8 +818,30 @@ public class DefaultOperationManager implements OperationManager
ensureStarted();
Interceptor head = directoryService.getInterceptor( getRootDseContext.getNextInterceptor() );
+ Entry root;
- Entry root = head.getRootDse( getRootDseContext );
+ try
+ {
+ lockRead();
+
+ Partition partition = directoryService.getPartitionNexus().getPartition( Dn.ROOT_DSE );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ getRootDseContext.setPartition( partition );
+ getRootDseContext.setTransaction( partitionTxn );
+
+ root = head.getRootDse( getRootDseContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ finally
+ {
+ unlockRead();
+ }
if ( IS_DEBUG )
{
@@ -716,7 +850,7 @@ public class DefaultOperationManager implements OperationManager
if ( IS_TIME )
{
- OPERATION_TIME.debug( "GetRootDSE operation took " + ( System.nanoTime() - opStart ) + " ns" );
+ OPERATION_TIME.debug( "GetRootDSE operation took {} ns", ( System.nanoTime() - opStart ) );
}
return root;
@@ -759,7 +893,19 @@ public class DefaultOperationManager implements OperationManager
try
{
- result = head.hasEntry( hasEntryContext );
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ hasEntryContext.setPartition( partition );
+ hasEntryContext.setTransaction( partitionTxn );
+
+ result = head.hasEntry( hasEntryContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
finally
{
@@ -773,7 +919,7 @@ public class DefaultOperationManager implements OperationManager
if ( IS_TIME )
{
- OPERATION_TIME.debug( "HasEntry operation took " + ( System.nanoTime() - opStart ) + " ns" );
+ OPERATION_TIME.debug( "HasEntry operation took {} ns", ( System.nanoTime() - opStart ) );
}
return result;
@@ -811,16 +957,29 @@ public class DefaultOperationManager implements OperationManager
dn = new Dn( directoryService.getSchemaManager(), dn );
lookupContext.setDn( dn );
}
-
- lockRead();
-
- try
+
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ lookupContext.setPartition( partition );
+
+ // Start a read transaction right away
+ try ( PartitionTxn transaction = partition.beginReadTransaction() )
{
- entry = head.lookup( lookupContext );
+ lookupContext.setTransaction( transaction );
+
+ lockRead();
+
+ try
+ {
+ entry = head.lookup( lookupContext );
+ }
+ finally
+ {
+ unlockRead();
+ }
}
- finally
+ catch ( IOException ioe )
{
- unlockRead();
+ throw new LdapOtherException( ioe.getMessage(), ioe );
}
if ( IS_DEBUG )
@@ -921,11 +1080,18 @@ public class DefaultOperationManager implements OperationManager
// Unlock the ReferralManager
referralManager.unlock();
}
-
+
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ modifyContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
lockWrite();
try
{
+ partitionTxn = partition.beginWriteTransaction();
+ modifyContext.setTransaction( partitionTxn );
+
// populate the context with the old entry
eagerlyPopulateFields( modifyContext );
@@ -933,6 +1099,36 @@ public class DefaultOperationManager implements OperationManager
Interceptor head = directoryService.getInterceptor( modifyContext.getNextInterceptor() );
head.modify( modifyContext );
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( partitionTxn != null )
+ {
+ partitionTxn.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
}
finally
{
@@ -1051,9 +1247,18 @@ public class DefaultOperationManager implements OperationManager
}
lockWrite();
+
+ // Find the working partition
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ moveContext.setPartition( partition );
+ // Start a Write transaction right away
+ PartitionTxn transaction = null;
+
try
{
+ transaction = partition.beginWriteTransaction();
+ moveContext.setTransaction( transaction );
Entry originalEntry = getOriginalEntry( moveContext );
moveContext.setOriginalEntry( originalEntry );
@@ -1062,6 +1267,39 @@ public class DefaultOperationManager implements OperationManager
Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() );
head.move( moveContext );
+ transaction.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
}
finally
{
@@ -1180,17 +1418,59 @@ public class DefaultOperationManager implements OperationManager
directoryService.getReferralManager().unlock();
}
- lockWrite();
+ // Find the working partition
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ moveAndRenameContext.setPartition( partition );
+ PartitionTxn transaction = null;
+
+ lockWrite();
+
try
{
+ transaction = partition.beginWriteTransaction();
moveAndRenameContext.setOriginalEntry( getOriginalEntry( moveAndRenameContext ) );
moveAndRenameContext.setModifiedEntry( moveAndRenameContext.getOriginalEntry().clone() );
+ moveAndRenameContext.setTransaction( transaction );
// Call the MoveAndRename method
Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() );
head.moveAndRename( moveAndRenameContext );
+
+ transaction.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
}
finally
{
@@ -1303,22 +1583,90 @@ public class DefaultOperationManager implements OperationManager
directoryService.getReferralManager().unlock();
}
- // Call the rename method
- // populate the context with the old entry
-
lockWrite();
+ // Call the rename method
try
{
- eagerlyPopulateFields( renameContext );
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+ renameContext.setPartition( partition );
+
+ // populate the context with the old entry
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginReadTransaction();
+
+ renameContext.setTransaction( partitionTxn );
+
+ eagerlyPopulateFields( renameContext );
+ }
+ finally
+ {
+ try
+ {
+ // Nothing to do
+ if ( partitionTxn != null )
+ {
+ partitionTxn.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+
+
Entry originalEntry = getOriginalEntry( renameContext );
renameContext.setOriginalEntry( originalEntry );
renameContext.setModifiedEntry( originalEntry.clone() );
// Call the Rename method
+ PartitionTxn transaction = null;
Interceptor head = directoryService.getInterceptor( renameContext.getNextInterceptor() );
+
+ try
+ {
+ transaction = partition.beginWriteTransaction();
+ renameContext.setTransaction( transaction );
- head.rename( renameContext );
+ head.rename( renameContext );
+ transaction.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ if ( transaction != null )
+ {
+ transaction.abort();
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+ }
}
finally
{
@@ -1420,16 +1768,26 @@ public class DefaultOperationManager implements OperationManager
Interceptor head = directoryService.getInterceptor( searchContext.getNextInterceptor() );
EntryFilteringCursor cursor = null;
-
- lockRead();
-
- try
+ Partition partition = directoryService.getPartitionNexus().getPartition( dn );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- cursor = head.search( searchContext );
+ searchContext.setPartition( partition );
+ searchContext.setTransaction( partitionTxn );
+ lockRead();
+
+ try
+ {
+ cursor = head.search( searchContext );
+ }
+ finally
+ {
+ unlockRead();
+ }
}
- finally
+ catch ( IOException ioe )
{
- unlockRead();
+ throw new LdapOtherException( ioe.getMessage(), ioe );
}
if ( IS_DEBUG )
diff --git a/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java b/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
index 14953f7..2b58b14 100644
--- a/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
+++ b/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
@@ -145,7 +145,7 @@ public enum I18n
// ERR_109( "ERR_109" ),
// ERR_110( "ERR_110" ),
// ERR_111( "ERR_111" ),
- ERR_112_COULD_NOT_CREATE_DIRECORY("ERR_112_COULD_NOT_CREATE_DIRECORY"),
+ ERR_112_COULD_NOT_CREATE_DIRECTORY("ERR_112_COULD_NOT_CREATE_DIRECTORY"),
ERR_113_COULD_NOT_DELETE_FILE_OR_DIRECTORY("ERR_113_COULD_NOT_DELETE_FILE_OR_DIRECTORY"),
ERR_114("ERR_114"),
ERR_115("ERR_115"),
@@ -248,7 +248,7 @@ public enum I18n
ERR_212("ERR_212"),
ERR_213("ERR_213"),
ERR_214("ERR_214"),
- ERR_215("ERR_215"),
+ ERR_215_CANNOT_STORE_CLONED_SERVER_ENTRY("ERR_215_CANNOT_STORE_CLONED_SERVER_ENTRY"),
ERR_216_ID_FOR_PARENT_NOT_FOUND("ERR_216_ID_FOR_PARENT_NOT_FOUND"),
ERR_217("ERR_217"),
ERR_218("ERR_218"),
diff --git a/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties b/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
index 7644f44..ca9eca9 100644
--- a/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
+++ b/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
@@ -133,7 +133,7 @@ ERR_91=Attempt to destroy wrapped partition failed.
# ERR_109=
# ERR_110=
# ERR_111=
-ERR_112_COULD_NOT_CREATE_DIRECORY=Could not create directory {0}
+ERR_112_COULD_NOT_CREATE_DIRECTORY=Could not create directory {0}
ERR_113_COULD_NOT_DELETE_FILE_OR_DIRECTORY=Could not delete file or directory {0}
ERR_114=Unable to create a DirectoryService instance for unknow reason
ERR_115=Failed to delete the working directory.
@@ -236,7 +236,7 @@ ERR_211=ldif file name must be provided
ERR_212=No Normalizer present for attribute type {0}
ERR_213=in memory index cannot store the data on disk
ERR_214=in memory index doesn''t support explicit caching
-ERR_215=Cannot store a ClonedServerEntry
+ERR_215_CANNOT_STORE_CLONED_SERVER_ENTRY=Cannot store a ClonedServerEntry
ERR_216_ID_FOR_PARENT_NOT_FOUND=Id for parent ''{0}'' not found!
ERR_217=Entry {0} contains no objectClass attribute: {1}
ERR_218=Not a normalized name: {0}
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java
index dea21bf..5a4a568 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java
@@ -228,7 +228,7 @@ public final class MojoHelperUtils
if ( !dest.mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, dest ) );
+ throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, dest ) );
}
for ( File file : files )
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/archive/ArchiveInstallerCommand.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/archive/ArchiveInstallerCommand.java
index 2c1a8ad..50aa5cc 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/archive/ArchiveInstallerCommand.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/archive/ArchiveInstallerCommand.java
@@ -166,7 +166,7 @@ public class ArchiveInstallerCommand extends LinuxInstallerCommand<ArchiveTarget
// will be packaged to form the installer
if ( !getTargetDirectory().mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, getTargetDirectory() ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, getTargetDirectory() ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/bin/BinInstallerCommand.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/bin/BinInstallerCommand.java
index 584370b..97e2c66 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/bin/BinInstallerCommand.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/bin/BinInstallerCommand.java
@@ -87,7 +87,7 @@ public class BinInstallerCommand extends LinuxInstallerCommand<BinTarget>
// Creating the target directory
if ( !getTargetDirectory().mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, getTargetDirectory() ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, getTargetDirectory() ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -104,7 +104,7 @@ public class BinInstallerCommand extends LinuxInstallerCommand<BinTarget>
if ( !instanceDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, instanceDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, instanceDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -130,7 +130,7 @@ public class BinInstallerCommand extends LinuxInstallerCommand<BinTarget>
if ( !binShDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, binShDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, binShDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/deb/DebInstallerCommand.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/deb/DebInstallerCommand.java
index 783efb2..6a2974c 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/deb/DebInstallerCommand.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/deb/DebInstallerCommand.java
@@ -102,7 +102,7 @@ public class DebInstallerCommand extends LinuxInstallerCommand<DebTarget>
if ( !getTargetDirectory().mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, getTargetDirectory() ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, getTargetDirectory() ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -119,7 +119,7 @@ public class DebInstallerCommand extends LinuxInstallerCommand<DebTarget>
if ( !debEtcInitdDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, debEtcInitdDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, debEtcInitdDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -139,7 +139,7 @@ public class DebInstallerCommand extends LinuxInstallerCommand<DebTarget>
if ( !debDebianDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, debDebianDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, debDebianDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/macosxpkg/MacOsXPkgInstallerCommand.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/macosxpkg/MacOsXPkgInstallerCommand.java
index 1280252..f218d43 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/macosxpkg/MacOsXPkgInstallerCommand.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/macosxpkg/MacOsXPkgInstallerCommand.java
@@ -211,7 +211,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !targetDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, targetDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, targetDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -223,7 +223,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, pkgRootDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, pkgRootDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -232,7 +232,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootUsrBinDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, pkgRootUsrBinDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, pkgRootUsrBinDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -242,7 +242,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootUsrLocalApachedsDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootUsrLocalApachedsDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -252,7 +252,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootInstancesDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, pkgRootInstancesDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, pkgRootInstancesDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -261,7 +261,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootInstancesDefaultDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootInstancesDefaultDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -272,7 +272,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootInstancesDefaultConfDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootInstancesDefaultConfDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -282,7 +282,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootInstancesDefaultDirectoryLog.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootInstancesDefaultDirectoryLog ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -293,7 +293,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootInstancesDefaultDirectoryPartitions.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootInstancesDefaultDirectoryPartitions ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -303,7 +303,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootInstancesDefaultDirectoryRun.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootInstancesDefaultDirectoryRun ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -313,7 +313,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgRootLibraryLaunchDaemons.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgRootLibraryLaunchDaemons ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -342,7 +342,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgResourcesEnglishDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY,
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY,
pkgResourcesEnglishDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
@@ -352,7 +352,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !pkgScriptsDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, pkgScriptsDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, pkgScriptsDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -415,7 +415,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !dmgDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, dmgDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, dmgDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -427,7 +427,7 @@ public class MacOsXPkgInstallerCommand extends AbstractMojoCommand<MacOsXPkgTarg
if ( !dmgDmgBackgroundDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, dmgDmgBackgroundDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, dmgDmgBackgroundDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/nsis/NsisInstallerCommand.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/nsis/NsisInstallerCommand.java
index 645481a..eb1fe2d 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/nsis/NsisInstallerCommand.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/nsis/NsisInstallerCommand.java
@@ -157,7 +157,7 @@ public class NsisInstallerCommand extends AbstractMojoCommand<NsisTarget>
if ( !targetDirectory.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, targetDirectory ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, targetDirectory ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
diff --git a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/rpm/RpmInstallerCommand.java b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/rpm/RpmInstallerCommand.java
index ae8f6f5..fc55e06 100644
--- a/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/rpm/RpmInstallerCommand.java
+++ b/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/rpm/RpmInstallerCommand.java
@@ -91,7 +91,7 @@ public class RpmInstallerCommand extends LinuxInstallerCommand<RpmTarget>
// Creating the target directory
if ( !getTargetDirectory().mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, getTargetDirectory() ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, getTargetDirectory() ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -105,7 +105,7 @@ public class RpmInstallerCommand extends LinuxInstallerCommand<RpmTarget>
if ( !rpmBuild.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, rpmBuild ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, rpmBuild ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -114,7 +114,7 @@ public class RpmInstallerCommand extends LinuxInstallerCommand<RpmTarget>
if ( !rpmRpms.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, rpmRpms ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, rpmRpms ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -123,7 +123,7 @@ public class RpmInstallerCommand extends LinuxInstallerCommand<RpmTarget>
if ( !rpmSources.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, rpmSources ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, rpmSources ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -132,7 +132,7 @@ public class RpmInstallerCommand extends LinuxInstallerCommand<RpmTarget>
if ( !rpmSpecs.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, rpmSpecs ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, rpmSpecs ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
@@ -141,7 +141,7 @@ public class RpmInstallerCommand extends LinuxInstallerCommand<RpmTarget>
if ( !rpmSrpms.mkdirs() )
{
- Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, rpmSrpms ) );
+ Exception e = new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, rpmSrpms ) );
log.error( e.getLocalizedMessage() );
throw new MojoFailureException( e.getMessage() );
}
diff --git a/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java b/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
index 95856e1..45a5ec4 100644
--- a/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
+++ b/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
@@ -310,6 +310,8 @@ public class KeyDerivationInterceptor extends BaseInterceptor
SchemaConstants.OBJECT_CLASS_AT,
KerberosAttribute.KRB5_PRINCIPAL_NAME_AT,
KerberosAttribute.KRB5_KEY_VERSION_NUMBER_AT );
+ lookupContext.setPartition( modContext.getPartition() );
+ lookupContext.setTransaction( modContext.getTransaction() );
Entry userEntry = directoryService.getPartitionNexus().lookup( lookupContext );
diff --git a/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java b/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
index 216ce4f..b0b5f08 100644
--- a/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
+++ b/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
@@ -40,6 +40,7 @@ import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
import org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException;
import org.apache.directory.api.ldap.model.filter.ExprNode;
import org.apache.directory.api.ldap.model.filter.PresenceNode;
@@ -78,7 +79,9 @@ import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOpe
import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -762,25 +765,34 @@ public class AdministrativePointInterceptor extends BaseInterceptor
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, Dn.ROOT_DSE, filter,
controls );
-
+ Partition partition = nexus.getPartition( Dn.ROOT_DSE );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
-
- EntryFilteringCursor results = nexus.search( searchOperationContext );
-
- try
+ searchOperationContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- while ( results.next() )
+ searchOperationContext.setTransaction( partitionTxn );
+ EntryFilteringCursor results = nexus.search( searchOperationContext );
+
+ try
{
- Entry entry = results.get();
-
- entries.add( entry );
+ while ( results.next() )
+ {
+ Entry entry = results.get();
+
+ entries.add( entry );
+ }
+
+ results.close();
+ }
+ catch ( Exception e )
+ {
+ throw new LdapOperationException( e.getMessage(), e );
}
-
- results.close();
}
catch ( Exception e )
{
- throw new LdapOperationException( e.getMessage(), e );
+ throw new LdapOtherException( e.getMessage(), e );
}
return entries;
diff --git a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AbstractAuthenticator.java b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AbstractAuthenticator.java
index 853a8ac..bb289d6 100644
--- a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AbstractAuthenticator.java
+++ b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AbstractAuthenticator.java
@@ -29,6 +29,7 @@ import static org.apache.directory.api.ldap.model.constants.PasswordPolicySchema
import static org.apache.directory.api.ldap.model.constants.PasswordPolicySchemaConstants.PWD_LAST_SUCCESS_AT;
import static org.apache.directory.api.ldap.model.constants.PasswordPolicySchemaConstants.PWD_START_TIME_AT;
+import java.io.IOException;
import java.util.Collections;
import java.util.Date;
@@ -39,6 +40,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Modification;
import org.apache.directory.api.ldap.model.entry.ModificationOperation;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.password.PasswordUtil;
import org.apache.directory.api.util.DateUtils;
@@ -47,6 +49,8 @@ import org.apache.directory.server.core.api.InterceptorEnum;
import org.apache.directory.server.core.api.authn.ppolicy.PasswordPolicyConfiguration;
import org.apache.directory.server.core.api.authn.ppolicy.PasswordPolicyException;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -203,6 +207,53 @@ public abstract class AbstractAuthenticator implements Authenticator
{
this.baseDn = baseDn;
}
+
+
+ private void internalModify( ModifyOperationContext modContext ) throws LdapException
+ {
+ Partition partition = directoryService.getPartitionNexus().getPartition( modContext.getDn() );
+ modContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ modContext.setTransaction( partitionTxn );
+
+ directoryService.getPartitionNexus().modify( modContext );
+
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( partitionTxn != null )
+ {
+ partitionTxn.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+ }
+ }
/**
@@ -258,10 +309,9 @@ public abstract class AbstractAuthenticator implements Authenticator
ModifyOperationContext modContext = new ModifyOperationContext(
directoryService.getAdminSession() );
modContext.setDn( userEntry.getDn() );
-
modContext.setModItems( Collections.singletonList( pwdAccountLockMod ) );
- directoryService.getPartitionNexus().modify( modContext );
+ internalModify( modContext );
}
}
}
diff --git a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
index 9a51000..3f17125 100644
--- a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
+++ b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
@@ -36,6 +36,7 @@ import static org.apache.directory.api.ldap.model.entry.ModificationOperation.AD
import static org.apache.directory.api.ldap.model.entry.ModificationOperation.REMOVE_ATTRIBUTE;
import static org.apache.directory.api.ldap.model.entry.ModificationOperation.REPLACE_ATTRIBUTE;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -64,6 +65,7 @@ import org.apache.directory.api.ldap.model.exception.LdapAuthenticationException
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
@@ -97,6 +99,8 @@ import org.apache.directory.server.core.api.interceptor.context.OperationContext
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.core.authn.ppolicy.PpolicyConfigContainer;
import org.apache.directory.server.core.shared.DefaultCoreSession;
import org.apache.directory.server.i18n.I18n;
@@ -465,6 +469,53 @@ public class AuthenticationInterceptor extends BaseInterceptor
return selectedAuthenticator;
}
+
+
+ private void internalModify( OperationContext opContext, ModifyOperationContext bindModCtx ) throws LdapException
+ {
+ Partition partition = opContext.getPartition();
+ bindModCtx.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ bindModCtx.setTransaction( partitionTxn );
+
+ directoryService.getPartitionNexus().modify( bindModCtx );
+
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ try
+ {
+ if ( partitionTxn != null )
+ {
+ partitionTxn.abort();
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+ }
+ }
/**
@@ -565,6 +616,9 @@ public class AuthenticationInterceptor extends BaseInterceptor
{
LookupOperationContext lookupContext = new LookupOperationContext( adminSession, bindDn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( bindContext.getPartition() );
+ lookupContext.setTransaction( bindContext.getTransaction() );
+
userEntry = directoryService.getPartitionNexus().lookup( lookupContext );
}
@@ -657,14 +711,13 @@ public class AuthenticationInterceptor extends BaseInterceptor
Modification csnMod = new DefaultModification( REPLACE_ATTRIBUTE, directoryService.getAtProvider()
.getEntryCSN(), csnVal );
mods.add( csnMod );
-
ModifyOperationContext bindModCtx = new ModifyOperationContext( adminSession );
bindModCtx.setDn( bindDn );
bindModCtx.setEntry( userEntry );
bindModCtx.setModItems( mods );
bindModCtx.setPushToEvtInterceptor( true );
- directoryService.getPartitionNexus().modify( bindModCtx );
+ internalModify( bindContext, bindModCtx );
}
}
@@ -745,8 +798,8 @@ public class AuthenticationInterceptor extends BaseInterceptor
bindModCtx.setEntry( userEntry );
bindModCtx.setModItems( mods );
bindModCtx.setPushToEvtInterceptor( true );
-
- directoryService.getPartitionNexus().modify( bindModCtx );
+
+ internalModify( bindContext, bindModCtx );
}
if ( isPPolicyReqCtrlPresent )
@@ -1022,6 +1075,9 @@ public class AuthenticationInterceptor extends BaseInterceptor
LookupOperationContext lookupContext = new LookupOperationContext( adminSession, modifyContext.getDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( modifyContext.getPartition() );
+ lookupContext.setTransaction( modifyContext.getTransaction() );
+
entry = directoryService.getPartitionNexus().lookup( lookupContext );
if ( ( policyConfig.getPwdMinAge() > 0 ) || ( policyConfig.getPwdMaxAge() > 0 ) )
@@ -1076,7 +1132,7 @@ public class AuthenticationInterceptor extends BaseInterceptor
internalModifyCtx.setEntry( entry );
internalModifyCtx.setModItems( mods );
- directoryService.getPartitionNexus().modify( internalModifyCtx );
+ internalModify( modifyContext, internalModifyCtx );
if ( removePwdReset || pwdModDetails.isDelete() )
{
diff --git a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java
index 2941d27..d6d0db5 100644
--- a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java
+++ b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java
@@ -275,6 +275,9 @@ public class SimpleAuthenticator extends AbstractAuthenticator
*/
LookupOperationContext lookupContext = new LookupOperationContext( getDirectoryService().getAdminSession(),
bindContext.getDn(), SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
+
+ lookupContext.setPartition( bindContext.getPartition() );
+ lookupContext.setTransaction( bindContext.getTransaction() );
userEntry = getDirectoryService().getPartitionNexus().lookup( lookupContext );
diff --git a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
index 9c5e4d5..b676c76 100644
--- a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
+++ b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
@@ -20,6 +20,7 @@
package org.apache.directory.server.core.authz;
+import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,6 +45,7 @@ import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
import org.apache.directory.api.ldap.model.exception.LdapOperationErrorException;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.filter.EqualityNode;
import org.apache.directory.api.ldap.model.filter.ExprNode;
import org.apache.directory.api.ldap.model.filter.OrNode;
@@ -73,7 +75,9 @@ import org.apache.directory.server.core.api.interceptor.context.MoveOperationCon
import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.core.api.subtree.SubentryUtils;
import org.apache.directory.server.core.authz.support.ACDFEngine;
import org.apache.directory.server.core.authz.support.AciContext;
@@ -192,27 +196,37 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
CoreSession adminSession = directoryService.getAdminSession();
- SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, Dn.ROOT_DSE, filter,
- controls );
+ SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, Dn.ROOT_DSE, filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
-
- EntryFilteringCursor results = nexus.search( searchOperationContext );
-
- try
+ Partition partition = nexus.getPartition( Dn.ROOT_DSE );
+ searchOperationContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- while ( results.next() )
- {
- Entry entry = results.get();
+ searchOperationContext.setTransaction( partitionTxn );
- tupleCache.subentryAdded( entry.getDn(), entry );
+ EntryFilteringCursor results = nexus.search( searchOperationContext );
+
+ try
+ {
+ while ( results.next() )
+ {
+ Entry entry = results.get();
+
+ tupleCache.subentryAdded( entry.getDn(), entry );
+ }
+
+ results.close();
+ }
+ catch ( Exception e )
+ {
+ throw new LdapOperationException( e.getMessage(), e );
}
-
- results.close();
}
- catch ( Exception e )
+ catch ( IOException ioe )
{
- throw new LdapOperationException( e.getMessage(), e );
+ throw new LdapOtherException( ioe.getMessage(), ioe );
}
}
@@ -235,7 +249,7 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
new EqualityNode<String>( ocAt, new Value( ocAt, SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC ) ) );
CoreSession adminSession = directoryService.getAdminSession();
-
+
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, Dn.ROOT_DSE, filter,
controls );
@@ -366,6 +380,8 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
originalEntry = directoryService.getPartitionNexus().lookup( lookupContext );
}
@@ -450,6 +466,8 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
Entry administrativeEntry = ( ( ClonedServerEntry ) directoryService.getPartitionNexus().lookup( lookupContext ) )
.getOriginalEntry();
@@ -745,6 +763,9 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
LookupOperationContext lookupContext = new LookupOperationContext( session, dn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( hasEntryContext.getPartition() );
+ lookupContext.setTransaction( hasEntryContext.getTransaction() );
+
Entry entry = directoryService.getPartitionNexus().lookup( lookupContext );
Set<String> userGroups = groupCache.getGroups( principalDn.getNormName() );
@@ -1013,6 +1034,9 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
// but after this service.
LookupOperationContext lookupContext = new LookupOperationContext( session, oriChildName,
SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( moveContext.getPartition() );
+ lookupContext.setTransaction( moveContext.getTransaction() );
+
Entry importedEntry = directoryService.getPartitionNexus().lookup( lookupContext );
// As the target entry does not exist yet and so
@@ -1110,6 +1134,9 @@ public class AciAuthorizationInterceptor extends BaseInterceptor
LookupOperationContext lookupContext = new LookupOperationContext( session, oldDn,
SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( moveAndRenameContext.getPartition() );
+ lookupContext.setTransaction( moveAndRenameContext.getTransaction() );
+
Entry importedEntry = directoryService.getPartitionNexus().lookup( lookupContext );
// As the target entry does not exist yet and so
diff --git a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java
index fb45ced..b47faeb 100644
--- a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java
+++ b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java
@@ -20,6 +20,7 @@
package org.apache.directory.server.core.authz;
+import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -28,6 +29,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.server.constants.ServerDNConstants;
import org.apache.directory.server.core.api.CoreSession;
@@ -44,7 +46,9 @@ import org.apache.directory.server.core.api.interceptor.context.MoveOperationCon
import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -135,8 +139,21 @@ public class DefaultAuthorizationInterceptor extends BaseInterceptor
// read in the administrators and cache their normalized names
Set<String> newAdministrators = new HashSet<>( 2 );
CoreSession adminSession = directoryService.getAdminSession();
+ Partition partition = nexus.getPartition( adminGroupDn );
+ Entry adminGroup;
+
+ LookupOperationContext lookupContext = new LookupOperationContext( adminSession, adminGroupDn );
+ lookupContext.setPartition( partition );
- Entry adminGroup = nexus.lookup( new LookupOperationContext( adminSession, adminGroupDn ) );
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+ adminGroup = nexus.lookup( lookupContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
if ( adminGroup == null )
{
diff --git a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
index 75c959c..540252e 100644
--- a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
+++ b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
@@ -50,6 +50,7 @@ import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.DnFactory;
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
@@ -148,10 +149,14 @@ public class GroupCache
ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
ctls.setReturningAttributes( new String[]
{ SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES } );
+
+ Partition partition = nexus.getPartition( baseDn );
SearchOperationContext searchOperationContext = new SearchOperationContext( session,
baseDn, filter, ctls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
+ searchOperationContext.setPartition( partition );
+ searchOperationContext.setTransaction( partition.beginReadTransaction() );
EntryFilteringCursor results = nexus.search( searchOperationContext );
try
diff --git a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/TupleCache.java b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/TupleCache.java
index d7c0548..5aa7f5a 100644
--- a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/TupleCache.java
+++ b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/TupleCache.java
@@ -55,6 +55,7 @@ import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.DnFactory;
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
@@ -126,10 +127,13 @@ public class TupleCache
{ SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES } );
Dn baseDn = dnFactory.create( suffix );
-
+ Partition partition = nexus.getPartition( baseDn );
+
SearchOperationContext searchOperationContext = new SearchOperationContext( session,
baseDn, filter, ctls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( partition );
+ searchOperationContext.setTransaction( partition.beginReadTransaction() );
EntryFilteringCursor results = nexus.search( searchOperationContext );
diff --git a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/ACDFEngine.java b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/ACDFEngine.java
index 6def0e2..fa6a572 100644
--- a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/ACDFEngine.java
+++ b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/ACDFEngine.java
@@ -127,6 +127,9 @@ public class ACDFEngine
CoreSession session = aciContext.getOperationContext().getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, aciContext.getUserDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( aciContext.getOperationContext().getPartition() );
+ lookupContext.setTransaction( aciContext.getOperationContext().getTransaction() );
+
Entry userEntry = session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
// Determine the scope of the requested operation.
diff --git a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
index 4d94ed8..dbcd038 100644
--- a/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
+++ b/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/MaxImmSubFilter.java
@@ -146,6 +146,8 @@ public class MaxImmSubFilter implements ACITupleFilter
SearchOperationContext searchContext = new SearchOperationContext( opContext.getSession(),
baseDn, childrenFilter, childrenSearchControls );
searchContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
+ searchContext.setPartition( opContext.getPartition() );
+ searchContext.setTransaction( opContext.getTransaction() );
results = opContext.getSession().getDirectoryService().getPartitionNexus().search( searchContext );
diff --git a/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java b/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
index 7a0b067..333b08d 100644
--- a/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
+++ b/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
@@ -397,6 +397,9 @@ public class ChangeLogInterceptor extends BaseInterceptor
{
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, dn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
+
serverEntry = directoryService.getPartitionNexus().lookup( lookupContext );
}
diff --git a/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java b/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
index b3a483b..49daba6 100644
--- a/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
+++ b/interceptors/collective/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
@@ -407,6 +407,9 @@ public class CollectiveAttributeInterceptor extends BaseInterceptor
LookupOperationContext lookupContext = new LookupOperationContext( session, subentryDn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
+
Entry subentry = directoryService.getPartitionNexus().lookup( lookupContext );
//LOG.debug( "Fetched the subentry : {}", subentry.getDn().getName() );
diff --git a/interceptors/event/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java b/interceptors/event/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
index 2a096e3..e9a8276 100644
--- a/interceptors/event/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
+++ b/interceptors/event/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
@@ -320,6 +320,8 @@ public class EventInterceptor extends BaseInterceptor
CoreSession session = modifyContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, modifyContext.getDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( modifyContext.getPartition() );
+ lookupContext.setTransaction( modifyContext.getTransaction() );
Entry alteredEntry = directoryService.getPartitionNexus().lookup( lookupContext );
modifyContext.setAlteredEntry( alteredEntry );
@@ -408,6 +410,8 @@ public class EventInterceptor extends BaseInterceptor
CoreSession session = renameContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, renameContext.getNewDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( renameContext.getPartition() );
+ lookupContext.setTransaction( renameContext.getTransaction() );
Entry alteredEntry = directoryService.getPartitionNexus().lookup( lookupContext );
renameContext.setModifiedEntry( alteredEntry );
diff --git a/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java b/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
index cc77318..b4d9f22 100644
--- a/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
+++ b/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
@@ -159,6 +159,8 @@ public class ExceptionInterceptor extends BaseInterceptor
CoreSession session = addContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( addContext.getPartition() );
+ lookupContext.setTransaction( addContext.getTransaction() );
attrs = directoryService.getPartitionNexus().lookup( lookupContext );
}
@@ -330,7 +332,11 @@ public class ExceptionInterceptor extends BaseInterceptor
// check to see if target entry exists
Dn newDn = renameContext.getNewDn();
- if ( nexus.hasEntry( new HasEntryOperationContext( renameContext.getSession(), newDn ) ) )
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( renameContext.getSession(), newDn );
+ hasEntryContext.setPartition( renameContext.getPartition() );
+ hasEntryContext.setTransaction( renameContext.getTransaction() );
+
+ if ( nexus.hasEntry( hasEntryContext ) )
{
// Ok, the target entry already exists.
// If the target entry has the same name than the modified entry, it's a rename on itself,
diff --git a/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java b/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
index 7211c80..7861761 100644
--- a/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
+++ b/interceptors/number/src/main/java/org/apache/directory/server/core/number/NumberIncrementingInterceptor.java
@@ -20,6 +20,7 @@
package org.apache.directory.server.core.number;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,6 +36,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Modification;
import org.apache.directory.api.ldap.model.entry.ModificationOperation;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.MatchingRule;
import org.apache.directory.server.core.api.DirectoryService;
@@ -44,6 +46,7 @@ import org.apache.directory.server.core.api.interceptor.context.AddOperationCont
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,8 +78,21 @@ public class NumberIncrementingInterceptor extends BaseInterceptor
Partition systemPartition = directoryService.getSystemPartition();
LookupOperationContext lookupContext = new LookupOperationContext( directoryService.getAdminSession(), numberHolder, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
- Entry entry = systemPartition.lookup( lookupContext );
+ lookupContext.setPartition( systemPartition );
+
+ Entry entry;
+ try ( PartitionTxn partitionTxn = systemPartition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+
+ entry = systemPartition.lookup( lookupContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
if ( entry == null )
{
//FIXME make sure this entry addition gets replicated
@@ -91,9 +107,47 @@ public class NumberIncrementingInterceptor extends BaseInterceptor
AddOperationContext addContext = new AddOperationContext( directoryService.getAdminSession() );
addContext.setDn( numberHolder );
addContext.setEntry( new ClonedServerEntry( entry ) );
+ addContext.setPartition( systemPartition );
+ PartitionTxn partitionTxn = null;
- LOG.debug( "Adding container entry to hold numeric attribute values" );
- systemPartition.add( addContext );
+ try
+ {
+ partitionTxn = systemPartition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ LOG.debug( "Adding container entry to hold numeric attribute values" );
+ systemPartition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ if ( partitionTxn != null )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
else
{
diff --git a/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java b/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
index f7cef70..d9c6ab7 100644
--- a/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
+++ b/interceptors/operational/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
@@ -56,6 +56,7 @@ import org.apache.directory.server.core.api.interceptor.context.LookupOperationC
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
@@ -180,10 +181,11 @@ public class OperationalAttributeInterceptor extends BaseInterceptor
* {@inheritDoc}
*/
@Override
- public boolean accept( SearchOperationContext operation, Entry entry ) throws LdapException
+ public boolean accept( SearchOperationContext searchOperationContext, Entry entry ) throws LdapException
{
// Add the nbChildren/nbSubordinates attributes if required
- processSubordinates( operation.getReturningAttributes(), operation.isAllOperationalAttributes(), entry );
+ processSubordinates( searchOperationContext, searchOperationContext.getReturningAttributes(),
+ searchOperationContext.isAllOperationalAttributes(), entry );
return true;
}
@@ -343,7 +345,7 @@ public class OperationalAttributeInterceptor extends BaseInterceptor
denormalizeEntryOpAttrs( entry );
// Add the nbChildren/nbSubordinates attributes if required
- processSubordinates( lookupContext.getReturningAttributes(), lookupContext.isAllOperationalAttributes(), entry );
+ processSubordinates( lookupContext, lookupContext.getReturningAttributes(), lookupContext.isAllOperationalAttributes(), entry );
return entry;
}
@@ -657,8 +659,8 @@ public class OperationalAttributeInterceptor extends BaseInterceptor
}
- private void processSubordinates( Set<AttributeTypeOptions> returningAttributes, boolean allAttributes, Entry entry )
- throws LdapException
+ private void processSubordinates( OperationContext operationContext, Set<AttributeTypeOptions> returningAttributes,
+ boolean allAttributes, Entry entry ) throws LdapException
{
// Bypass the rootDSE : we won't get the nbChildren and nbSubordiantes for this special entry
if ( Dn.isNullOrEmpty( entry.getDn() ) )
@@ -680,7 +682,7 @@ public class OperationalAttributeInterceptor extends BaseInterceptor
if ( nbChildrenRequested || nbSubordinatesRequested )
{
Partition partition = directoryService.getPartitionNexus().getPartition( entry.getDn() );
- Subordinates subordinates = partition.getSubordinates( entry );
+ Subordinates subordinates = partition.getSubordinates( operationContext.getTransaction(), entry );
long nbChildren = subordinates.getNbChildren();
long nbSubordinates = subordinates.getNbSubordinates();
diff --git a/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java b/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
index ef56c13..8415d38 100644
--- a/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
+++ b/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
@@ -332,6 +332,8 @@ public class ReferralInterceptor extends BaseInterceptor
// on eferral tests...
LookupOperationContext lookupContext =
new LookupOperationContext( modifyContext.getSession(), dn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( modifyContext.getPartition() );
+ lookupContext.setTransaction( modifyContext.getTransaction() );
Entry newEntry = nexus.lookup( lookupContext );
@@ -434,6 +436,8 @@ public class ReferralInterceptor extends BaseInterceptor
// Update the referralManager
LookupOperationContext lookupContext = new LookupOperationContext( renameContext.getSession(),
renameContext.getNewDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( renameContext.getPartition() );
+ lookupContext.setTransaction( renameContext.getTransaction() );
Entry newEntry = nexus.lookup( lookupContext );
diff --git a/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java b/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java
index cb92b5b..8886368 100644
--- a/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java
+++ b/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java
@@ -38,6 +38,7 @@ import org.apache.directory.api.ldap.model.csn.CsnFactory;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
import org.apache.directory.api.ldap.model.name.Dn;
@@ -48,6 +49,7 @@ import org.apache.directory.api.ldap.schema.extractor.impl.ResourceMap;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -91,15 +93,26 @@ public class SchemaLdifToPartitionExtractor implements SchemaLdifExtractor
Dn dn = new Dn( schemaManager, SchemaConstants.OU_SCHEMA );
HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( null, dn );
- if ( partition.hasEntry( hasEntryContext ) )
+ hasEntryContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
- LOG.info( "Schema entry 'ou=schema' exists: extracted state set to true." );
- extracted = true;
+ hasEntryContext.setTransaction( partitionTxn );
+
+ if ( partition.hasEntry( hasEntryContext ) )
+ {
+ LOG.info( "Schema entry 'ou=schema' exists: extracted state set to true." );
+ extracted = true;
+ }
+ else
+ {
+ LOG.info( "Schema entry 'ou=schema' does NOT exist: extracted state set to false." );
+ extracted = false;
+ }
}
- else
+ catch ( IOException ioe )
{
- LOG.info( "Schema entry 'ou=schema' does NOT exist: extracted state set to false." );
- extracted = false;
+ throw new LdapOtherException( ioe.getMessage(), ioe );
}
}
@@ -248,7 +261,47 @@ public class SchemaLdifToPartitionExtractor implements SchemaLdifExtractor
{
Entry entry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
AddOperationContext addContext = new AddOperationContext( null, entry );
- partition.add( addContext );
+ addContext.setPartition( partition );
+
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ if ( partitionTxn != null )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
}
catch ( LdapException ne )
diff --git a/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java b/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
index 56144ac..66db0fb 100644
--- a/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
+++ b/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
@@ -48,6 +48,7 @@ import org.apache.directory.server.core.api.interceptor.Interceptor;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
/**
@@ -135,9 +136,13 @@ public class SchemaSubentryModifier
SchemaConstants.OU_SCHEMA );
Entry entry = getEntry( dn, comparatorDescription );
+
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
addContext.setCurrentInterceptor( position );
+ addContext.setPartition( partition );
+ addContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.add( addContext );
}
@@ -155,8 +160,12 @@ public class SchemaSubentryModifier
Entry entry = getEntry( dn, normalizerDescription );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
addContext.setCurrentInterceptor( position );
+ addContext.setPartition( partition );
+ addContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.add( addContext );
}
@@ -174,8 +183,12 @@ public class SchemaSubentryModifier
Entry entry = getEntry( dn, syntaxCheckerDescription );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
addContext.setCurrentInterceptor( position );
+ addContext.setPartition( partition );
+ addContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.add( addContext );
}
@@ -189,8 +202,12 @@ public class SchemaSubentryModifier
Entry entry = factory.getAttributes( obj, schema, schemaManager );
entry.setDn( dn );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
addContext.setCurrentInterceptor( position );
+ addContext.setPartition( partition );
+ addContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.add( addContext );
}
@@ -201,9 +218,13 @@ public class SchemaSubentryModifier
{
Dn dn = getDn( obj );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
deleteContext.setCurrentInterceptor( position );
+ deleteContext.setPartition( partition );
+ deleteContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.delete( deleteContext );
}
@@ -219,9 +240,13 @@ public class SchemaSubentryModifier
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
deleteContext.setCurrentInterceptor( position );
+ deleteContext.setPartition( partition );
+ deleteContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.delete( deleteContext );
}
@@ -237,9 +262,13 @@ public class SchemaSubentryModifier
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
deleteContext.setCurrentInterceptor( position );
+ deleteContext.setPartition( partition );
+ deleteContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.delete( deleteContext );
}
@@ -255,9 +284,13 @@ public class SchemaSubentryModifier
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
+ Partition partition = modifyContext.getSession().getDirectoryService().getPartitionNexus().getPartition( dn );
+
DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
deleteContext.setCurrentInterceptor( position );
+ deleteContext.setPartition( partition );
+ deleteContext.setTransaction( modifyContext.getTransaction() );
nextInterceptor.delete( deleteContext );
}
diff --git a/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java b/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
index 5139880..49245b0 100644
--- a/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
+++ b/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
@@ -75,6 +75,7 @@ import org.apache.directory.server.core.api.interceptor.context.MoveOperationCon
import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
import org.apache.directory.server.core.api.subtree.SubentryCache;
import org.apache.directory.server.core.api.subtree.SubtreeEvaluator;
@@ -225,10 +226,13 @@ public class SubentryInterceptor extends BaseInterceptor
CoreSession adminSession = directoryService.getAdminSession();
Dn suffixDn = dnFactory.create( suffix );
+ Partition partition = nexus.getPartition( suffixDn );
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, suffixDn, filter,
controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( partition );
+ searchOperationContext.setTransaction( partition.beginReadTransaction() );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
@@ -353,8 +357,8 @@ public class SubentryInterceptor extends BaseInterceptor
/**
* Update all the entries under an AP adding the
*/
- private void updateEntries( OperationEnum operation, CoreSession session, Dn subentryDn, Dn apDn,
- SubtreeSpecification ss, Dn baseDn, List<Attribute> operationalAttributes ) throws LdapException
+ private void updateEntries( OperationContext opContext, OperationEnum operation,
+ Dn apDn, SubtreeSpecification ss, Dn baseDn, List<Attribute> operationalAttributes ) throws LdapException
{
ExprNode filter = ObjectClassNode.OBJECT_CLASS_NODE; // (objectClass=*)
SearchControls controls = new SearchControls();
@@ -362,9 +366,11 @@ public class SubentryInterceptor extends BaseInterceptor
controls.setReturningAttributes( new String[]
{ SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES, SchemaConstants.ALL_USER_ATTRIBUTES } );
- SearchOperationContext searchOperationContext = new SearchOperationContext( session,
+ SearchOperationContext searchOperationContext = new SearchOperationContext( opContext.getSession(),
baseDn, filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( opContext.getPartition() );
+ searchOperationContext.setTransaction( opContext.getTransaction() );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
@@ -386,7 +392,7 @@ public class SubentryInterceptor extends BaseInterceptor
break;
case REMOVE:
- modifications = getOperationalModsForRemove( subentryDn, candidate );
+ modifications = getOperationalModsForRemove( opContext.getDn(), candidate );
break;
case REPLACE:
@@ -398,8 +404,12 @@ public class SubentryInterceptor extends BaseInterceptor
throw new IllegalArgumentException( "Unexpected operation " + operation );
}
- LOG.debug( "The entry {} has been evaluated to true for subentry {}", candidate.getDn(), subentryDn );
- nexus.modify( new ModifyOperationContext( session, candidateDn, modifications ) );
+ LOG.debug( "The entry {} has been evaluated to true for subentry {}", candidate.getDn(), opContext.getDn() );
+ ModifyOperationContext modifyContext = new ModifyOperationContext( opContext.getSession(), candidateDn, modifications );
+ modifyContext.setPartition( opContext.getPartition() );
+ modifyContext.setTransaction( opContext.getTransaction() );
+
+ nexus.modify( modifyContext );
}
}
@@ -442,6 +452,8 @@ public class SubentryInterceptor extends BaseInterceptor
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, apDn,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
Entry administrationPoint = directoryService.getPartitionNexus().lookup( lookupContext );
@@ -499,6 +511,8 @@ public class SubentryInterceptor extends BaseInterceptor
SearchOperationContext searchOperationContext = new SearchOperationContext( opContext.getSession(), name,
filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setTransaction( opContext.getTransaction() );
+ searchOperationContext.setPartition( opContext.getPartition() );
EntryFilteringCursor aps = nexus.search( searchOperationContext );
@@ -958,7 +972,7 @@ public class SubentryInterceptor extends BaseInterceptor
Dn baseDn = apDn;
baseDn = baseDn.add( subentry.getSubtreeSpecification().getBase() );
- updateEntries( OperationEnum.ADD, addContext.getSession(), dn, apDn, subentry.getSubtreeSpecification(),
+ updateEntries( addContext, OperationEnum.ADD, apDn, subentry.getSubtreeSpecification(),
baseDn, operationalAttributes );
// Store the newly modified entry into the context for later use in interceptor
@@ -1053,7 +1067,7 @@ public class SubentryInterceptor extends BaseInterceptor
baseDn = baseDn.add( removedSubentry.getSubtreeSpecification().getBase() );
// Remove all the references to this removed subentry from all the selected entries
- updateEntries( OperationEnum.REMOVE, deleteContext.getSession(), dn, apDn,
+ updateEntries( deleteContext, OperationEnum.REMOVE, apDn,
removedSubentry.getSubtreeSpecification(), baseDn, null );
// Update the cache
@@ -1144,6 +1158,8 @@ public class SubentryInterceptor extends BaseInterceptor
SearchOperationContext searchOperationContext = new SearchOperationContext( modifyContext.getSession(),
oldBaseDn, filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( modifyContext.getPartition() );
+ searchOperationContext.setTransaction( modifyContext.getTransaction() );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
@@ -1156,8 +1172,12 @@ public class SubentryInterceptor extends BaseInterceptor
if ( directoryService.getEvaluator().evaluate( ssOld, apName, candidateDn, candidate ) )
{
- nexus.modify( new ModifyOperationContext( modifyContext.getSession(), candidateDn,
- getOperationalModsForRemove( dn, candidate ) ) );
+ ModifyOperationContext newModifyContext = new ModifyOperationContext( modifyContext.getSession(), candidateDn,
+ getOperationalModsForRemove( dn, candidate ) );
+ newModifyContext.setPartition( modifyContext.getPartition() );
+ newModifyContext.setTransaction( modifyContext.getTransaction() );
+
+ nexus.modify( newModifyContext );
}
}
@@ -1188,6 +1208,8 @@ public class SubentryInterceptor extends BaseInterceptor
searchOperationContext = new SearchOperationContext( modifyContext.getSession(), newBaseDn, filter,
controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( modifyContext.getPartition() );
+ searchOperationContext.setTransaction( modifyContext.getTransaction() );
subentries = nexus.search( searchOperationContext );
@@ -1234,7 +1256,10 @@ public class SubentryInterceptor extends BaseInterceptor
if ( !subentriesOpAttrMods.isEmpty() )
{
- nexus.modify( new ModifyOperationContext( modifyContext.getSession(), dn, subentriesOpAttrMods ) );
+ ModifyOperationContext newModifyContext = new ModifyOperationContext( modifyContext.getSession(), dn, subentriesOpAttrMods );
+ newModifyContext.setPartition( modifyContext.getPartition() );
+ newModifyContext.setTransaction( modifyContext.getTransaction() );
+ nexus.modify( newModifyContext );
}
}
}
@@ -1317,6 +1342,8 @@ public class SubentryInterceptor extends BaseInterceptor
baseDn,
filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( moveContext.getPartition() );
+ searchOperationContext.setTransaction( moveContext.getTransaction() );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
@@ -1335,9 +1362,11 @@ public class SubentryInterceptor extends BaseInterceptor
if ( directoryService.getEvaluator().evaluate( ss, apName, dn, candidate ) )
{
- nexus.modify( new ModifyOperationContext( moveContext.getSession(), dn,
- getOperationalModsForReplace(
- oldDn, newName, subentry, candidate ) ) );
+ ModifyOperationContext newModifyContext = new ModifyOperationContext( moveContext.getSession(), dn,
+ getOperationalModsForReplace( oldDn, newName, subentry, candidate ) );
+ newModifyContext.setPartition( moveContext.getPartition() );
+ newModifyContext.setTransaction( moveContext.getTransaction() );
+ nexus.modify( newModifyContext );
}
}
}
@@ -1383,7 +1412,10 @@ public class SubentryInterceptor extends BaseInterceptor
// Update the entry operational attributes
if ( !mods.isEmpty() )
{
- nexus.modify( new ModifyOperationContext( moveContext.getSession(), newDn, mods ) );
+ ModifyOperationContext newModifyContext = new ModifyOperationContext( moveContext.getSession(), newDn, mods );
+ newModifyContext.setPartition( moveContext.getPartition() );
+ newModifyContext.setTransaction( moveContext.getTransaction() );
+ nexus.modify( newModifyContext );
}
}
}
@@ -1432,6 +1464,8 @@ public class SubentryInterceptor extends BaseInterceptor
moveAndRenameContext.getSession(), baseDn,
filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( moveAndRenameContext.getPartition() );
+ searchOperationContext.setTransaction( moveAndRenameContext.getTransaction() );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
@@ -1449,9 +1483,11 @@ public class SubentryInterceptor extends BaseInterceptor
if ( directoryService.getEvaluator().evaluate( ss, apName, dn, candidate ) )
{
- nexus.modify( new ModifyOperationContext( moveAndRenameContext.getSession(), dn,
- getOperationalModsForReplace(
- oldDn, newName, subentry, candidate ) ) );
+ ModifyOperationContext newModifyContext = new ModifyOperationContext( moveAndRenameContext.getSession(), dn,
+ getOperationalModsForReplace( oldDn, newName, subentry, candidate ) );
+ newModifyContext.setPartition( moveAndRenameContext.getPartition() );
+ newModifyContext.setTransaction( moveAndRenameContext.getTransaction() );
+ nexus.modify( newModifyContext );
}
}
}
@@ -1536,6 +1572,8 @@ public class SubentryInterceptor extends BaseInterceptor
baseDn,
filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
+ searchOperationContext.setPartition( renameContext.getPartition() );
+ searchOperationContext.setTransaction( renameContext.getTransaction() );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
@@ -1594,7 +1632,10 @@ public class SubentryInterceptor extends BaseInterceptor
if ( !mods.isEmpty() )
{
- nexus.modify( new ModifyOperationContext( renameContext.getSession(), newName, mods ) );
+ ModifyOperationContext newModifyContext = new ModifyOperationContext( renameContext.getSession(), newName, mods );
+ newModifyContext.setPartition( renameContext.getPartition() );
+ newModifyContext.setTransaction( renameContext.getTransaction() );
+ nexus.modify( newModifyContext );
}
}
}
diff --git a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java
index 19b4306..4398e14 100644
--- a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java
+++ b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java
@@ -64,6 +64,8 @@ public abstract class AbstractStoredProcedureParameterInjector implements Stored
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext =
new LookupOperationContext( session, ldapCtxName, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
return session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
}
diff --git a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java
index 3078f2f..c212983 100644
--- a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java
+++ b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java
@@ -76,7 +76,9 @@ public class DeleteStoredProcedureParameterInjector extends AbstractStoredProced
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, deletedEntryName,
SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
-
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
+
return session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
}
}
diff --git a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
index 393bf3c..b9dcfbd 100644
--- a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
+++ b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
@@ -108,7 +108,9 @@ public class ModifyStoredProcedureParameterInjector extends AbstractStoredProced
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, modifiedEntryName,
SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
-
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
+
return session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
}
}
diff --git a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java
index eaba815..911b711 100644
--- a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java
+++ b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java
@@ -142,6 +142,8 @@ public class TriggerInterceptor extends BaseInterceptor
CoreSession session = opContext.getSession();
LookupOperationContext lookupContext =
new LookupOperationContext( session, parentDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( opContext.getPartition() );
+ lookupContext.setTransaction( opContext.getTransaction() );
entry = directoryService.getPartitionNexus().lookup( lookupContext );
}
@@ -289,7 +291,6 @@ public class TriggerInterceptor extends BaseInterceptor
/**
* NOTE: We do not handle entryTriggerSpecs for ADD operation.
*/
-
Map<ActionTime, List<TriggerSpecification>> triggerMap = getActionTimeMappedTriggerSpecsForOperation(
triggerSpecs, LdapOperation.ADD );
@@ -416,6 +417,8 @@ public class TriggerInterceptor extends BaseInterceptor
CoreSession session = moveContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, dn,
SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( moveContext.getPartition() );
+ lookupContext.setTransaction( moveContext.getTransaction() );
Entry importedEntry = directoryService.getPartitionNexus().lookup( lookupContext );
@@ -495,6 +498,8 @@ public class TriggerInterceptor extends BaseInterceptor
CoreSession session = moveAndRenameContext.getSession();
LookupOperationContext lookupContext = new LookupOperationContext( session, oldDn,
SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+ lookupContext.setPartition( moveAndRenameContext.getPartition() );
+ lookupContext.setTransaction( moveAndRenameContext.getTransaction() );
Entry importedEntry = directoryService.getPartitionNexus().lookup( lookupContext );
diff --git a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java
index 4361c4b..31ea2fb 100644
--- a/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java
+++ b/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java
@@ -53,6 +53,7 @@ import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
import org.apache.directory.server.i18n.I18n;
import org.slf4j.Logger;
@@ -128,9 +129,12 @@ public class TriggerSpecCache
CoreSession adminSession = directoryService.getAdminSession();
+ Partition partition = nexus.getPartition( baseDn );
SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, baseDn,
filter, ctls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
+ searchOperationContext.setPartition( partition );
+ searchOperationContext.setTransaction( partition.beginReadTransaction() );
EntryFilteringCursor results = nexus.search( searchOperationContext );
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
index cc8fe8e..8178ebf 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
@@ -121,7 +121,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
@SuppressWarnings("unchecked")
public void beforeKey( K key ) throws LdapException, CursorException
{
- checkNotClosed( "beforeKey()" );
+ checkNotClosed();
try
{
browser = ( ( BTree<K, V> ) table.getBTree() ).browse( key );
@@ -141,7 +141,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
@SuppressWarnings("unchecked")
public void afterKey( K key ) throws LdapException, CursorException
{
- checkNotClosed( "afterKey()" );
+ checkNotClosed();
try
{
@@ -157,7 +157,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
*/
while ( browser.getNext( jdbmTuple ) )
{
- checkNotClosed( "afterKey()" );
+ checkNotClosed();
K next = jdbmTuple.getKey();
int nextCompared = table.getKeyComparator().compare( next, key );
@@ -231,7 +231,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
@SuppressWarnings("unchecked")
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst()" );
+ checkNotClosed();
try
{
browser = table.getBTree().browse();
@@ -251,7 +251,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
@SuppressWarnings("unchecked")
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast()" );
+ checkNotClosed();
try
{
browser = table.getBTree().browse( null );
@@ -292,7 +292,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
if ( browser == null )
{
@@ -350,7 +350,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next()" );
+ checkNotClosed();
if ( browser == null )
{
@@ -413,7 +413,7 @@ public class DupsContainerCursor<K, V> extends AbstractCursor<Tuple<K, DupsConta
*/
public Tuple<K, DupsContainer<V>> get() throws CursorException
{
- checkNotClosed( "get()" );
+ checkNotClosed();
if ( valueAvailable )
{
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
index 577199b..080a599 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
@@ -119,7 +119,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
public void beforeValue( K key, V value ) throws LdapException, CursorException
{
- checkNotClosed( "beforeValue()" );
+ checkNotClosed();
containerCursor.before( new Tuple<K, DupsContainer<V>>( key, null ) );
if ( containerCursor.next() )
@@ -173,7 +173,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
public void afterValue( K key, V value ) throws LdapException, CursorException
{
- checkNotClosed( "afterValue()" );
+ checkNotClosed();
/*
* There is a subtle difference between after and before handling
* with duplicate key values. Say we have the following tuples:
@@ -270,7 +270,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst()" );
+ checkNotClosed();
clearValue();
containerCursor.beforeFirst();
containerTuple.setKey( null );
@@ -284,7 +284,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast()" );
+ checkNotClosed();
clearValue();
containerCursor.afterLast();
containerTuple.setKey( null );
@@ -298,7 +298,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public boolean first() throws LdapException, CursorException
{
- checkNotClosed( "first()" );
+ checkNotClosed();
clearValue();
dupsCursor = null;
@@ -346,7 +346,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public boolean last() throws LdapException, CursorException
{
- checkNotClosed( "last()" );
+ checkNotClosed();
clearValue();
dupsCursor = null;
@@ -403,7 +403,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
/*
* If the iterator over the values of the current key is null or is
* extinguished then we need to advance to the previous key.
@@ -479,7 +479,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next()" );
+ checkNotClosed();
/*
* If the iterator over the values of the current key is null or is
* extinguished then we need to advance to the next key.
@@ -561,7 +561,7 @@ class DupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public Tuple<K, V> get() throws CursorException
{
- checkNotClosed( "get()" );
+ checkNotClosed();
if ( !valueAvailable )
{
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDnIndex.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDnIndex.java
index 54a0f1b..01b9ff0 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDnIndex.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDnIndex.java
@@ -22,14 +22,11 @@ package org.apache.directory.server.core.partition.impl.btree.jdbm;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
-import jdbm.helper.MRU;
-import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
-import jdbm.recman.TransactionManager;
+import jdbm.RecordManager;
+import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.MatchingRule;
@@ -59,7 +56,7 @@ public class JdbmDnIndex extends JdbmIndex<Dn>
}
- public void init( SchemaManager schemaManager, AttributeType attributeType ) throws IOException
+ public void init( RecordManager recMan, SchemaManager schemaManager, AttributeType attributeType ) throws LdapException, IOException
{
LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
@@ -79,12 +76,7 @@ public class JdbmDnIndex extends JdbmIndex<Dn>
String path = new File( this.wkDirPath, attributeType.getOid() ).getAbsolutePath();
- //System.out.println( "IDX Created index " + path )
- BaseRecordManager base = new BaseRecordManager( path );
- TransactionManager transactionManager = base.getTransactionManager();
- transactionManager.setMaximumTransactionsInLog( 2000 );
-
- recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
+ this.recMan = recMan;
try
{
@@ -93,17 +85,10 @@ public class JdbmDnIndex extends JdbmIndex<Dn>
catch ( IOException e )
{
// clean up
- close();
+ close( null );
throw e;
}
- // finally write a text file in the format <OID>-<attribute-name>.txt
- FileWriter fw = new FileWriter( new File( path + "-" + attributeType.getName() + ".txt" ) );
-
- // write the AttributeType description
- fw.write( attributeType.toString() );
- fw.close();
-
initialized = true;
}
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
index b023652..5556006 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
@@ -21,26 +21,24 @@ package org.apache.directory.server.core.partition.impl.btree.jdbm;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import jdbm.RecordManager;
import jdbm.helper.ByteArraySerializer;
-import jdbm.helper.MRU;
-import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
-import jdbm.recman.TransactionManager;
import org.apache.directory.api.ldap.model.cursor.Cursor;
+import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.EmptyCursor;
import org.apache.directory.api.ldap.model.cursor.Tuple;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.MatchingRule;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.ldap.model.schema.comparators.SerializableComparator;
import org.apache.directory.api.ldap.model.schema.comparators.UuidComparator;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.core.partition.impl.btree.IndexCursorAdaptor;
import org.apache.directory.server.i18n.I18n;
import org.apache.directory.server.xdbm.AbstractIndex;
@@ -136,7 +134,7 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
* @param attributeType The attributeType this index is created for
* @throws IOException If the initialization failed
*/
- public void init( SchemaManager schemaManager, AttributeType attributeType ) throws IOException
+ public void init( RecordManager recMan, SchemaManager schemaManager, AttributeType attributeType ) throws LdapException, IOException
{
LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
@@ -147,19 +145,6 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
setAttributeId( attributeType.getName() );
}
- if ( this.wkDirPath == null )
- {
- NullPointerException e = new NullPointerException( "The index working directory has not be set" );
-
- throw e;
- }
-
- String path = new File( this.wkDirPath, attributeType.getOid() ).getAbsolutePath();
-
- BaseRecordManager base = new BaseRecordManager( path );
- TransactionManager transactionManager = base.getTransactionManager();
- transactionManager.setMaximumTransactionsInLog( 2000 );
-
// see DIRSERVER-2002
// prevent the OOM when more than 50k users are loaded at a stretch
// adding this system property to make it configurable till JDBM gets replaced by Mavibot
@@ -168,8 +153,8 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
int recCacheSize = Integer.parseInt( cacheSizeVal );
LOG.info( "Setting CacheRecondManager's cache size to {}", recCacheSize );
-
- recMan = new CacheRecordManager( base, new MRU( recCacheSize ) );
+
+ this.recMan = recMan;
try
{
@@ -178,16 +163,10 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
catch ( IOException e )
{
// clean up
- close();
+ close( null );
throw e;
}
- // finally write a text file in the format <OID>-<attribute-name>.txt
- FileWriter fw = new FileWriter( new File( path + "-" + attributeType.getName() + ".txt" ) );
- // write the AttributeType description
- fw.write( attributeType.toString() );
- fw.close();
-
initialized = true;
}
@@ -210,7 +189,7 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
throw new IOException( I18n.err( I18n.ERR_574, attributeType.getName() ) );
}
- comp = new SerializableComparator<K>( mr.getOid() );
+ comp = new SerializableComparator<>( mr.getOid() );
/*
* The forward key/value map stores attribute values to master table
@@ -222,13 +201,13 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
if ( mr.getSyntax().isHumanReadable() )
{
- forward = new JdbmTable<K, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit,
+ forward = new JdbmTable<>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit,
recMan,
comp, UuidComparator.INSTANCE, StringSerializer.INSTANCE, UuidSerializer.INSTANCE );
}
else
{
- forward = new JdbmTable<K, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit,
+ forward = new JdbmTable<>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit,
recMan,
comp, UuidComparator.INSTANCE, new ByteArraySerializer(), UuidSerializer.INSTANCE );
}
@@ -243,12 +222,12 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
{
if ( attributeType.isSingleValued() )
{
- reverse = new JdbmTable<String, K>( schemaManager, attributeType.getOid() + REVERSE_BTREE, recMan,
+ reverse = new JdbmTable<>( schemaManager, attributeType.getOid() + REVERSE_BTREE, recMan,
UuidComparator.INSTANCE, UuidSerializer.INSTANCE, null );
}
else
{
- reverse = new JdbmTable<String, K>( schemaManager, attributeType.getOid() + REVERSE_BTREE, numDupLimit,
+ reverse = new JdbmTable<>( schemaManager, attributeType.getOid() + REVERSE_BTREE, numDupLimit,
recMan,
UuidComparator.INSTANCE, comp, UuidSerializer.INSTANCE, null );
}
@@ -292,7 +271,6 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
*/
public void setWkDirPath( URI wkDirPath )
{
- //.out.println( "IDX Defining a WorkingDir : " + wkDirPath );
protect( "wkDirPath" );
this.wkDirPath = new File( wkDirPath );
}
@@ -316,33 +294,38 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* {@inheritDoc}
*/
- public long count() throws IOException
+ public long count( PartitionTxn partitionTxn ) throws LdapException
{
- return forward.count();
+ return forward.count( partitionTxn );
}
/**
* {@inheritDoc}
*/
- public long count( K attrVal ) throws Exception
+ public long count( PartitionTxn partitionTxn, K attrVal ) throws LdapException
{
- return forward.count( attrVal );
+ return forward.count( partitionTxn, attrVal );
}
- public long greaterThanCount( K attrVal ) throws Exception
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long greaterThanCount( PartitionTxn partitionTxn, K attrVal ) throws LdapException
{
- return forward.greaterThanCount( attrVal );
+ return forward.greaterThanCount( partitionTxn, attrVal );
}
/**
* @see org.apache.directory.server.xdbm.Index#lessThanCount(java.lang.Object)
*/
- public long lessThanCount( K attrVal ) throws Exception
+ @Override
+ public long lessThanCount( PartitionTxn partitionTxn, K attrVal ) throws LdapException
{
- return forward.lessThanCount( attrVal );
+ return forward.lessThanCount( partitionTxn, attrVal );
}
@@ -353,20 +336,20 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* @see Index#forwardLookup(java.lang.Object)
*/
- public String forwardLookup( K attrVal ) throws Exception
+ public String forwardLookup( PartitionTxn partitionTxn, K attrVal ) throws LdapException
{
- return forward.get( attrVal );
+ return forward.get( partitionTxn, attrVal );
}
/**
* {@inheritDoc}
*/
- public K reverseLookup( String id ) throws LdapException
+ public K reverseLookup( PartitionTxn partitionTxn, String id ) throws LdapException
{
if ( withReverse )
{
- return reverse.get( id );
+ return reverse.get( partitionTxn, id );
}
else
{
@@ -382,14 +365,14 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* {@inheritDoc}
*/
- public synchronized void add( K attrVal, String id ) throws Exception
+ public synchronized void add( PartitionTxn partitionTxn, K attrVal, String id ) throws LdapException
{
// The pair to be added must exists
- forward.put( attrVal, id );
+ forward.put( partitionTxn, attrVal, id );
if ( withReverse )
{
- reverse.put( id, attrVal );
+ reverse.put( partitionTxn, id, attrVal );
}
}
@@ -397,16 +380,16 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* {@inheritDoc}
*/
- public synchronized void drop( K attrVal, String id ) throws Exception
+ public synchronized void drop( PartitionTxn partitionTxn, K attrVal, String id ) throws LdapException
{
// The pair to be removed must exists
- if ( forward.has( attrVal, id ) )
+ if ( forward.has( partitionTxn, attrVal, id ) )
{
- forward.remove( attrVal, id );
+ forward.remove( partitionTxn, attrVal, id );
if ( withReverse )
{
- reverse.remove( id, attrVal );
+ reverse.remove( partitionTxn, id, attrVal );
}
}
}
@@ -415,7 +398,7 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* {@inheritDoc}
*/
- public void drop( String entryId ) throws Exception
+ public void drop( PartitionTxn partitionTxn, String entryId ) throws LdapException
{
if ( withReverse )
{
@@ -423,25 +406,32 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
{
// Build a cursor to iterate on all the keys referencing
// this entryId
- Cursor<Tuple<String, K>> values = reverse.cursor( entryId );
+ Cursor<Tuple<String, K>> values = reverse.cursor( partitionTxn, entryId );
- while ( values.next() )
+ try
{
- // Remove the Key -> entryId from the index
- forward.remove( values.get().getValue(), entryId );
+ while ( values.next() )
+ {
+ // Remove the Key -> entryId from the index
+ forward.remove( partitionTxn, values.get().getValue(), entryId );
+ }
+
+ values.close();
+ }
+ catch ( CursorException | IOException e )
+ {
+ throw new LdapOtherException( e.getMessage(), e );
}
-
- values.close();
}
else
{
- K key = reverse.get( entryId );
+ K key = reverse.get( partitionTxn, entryId );
- forward.remove( key );
+ forward.remove( partitionTxn, key );
}
// Remove the id -> key from the reverse index
- reverse.remove( entryId );
+ reverse.remove( partitionTxn, entryId );
}
}
@@ -449,64 +439,73 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
// ------------------------------------------------------------------------
// Index Cursor Operations
// ------------------------------------------------------------------------
- @SuppressWarnings("unchecked")
- public Cursor<IndexEntry<K, String>> reverseCursor() throws Exception
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Cursor<IndexEntry<K, String>> reverseCursor( PartitionTxn partitionTxn )
{
if ( withReverse )
{
- return new IndexCursorAdaptor<K>( ( Cursor ) reverse.cursor(), false );
+ return new IndexCursorAdaptor<>( partitionTxn, ( Cursor ) reverse.cursor(), false );
}
else
{
- return new EmptyIndexCursor<K>();
+ return new EmptyIndexCursor<>( partitionTxn );
}
}
@SuppressWarnings("unchecked")
- public Cursor<IndexEntry<K, String>> forwardCursor() throws LdapException
+ public Cursor<IndexEntry<K, String>> forwardCursor( PartitionTxn partitionTxn ) throws LdapException
{
- return new IndexCursorAdaptor<K>( ( Cursor ) forward.cursor(), true );
+ return new IndexCursorAdaptor<>( partitionTxn, ( Cursor ) forward.cursor(), true );
}
- @SuppressWarnings("unchecked")
- public Cursor<IndexEntry<K, String>> reverseCursor( String id ) throws Exception
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Cursor<IndexEntry<K, String>> reverseCursor( PartitionTxn partitionTxn, String id ) throws LdapException
{
if ( withReverse )
{
- return new IndexCursorAdaptor<K>( ( Cursor ) reverse.cursor( id ), false );
+ return new IndexCursorAdaptor<>( partitionTxn, ( Cursor ) reverse.cursor( partitionTxn, id ), false );
}
else
{
- return new EmptyIndexCursor<K>();
+ return new EmptyIndexCursor<>( partitionTxn );
}
}
- @SuppressWarnings("unchecked")
- public Cursor<IndexEntry<K, String>> forwardCursor( K key ) throws Exception
+ public Cursor<IndexEntry<K, String>> forwardCursor( PartitionTxn partitionTxn, K key ) throws LdapException
{
- return new IndexCursorAdaptor<K>( ( Cursor ) forward.cursor( key ), true );
+ return new IndexCursorAdaptor<>( partitionTxn, ( Cursor ) forward.cursor( partitionTxn, key ), true );
}
- public Cursor<K> reverseValueCursor( String id ) throws Exception
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Cursor<K> reverseValueCursor( PartitionTxn partitionTxn, String id ) throws LdapException
{
if ( withReverse )
{
- return reverse.valueCursor( id );
+ return reverse.valueCursor( partitionTxn, id );
}
else
{
- return new EmptyCursor<K>();
+ return new EmptyCursor<>();
}
}
- public Cursor<String> forwardValueCursor( K key ) throws Exception
+ public Cursor<String> forwardValueCursor( PartitionTxn partitionTxn, K key ) throws LdapException
{
- return forward.valueCursor( key );
+ return forward.valueCursor( partitionTxn, key );
}
@@ -516,29 +515,29 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* {@inheritDoc}
*/
- public boolean forward( K attrVal ) throws Exception
+ public boolean forward( PartitionTxn partitionTxn, K attrVal ) throws LdapException
{
- return forward.has( attrVal );
+ return forward.has( partitionTxn, attrVal );
}
/**
* {@inheritDoc}
*/
- public boolean forward( K attrVal, String id ) throws LdapException
+ public boolean forward( PartitionTxn partitionTxn, K attrVal, String id ) throws LdapException
{
- return forward.has( attrVal, id );
+ return forward.has( partitionTxn, attrVal, id );
}
/**
* {@inheritDoc}
*/
- public boolean reverse( String id ) throws Exception
+ public boolean reverse( PartitionTxn partitionTxn, String id ) throws LdapException
{
if ( withReverse )
{
- return reverse.has( id );
+ return reverse.has( partitionTxn, id );
}
else
{
@@ -550,9 +549,9 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
* {@inheritDoc}
*/
- public boolean reverse( String id, K attrVal ) throws Exception
+ public boolean reverse( PartitionTxn partitionTxn, String id, K attrVal ) throws LdapException
{
- return forward.has( attrVal, id );
+ return forward.has( partitionTxn, attrVal, id );
}
@@ -560,55 +559,27 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
// Maintenance Methods
// ------------------------------------------------------------------------
/**
- * @see org.apache.directory.server.xdbm.Index#close()
+ * {@inheritDoc}
*/
- public synchronized void close() throws IOException
+ @Override
+ public synchronized void close( PartitionTxn partitionTxn ) throws LdapException, IOException
{
if ( forward != null )
{
- forward.close();
+ forward.close( partitionTxn );
}
if ( reverse != null )
{
- reverse.close();
- }
-
- commit( recMan );
- recMan.close();
- }
-
-
- /**
- * @see Index#sync()
- */
- public synchronized void sync() throws IOException
- {
- // Commit
- recMan.commit();
-
- // And flush the journal
- if ( ( commitNumber.get() % 4000 ) == 0 )
- {
- BaseRecordManager baseRecordManager = null;
-
- if ( recMan instanceof CacheRecordManager )
- {
- baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() );
- }
- else
- {
- baseRecordManager = ( ( BaseRecordManager ) recMan );
- }
-
- baseRecordManager.getTransactionManager().synchronizeLog();
+ reverse.close( partitionTxn );
}
}
-
+
/**
* {@inheritDoc}
*/
+ @Override
public boolean isDupsEnabled()
{
if ( withReverse )
@@ -623,20 +594,6 @@ public class JdbmIndex<K> extends AbstractIndex<K, String>
/**
- * Commit the modification on disk
- *
- * @param recordManager The recordManager used for the commit
- */
- private void commit( RecordManager recordManager ) throws IOException
- {
- if ( commitNumber.incrementAndGet() % 2000 == 0 )
- {
- sync();
- }
- }
-
-
- /**
* @see Object#toString()
*/
public String toString()
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
index 0553f81..04b47fe 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
@@ -20,6 +20,7 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
+import java.io.IOException;
import java.util.UUID;
import jdbm.RecordManager;
@@ -45,7 +46,7 @@ public class JdbmMasterTable extends JdbmTable<String, Entry> implements MasterT
* @param schemaManager the schema manager
* @throws Exception if there is an error opening the Db file.
*/
- public JdbmMasterTable( RecordManager recMan, SchemaManager schemaManager ) throws Exception
+ public JdbmMasterTable( RecordManager recMan, SchemaManager schemaManager ) throws IOException
{
super( schemaManager, DBF, recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE,
new EntrySerializer( schemaManager ) );
@@ -68,10 +69,8 @@ public class JdbmMasterTable extends JdbmTable<String, Entry> implements MasterT
* used for the fictitious parent of the suffix root entry.
*
* @return the current value incremented by one.
- * @throws Exception if the admin table storing sequences cannot be
- * read and written to.
*/
- public String getNextId( Entry entry ) throws Exception
+ public String getNextId( Entry entry )
{
return UUID.randomUUID().toString();
}
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
index ba1fa42..354a2bd 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
@@ -40,12 +40,14 @@ import net.sf.ehcache.Element;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.csn.CsnFactory;
import org.apache.directory.api.ldap.model.cursor.Cursor;
+import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.Tuple;
import org.apache.directory.api.ldap.model.entry.Attribute;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
@@ -64,6 +66,9 @@ import org.apache.directory.server.core.api.interceptor.context.MoveOperationCon
import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionReadTxn;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.core.api.partition.PartitionWriteTxn;
import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
import org.apache.directory.server.i18n.I18n;
import org.apache.directory.server.xdbm.Index;
@@ -130,7 +135,7 @@ public class JdbmPartition extends AbstractBTreePartition
/**
* Rebuild the indexes
*/
- private int rebuildIndexes() throws Exception
+ private int rebuildIndexes( PartitionTxn partitionTxn ) throws LdapException, IOException
{
Cursor<Tuple<String, Entry>> cursor = getMasterTable().cursor();
@@ -172,7 +177,7 @@ public class JdbmPartition extends AbstractBTreePartition
}
// Inject the parentIdAndRdn in the rdnIndex
- rdnIdx.add( parentIdAndRdn, id );
+ rdnIdx.add( partitionTxn, parentIdAndRdn, id );
// Process the ObjectClass index
// Update the ObjectClass index
@@ -194,14 +199,14 @@ public class JdbmPartition extends AbstractBTreePartition
continue;
}
- objectClassIdx.add( valueStr, id );
+ objectClassIdx.add( partitionTxn, valueStr, id );
}
// The Alias indexes
if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
{
Attribute aliasAttr = entry.get( aliasedObjectNameAT );
- addAliasIndices( id, dn, new Dn( schemaManager, aliasAttr.getString() ) );
+ addAliasIndices( partitionTxn, id, dn, new Dn( schemaManager, aliasAttr.getString() ) );
}
// The entryCSN index
@@ -214,7 +219,7 @@ public class JdbmPartition extends AbstractBTreePartition
throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
}
- entryCsnIdx.add( entryCsn.getString(), id );
+ entryCsnIdx.add( partitionTxn, entryCsn.getString(), id );
// The AdministrativeRole index
// Update the AdministrativeRole index, if needed
@@ -225,11 +230,11 @@ public class JdbmPartition extends AbstractBTreePartition
for ( Value value : adminRoles )
{
- adminRoleIdx.add( value.getValue(), id );
+ adminRoleIdx.add( partitionTxn, value.getValue(), id );
}
// Adds only those attributes that are indexed
- presenceIdx.add( administrativeRoleAT.getOid(), id );
+ presenceIdx.add( partitionTxn, administrativeRoleAT.getOid(), id );
}
// And the user indexess
@@ -248,11 +253,11 @@ public class JdbmPartition extends AbstractBTreePartition
for ( Value value : attribute )
{
- idx.add( value.getValue(), id );
+ idx.add( partitionTxn, value.getValue(), id );
}
// Adds only those attributes that are indexed
- presenceIdx.add( attributeOid, id );
+ presenceIdx.add( partitionTxn, attributeOid, id );
}
}
}
@@ -260,9 +265,8 @@ public class JdbmPartition extends AbstractBTreePartition
}
catch ( Exception e )
{
- e.printStackTrace();
System.out.println( "Exiting after fetching entries " + repaired );
- throw e;
+ throw new LdapOtherException( e.getMessage(), e );
}
finally
{
@@ -276,7 +280,7 @@ public class JdbmPartition extends AbstractBTreePartition
/**
* Update the children and descendant counters in the RDN index
*/
- private void updateRdnIndexCounters() throws Exception
+ private void updateRdnIndexCounters( PartitionTxn partitionTxn ) throws LdapException, IOException
{
Cursor<Tuple<String, Entry>> cursor = getMasterTable().cursor();
@@ -296,15 +300,14 @@ public class JdbmPartition extends AbstractBTreePartition
if ( parentId != Partition.ROOT_ID )
{
- updateRdnIdx( parentId, ADD_CHILD, 0 );
+ updateRdnIdx( partitionTxn, parentId, ADD_CHILD, 0 );
}
}
}
catch ( Exception e )
{
- e.printStackTrace();
System.out.println( "Exiting, wasn't able to update the RDN index counters" );
- throw e;
+ throw new LdapOtherException( e.getMessage(), e );
}
finally
{
@@ -317,8 +320,21 @@ public class JdbmPartition extends AbstractBTreePartition
* {@inheritDoc}
*/
@Override
- protected void doRepair() throws Exception
+ protected void doRepair() throws LdapException
{
+ BaseRecordManager base;
+
+ try
+ {
+ base = new BaseRecordManager( getPartitionPath().getPath() );
+ TransactionManager transactionManager = base.getTransactionManager();
+ transactionManager.setMaximumTransactionsInLog( 2000 );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
// Find the underlying directories
File partitionDir = new File( getPartitionPath() );
@@ -328,51 +344,59 @@ public class JdbmPartition extends AbstractBTreePartition
// then add all index objects to a list
List<String> allIndices = new ArrayList<>();
- // Iterate on the declared indexes, deleting the old ones
- for ( Index<?, String> index : getIndexedAttributes() )
+ try
{
- // Index won't be initialized at this time, so lookup AT registry to get the OID
- AttributeType indexAT = schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() );
- String oid = indexAT.getOid();
- allIndices.add( oid );
-
- // take the part after removing .db from the
- String name = oid + JDBM_DB_FILE_EXTN;
-
- // if the name doesn't exist in the list of index DB files
- // this is a new index and we need to build it
- if ( indexDbFileNameList.contains( name ) )
+ // Iterate on the declared indexes, deleting the old ones
+ for ( Index<?, String> index : getIndexedAttributes() )
{
- ( ( JdbmIndex<?> ) index ).close();
+ // Index won't be initialized at this time, so lookup AT registry to get the OID
+ AttributeType indexAT = schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() );
+ String oid = indexAT.getOid();
+ allIndices.add( oid );
- File indexFile = new File( partitionDir, name );
- indexFile.delete();
+ // take the part after removing .db from the
+ String name = oid + JDBM_DB_FILE_EXTN;
- // Recreate the index
- ( ( JdbmIndex<?> ) index ).init( schemaManager, indexAT );
+ // if the name doesn't exist in the list of index DB files
+ // this is a new index and we need to build it
+ if ( indexDbFileNameList.contains( name ) )
+ {
+ ( ( JdbmIndex<?> ) index ).close( null );
+
+ File indexFile = new File( partitionDir, name );
+ indexFile.delete();
+
+ // Recreate the index
+ ( ( JdbmIndex<?> ) index ).init( base, schemaManager, indexAT );
+ }
}
- }
+ // Ok, now, rebuild the indexes.
+ int masterTableCount = rebuildIndexes( null );
+
+ // Now that the RdnIndex has been rebuilt, we have to update the nbChildren and nbDescendants values
+ // We loop again on the MasterTable
+ updateRdnIndexCounters( null );
- // Ok, now, rebuild the indexes.
- int masterTableCount = rebuildIndexes();
-
- // Now that the RdnIndex has been rebuilt, we have to update the nbChildren and nbDescendants values
- // We loop again on the MasterTable
- updateRdnIndexCounters();
-
- // Flush the indexes on disk
- sync();
+ // Flush the indexes on disk
+ sync();
- System.out.println( "Total entries present in the partition " + masterTableCount );
- System.out.println( "Repair complete" );
+ System.out.println( "Total entries present in the partition " + masterTableCount );
+ System.out.println( "Repair complete" );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
@Override
- protected void doInit() throws Exception
+ protected void doInit() throws LdapException
{
if ( !initialized )
{
+ BaseRecordManager base;
+
// setup optimizer and registries for parent
if ( !optimizerEnabled )
{
@@ -380,7 +404,7 @@ public class JdbmPartition extends AbstractBTreePartition
}
else
{
- setOptimizer( new DefaultOptimizer<Entry>( this ) );
+ setOptimizer( new DefaultOptimizer( this ) );
}
EvaluatorBuilder evaluatorBuilder = new EvaluatorBuilder( this, schemaManager );
@@ -390,11 +414,65 @@ public class JdbmPartition extends AbstractBTreePartition
// Create the underlying directories (only if needed)
File partitionDir = new File( getPartitionPath() );
+
if ( !partitionDir.exists() && !partitionDir.mkdirs() )
{
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, partitionDir ) );
+ throw new LdapOtherException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECTORY, partitionDir ) );
+ }
+
+ // First, check if the file storing the data exists
+ String path = partitionDir.getPath() + File.separator + id;
+
+ try
+ {
+ base = new BaseRecordManager( path );
+ TransactionManager transactionManager = base.getTransactionManager();
+ transactionManager.setMaximumTransactionsInLog( 2000 );
+
+ // prevent the OOM when more than 50k users are loaded at a stretch
+ // adding this system property to make it configurable till JDBM gets replaced by Mavibot
+ String cacheSizeVal = System.getProperty( "jdbm.recman.cache.size", "100" );
+
+ int recCacheSize = Integer.parseInt( cacheSizeVal );
+
+ LOG.info( "Setting CacheRecondManager's cache size to {}", recCacheSize );
+
+ recMan = new CacheRecordManager( base, new MRU( recCacheSize ) );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+
+ // Iterate on the declared indexes
+ List<String> allIndices = new ArrayList<>();
+ List<Index<?, String>> indexToBuild = new ArrayList<>();
+
+ for ( Index<?, String> index : getIndexedAttributes() )
+ {
+ String oid = schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() ).getOid();
+ allIndices.add( oid );
+
+ // if the name doesn't exist in the database
+ // this is a new index and we need to build it
+ try
+ {
+ // Check the forward index only (we suppose we never will add a reverse index later on)
+ String forwardIndex = oid + "_forward";
+
+ if ( recMan.getNamedObject( forwardIndex ) == 0 )
+ {
+ // The index does not exist in the database, we need to build it
+ indexToBuild.add( index );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
+ /*
// get all index db files first
File[] allIndexDbFiles = partitionDir.listFiles( DB_FILTER );
@@ -423,17 +501,11 @@ public class JdbmPartition extends AbstractBTreePartition
indexToBuild.add( index );
}
}
+ */
// Initialize the indexes
super.doInit();
- // First, check if the file storing the data exists
- String path = partitionDir.getPath() + File.separator + "master";
-
- BaseRecordManager base = new BaseRecordManager( path );
- TransactionManager transactionManager = base.getTransactionManager();
- transactionManager.setMaximumTransactionsInLog( 2000 );
-
if ( cacheSize < 0 )
{
cacheSize = DEFAULT_CACHE_SIZE;
@@ -444,25 +516,22 @@ public class JdbmPartition extends AbstractBTreePartition
LOG.debug( "Using the custom configured cache size of {} for {} partition", cacheSize, id );
}
- // prevent the OOM when more than 50k users are loaded at a stretch
- // adding this system property to make it configurable till JDBM gets replaced by Mavibot
- String cacheSizeVal = System.getProperty( "jdbm.recman.cache.size", "100" );
-
- int recCacheSize = Integer.parseInt( cacheSizeVal );
-
- LOG.info( "Setting CacheRecondManager's cache size to {}", recCacheSize );
-
- recMan = new CacheRecordManager( base, new MRU( recCacheSize ) );
-
// Create the master table (the table containing all the entries)
- master = new JdbmMasterTable( recMan, schemaManager );
+ try
+ {
+ master = new JdbmMasterTable( recMan, schemaManager );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
if ( !indexToBuild.isEmpty() )
{
- buildUserIndex( indexToBuild );
+ buildUserIndex( beginReadTransaction(), indexToBuild );
}
- deleteUnusedIndexFiles( allIndices, allIndexDbFiles );
+ //deleteUnusedIndexFiles( allIndices, allIndexDbFiles );
if ( cacheService != null )
{
@@ -491,7 +560,19 @@ public class JdbmPartition extends AbstractBTreePartition
if ( suffixDn.equals( contextEntryDn ) )
{
// Looking for the current context entry
- Entry suffixEntry = lookup( new LookupOperationContext( null, suffixDn ) );
+ Entry suffixEntry;
+ LookupOperationContext lookupContext = new LookupOperationContext( null, suffixDn );
+ lookupContext.setPartition( this );
+
+ try ( PartitionTxn partitionTxn = beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn );
+ suffixEntry = lookup( lookupContext );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
// We're only adding the context entry if it doesn't already exist
if ( suffixEntry == null )
@@ -518,7 +599,46 @@ public class JdbmPartition extends AbstractBTreePartition
}
// And add this entry to the underlying partition
- add( new AddOperationContext( null, contextEntry ) );
+ PartitionTxn partitionTxn = null;
+ AddOperationContext addContext = new AddOperationContext( null, contextEntry );
+
+ try
+ {
+ partitionTxn = beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( LdapException le )
+ {
+ if ( partitionTxn != null )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
+ }
+
+ throw le;
+ }
+ catch ( IOException ioe )
+ {
+ try
+ {
+ partitionTxn.abort();
+ }
+ catch ( IOException ioe2 )
+ {
+ throw new LdapOtherException( ioe2.getMessage(), ioe2 );
+ }
+
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
}
}
}
@@ -554,27 +674,36 @@ public class JdbmPartition extends AbstractBTreePartition
* @throws Exception on failures to sync database files to disk
*/
@Override
- public synchronized void sync() throws Exception
+ public synchronized void sync() throws LdapException
{
if ( !initialized )
{
return;
}
-
- // Sync all system indices
- for ( Index<?, String> idx : systemIndices.values() )
+
+ try
{
- idx.sync();
+ // Commit
+ recMan.commit();
+
+ // And flush the journal
+ BaseRecordManager baseRecordManager = null;
+
+ if ( recMan instanceof CacheRecordManager )
+ {
+ baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() );
+ }
+ else
+ {
+ baseRecordManager = ( ( BaseRecordManager ) recMan );
+ }
+
+ baseRecordManager.getTransactionManager().synchronizeLog();
}
-
- // Sync all user defined userIndices
- for ( Index<?, String> idx : userIndices.values() )
+ catch ( IOException ioe )
{
- idx.sync();
+ throw new LdapOtherException( ioe.getMessage(), ioe );
}
-
- // Sync the master table
- ( ( JdbmMasterTable ) master ).sync();
}
@@ -588,48 +717,55 @@ public class JdbmPartition extends AbstractBTreePartition
* @param indices then selected indexes that need to be built
* @throws Exception in case of any problems while building the index
*/
- private void buildUserIndex( List<Index<?, String>> indices ) throws Exception
+ private void buildUserIndex( PartitionTxn partitionTxn, List<Index<?, String>> indices ) throws LdapException
{
- Cursor<Tuple<String, Entry>> cursor = master.cursor();
- cursor.beforeFirst();
-
- while ( cursor.next() )
+ try
{
- for ( Index index : indices )
+ Cursor<Tuple<String, Entry>> cursor = master.cursor();
+ cursor.beforeFirst();
+
+ while ( cursor.next() )
{
- AttributeType atType = index.getAttribute();
-
- String attributeOid = index.getAttribute().getOid();
-
- if ( systemIndices.get( attributeOid ) != null )
- {
- // skipping building of the system index
- continue;
- }
-
- LOG.info( "building the index for attribute type {}", atType );
-
- Tuple<String, Entry> tuple = cursor.get();
-
- String id = tuple.getKey();
- Entry entry = tuple.getValue();
-
- Attribute entryAttr = entry.get( atType );
-
- if ( entryAttr != null )
+ for ( Index index : indices )
{
- for ( Value value : entryAttr )
+ AttributeType atType = index.getAttribute();
+
+ String attributeOid = index.getAttribute().getOid();
+
+ if ( systemIndices.get( attributeOid ) != null )
{
- index.add( value.getValue(), id );
+ // skipping building of the system index
+ continue;
+ }
+
+ LOG.info( "building the index for attribute type {}", atType );
+
+ Tuple<String, Entry> tuple = cursor.get();
+
+ String id = tuple.getKey();
+ Entry entry = tuple.getValue();
+
+ Attribute entryAttr = entry.get( atType );
+
+ if ( entryAttr != null )
+ {
+ for ( Value value : entryAttr )
+ {
+ index.add( partitionTxn, value.getValue(), id );
+ }
+
+ // Adds only those attributes that are indexed
+ presenceIdx.add( partitionTxn, attributeOid, id );
}
-
- // Adds only those attributes that are indexed
- presenceIdx.add( attributeOid, id );
}
}
+
+ cursor.close();
+ }
+ catch ( CursorException | IOException e )
+ {
+ throw new LdapOtherException( e.getMessage(), e );
}
-
- cursor.close();
}
@@ -659,24 +795,6 @@ public class JdbmPartition extends AbstractBTreePartition
if ( deleted )
{
LOG.info( "Deleted unused index file {}", file.getAbsolutePath() );
-
- try
- {
- String atName = schemaManager.lookupAttributeTypeRegistry( name ).getName();
- File txtFile = new File( file.getParent(), name + "-" + atName + ".txt" );
-
- deleted = txtFile.delete();
-
- if ( !deleted )
- {
- LOG.info( "couldn't delete the index name helper file {}", txtFile );
- }
- }
- catch ( Exception e )
- {
- LOG.warn( "couldn't find the attribute's name with oid {}", name );
- LOG.warn( "", e );
- }
}
else
{
@@ -691,7 +809,7 @@ public class JdbmPartition extends AbstractBTreePartition
* {@inheritDoc}
*/
@Override
- protected Index<?, String> convertAndInit( Index<?, String> index ) throws Exception
+ protected Index<?, String> convertAndInit( Index<?, String> index ) throws LdapException
{
JdbmIndex<?> jdbmIndex;
@@ -706,11 +824,6 @@ public class JdbmPartition extends AbstractBTreePartition
else if ( index instanceof JdbmIndex<?> )
{
jdbmIndex = ( JdbmIndex<?> ) index;
-
- if ( jdbmIndex.getWkDirPath() == null )
- {
- jdbmIndex.setWkDirPath( partitionPath );
- }
}
else
{
@@ -719,10 +832,16 @@ public class JdbmPartition extends AbstractBTreePartition
jdbmIndex = new JdbmIndex( index.getAttributeId(), true );
jdbmIndex.setCacheSize( index.getCacheSize() );
jdbmIndex.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT );
- jdbmIndex.setWkDirPath( index.getWkDirPath() );
}
- jdbmIndex.init( schemaManager, schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() ) );
+ try
+ {
+ jdbmIndex.init( recMan, schemaManager, schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() ) );
+ }
+ catch ( IOException ioe )
+ {
+ throw new LdapOtherException( ioe.getMessage(), ioe );
+ }
return jdbmIndex;
}
@@ -732,7 +851,7 @@ public class JdbmPartition extends AbstractBTreePartition
* {@inheritDoc}
*/
@Override
- protected synchronized void doDestroy() throws Exception
+ protected synchronized void doDestroy( PartitionTxn partitionTxn ) throws LdapException
{
MultiException errors = new MultiException( I18n.err( I18n.ERR_577 ) );
@@ -743,7 +862,7 @@ public class JdbmPartition extends AbstractBTreePartition
try
{
- super.doDestroy();
+ super.doDestroy( partitionTxn );
}
catch ( Exception e )
{
@@ -771,7 +890,7 @@ public class JdbmPartition extends AbstractBTreePartition
if ( errors.size() > 0 )
{
- throw errors;
+ throw new LdapOtherException( errors.getMessage(), errors );
}
}
@@ -780,7 +899,7 @@ public class JdbmPartition extends AbstractBTreePartition
* {@inheritDoc}
*/
@Override
- protected final Index createSystemIndex( String oid, URI path, boolean withReverse ) throws Exception
+ protected final Index createSystemIndex( String oid, URI path, boolean withReverse ) throws LdapException
{
LOG.debug( "Supplied index {} is not a JdbmIndex. "
+ "Will create new JdbmIndex using copied configuration parameters." );
@@ -892,4 +1011,17 @@ public class JdbmPartition extends AbstractBTreePartition
entryCache.put( new Element( id, addedEntry ) );
}
+
+ @Override
+ public PartitionReadTxn beginReadTransaction()
+ {
+ return new PartitionReadTxn();
+ }
+
+
+ @Override
+ public PartitionWriteTxn beginWriteTransaction()
+ {
+ return new JdbmPartitionWriteTxn( recMan, isSyncOnWrite() );
+ }
}
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartitionWriteTxn.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartitionWriteTxn.java
new file mode 100644
index 0000000..43b4b01
--- /dev/null
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartitionWriteTxn.java
@@ -0,0 +1,87 @@
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+import java.io.IOException;
+
+import org.apache.directory.server.core.api.partition.PartitionWriteTxn;
+
+import jdbm.RecordManager;
+import jdbm.recman.BaseRecordManager;
+import jdbm.recman.CacheRecordManager;
+
+public class JdbmPartitionWriteTxn extends PartitionWriteTxn
+{
+ /** The associated record manager */
+ private RecordManager recordManager;
+
+ /** A flag used to flush data immediately or not */
+ private boolean syncOnWrite = false;
+
+ /**
+ *
+ * @param recordManager
+ * @param syncOnWrite
+ */
+ public JdbmPartitionWriteTxn( RecordManager recordManager, boolean syncOnWrite )
+ {
+ this.recordManager = recordManager;
+ this.syncOnWrite = syncOnWrite;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void commit() throws IOException
+ {
+ recordManager.commit();
+
+ // And flush the journal
+ BaseRecordManager baseRecordManager = null;
+
+ if ( recordManager instanceof CacheRecordManager )
+ {
+ baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recordManager ).getRecordManager() );
+ }
+ else
+ {
+ baseRecordManager = ( ( BaseRecordManager ) recordManager );
+ }
+
+
+ if ( syncOnWrite )
+ {
+ baseRecordManager.getTransactionManager().synchronizeLog();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void abort() throws IOException
+ {
+ recordManager.rollback();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isClosed()
+ {
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws IOException
+ {
+ commit();
+ }
+}
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
index 58574f5..245611c 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
@@ -21,15 +21,11 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
-import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
-import jdbm.helper.MRU;
-import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
-import jdbm.recman.TransactionManager;
+import jdbm.RecordManager;
+import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.schema.AttributeType;
import org.apache.directory.api.ldap.model.schema.MatchingRule;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
@@ -61,7 +57,7 @@ public class JdbmRdnIndex extends JdbmIndex<ParentIdAndRdn>
}
- public void init( SchemaManager schemaManager, AttributeType attributeType ) throws IOException
+ public void init( RecordManager recMan, SchemaManager schemaManager, AttributeType attributeType ) throws LdapException, IOException
{
LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
@@ -79,14 +75,8 @@ public class JdbmRdnIndex extends JdbmIndex<ParentIdAndRdn>
throw e;
}
- String path = new File( this.wkDirPath, attributeType.getOid() ).getAbsolutePath();
-
//System.out.println( "IDX Created index " + path )
- BaseRecordManager base = new BaseRecordManager( path );
- TransactionManager transactionManager = base.getTransactionManager();
- transactionManager.setMaximumTransactionsInLog( 2000 );
-
- recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
+ this.recMan = recMan;
try
{
@@ -95,17 +85,10 @@ public class JdbmRdnIndex extends JdbmIndex<ParentIdAndRdn>
catch ( IOException e )
{
// clean up
- close();
+ close( null );
throw e;
}
- // finally write a text file in the format <OID>-<attribute-name>.txt
- FileWriter fw = new FileWriter( new File( path + "-" + attributeType.getName() + ".txt" ) );
-
- // write the AttributeType description
- fw.write( attributeType.toString() );
- fw.close();
-
initialized = true;
}
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
index df94782..2632b3d 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
@@ -29,8 +29,6 @@ import jdbm.btree.BTree;
import jdbm.helper.Serializer;
import jdbm.helper.Tuple;
import jdbm.helper.TupleBrowser;
-import jdbm.recman.BaseRecordManager;
-import jdbm.recman.CacheRecordManager;
import org.apache.directory.api.ldap.model.cursor.Cursor;
import org.apache.directory.api.ldap.model.cursor.CursorException;
@@ -43,7 +41,6 @@ import org.apache.directory.api.ldap.model.schema.comparators.SerializableCompar
import org.apache.directory.api.util.Strings;
import org.apache.directory.api.util.SynchronizedLRUMap;
import org.apache.directory.server.core.api.partition.PartitionTxn;
-import org.apache.directory.server.core.api.partition.PartitionWriteTxn;
import org.apache.directory.server.core.avltree.ArrayMarshaller;
import org.apache.directory.server.core.avltree.ArrayTree;
import org.apache.directory.server.core.avltree.ArrayTreeCursor;
@@ -65,9 +62,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
/** A logger for this class */
private static final Logger LOG = LoggerFactory.getLogger( JdbmTable.class );
- /** the key to store and retreive the count information */
- private static final String SZSUFFIX = "_btree_sz";
-
/** the JDBM record manager for the file this table is managed in */
private final RecordManager recMan;
@@ -135,11 +129,8 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
this.numDupLimit = numDupLimit;
this.recMan = manager;
-
this.valueSerializer = valueSerializer;
-
this.allowsDuplicates = true;
-
long recId = recMan.getNamedObject( name );
if ( recId == 0 ) // Create new main BTree
@@ -149,28 +140,17 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
// explicitly managed by this code. Value serialization is delegated to these
// marshallers.
- bt = new BTree<K, V>( recMan, keyComparator, keySerializer, null );
+ bt = new BTree<>( recMan, keyComparator, keySerializer, null );
recId = bt.getRecordId();
recMan.setNamedObject( name, recId );
- recId = recMan.insert( 0 );
- recMan.setNamedObject( name + SZSUFFIX, recId );
}
else
// Load existing BTree
{
bt = new BTree<K, V>().load( recMan, recId );
( ( SerializableComparator<K> ) bt.getComparator() ).setSchemaManager( schemaManager );
- recId = recMan.getNamedObject( name + SZSUFFIX );
- Object value = recMan.fetch( recId );
-
- if ( value instanceof Integer )
- {
- count = ( ( Integer ) value ).longValue();
- }
- else
- {
- count = ( Long ) value;
- }
+
+ count = bt.size();
}
}
@@ -210,26 +190,14 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
bt = new BTree<K, V>().load( recMan, recId );
( ( SerializableComparator<K> ) bt.getComparator() ).setSchemaManager( schemaManager );
bt.setValueSerializer( valueSerializer );
- recId = recMan.getNamedObject( name + SZSUFFIX );
-
- Object value = recMan.fetch( recId );
-
- if ( value instanceof Integer )
- {
- count = ( ( Integer ) value ).longValue();
- }
- else
- {
- count = ( Long ) value;
- }
+
+ count = bt.size();
}
else
{
bt = new BTree<>( recMan, keyComparator, keySerializer, valueSerializer );
recId = bt.getRecordId();
recMan.setNamedObject( name, recId );
- recId = recMan.insert( 0 );
- recMan.setNamedObject( name + SZSUFFIX, recId );
}
}
@@ -552,7 +520,7 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
*/
@Override
@SuppressWarnings("unchecked")
- public synchronized void put( PartitionWriteTxn transaction, K key, V value ) throws LdapException
+ public synchronized void put( PartitionTxn transaction, K key, V value ) throws LdapException
{
try
{
@@ -582,8 +550,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
LOG.debug( "<--- Add ONE {} = {}", name, key );
}
- commit( recMan );
-
return;
}
@@ -621,7 +587,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
}
count++;
- commit( recMan );
return;
}
@@ -638,8 +603,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
{
LOG.debug( "<--- Add BTREE {} = {}", name, key );
}
-
- commit( recMan );
}
catch ( IOException | CursorException | LdapException e )
{
@@ -654,7 +617,7 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
*/
@SuppressWarnings("unchecked")
@Override
- public synchronized void remove( PartitionWriteTxn transaction, K key, V value ) throws LdapException
+ public synchronized void remove( PartitionTxn transaction, K key, V value ) throws LdapException
{
try
{
@@ -688,8 +651,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
LOG.debug( "<--- Remove ONE " + name + " = " + key + ", " + value );
}
- commit( recMan );
-
return;
}
@@ -721,8 +682,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
LOG.debug( "<--- Remove AVL " + name + " = " + key + ", " + value );
}
- commit( recMan );
-
return;
}
@@ -752,8 +711,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
LOG.debug( "<--- Remove BTREE " + name + " = " + key + ", " + value );
}
- commit( recMan );
-
return;
}
}
@@ -768,7 +725,7 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
* {@inheritDoc}
*/
@Override
- public synchronized void remove( PartitionWriteTxn transaction, K key ) throws LdapException
+ public synchronized void remove( PartitionTxn transaction, K key ) throws LdapException
{
try
{
@@ -803,8 +760,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
LOG.debug( "<--- Remove ONE {} = {}", name, key );
}
- commit( recMan );
-
return;
}
@@ -823,8 +778,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
recMan.delete( tree.getRecordId() );
duplicateBtrees.remove( tree.getRecordId() );
- commit( recMan );
-
return;
}
else
@@ -837,8 +790,6 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
LOG.debug( "<--- Remove AVL {} = {}", name, key );
}
- commit( recMan );
-
return;
}
}
@@ -853,7 +804,7 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
* {@inheritDoc}
*/
@Override
- public Cursor<org.apache.directory.api.ldap.model.cursor.Tuple<K, V>> cursor( PartitionTxn transaction ) throws LdapException
+ public Cursor<org.apache.directory.api.ldap.model.cursor.Tuple<K, V>> cursor()
{
if ( allowsDuplicates )
{
@@ -868,8 +819,7 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
* {@inheritDoc}
*/
@Override
- @SuppressWarnings("unchecked")
- public Cursor<org.apache.directory.api.ldap.model.cursor.Tuple<K, V>> cursor( PartitionTxn transaction, K key ) throws LdapException
+ public Cursor<org.apache.directory.api.ldap.model.cursor.Tuple<K, V>> cursor( PartitionTxn partitionTxn, K key ) throws LdapException
{
if ( key == null )
{
@@ -956,53 +906,13 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
// ------------------------------------------------------------------------
// Maintenance Operations
// ------------------------------------------------------------------------
-
/**
- * @see Table#close()
+ * {@inheritDoc}
*/
@Override
public synchronized void close( PartitionTxn transaction ) throws LdapException
{
- try
- {
- sync();
- }
- catch ( IOException ioe )
- {
- throw new LdapOtherException( ioe.getMessage() );
- }
- }
-
-
- /**
- * Synchronizes the buffers with disk.
- *
- * @throws IOException if errors are encountered on the flush
- */
- public synchronized void sync() throws IOException
- {
- long recId = recMan.getNamedObject( name + SZSUFFIX );
- recMan.update( recId, count );
-
- // Commit
- recMan.commit();
-
- // And flush the journal
- if ( ( commitNumber.get() % 2000 ) == 0 )
- {
- BaseRecordManager baseRecordManager = null;
-
- if ( recMan instanceof CacheRecordManager )
- {
- baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() );
- }
- else
- {
- baseRecordManager = ( ( BaseRecordManager ) recMan );
- }
-
- baseRecordManager.getTransactionManager().synchronizeLog();
- }
+ // Nothing to do
}
@@ -1180,18 +1090,4 @@ public class JdbmTable<K, V> extends AbstractTable<K, V>
return bTree;
}
-
-
- /**
- * Commit the modification on disk
- *
- * @param recordManager The recordManager used for the commit
- */
- private void commit( RecordManager recordManager ) throws IOException
- {
- if ( commitNumber.incrementAndGet() % 2000 == 0 )
- {
- sync();
- }
- }
}
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java
index ccbd7af..ad08894 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursor.java
@@ -95,7 +95,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
public void before( E element ) throws LdapException, CursorException
{
- checkNotClosed( "before()" );
+ checkNotClosed();
try
{
browser = btree.browse( element );
@@ -127,7 +127,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
while ( browser.getNext( tuple ) )
{
- checkNotClosed( "after()" );
+ checkNotClosed();
E next = ( E ) tuple.getKey();
int nextCompared = comparator.compare( next, element );
@@ -160,7 +160,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst()" );
+ checkNotClosed();
try
{
browser = btree.browse();
@@ -178,7 +178,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast()" );
+ checkNotClosed();
try
{
browser = btree.browse( null );
@@ -215,7 +215,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
try
{
@@ -247,7 +247,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next()" );
+ checkNotClosed();
try
{
@@ -280,7 +280,7 @@ public class KeyBTreeCursor<E> extends AbstractCursor<E>
*/
public E get() throws CursorException
{
- checkNotClosed( "get()" );
+ checkNotClosed();
if ( valueAvailable )
{
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java
index 02549d8..af3d2ae 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyTupleBTreeCursor.java
@@ -120,7 +120,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void beforeValue( K key, V value ) throws Exception
{
- checkNotClosed( "beforeValue()" );
+ checkNotClosed();
if ( key != null && !key.equals( this.key ) )
{
throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
@@ -155,7 +155,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
while ( browser.getNext( valueTuple ) )
{
- checkNotClosed( "afterValue" );
+ checkNotClosed();
V next = ( V ) valueTuple.getKey();
@@ -199,7 +199,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void before( Tuple<K, V> element ) throws LdapException, CursorException
{
- checkNotClosed( "before()" );
+ checkNotClosed();
try
{
browser = btree.browse( element.getValue() );
@@ -226,7 +226,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst()" );
+ checkNotClosed();
try
{
browser = btree.browse();
@@ -244,7 +244,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast()" );
+ checkNotClosed();
try
{
browser = btree.browse( null );
@@ -284,7 +284,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
@SuppressWarnings("unchecked")
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
try
{
@@ -322,7 +322,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
@SuppressWarnings("unchecked")
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "next()" );
+ checkNotClosed();
try
{
@@ -360,7 +360,7 @@ public class KeyTupleBTreeCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public Tuple<K, V> get() throws CursorException
{
- checkNotClosed( "get()" );
+ checkNotClosed();
if ( valueAvailable )
{
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java
index edff4ac..8626c54 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java
@@ -62,7 +62,6 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
* Creates a Cursor over the tuples of a JDBM table.
*
* @param table the JDBM Table to build a Cursor over
- * @throws IOException of there are problems accessing the BTree
*/
NoDupsCursor( JdbmTable<K, V> table )
{
@@ -93,7 +92,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
public void beforeKey( K key ) throws LdapException, CursorException
{
- checkNotClosed( "beforeKey()" );
+ checkNotClosed();
try
{
browser = table.getBTree().browse( key );
@@ -122,7 +121,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
while ( browser.getNext( jdbmTuple ) )
{
- checkNotClosed( "afterKey()" );
+ checkNotClosed();
K next = ( K ) jdbmTuple.getKey();
int nextCompared = table.getKeyComparator().compare( next, key );
@@ -182,7 +181,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void beforeFirst() throws LdapException, CursorException
{
- checkNotClosed( "beforeFirst()" );
+ checkNotClosed();
try
{
browser = table.getBTree().browse();
@@ -200,7 +199,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public void afterLast() throws LdapException, CursorException
{
- checkNotClosed( "afterLast()" );
+ checkNotClosed();
try
{
browser = table.getBTree().browse( null );
@@ -239,7 +238,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
@SuppressWarnings("unchecked")
public boolean previous() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
if ( browser == null )
{
@@ -280,7 +279,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
@SuppressWarnings("unchecked")
public boolean next() throws LdapException, CursorException
{
- checkNotClosed( "previous()" );
+ checkNotClosed();
if ( browser == null )
{
@@ -320,7 +319,7 @@ class NoDupsCursor<K, V> extends AbstractCursor<Tuple<K, V>>
*/
public Tuple<K, V> get() throws CursorException
{
- checkNotClosed( "get()" );
+ checkNotClosed();
if ( valueAvailable )
{
return returnedTuple;
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java
index 67a01f8..1832045 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursorTest.java
@@ -42,6 +42,8 @@ import org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtr
import org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.api.util.exception.Exceptions;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.xdbm.MockPartitionReadTxn;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -65,6 +67,7 @@ public class DupsContainerCursorTest
private static SchemaManager schemaManager;
RecordManager recman;
private static final int SIZE = 15;
+ private PartitionTxn partitionTxn;
@BeforeClass
@@ -114,6 +117,7 @@ public class DupsContainerCursorTest
comparator.setSchemaManager( schemaManager );
table = new JdbmTable<String, String>( schemaManager, "test", SIZE, recman,
comparator, comparator, null, new DefaultSerializer() );
+ partitionTxn = new MockPartitionReadTxn();
LOG.debug( "Created new table and populated it with data" );
}
@@ -121,7 +125,7 @@ public class DupsContainerCursorTest
@After
public void destroyTable() throws Exception
{
- table.close();
+ table.close( partitionTxn );
table = null;
recman.close();
recman = null;
@@ -187,7 +191,7 @@ public class DupsContainerCursorTest
@Test
public void testOnTableWithSingleEntry() throws Exception
{
- table.put( "1", "1" );
+ table.put( partitionTxn, "1", "1" );
Cursor<Tuple<String, DupsContainer<String>>> cursor =
new DupsContainerCursor<String, String>( table );
assertTrue( cursor.first() );
@@ -209,7 +213,7 @@ public class DupsContainerCursorTest
for ( int i = 1; i < 10; i++ )
{
String istr = Integer.toString( i );
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
Cursor<Tuple<String, DupsContainer<String>>> cursor =
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
index 7189be8..5665f62 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursorTest.java
@@ -41,6 +41,8 @@ import org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtr
import org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.api.util.exception.Exceptions;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.xdbm.MockPartitionReadTxn;
import org.apache.directory.server.xdbm.Table;
import org.junit.After;
import org.junit.Before;
@@ -66,6 +68,7 @@ public class DupsCursorTest
File dbFile;
RecordManager recman;
private static SchemaManager schemaManager;
+ private PartitionTxn partitionTxn;
@BeforeClass
@@ -114,6 +117,9 @@ public class DupsCursorTest
table = new JdbmTable<String, String>( schemaManager, "test", SIZE, recman,
comparator, comparator, null, new DefaultSerializer() );
+
+ partitionTxn = new MockPartitionReadTxn();
+
LOG.debug( "Created new table and populated it with data" );
}
@@ -121,7 +127,7 @@ public class DupsCursorTest
@After
public void destroyTable() throws Exception
{
- table.close();
+ table.close( partitionTxn );
table = null;
recman.close();
recman = null;
@@ -162,7 +168,7 @@ public class DupsCursorTest
for ( int i = 0; i < SIZE - 1; i++ )
{
String istr = Integer.toString( i );
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
Cursor<Tuple<String, String>> cursor = table.cursor();
@@ -187,7 +193,7 @@ public class DupsCursorTest
for ( int i = 0; i < SIZE - 1; i++ )
{
String istr = Integer.toString( i );
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
Cursor<Tuple<String, String>> cursor = table.cursor();
@@ -215,11 +221,11 @@ public class DupsCursorTest
if ( i > 12 && i < 17 + SIZE )
{
- table.put( "13", istr );
+ table.put( partitionTxn, "13", istr );
}
else
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -258,12 +264,12 @@ public class DupsCursorTest
if ( i > 12 && i < 17 + SIZE )
{
- table.put( "13", Integer.toString( i ) );
+ table.put( partitionTxn, "13", Integer.toString( i ) );
}
else
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -303,11 +309,11 @@ public class DupsCursorTest
if ( i > 12 && i < 17 )
{
- table.put( "13", istr );
+ table.put( partitionTxn, "13", istr );
}
else
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -435,12 +441,12 @@ public class DupsCursorTest
if ( i < 2 + SIZE ) // keys with multiple values
{
- table.put( "0", istr );
+ table.put( partitionTxn, "0", istr );
}
else
// keys with single values
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -570,12 +576,12 @@ public class DupsCursorTest
if ( i < 2 + SIZE ) // keys with multiple values
{
- table.put( "0", istr );
+ table.put( partitionTxn, "0", istr );
}
else
// keys with single values
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -702,12 +708,12 @@ public class DupsCursorTest
if ( i > 2 + SIZE ) // keys with multiple values
{
- table.put( Integer.toString( 3 + SIZE ), istr );
+ table.put( partitionTxn, Integer.toString( 3 + SIZE ), istr );
}
else
// keys with single values
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -845,16 +851,16 @@ public class DupsCursorTest
@Test
public void testOverDupLimit() throws Exception
{
- table.put( "5", "5" );
- table.put( "6", "6" );
+ table.put( partitionTxn, "5", "5" );
+ table.put( partitionTxn, "6", "6" );
for ( int i = 0; i < 20; i++ )
{
- table.put( "7", Integer.toString( i ) );
+ table.put( partitionTxn, "7", Integer.toString( i ) );
}
- table.put( "8", "8" );
- table.put( "9", "9" );
+ table.put( partitionTxn, "8", "8" );
+ table.put( partitionTxn, "9", "9" );
Cursor<Tuple<String, String>> cursor = table.cursor();
assertNotNull( cursor );
@@ -870,16 +876,16 @@ public class DupsCursorTest
@Test
public void testUnderDupLimit() throws Exception
{
- table.put( "5", "5" );
- table.put( "6", "6" );
+ table.put( partitionTxn, "5", "5" );
+ table.put( partitionTxn, "6", "6" );
for ( int i = 0; i < 10; i++ )
{
- table.put( "7", Integer.toString( i ) );
+ table.put( partitionTxn, "7", Integer.toString( i ) );
}
- table.put( "8", "8" );
- table.put( "9", "9" );
+ table.put( partitionTxn, "8", "8" );
+ table.put( partitionTxn, "9", "9" );
Cursor<Tuple<String, String>> cursor = table.cursor();
assertNotNull( cursor );
@@ -901,7 +907,7 @@ public class DupsCursorTest
if ( i > 12 && i < 17 ) // keys with multiple values
{
- table.put( "13", Integer.toString( i ) );
+ table.put( partitionTxn, "13", Integer.toString( i ) );
}
else if ( i > 17 && i < 21 ) // adds hole with no keys for i
{
@@ -909,7 +915,7 @@ public class DupsCursorTest
else
// keys with single values
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -922,7 +928,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -954,7 +960,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -985,7 +991,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1023,7 +1029,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has(partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1060,7 +1066,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1095,7 +1101,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1131,7 +1137,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1168,7 +1174,7 @@ public class DupsCursorTest
{
if ( i > 17 && i < 21 )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1201,7 +1207,7 @@ public class DupsCursorTest
if ( i > 12 && i < 17 + SIZE ) // keys with multiple values
{
- table.put( "13", Integer.toString( i ) );
+ table.put( partitionTxn, "13", Integer.toString( i ) );
}
else if ( i > 17 + SIZE && i < 21 + SIZE ) // adds hole with no keys for i
{
@@ -1209,7 +1215,7 @@ public class DupsCursorTest
else
// keys with single values
{
- table.put( istr, istr );
+ table.put( partitionTxn, istr, istr );
}
}
@@ -1222,7 +1228,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1254,7 +1260,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1287,7 +1293,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1325,7 +1331,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1362,7 +1368,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1399,7 +1405,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1435,7 +1441,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
@@ -1470,7 +1476,7 @@ public class DupsCursorTest
{
if ( i > 17 + SIZE && i < 21 + SIZE )
{
- assertFalse( table.has( Integer.toString( i ) ) );
+ assertFalse( table.has( partitionTxn, Integer.toString( i ) ) );
continue;
}
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
index c0eb0ba..15e92b9 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
@@ -20,8 +20,8 @@
package org.apache.directory.server.core.partition.impl.btree.jdbm;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java
index 215211a..e9e8e6d 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java
@@ -28,8 +28,9 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
-import org.apache.directory.api.util.FileUtils;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.Cursor;
import org.apache.directory.api.ldap.model.schema.AttributeType;
@@ -38,15 +39,22 @@ import org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor;
import org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor;
import org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.api.util.FileUtils;
import org.apache.directory.api.util.Strings;
import org.apache.directory.api.util.exception.Exceptions;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.MockPartitionReadTxn;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import jdbm.recman.BaseRecordManager;
+import jdbm.recman.TransactionManager;
+
/**
* Tests the JdbmIndex.
@@ -55,25 +63,30 @@ import org.junit.Test;
*/
public class JdbmIndexTest
{
- private static File dbFileDir;
- Index<String, String> idx;
+ private Index<String, String> idx;
private static SchemaManager schemaManager;
+ private PartitionTxn partitionTxn;
+
+ /** The recordManager used */
+ private BaseRecordManager recMan;
+
+ /** The temporary directory the files will be created in */
+ private static Path tempDir;
+
+ /** The temporary index file */
+ private File tmpIndexFile;
+
+ /** A temporary file */
+ private Path tempFile;
@BeforeClass
public static void init() throws Exception
{
- String workingDirectory = System.getProperty( "workingDirectory" );
-
- if ( workingDirectory == null )
- {
- String path = JdbmIndexTest.class.getResource( "" ).getPath();
- int targetPos = path.indexOf( "target" );
- workingDirectory = path.substring( 0, targetPos + 6 );
- }
+ tempDir = Files.createTempDirectory( JdbmIndexTest.class.getSimpleName() );
- File schemaRepository = new File( workingDirectory, "schema" );
- SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ File schemaRepository = new File( tempDir.toFile(), "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tempDir.toFile() );
extractor.extractOrCopy( true );
LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
schemaManager = new DefaultSchemaManager( loader );
@@ -90,12 +103,14 @@ public class JdbmIndexTest
@Before
public void setup() throws IOException
{
-
- File tmpIndexFile = File.createTempFile( JdbmIndexTest.class.getSimpleName(), "db" );
- tmpIndexFile.deleteOnExit();
- dbFileDir = new File( tmpIndexFile.getParentFile(), JdbmIndexTest.class.getSimpleName() );
-
- dbFileDir.mkdirs();
+ tempFile = Files.createTempFile( tempDir, "data", null );
+
+ tmpIndexFile = tempFile.toFile();
+ partitionTxn = new MockPartitionReadTxn();
+
+ recMan = new BaseRecordManager( tmpIndexFile.getPath() );
+ TransactionManager transactionManager = recMan.getTransactionManager();
+ transactionManager.setMaximumTransactionsInLog( 2000 );
}
@@ -103,11 +118,13 @@ public class JdbmIndexTest
public void teardown() throws Exception
{
destroyIndex();
-
- if ( ( dbFileDir != null ) && dbFileDir.exists() )
- {
- FileUtils.deleteDirectory( dbFileDir );
- }
+ }
+
+
+ @AfterClass
+ public static void cleanup() throws Exception
+ {
+ FileUtils.deleteDirectory( tempDir.toFile() );
}
@@ -115,20 +132,7 @@ public class JdbmIndexTest
{
if ( idx != null )
{
- idx.sync();
- idx.close();
-
- // created by this test
- File dbFile = new File( idx.getWkDirPath().getPath(), idx.getAttribute().getOid() + ".db" );
- assertTrue( dbFile.delete() );
-
- // created by TransactionManager, if transactions are not disabled
- File logFile = new File( idx.getWkDirPath().getPath(), idx.getAttribute().getOid() + ".lg" );
-
- if ( logFile.exists() )
- {
- assertTrue( logFile.delete() );
- }
+ idx.close( partitionTxn );
}
idx = null;
@@ -139,7 +143,7 @@ public class JdbmIndexTest
{
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OU_AT );
JdbmIndex<String> index = new JdbmIndex<String>( attributeType.getName(), false );
- index.setWkDirPath( dbFileDir.toURI() );
+ index.setWkDirPath( tmpIndexFile.toURI() );
initIndex( index );
}
@@ -153,7 +157,7 @@ public class JdbmIndexTest
jdbmIdx = new JdbmIndex<String>( attributeType.getName(), false );
}
- jdbmIdx.init( schemaManager, attributeType );
+ jdbmIdx.init( recMan, schemaManager, attributeType );
this.idx = jdbmIdx;
}
@@ -188,7 +192,7 @@ public class JdbmIndexTest
destroyIndex();
JdbmIndex<String> index = new JdbmIndex<String>( "foo", false );
- index.setWkDirPath( dbFileDir.toURI() );
+ index.setWkDirPath( tmpIndexFile.toURI() );
initIndex( index );
assertEquals( "foo", idx.getAttributeId() );
}
@@ -220,7 +224,7 @@ public class JdbmIndexTest
@Test
public void testWkDirPath() throws Exception
{
- File wkdir = new File( dbFileDir, "foo" );
+ File wkdir = new File( tmpIndexFile, "foo" );
// uninitialized index
JdbmIndex<String> jdbmIndex = new JdbmIndex<String>( "foo", false );
@@ -239,7 +243,7 @@ public class JdbmIndexTest
{
}
- assertEquals( dbFileDir.toURI(), idx.getWkDirPath() );
+ assertEquals( tmpIndexFile.toURI(), idx.getWkDirPath() );
destroyIndex();
jdbmIndex = new JdbmIndex<String>( "ou", false );
@@ -294,16 +298,16 @@ public class JdbmIndexTest
public void testCount() throws Exception
{
initIndex();
- assertEquals( 0, idx.count() );
+ assertEquals( 0, idx.count( partitionTxn ) );
- idx.add( "foo", Strings.getUUID( 1234L ) );
- assertEquals( 1, idx.count() );
+ idx.add( partitionTxn, "foo", Strings.getUUID( 1234L ) );
+ assertEquals( 1, idx.count( partitionTxn ) );
- idx.add( "foo", Strings.getUUID( 333L ) );
- assertEquals( 2, idx.count() );
+ idx.add( partitionTxn, "foo", Strings.getUUID( 333L ) );
+ assertEquals( 2, idx.count( partitionTxn ) );
- idx.add( "bar", Strings.getUUID( 555L ) );
- assertEquals( 3, idx.count() );
+ idx.add( partitionTxn, "bar", Strings.getUUID( 555L ) );
+ assertEquals( 3, idx.count( partitionTxn ) );
}
@@ -311,16 +315,16 @@ public class JdbmIndexTest
public void testCountOneArg() throws Exception
{
initIndex();
- assertEquals( 0, idx.count( " foo " ) );
+ assertEquals( 0, idx.count( partitionTxn, " foo " ) );
- idx.add( "bar", Strings.getUUID( 1234L ) );
- assertEquals( 0, idx.count( " foo " ) );
+ idx.add( partitionTxn, "bar", Strings.getUUID( 1234L ) );
+ assertEquals( 0, idx.count( partitionTxn, " foo " ) );
- idx.add( " foo ", Strings.getUUID( 1234L ) );
- assertEquals( 1, idx.count( " foo " ) );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 1234L ) );
+ assertEquals( 1, idx.count( partitionTxn, " foo " ) );
- idx.add( " foo ", Strings.getUUID( 333L ) );
- assertEquals( 2, idx.count( " foo " ) );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 333L ) );
+ assertEquals( 2, idx.count( partitionTxn, " foo " ) );
}
@@ -328,15 +332,15 @@ public class JdbmIndexTest
public void testGreaterThanCount() throws Exception
{
initIndex();
- assertEquals( 0, idx.greaterThanCount( "a" ) );
+ assertEquals( 0, idx.greaterThanCount( partitionTxn, "a" ) );
for ( char ch = 'a'; ch <= 'z'; ch++ )
{
- idx.add( String.valueOf( ch ), Strings.getUUID( ch ) );
+ idx.add( partitionTxn, String.valueOf( ch ), Strings.getUUID( ch ) );
}
// We should not go above the magic limit of 10
- assertEquals( 10, idx.greaterThanCount( "a" ) );
+ assertEquals( 10, idx.greaterThanCount( partitionTxn, "a" ) );
}
@@ -344,15 +348,15 @@ public class JdbmIndexTest
public void testLessThanCount() throws Exception
{
initIndex();
- assertEquals( 0, idx.lessThanCount( "z" ) );
+ assertEquals( 0, idx.lessThanCount( partitionTxn, "z" ) );
for ( char ch = 'a'; ch <= 'z'; ch++ )
{
- idx.add( String.valueOf( ch ), Strings.getUUID( ch ) );
+ idx.add( partitionTxn, String.valueOf( ch ), Strings.getUUID( ch ) );
}
// We should not go above the magic limit of 10
- assertEquals( 10, idx.lessThanCount( "z" ) );
+ assertEquals( 10, idx.lessThanCount( partitionTxn, "z" ) );
}
@@ -365,21 +369,21 @@ public class JdbmIndexTest
{
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( "seeAlso" );
JdbmIndex<String> index = new JdbmIndex<String>( attributeType.getName(), false );
- index.setWkDirPath( dbFileDir.toURI() );
- index.init( schemaManager, attributeType );
+ index.setWkDirPath( tmpIndexFile.toURI() );
+ index.init( recMan, schemaManager, attributeType );
this.idx = index;
String foobarDn = "uid=foo,ou=bar";
String bazbarDn = "uid=baz,ou=bar";
- assertNull( idx.forwardLookup( foobarDn ) );
- assertNull( idx.forwardLookup( bazbarDn ) );
- idx.add( foobarDn, Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( foobarDn ) );
- assertNull( idx.forwardLookup( bazbarDn ) );
- idx.add( bazbarDn, Strings.getUUID( 24L ) );
- assertEquals( Strings.getUUID( 24L ), idx.forwardLookup( bazbarDn ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( foobarDn ) );
+ assertNull( idx.forwardLookup( partitionTxn, foobarDn ) );
+ assertNull( idx.forwardLookup( partitionTxn, bazbarDn ) );
+ idx.add( partitionTxn, foobarDn, Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, foobarDn ) );
+ assertNull( idx.forwardLookup( partitionTxn, bazbarDn ) );
+ idx.add( partitionTxn, bazbarDn, Strings.getUUID( 24L ) );
+ assertEquals( Strings.getUUID( 24L ), idx.forwardLookup( partitionTxn, bazbarDn ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, foobarDn ) );
}
@@ -387,23 +391,23 @@ public class JdbmIndexTest
public void testLookups() throws Exception
{
initIndex();
- assertNull( idx.forwardLookup( " foo " ) );
- assertNull( idx.forwardLookup( " bar " ) );
-
- idx.add( " foo ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
- assertTrue( idx.forward( " foo ", Strings.getUUID( 0L ) ) );
-
- idx.add( " foo ", Strings.getUUID( 1L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
- assertTrue( idx.forward( " foo ", Strings.getUUID( 0L ) ) );
- assertTrue( idx.forward( " foo ", Strings.getUUID( 1L ) ) );
-
- idx.add( "bar", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " bar " ) );
- assertTrue( idx.forward( " bar ", Strings.getUUID( 0L ) ) );
- assertTrue( idx.forward( " foo ", Strings.getUUID( 0L ) ) );
- assertTrue( idx.forward( " foo ", Strings.getUUID( 1L ) ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " bar " ) );
+
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
+ assertTrue( idx.forward( partitionTxn, " foo ", Strings.getUUID( 0L ) ) );
+
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 1L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
+ assertTrue( idx.forward( partitionTxn, " foo ", Strings.getUUID( 0L ) ) );
+ assertTrue( idx.forward( partitionTxn, " foo ", Strings.getUUID( 1L ) ) );
+
+ idx.add( partitionTxn, "bar", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " bar " ) );
+ assertTrue( idx.forward( partitionTxn, " bar ", Strings.getUUID( 0L ) ) );
+ assertTrue( idx.forward( partitionTxn, " foo ", Strings.getUUID( 0L ) ) );
+ assertTrue( idx.forward( partitionTxn, " foo ", Strings.getUUID( 1L ) ) );
}
@@ -411,33 +415,33 @@ public class JdbmIndexTest
public void testAddDropById() throws Exception
{
initIndex();
- assertNull( idx.forwardLookup( " foo " ) );
- assertNull( idx.forwardLookup( " bar " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " bar " ) );
// test add/drop without adding any duplicates
- idx.add( " foo ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
- idx.drop( " foo ", Strings.getUUID( 0L ) );
- assertNull( idx.forwardLookup( " foo " ) );
+ idx.drop( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
// test add/drop with duplicates in bulk
- idx.add( " foo ", Strings.getUUID( 0L ) );
- idx.add( " foo ", Strings.getUUID( 1L ) );
- idx.add( " bar ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " bar " ) );
-
- idx.drop( " foo ", Strings.getUUID( 0L ) );
- idx.drop( " bar ", Strings.getUUID( 0L ) );
- assertFalse( idx.forward( " bar ", Strings.getUUID( 0L ) ) );
- assertFalse( idx.forward( " foo ", Strings.getUUID( 0L ) ) );
-
- idx.drop( " bar ", Strings.getUUID( 1L ) );
- idx.drop( " foo ", Strings.getUUID( 1L ) );
- assertNull( idx.forwardLookup( " foo " ) );
- assertNull( idx.forwardLookup( " bar " ) );
- assertEquals( 0, idx.count() );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 1L ) );
+ idx.add( partitionTxn, " bar ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " bar " ) );
+
+ idx.drop( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ idx.drop( partitionTxn, " bar ", Strings.getUUID( 0L ) );
+ assertFalse( idx.forward( partitionTxn, " bar ", Strings.getUUID( 0L ) ) );
+ assertFalse( idx.forward( partitionTxn, " foo ", Strings.getUUID( 0L ) ) );
+
+ idx.drop( partitionTxn, " bar ", Strings.getUUID( 1L ) );
+ idx.drop( partitionTxn, " foo ", Strings.getUUID( 1L ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " bar " ) );
+ assertEquals( 0, idx.count( partitionTxn ) );
}
@@ -445,35 +449,35 @@ public class JdbmIndexTest
public void testAddDropOneByOne() throws Exception
{
initIndex();
- assertNull( idx.forwardLookup( " foo " ) );
- assertNull( idx.forwardLookup( " bar " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " bar " ) );
// test add/drop without adding any duplicates
- idx.add( " foo ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
- idx.drop( " foo ", Strings.getUUID( 0L ) );
- assertNull( idx.forwardLookup( " foo " ) );
+ idx.drop( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
// test add/drop with duplicates but one at a time
- idx.add( " foo ", Strings.getUUID( 0L ) );
- idx.add( " foo ", Strings.getUUID( 1L ) );
- idx.add( " bar ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " bar " ) );
-
- idx.drop( " bar ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( " foo " ) );
- assertFalse( idx.forward( " bar ", Strings.getUUID( 0L ) ) );
-
- idx.drop( " foo ", Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 1L ), idx.forwardLookup( " foo " ) );
- assertFalse( idx.forward( " foo ", Strings.getUUID( 0L ) ) );
-
- idx.drop( " foo ", Strings.getUUID( 1L ) );
- assertNull( idx.forwardLookup( " foo " ) );
- assertNull( idx.forwardLookup( " bar " ) );
- assertEquals( 0, idx.count() );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 1L ) );
+ idx.add( partitionTxn, " bar ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " bar " ) );
+
+ idx.drop( partitionTxn, " bar ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, " foo " ) );
+ assertFalse( idx.forward( partitionTxn, " bar ", Strings.getUUID( 0L ) ) );
+
+ idx.drop( partitionTxn, " foo ", Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 1L ), idx.forwardLookup( partitionTxn, " foo " ) );
+ assertFalse( idx.forward( partitionTxn, " foo ", Strings.getUUID( 0L ) ) );
+
+ idx.drop( partitionTxn, " foo ", Strings.getUUID( 1L ) );
+ assertNull( idx.forwardLookup( partitionTxn, " foo " ) );
+ assertNull( idx.forwardLookup( partitionTxn, " bar " ) );
+ assertEquals( 0, idx.count( partitionTxn ) );
}
@@ -485,22 +489,22 @@ public class JdbmIndexTest
public void testCursors() throws Exception
{
initIndex();
- assertEquals( 0, idx.count() );
+ assertEquals( 0, idx.count( partitionTxn ) );
- idx.add( " foo ", Strings.getUUID( 1234L ) );
- assertEquals( 1, idx.count() );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 1234L ) );
+ assertEquals( 1, idx.count( partitionTxn ) );
- idx.add( " foo ", Strings.getUUID( 333L ) );
- assertEquals( 2, idx.count() );
+ idx.add( partitionTxn, " foo ", Strings.getUUID( 333L ) );
+ assertEquals( 2, idx.count( partitionTxn ) );
- idx.add( "bar", Strings.getUUID( 555L ) );
- assertEquals( 3, idx.count() );
+ idx.add( partitionTxn, "bar", Strings.getUUID( 555L ) );
+ assertEquals( 3, idx.count( partitionTxn ) );
// use forward index's cursor
- Cursor<IndexEntry<String, String>> cursor = idx.forwardCursor();
+ Cursor<IndexEntry<String, String>> cursor = idx.forwardCursor( partitionTxn );
cursor.beforeFirst();
- assertEquals( 3, idx.count() );
+ assertEquals( 3, idx.count( partitionTxn ) );
cursor.next();
IndexEntry<String, String> e1 = cursor.get();
@@ -529,8 +533,8 @@ public class JdbmIndexTest
try
{
AttributeType noEqMatchAttribute = new AttributeType( "1.1" );
- jdbmIndex.setWkDirPath( dbFileDir.toURI() );
- jdbmIndex.init( schemaManager, noEqMatchAttribute );
+ jdbmIndex.setWkDirPath( tmpIndexFile.toURI() );
+ jdbmIndex.init( recMan, schemaManager, noEqMatchAttribute );
fail( "should not get here" );
}
catch ( IOException e )
@@ -547,8 +551,8 @@ public class JdbmIndexTest
public void testSingleValuedAttribute() throws Exception
{
JdbmIndex<Object> jdbmIndex = new JdbmIndex<Object>( SchemaConstants.CREATORS_NAME_AT, false );
- jdbmIndex.setWkDirPath( dbFileDir.toURI() );
- jdbmIndex.init( schemaManager, schemaManager.lookupAttributeTypeRegistry( SchemaConstants.CREATORS_NAME_AT ) );
- jdbmIndex.close();
+ jdbmIndex.setWkDirPath( tmpIndexFile.toURI() );
+ jdbmIndex.init( recMan, schemaManager, schemaManager.lookupAttributeTypeRegistry( SchemaConstants.CREATORS_NAME_AT ) );
+ jdbmIndex.close( partitionTxn );
}
}
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
index 4259fcf..a31b64c 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTableTest.java
@@ -36,6 +36,8 @@ import org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.api.util.Strings;
import org.apache.directory.api.util.exception.Exceptions;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.xdbm.MockPartitionReadTxn;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,7 +59,7 @@ public class JdbmMasterTableTest
File dbFile;
RecordManager recman;
SchemaManager schemaManager = null;
-
+ private PartitionTxn partitionTxn;
public JdbmMasterTableTest() throws Exception
{
@@ -103,7 +105,10 @@ public class JdbmMasterTableTest
LOG.debug( "Created new table and populated it with data" );
JdbmMasterTable t2 = new JdbmMasterTable( recman, schemaManager );
- t2.close();
+
+ partitionTxn = new MockPartitionReadTxn();
+
+ t2.close( partitionTxn );
}
@@ -112,7 +117,7 @@ public class JdbmMasterTableTest
{
if ( table != null )
{
- table.close();
+ table.close( partitionTxn );
}
table = null;
@@ -140,7 +145,7 @@ public class JdbmMasterTableTest
@Test
public void testAll() throws Exception
{
- assertNull( table.get( Strings.getUUID( 0L ) ) );
- assertEquals( 0, table.count() );
+ assertNull( table.get( partitionTxn, Strings.getUUID( 0L ) ) );
+ assertEquals( 0, table.count( partitionTxn ) );
}
}
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
index a1f8030..4f1f63e 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
@@ -22,11 +22,12 @@ package org.apache.directory.server.core.partition.impl.btree.jdbm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.directory.api.util.FileUtils;
import org.apache.directory.api.ldap.model.cursor.Cursor;
@@ -39,14 +40,20 @@ import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.api.util.Strings;
import org.apache.directory.api.util.exception.Exceptions;
import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.MockPartitionReadTxn;
import org.apache.directory.server.xdbm.ParentIdAndRdn;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import jdbm.recman.BaseRecordManager;
+import jdbm.recman.TransactionManager;
+
/**
* Tests the JdbmRdnIndex.
@@ -58,22 +65,28 @@ public class JdbmRdnIndexTest
private static File dbFileDir;
Index<ParentIdAndRdn, String> idx;
private static SchemaManager schemaManager;
+ private PartitionTxn partitionTxn;
+
+ /** The temporary directory the files will be created in */
+ private static Path tempDir;
+
+ /** The temporary index file */
+ private File tmpIndexFile;
+
+ /** A temporary file */
+ private Path tempFile;
+
+ /** The RecordManager */
+ private BaseRecordManager recMan;
@BeforeClass
public static void init() throws Exception
{
- String workingDirectory = System.getProperty( "workingDirectory" );
-
- if ( workingDirectory == null )
- {
- String path = JdbmRdnIndexTest.class.getResource( "" ).getPath();
- int targetPos = path.indexOf( "target" );
- workingDirectory = path.substring( 0, targetPos + 6 );
- }
+ tempDir = Files.createTempDirectory( JdbmIndexTest.class.getSimpleName() );
- File schemaRepository = new File( workingDirectory, "schema" );
- SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ File schemaRepository = new File( tempDir.toFile(), "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tempDir.toFile() );
extractor.extractOrCopy( true );
LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
schemaManager = new DefaultSchemaManager( loader );
@@ -90,12 +103,14 @@ public class JdbmRdnIndexTest
@Before
public void setup() throws IOException
{
+ tempFile = Files.createTempFile( tempDir, "data", null );
- File tmpIndexFile = File.createTempFile( JdbmRdnIndexTest.class.getSimpleName(), "db" );
+ tmpIndexFile = tempFile.toFile();
tmpIndexFile.deleteOnExit();
- dbFileDir = new File( tmpIndexFile.getParentFile(), JdbmRdnIndexTest.class.getSimpleName() );
-
- dbFileDir.mkdirs();
+
+ recMan = new BaseRecordManager( tmpIndexFile.getPath() );
+ TransactionManager transactionManager = recMan.getTransactionManager();
+ transactionManager.setMaximumTransactionsInLog( 2000 );
}
@@ -103,32 +118,21 @@ public class JdbmRdnIndexTest
public void teardown() throws Exception
{
destroyIndex();
-
- if ( ( dbFileDir != null ) && dbFileDir.exists() )
- {
- FileUtils.deleteDirectory( dbFileDir );
- }
}
+
+
+ @AfterClass
+ public static void cleanup() throws Exception
+ {
+ FileUtils.deleteDirectory( tempDir.toFile() );
+ }
void destroyIndex() throws Exception
{
if ( idx != null )
{
- idx.sync();
- idx.close();
-
- // created by this test
- File dbFile = new File( idx.getWkDirPath().getPath(), idx.getAttribute().getOid() + ".db" );
- assertTrue( dbFile.delete() );
-
- // created by TransactionManager, if transactions are not disabled
- File logFile = new File( idx.getWkDirPath().getPath(), idx.getAttribute().getOid() + ".lg" );
-
- if ( logFile.exists() )
- {
- assertTrue( logFile.delete() );
- }
+ idx.close( partitionTxn );
}
idx = null;
@@ -138,8 +142,9 @@ public class JdbmRdnIndexTest
void initIndex() throws Exception
{
JdbmRdnIndex index = new JdbmRdnIndex();
- index.setWkDirPath( dbFileDir.toURI() );
+ index.setWkDirPath( tmpIndexFile.toURI() );
initIndex( index );
+ partitionTxn = new MockPartitionReadTxn();
}
@@ -150,7 +155,7 @@ public class JdbmRdnIndexTest
jdbmIdx = new JdbmRdnIndex();
}
- jdbmIdx.init( schemaManager,
+ jdbmIdx.init( recMan, schemaManager,
schemaManager.lookupAttributeTypeRegistry( ApacheSchemaConstants.APACHE_RDN_AT_OID ) );
this.idx = jdbmIdx;
}
@@ -208,7 +213,7 @@ public class JdbmRdnIndexTest
{
}
- assertEquals( dbFileDir.toURI(), idx.getWkDirPath() );
+ assertEquals( tmpIndexFile.toURI(), idx.getWkDirPath() );
destroyIndex();
@@ -241,26 +246,26 @@ public class JdbmRdnIndexTest
public void testCount() throws Exception
{
initIndex();
- assertEquals( 0, idx.count() );
+ assertEquals( 0, idx.count( partitionTxn ) );
ParentIdAndRdn key = new ParentIdAndRdn( Strings.getUUID( 0L ), new Rdn( "cn=key" ) );
- idx.add( key, Strings.getUUID( 0L ) );
- assertEquals( 1, idx.count() );
+ idx.add( partitionTxn, key, Strings.getUUID( 0L ) );
+ assertEquals( 1, idx.count( partitionTxn ) );
// setting a different parentId should make this key a different key
key = new ParentIdAndRdn( Strings.getUUID( 1L ), new Rdn( "cn=key" ) );
- idx.add( key, Strings.getUUID( 1L ) );
- assertEquals( 2, idx.count() );
+ idx.add( partitionTxn, key, Strings.getUUID( 1L ) );
+ assertEquals( 2, idx.count( partitionTxn ) );
//count shouldn't get affected cause of inserting the same key
- idx.add( key, Strings.getUUID( 2L ) );
- assertEquals( 2, idx.count() );
+ idx.add( partitionTxn, key, Strings.getUUID( 2L ) );
+ assertEquals( 2, idx.count( partitionTxn ) );
key = new ParentIdAndRdn( Strings.getUUID( 2L ), new Rdn( "cn=key" ) );
- idx.add( key, Strings.getUUID( 3L ) );
- assertEquals( 3, idx.count() );
+ idx.add( partitionTxn, key, Strings.getUUID( 3L ) );
+ assertEquals( 3, idx.count( partitionTxn ) );
}
@@ -271,10 +276,10 @@ public class JdbmRdnIndexTest
ParentIdAndRdn key = new ParentIdAndRdn( Strings.getUUID( 0L ), new Rdn( "cn=key" ) );
- assertEquals( 0, idx.count( key ) );
+ assertEquals( 0, idx.count( partitionTxn, key ) );
- idx.add( key, Strings.getUUID( 0L ) );
- assertEquals( 1, idx.count( key ) );
+ idx.add( partitionTxn, key, Strings.getUUID( 0L ) );
+ assertEquals( 1, idx.count( partitionTxn, key ) );
}
@@ -289,17 +294,17 @@ public class JdbmRdnIndexTest
ParentIdAndRdn key = new ParentIdAndRdn( Strings.getUUID( 0L ), new Rdn( schemaManager, "cn=key" ) );
- assertNull( idx.forwardLookup( key ) );
+ assertNull( idx.forwardLookup( partitionTxn, key ) );
- idx.add( key, Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( key ) );
- assertEquals( key, idx.reverseLookup( Strings.getUUID( 0L ) ) );
+ idx.add( partitionTxn, key, Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, key ) );
+ assertEquals( key, idx.reverseLookup( partitionTxn, Strings.getUUID( 0L ) ) );
// check with the different case in UP name, this ensures that the custom
// key comparator is used
key = new ParentIdAndRdn( Strings.getUUID( 0L ), new Rdn( schemaManager, "cn=KEY" ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( key ) );
- assertEquals( key, idx.reverseLookup( Strings.getUUID( 0L ) ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( partitionTxn, key ) );
+ assertEquals( key, idx.reverseLookup( partitionTxn, Strings.getUUID( 0L ) ) );
}
@@ -310,15 +315,15 @@ public class JdbmRdnIndexTest
ParentIdAndRdn key = new ParentIdAndRdn( Strings.getUUID( 0L ), new Rdn( "cn=key" ) );
- assertNull( idx.forwardLookup( key ) );
+ assertNull( idx.forwardLookup( partitionTxn, key ) );
// test add/drop without adding any duplicates
- idx.add( key, Strings.getUUID( 0L ) );
- assertEquals( Strings.getUUID( 0L ), idx.forwardLookup( key ) );
+ idx.add( partitionTxn, key, Strings.getUUID( 0L ) );
+ assertEquals( Strings.getUUID( 0L ), idx.forwardLookup(partitionTxn, key ) );
- idx.drop( key, Strings.getUUID( 0L ) );
- assertNull( idx.forwardLookup( key ) );
- assertNull( idx.reverseLookup( Strings.getUUID( 0L ) ) );
+ idx.drop( partitionTxn, key, Strings.getUUID( 0L ) );
+ assertNull( idx.forwardLookup( partitionTxn, key ) );
+ assertNull( idx.reverseLookup( partitionTxn, Strings.getUUID( 0L ) ) );
}
@@ -333,22 +338,22 @@ public class JdbmRdnIndexTest
ParentIdAndRdn key = new ParentIdAndRdn( Strings.getUUID( 0L ), new Rdn( "cn=key" ) );
- assertEquals( 0, idx.count() );
+ assertEquals( 0, idx.count( partitionTxn ) );
- idx.add( key, Strings.getUUID( 0L ) );
- assertEquals( 1, idx.count() );
+ idx.add( partitionTxn, key, Strings.getUUID( 0L ) );
+ assertEquals( 1, idx.count( partitionTxn ) );
for ( long i = 1; i < 5; i++ )
{
key = new ParentIdAndRdn( Strings.getUUID( i ), new Rdn( "cn=key" + i ) );
- idx.add( key, Strings.getUUID( i ) );
+ idx.add( partitionTxn, key, Strings.getUUID( i ) );
}
- assertEquals( 5, idx.count() );
+ assertEquals( 5, idx.count( partitionTxn ) );
// use forward index's cursor
- Cursor<IndexEntry<ParentIdAndRdn, String>> cursor = idx.forwardCursor();
+ Cursor<IndexEntry<ParentIdAndRdn, String>> cursor = idx.forwardCursor( partitionTxn );
cursor.beforeFirst();
cursor.next();
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
index a542c3e..87021a5 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
@@ -28,6 +28,8 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -68,18 +70,22 @@ import org.apache.directory.server.core.api.MockDirectoryService;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.ModDnAva;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.apache.directory.server.core.shared.DefaultDnFactory;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexNotFoundException;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.StoreUtils;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jdbm.recman.BaseRecordManager;
+
/**
* Unit test cases for JdbmStore
@@ -91,8 +97,7 @@ public class JdbmStoreTest
{
private static final Logger LOG = LoggerFactory.getLogger( JdbmStoreTest.class );
- File wkdir;
- JdbmPartition store;
+ JdbmPartition partition;
CoreSession session;
private static SchemaManager schemaManager = null;
@@ -113,22 +118,22 @@ public class JdbmStoreTest
private static AttributeType SN_AT;
private static CacheService cacheService;
-
+ private PartitionTxn partitionTxn;
+
+ /** The recordManager used */
+ private BaseRecordManager recMan;
+
+ /** The temporary directory the files will be created in */
+ private static Path tempDir;
+
@BeforeClass
public static void setup() throws Exception
{
- String workingDirectory = System.getProperty( "workingDirectory" );
-
- if ( workingDirectory == null )
- {
- String path = JdbmStoreTest.class.getResource( "" ).getPath();
- int targetPos = path.indexOf( "target" );
- workingDirectory = path.substring( 0, targetPos + 6 );
- }
+ tempDir = Files.createTempDirectory( JdbmIndexTest.class.getSimpleName() );
- File schemaRepository = new File( workingDirectory, "schema" );
- SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ File schemaRepository = new File( tempDir.toFile(), "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tempDir.toFile() );
extractor.extractOrCopy( true );
loader = new LdifSchemaLoader( schemaRepository );
schemaManager = new DefaultSchemaManager( loader );
@@ -157,38 +162,36 @@ public class JdbmStoreTest
public void createStore() throws Exception
{
// setup the working directory for the store
- wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
- wkdir.delete();
- wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-
StoreUtils.createdExtraAttributes( schemaManager );
// initialize the store
- store = new JdbmPartition( schemaManager, dnFactory );
- store.setId( "example" );
- store.setCacheSize( 10 );
- store.setPartitionPath( wkdir.toURI() );
- store.setSyncOnWrite( false );
+ partition = new JdbmPartition( schemaManager, dnFactory );
+ partition.setId( "example" );
+ partition.setCacheSize( 10 );
+ partition.setPartitionPath( tempDir.toUri() );
+ partition.setSyncOnWrite( false );
JdbmIndex ouIndex = new JdbmIndex( SchemaConstants.OU_AT_OID, false );
- ouIndex.setWkDirPath( wkdir.toURI() );
- store.addIndex( ouIndex );
+ ouIndex.setWkDirPath( tempDir.toUri() );
+ partition.addIndex( ouIndex );
JdbmIndex uidIndex = new JdbmIndex( SchemaConstants.UID_AT_OID, false );
- uidIndex.setWkDirPath( wkdir.toURI() );
- store.addIndex( uidIndex );
+ uidIndex.setWkDirPath( tempDir.toUri() );
+ partition.addIndex( uidIndex );
Dn suffixDn = new Dn( schemaManager, "o=Good Times Co." );
- store.setSuffixDn( suffixDn );
+ partition.setSuffixDn( suffixDn );
- store.setCacheService( cacheService );
- store.initialize();
+ partition.setCacheService( cacheService );
+ partition.initialize();
- StoreUtils.loadExampleData( store, schemaManager );
+ StoreUtils.loadExampleData( partition, schemaManager );
DirectoryService directoryService = new MockDirectoryService();
directoryService.setSchemaManager( schemaManager );
session = new MockCoreSession( new LdapPrincipal(), directoryService );
+
+ partitionTxn = partition.beginReadTransaction();
LOG.debug( "Created new store" );
}
@@ -197,20 +200,30 @@ public class JdbmStoreTest
@After
public void destroyStore() throws Exception
{
- if ( store != null )
+ if ( partition != null )
{
// make sure all files are closed so that they can be deleted on Windows.
- store.destroy();
+ partition.destroy( partitionTxn );
}
-
- store = null;
-
- if ( wkdir != null )
+
+ File[] files = tempDir.toFile().listFiles();
+
+ for ( File file : files )
{
- FileUtils.deleteDirectory( wkdir );
+ if ( !file.isDirectory() )
+ {
+ file.delete();
+ }
}
- wkdir = null;
+ partition = null;
+ }
+
+
+ @AfterClass
+ public static void cleanup() throws Exception
+ {
+ FileUtils.deleteDirectory( tempDir.toFile() );
}
@@ -223,15 +236,13 @@ public class JdbmStoreTest
public void testTwoComponentSuffix() throws Exception
{
// setup the working directory for the 2nd store
- File wkdir2 = File.createTempFile( getClass().getSimpleName(), "db2" );
- wkdir2.delete();
- wkdir2 = new File( wkdir2.getParentFile(), getClass().getSimpleName() );
+ Path wkdir2 = Files.createTempDirectory( JdbmIndexTest.class.getSimpleName() + "_db2" );
- // initialize the 2nd store
+ // initialize the 2nd partition
JdbmPartition store2 = new JdbmPartition( schemaManager, dnFactory );
store2.setId( "example2" );
store2.setCacheSize( 10 );
- store2.setPartitionPath( wkdir2.toURI() );
+ store2.setPartitionPath( wkdir2.toFile().toURI() );
store2.setSyncOnWrite( false );
store2.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID, false ) );
store2.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID, false ) );
@@ -247,16 +258,20 @@ public class JdbmStoreTest
"dc: example",
SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString(),
SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-
- store2.add( new AddOperationContext( null, entry ) );
+
+ AddOperationContext addContext = new AddOperationContext( null, entry );
+ addContext.setPartition( store2 );
+ addContext.setTransaction( store2.beginWriteTransaction() );
+
+ store2.add( addContext );
// lookup the context entry
- String id = store2.getEntryId( suffixDn );
- Entry lookup = store2.fetch( id, suffixDn );
+ String id = store2.getEntryId( partitionTxn, suffixDn );
+ Entry lookup = store2.fetch( partitionTxn, id, suffixDn );
assertEquals( 2, lookup.getDn().size() );
// make sure all files are closed so that they can be deleted on Windows.
- store2.destroy();
+ store2.destroy( partitionTxn );
}
@@ -318,93 +333,93 @@ public class JdbmStoreTest
jdbmPartition.sync();
// make sure all files are closed so that they can be deleted on Windows.
- jdbmPartition.destroy();
+ jdbmPartition.destroy( partitionTxn );
}
@Test
public void testSimplePropertiesLocked() throws Exception
{
- assertNotNull( store.getAliasIndex() );
+ assertNotNull( partition.getAliasIndex() );
try
{
- store.addIndex( new JdbmIndex<Dn>( ApacheSchemaConstants.APACHE_ALIAS_AT_OID, true ) );
+ partition.addIndex( new JdbmIndex<Dn>( ApacheSchemaConstants.APACHE_ALIAS_AT_OID, true ) );
fail();
}
catch ( IllegalStateException e )
{
}
- assertEquals( 10, store.getCacheSize() );
+ assertEquals( 10, partition.getCacheSize() );
try
{
- store.setCacheSize( 24 );
+ partition.setCacheSize( 24 );
}
catch ( IllegalStateException e )
{
}
- assertNotNull( store.getPresenceIndex() );
+ assertNotNull( partition.getPresenceIndex() );
try
{
- store.addIndex( new JdbmIndex<String>( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID, false ) );
+ partition.addIndex( new JdbmIndex<String>( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID, false ) );
fail();
}
catch ( IllegalStateException e )
{
}
- assertNotNull( store.getId() );
+ assertNotNull( partition.getId() );
try
{
- store.setId( "foo" );
+ partition.setId( "foo" );
fail();
}
catch ( IllegalStateException e )
{
}
- assertNotNull( store.getRdnIndex() );
+ assertNotNull( partition.getRdnIndex() );
try
{
- store.addIndex( new JdbmRdnIndex() );
+ partition.addIndex( new JdbmRdnIndex() );
fail();
}
catch ( IllegalStateException e )
{
}
- assertNotNull( store.getOneAliasIndex() );
+ assertNotNull( partition.getOneAliasIndex() );
try
{
- store.addIndex( new JdbmIndex<Long>( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID, true ) );
+ partition.addIndex( new JdbmIndex<Long>( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID, true ) );
fail();
}
catch ( IllegalStateException e )
{
}
- assertNotNull( store.getSubAliasIndex() );
+ assertNotNull( partition.getSubAliasIndex() );
try
{
- store.addIndex( new JdbmIndex<Long>( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID, true ) );
+ partition.addIndex( new JdbmIndex<Long>( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID, true ) );
fail();
}
catch ( IllegalStateException e )
{
}
- assertNotNull( store.getSuffixDn() );
+ assertNotNull( partition.getSuffixDn() );
try
{
- store.setSuffixDn( EXAMPLE_COM );
+ partition.setSuffixDn( EXAMPLE_COM );
fail();
}
catch ( IllegalStateException e )
{
}
- Iterator<String> systemIndices = store.getSystemIndices();
+ Iterator<String> systemIndices = partition.getSystemIndices();
for ( int i = 0; i < 8; i++ )
{
@@ -413,11 +428,11 @@ public class JdbmStoreTest
}
assertFalse( systemIndices.hasNext() );
- assertNotNull( store.getSystemIndex( APACHE_ALIAS_AT ) );
+ assertNotNull( partition.getSystemIndex( APACHE_ALIAS_AT ) );
try
{
- store.getSystemIndex( SN_AT );
+ partition.getSystemIndex( SN_AT );
fail();
}
catch ( IndexNotFoundException e )
@@ -425,16 +440,16 @@ public class JdbmStoreTest
}
try
{
- store.getSystemIndex( DC_AT );
+ partition.getSystemIndex( DC_AT );
fail();
}
catch ( IndexNotFoundException e )
{
}
- assertNotNull( store.getSuffixDn() );
+ assertNotNull( partition.getSuffixDn() );
- Iterator<String> userIndices = store.getUserIndices();
+ Iterator<String> userIndices = partition.getUserIndices();
int count = 0;
while ( userIndices.hasNext() )
@@ -444,20 +459,20 @@ public class JdbmStoreTest
}
assertEquals( 2, count );
- assertFalse( store.hasUserIndexOn( DC_AT ) );
- assertTrue( store.hasUserIndexOn( OU_AT ) );
- assertTrue( store.hasSystemIndexOn( APACHE_ALIAS_AT ) );
- userIndices = store.getUserIndices();
+ assertFalse( partition.hasUserIndexOn( DC_AT ) );
+ assertTrue( partition.hasUserIndexOn( OU_AT ) );
+ assertTrue( partition.hasSystemIndexOn( APACHE_ALIAS_AT ) );
+ userIndices = partition.getUserIndices();
assertTrue( userIndices.hasNext() );
assertNotNull( userIndices.next() );
assertTrue( userIndices.hasNext() );
assertNotNull( userIndices.next() );
assertFalse( userIndices.hasNext() );
- assertNotNull( store.getUserIndex( OU_AT ) );
+ assertNotNull( partition.getUserIndex( OU_AT ) );
try
{
- store.getUserIndex( SN_AT );
+ partition.getUserIndex( SN_AT );
fail();
}
catch ( IndexNotFoundException e )
@@ -465,27 +480,27 @@ public class JdbmStoreTest
}
try
{
- store.getUserIndex( DC_AT );
+ partition.getUserIndex( DC_AT );
fail();
}
catch ( IndexNotFoundException e )
{
}
- assertNotNull( store.getPartitionPath() );
+ assertNotNull( partition.getPartitionPath() );
try
{
- store.setPartitionPath( new File( "." ).toURI() );
+ partition.setPartitionPath( new File( "." ).toURI() );
fail();
}
catch ( IllegalStateException e )
{
}
- assertTrue( store.isInitialized() );
- assertFalse( store.isSyncOnWrite() );
+ assertTrue( partition.isInitialized() );
+ assertFalse( partition.isSyncOnWrite() );
- store.sync();
+ partition.sync();
}
@@ -493,18 +508,18 @@ public class JdbmStoreTest
public void testFreshStore() throws Exception
{
Dn dn = new Dn( schemaManager, "o=Good Times Co." );
- assertEquals( Strings.getUUID( 1L ), store.getEntryId( dn ) );
- assertEquals( 11, store.count() );
- assertEquals( "o=Good Times Co.", store.getEntryDn( Strings.getUUID( 1L ) ).getName() );
- assertEquals( dn.getName(), store.getEntryDn( Strings.getUUID( 1L ) ).getName() );
- assertEquals( dn.getName(), store.getEntryDn( Strings.getUUID( 1L ) ).getName() );
+ assertEquals( Strings.getUUID( 1L ), partition.getEntryId( partitionTxn, dn ) );
+ assertEquals( 11, partition.count( partitionTxn ) );
+ assertEquals( "o=Good Times Co.", partition.getEntryDn( partitionTxn, Strings.getUUID( 1L ) ).getName() );
+ assertEquals( dn.getName(), partition.getEntryDn( partitionTxn, Strings.getUUID( 1L ) ).getName() );
+ assertEquals( dn.getName(), partition.getEntryDn( partitionTxn, Strings.getUUID( 1L ) ).getName() );
// note that the suffix entry returns 0 for it's parent which does not exist
- assertEquals( Strings.getUUID( 0L ), store.getParentId( store.getEntryId( dn ) ) );
- assertNull( store.getParentId( Strings.getUUID( 0L ) ) );
+ assertEquals( Strings.getUUID( 0L ), partition.getParentId( partitionTxn, partition.getEntryId( partitionTxn, dn ) ) );
+ assertNull( partition.getParentId( partitionTxn, Strings.getUUID( 0L ) ) );
// should NOW be allowed
- store.delete( Strings.getUUID( 1L ) );
+ partition.delete( partitionTxn, Strings.getUUID( 1L ) );
}
@@ -546,7 +561,21 @@ public class JdbmStoreTest
"entryUUID", Strings.getUUID( 12L ).toString() );
AddOperationContext addContext = new AddOperationContext( null, entry );
- store.add( addContext );
+ addContext.setPartition( store2 );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = store2.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ store2.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ }
store.delete( Strings.getUUID( 12L ) ); // drops the alias indices
}
@@ -562,8 +591,24 @@ public class JdbmStoreTest
"objectClass: organizationalPerson",
"ou: Not Present",
"cn: Martin King" );
+
AddOperationContext addContext = new AddOperationContext( null, entry );
- store.add( addContext );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ throw e;
+ }
}
@@ -575,7 +620,22 @@ public class JdbmStoreTest
"ou: Sales",
"cn: Martin King" );
AddOperationContext addContext = new AddOperationContext( null, entry );
- store.add( addContext );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ throw e;
+ }
}
@@ -589,7 +649,7 @@ public class JdbmStoreTest
Modification add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attrib );
- store.modify( dn, add );
+ partition.modify( partitionTxn, dn, add );
}
@@ -607,16 +667,38 @@ public class JdbmStoreTest
"entryUUID", UUID.randomUUID().toString() );
AddOperationContext addContext = new AddOperationContext( null, entry );
- store.add( addContext );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ }
Rdn rdn = new Rdn( schemaManager, "sn=James" );
- store.rename( dn, rdn, true, null );
+ partition.rename( partitionTxn, dn, rdn, true, null );
dn = new Dn( schemaManager, "sn=James,ou=Engineering,o=Good Times Co." );
- Entry renamed = store.lookup( new LookupOperationContext( session, dn ) );
- assertNotNull( renamed );
- assertEquals( "James", renamed.getDn().getRdn().getValue() );
+ LookupOperationContext lookupContext = new LookupOperationContext( session, dn );
+ lookupContext.setPartition( partition );
+
+ try ( PartitionTxn partitionTxn2 = partition.beginReadTransaction() )
+ {
+ lookupContext.setTransaction( partitionTxn2 );
+
+ Entry renamed = partition.lookup( lookupContext );
+ assertNotNull( renamed );
+ assertEquals( "James", renamed.getDn().getRdn().getValue() );
+ }
}
@@ -634,16 +716,30 @@ public class JdbmStoreTest
"entryUUID", UUID.randomUUID().toString() );
AddOperationContext addContext = new AddOperationContext( null, entry );
- store.add( addContext );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ }
Rdn rdn = new Rdn( schemaManager, "sn=Ja\\+es" );
- store.rename( dn, rdn, true, null );
+ partition.rename( partitionTxn, dn, rdn, true, null );
Dn dn2 = new Dn( schemaManager, "sn=Ja\\+es,ou=Engineering,o=Good Times Co." );
- String id = store.getEntryId( dn2 );
+ String id = partition.getEntryId( partitionTxn, dn2 );
assertNotNull( id );
- Entry entry2 = store.fetch( id, dn2 );
+ Entry entry2 = partition.fetch( partitionTxn, id, dn2 );
assertEquals( "Ja+es", entry2.get( "sn" ).getString() );
}
@@ -662,7 +758,21 @@ public class JdbmStoreTest
"entryUUID", UUID.randomUUID().toString() );
AddOperationContext addContext = new AddOperationContext( null, childEntry );
- store.add( addContext );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ }
Dn parentDn = new Dn( schemaManager, "ou=Sales,o=Good Times Co." );
@@ -676,20 +786,20 @@ public class JdbmStoreTest
modAvas.add( new ModDnAva( ModDnAva.ModDnType.DELETE, childDn.getRdn().getAva()) );
modDnAvas.put( SchemaConstants.CN_AT_OID, modAvas );
- store.moveAndRename( childDn, parentDn, rdn, modDnAvas, childEntry );
+ partition.moveAndRename( partitionTxn, childDn, parentDn, rdn, modDnAvas, childEntry );
// to drop the alias indices
childDn = new Dn( schemaManager, "commonName=Jim Bean,ou=Apache,ou=Board of Directors,o=Good Times Co." );
parentDn = new Dn( schemaManager, "ou=Engineering,o=Good Times Co." );
- assertEquals( 3, store.getSubAliasIndex().count() );
+ assertEquals( 3, partition.getSubAliasIndex().count( partitionTxn ) );
Dn newDn = parentDn.add( childDn.getRdn() );
- store.move( childDn, parentDn, newDn, null );
+ partition.move( partitionTxn, childDn, parentDn, newDn, null );
- assertEquals( 3, store.getSubAliasIndex().count() );
+ assertEquals( 3, partition.getSubAliasIndex().count( partitionTxn ) );
}
@@ -705,9 +815,9 @@ public class JdbmStoreTest
Modification add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attrib );
- Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
+ Entry lookedup = partition.fetch( partitionTxn, partition.getEntryId(partitionTxn, dn ), dn );
- store.modify( dn, add );
+ partition.modify( partitionTxn, dn, add );
assertTrue( lookedup.get( "sn" ).contains( attribVal ) );
}
@@ -724,17 +834,17 @@ public class JdbmStoreTest
Modification add = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attrib );
- Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
+ Entry lookedup = partition.fetch( partitionTxn, partition.getEntryId( partitionTxn, dn ), dn );
assertEquals( "WAlkeR", lookedup.get( "sn" ).get().getValue() ); // before replacing
- lookedup = store.modify( dn, add );
+ lookedup = partition.modify( partitionTxn, dn, add );
assertEquals( attribVal, lookedup.get( "sn" ).get().getValue() );
// testing the store.modify( dn, mod, entry ) API
Modification replace = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SN_AT, "JWalker" );
- lookedup = store.modify( dn, replace );
+ lookedup = partition.modify( partitionTxn, dn, replace );
assertEquals( "JWalker", lookedup.get( "sn" ).get().getValue() );
assertEquals( 1, lookedup.get( "sn" ).size() );
}
@@ -749,20 +859,20 @@ public class JdbmStoreTest
Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib );
- Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
+ Entry lookedup = partition.fetch( partitionTxn, partition.getEntryId( partitionTxn, dn ), dn );
assertNotNull( lookedup.get( "sn" ).get() );
- lookedup = store.modify( dn, add );
+ lookedup = partition.modify( partitionTxn, dn, add );
assertNull( lookedup.get( "sn" ) );
// add an entry for the sake of testing the remove operation
add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, SN_AT, "JWalker" );
- lookedup = store.modify( dn, add );
+ lookedup = partition.modify( partitionTxn, dn, add );
assertNotNull( lookedup.get( "sn" ) );
Modification remove = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, SN_AT );
- lookedup = store.modify( dn, remove );
+ lookedup = partition.modify( partitionTxn, dn, remove );
assertNull( lookedup.get( "sn" ) );
}
@@ -780,7 +890,21 @@ public class JdbmStoreTest
"entryUUID", UUID.randomUUID().toString() );
AddOperationContext addContext = new AddOperationContext( null, entry );
- store.add( addContext );
+ addContext.setPartition( partition );
+ PartitionTxn partitionTxn = null;
+
+ try
+ {
+ partitionTxn = partition.beginWriteTransaction();
+ addContext.setTransaction( partitionTxn );
+
+ partition.add( addContext );
+ partitionTxn.commit();
+ }
+ catch ( Exception e )
+ {
+ partitionTxn.abort();
+ }
Attribute attrib = new DefaultAttribute( SchemaConstants.OU_AT, OU_AT );
@@ -789,48 +913,11 @@ public class JdbmStoreTest
Modification add = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attrib );
- Entry lookedup = store.fetch( store.getEntryId( dn ), dn );
+ Entry lookedup = partition.fetch( partitionTxn, partition.getEntryId( partitionTxn, dn ), dn );
assertNull( lookedup.get( "ou" ) ); // before replacing
- lookedup = store.modify( dn, add );
+ lookedup = partition.modify( partitionTxn, dn, add );
assertEquals( attribVal, lookedup.get( "ou" ).get().getValue() );
}
-
-
- @Test
- public void testDeleteUnusedIndexFiles() throws Exception
- {
- File ouIndexDbFile = new File( wkdir, SchemaConstants.OU_AT_OID + ".db" );
- File ouIndexTxtFile = new File( wkdir, SchemaConstants.OU_AT_OID + "-ou.txt" );
- File uuidIndexDbFile = new File( wkdir, SchemaConstants.ENTRY_UUID_AT_OID + ".db" );
-
- assertTrue( ouIndexDbFile.exists() );
- assertTrue( ouIndexTxtFile.exists() );
-
- // destroy the store to manually start the init phase
- // by keeping the same work dir
- store.destroy();
-
- // just assert again that ou files exist even after destroying the store
- assertTrue( ouIndexDbFile.exists() );
- assertTrue( ouIndexTxtFile.exists() );
-
- store = new JdbmPartition( schemaManager, dnFactory );
- store.setId( "example" );
- store.setCacheSize( 10 );
- store.setPartitionPath( wkdir.toURI() );
- store.setSyncOnWrite( false );
- // do not add ou index this time
- store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID, false ) );
-
- Dn suffixDn = new Dn( schemaManager, "o=Good Times Co." );
- store.setSuffixDn( suffixDn );
- // init the store to call deleteUnusedIndexFiles() method
- store.setCacheService( cacheService );
- store.initialize();
-
- assertFalse( ouIndexDbFile.exists() );
- assertFalse( ouIndexTxtFile.exists() );
- }
}
diff --git a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
index 375d546..d03915a 100644
--- a/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
+++ b/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
@@ -39,6 +39,8 @@ import org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtr
import org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.api.util.exception.Exceptions;
+import org.apache.directory.server.core.api.partition.PartitionTxn;
+import org.apache.directory.server.xdbm.MockPartitionReadTxn;
import org.apache.directory.server.xdbm.Table;
import org.junit.After;
import org.junit.Before;
@@ -62,6 +64,7 @@ public class JdbmTableNoDuplicatesTest
File dbFile;
RecordManager recman;
private static SchemaManager schemaManager;
+ private PartitionTxn partitionTxn;
@BeforeClass
@@ -110,6 +113,8 @@ public class JdbmTableNoDuplicatesTest
comparator.setSchemaManager( schemaManager );
table = new JdbmTable<String, String>( schemaManager, "test", recman, comparator, null, null );
LOG.debug( "Created new table and populated it with data" );
+
+ partitionTxn = new MockPartitionReadTxn();
}
@@ -118,7 +123,7 @@ public class JdbmTableNoDuplicatesTest
{
if ( table != null )
{
- table.close();
+ table.close( partitionTxn );
}
table = null;
@@ -146,13 +151,13 @@ public class JdbmTableNoDuplicatesTest
@Test
public void testCloseReopen() throws Exception
{
- table.put( "1", "2" );
- table.close();
+ table.put( partitionTxn, "1", "2" );
+ table.close( partitionTxn );
SerializableComparator<String> comparator = new SerializableComparator<String>(
SchemaConstants.INTEGER_ORDERING_MATCH_MR_OID );
comparator.setSchemaManager( schemaManager );
table = new JdbmTable<String, String>( schemaManager, "test", recman, comparator, null, null );
- assertEquals( "2", table.get( "1" ) );
+ assertEquals( "2", table.get( partitionTxn, "1" ) );
}
@@ -169,25 +174,25 @@ public class JdbmTableNoDuplicatesTest
public void testWhenEmpty() throws Exception
{
// Test the count methods
- assertEquals( 0, table.count() );
- assertEquals( 0, table.count( "1" ) );
+ assertEquals( 0, table.count( partitionTxn ) );
+ assertEquals( 0, table.count( partitionTxn, "1" ) );
// Test get method
- assertNull( table.get( "0" ) );
+ assertNull( table.get( partitionTxn, "0" ) );
// Test remove methods
- table.remove( "1" );
- assertNull( table.get( "1" ) );
+ table.remove( partitionTxn, "1" );
+ assertNull( table.get( partitionTxn, "1" ) );
// Test has operations
- assertFalse( table.has( "1" ) );
- assertFalse( table.has( "1", "0" ) );
- assertFalse( table.hasGreaterOrEqual( "1" ) );
- assertFalse( table.hasLessOrEqual( "1" ) );
+ assertFalse( table.hasGreaterOrEqual( partitionTxn,"1" ) );
+ assertFalse( table.has( partitionTxn,"1", "0" ) );
+ assertFalse( table.hasGreaterOrEqual( partitionTxn,"1" ) );
+ assertFalse( table.hasLessOrEqual( partitionTxn,"1" ) );
try
{
- assertFalse( table.hasGreaterOrEqual( "1", "0" ) );
+ assertFalse( table.hasGreaterOrEqual( partitionTxn,"1", "0" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -196,7 +201,7 @@ public class JdbmTableNoDuplicatesTest
try
{
- assertFalse( table.hasLessOrEqual( "1", "0" ) );
+ assertFalse( table.hasLessOrEqual( partitionTxn, "1", "0" ) );
fail( "Should never get here." );
}
catch ( UnsupportedOperationException e )
@@ -212,11 +217,11 @@ public class JdbmTableNoDuplicatesTest
for ( int i = 0; i < 10; i++ )
{
String istr = Integer.toString( i );
- table.put( istr, istr );
+ table.put( partitionTxn,istr, istr );
}
- assertEquals( 10, table.count() );
- assertEquals( 1, table.count( "0" ) );
+ assertEquals( 10, table.count( partitionTxn ) );
+ assertEquals( 1, table.count( partitionTxn,"0" ) );
/*
* If counts are exact then we can test for exact values. Again this
@@ -224,8 +229,8 @@ public class JdbmTableNoDuplicatesTest
* case guesses are allowed.
*/
- assertEquals( 10, table.lessThanCount( "5" ) );
- assertEquals( 10, table.greaterThanCount( "5" ) );
+ assertEquals( 10, table.lessThanCount( partitionTxn, "5" ) );
+ assertEquals( 10, table.greaterThanCount( partitionTxn, "5" ) );
}
@@ -236,11 +241,11 @@ public class JdbmTableNoDuplicatesTest
@Test
public void testNullOrEmptyKeyValue() throws Exception
{
- assertEquals( 0, table.count() );
+ assertEquals( 0, table.count( partitionTxn ) );
try
{
- table.put( "1", null );
+ table.put( partitionTxn, "1", null );
fail( "should never get here due to IllegalArgumentException" );
}
... 17404 lines suppressed ...
--
To stop receiving notification emails like this one, please contact
elecharny@apache.org.