Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* Copyright 2007-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2016 ForgeRock AS.
* Portions Copyright 2025 3A Systems, LLC
* Portions Copyright 2025-2026 3A Systems, LLC
*/
package org.opends.server.backends.pluggable;

Expand All @@ -29,7 +29,7 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

import org.forgerock.i18n.LocalizableException;
import org.forgerock.i18n.LocalizableMessage;
Expand Down Expand Up @@ -93,9 +93,13 @@ public abstract class BackendImpl<C extends PluggableBackendCfg> extends LocalBa
/** The root container to use for this backend. */
private RootContainer rootContainer;

// FIXME: this is broken. Replace with read-write lock.
/** A count of the total operation threads currently in the backend. */
private final AtomicInteger threadTotalCount = new AtomicInteger(0);
/**
* A count of the total operation threads currently in the backend. Bumped
* twice per operation by all worker threads, so it uses LongAdder to avoid
* contending on a single cache line; it is only read when waiting for the
* backend to become quiescent.
*/
private final LongAdder threadTotalCount = new LongAdder();
/** The base DNs defined for this backend instance. */
private Set<DN> baseDNs;

Expand Down Expand Up @@ -130,14 +134,14 @@ private EntryContainer accessBegin(Operation operation, DN entryDN) throws Direc
{
throw new DirectoryException(ResultCode.UNDEFINED, ERR_BACKEND_ENTRY_DOESNT_EXIST.get(entryDN, getBackendID()));
}
threadTotalCount.getAndIncrement();
threadTotalCount.increment();
return ec;
}

/** End a Backend API method that accesses the EntryContainer. */
private void accessEnd()
{
threadTotalCount.getAndDecrement();
threadTotalCount.decrement();
}

/**
Expand All @@ -147,7 +151,7 @@ private void accessEnd()
*/
private void waitUntilQuiescent()
{
while (threadTotalCount.get() > 0)
while (threadTotalCount.sum() > 0)
{
// Still have threads accessing the storage so sleep a little
try
Expand Down Expand Up @@ -252,7 +256,7 @@ public void closeBackend()
}

// Make sure the thread counts are zero for next initialization.
threadTotalCount.set(0);
threadTotalCount.reset();

// Log an informational message.
logger.info(NOTE_BACKEND_OFFLINE, cfg.getBackendId());
Expand Down Expand Up @@ -340,7 +344,7 @@ public ConditionResult hasSubordinates(DN entryDN) throws DirectoryException
throw de;
}

container.sharedLock.lock();
container.beginSharedAccess();
try
{
return ConditionResult.valueOf(container.hasSubordinates(entryDN));
Expand All @@ -351,7 +355,7 @@ public ConditionResult hasSubordinates(DN entryDN) throws DirectoryException
}
finally
{
container.sharedLock.unlock();
container.endSharedAccess();
accessEnd();
}
}
Expand All @@ -362,7 +366,7 @@ public long getNumberOfEntriesInBaseDN(DN baseDN) throws DirectoryException
checkNotNull(baseDN, "baseDN must not be null");

final EntryContainer ec = accessBegin(null, baseDN);
ec.sharedLock.lock();
ec.beginSharedAccess();
try
{
return ec.getNumberOfEntriesInBaseDN();
Expand All @@ -374,7 +378,7 @@ public long getNumberOfEntriesInBaseDN(DN baseDN) throws DirectoryException
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -401,7 +405,7 @@ public long getNumberOfChildren(DN parentDN) throws DirectoryException
throw de;
}

ec.sharedLock.lock();
ec.beginSharedAccess();
try
{
return ec.getNumberOfChildren(parentDN);
Expand All @@ -412,7 +416,7 @@ public long getNumberOfChildren(DN parentDN) throws DirectoryException
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -421,7 +425,7 @@ public long getNumberOfChildren(DN parentDN) throws DirectoryException
public boolean entryExists(final DN entryDN) throws DirectoryException
{
EntryContainer ec = accessBegin(null, entryDN);
ec.sharedLock.lock();
ec.beginSharedAccess();
try
{
return ec.entryExists(entryDN);
Expand All @@ -432,7 +436,7 @@ public boolean entryExists(final DN entryDN) throws DirectoryException
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -441,7 +445,7 @@ public boolean entryExists(final DN entryDN) throws DirectoryException
public Entry getEntry(DN entryDN) throws DirectoryException
{
EntryContainer ec = accessBegin(null, entryDN);
ec.sharedLock.lock();
ec.beginSharedAccess();
try
{
return ec.getEntry(entryDN);
Expand All @@ -452,7 +456,7 @@ public Entry getEntry(DN entryDN) throws DirectoryException
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -462,7 +466,7 @@ public void addEntry(Entry entry, AddOperation addOperation) throws DirectoryExc
{
EntryContainer ec = accessBegin(addOperation, entry.getName());

ec.sharedLock.lock();
ec.beginSharedAccess();
try
{
ec.addEntry(entry, addOperation);
Expand All @@ -473,7 +477,7 @@ public void addEntry(Entry entry, AddOperation addOperation) throws DirectoryExc
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -484,7 +488,7 @@ public void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
{
EntryContainer ec = accessBegin(deleteOperation, entryDN);

ec.sharedLock.lock();
ec.beginSharedAccess();
try
{
ec.deleteEntry(entryDN, deleteOperation);
Expand All @@ -495,7 +499,7 @@ public void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -506,7 +510,7 @@ public void replaceEntry(Entry oldEntry, Entry newEntry, ModifyOperation modifyO
{
EntryContainer ec = accessBegin(modifyOperation, newEntry.getName());

ec.sharedLock.lock();
ec.beginSharedAccess();

try
{
Expand All @@ -518,7 +522,7 @@ public void replaceEntry(Entry oldEntry, Entry newEntry, ModifyOperation modifyO
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand All @@ -538,7 +542,7 @@ public void renameEntry(DN currentDN, Entry entry, ModifyDNOperation modifyDNOpe
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, WARN_FUNCTION_NOT_SUPPORTED.get());
}

currentContainer.sharedLock.lock();
currentContainer.beginSharedAccess();
try
{
currentContainer.renameEntry(currentDN, entry, modifyDNOperation);
Expand All @@ -549,7 +553,7 @@ public void renameEntry(DN currentDN, Entry entry, ModifyDNOperation modifyDNOpe
}
finally
{
currentContainer.sharedLock.unlock();
currentContainer.endSharedAccess();
accessEnd();
}
}
Expand All @@ -559,7 +563,7 @@ public void search(SearchOperation searchOperation) throws DirectoryException, C
{
EntryContainer ec = accessBegin(searchOperation, searchOperation.getBaseDN());

ec.sharedLock.lock();
ec.beginSharedAccess();

try
{
Expand All @@ -571,7 +575,7 @@ public void search(SearchOperation searchOperation) throws DirectoryException, C
}
finally
{
ec.sharedLock.unlock();
ec.endSharedAccess();
accessEnd();
}
}
Expand Down
Loading
Loading