| | |
| | | import org.opends.server.backends.jeb.ConfigurableEnvironment; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.EntryEncodeConfig; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.FilePermission; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @SuppressWarnings("unchecked") |
| | | public void initializeEntryCache(FileSystemEntryCacheCfg configuration) |
| | | throws ConfigException, InitializationException { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @SuppressWarnings("unchecked") |
| | | public void finalizeEntryCache() { |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean containsEntry(DN entryDN) |
| | | { |
| | | if (entryDN == null) { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Entry getEntry(DN entryDN) { |
| | | // Get the entry from the DN map if it is present. If not, then return |
| | | // null. |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public long getEntryID(DN entryDN) { |
| | | long entryID = -1; |
| | | cacheReadLock.lock(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public DN getEntryDN(Backend backend, long entryID) { |
| | | |
| | | DN entryDN = null; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void putEntry(Entry entry, Backend backend, long entryID) |
| | | { |
| | | try { |
| | | byte[] entryBytes = entry.encode(encodeConfig); |
| | | // TODO: Cache the buffer? |
| | | ByteStringBuilder buffer = new ByteStringBuilder(); |
| | | entry.encode(buffer, encodeConfig); |
| | | putEntryToDB(entry.getDN().toNormalizedString(), |
| | | backend, entryID, entryBytes); |
| | | backend, entryID, buffer); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean putEntryIfAbsent(Entry entry, Backend backend, long entryID) |
| | | { |
| | | cacheReadLock.lock(); |
| | |
| | | cacheReadLock.unlock(); |
| | | } |
| | | try { |
| | | byte[] entryBytes = entry.encode(encodeConfig); |
| | | // TODO: Cache the buffer? |
| | | ByteStringBuilder buffer = new ByteStringBuilder(); |
| | | entry.encode(buffer, encodeConfig); |
| | | return putEntryToDB(entry.getDN().toNormalizedString(), |
| | | backend, entryID, entryBytes); |
| | | backend, entryID, buffer); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void removeEntry(DN entryDN) { |
| | | |
| | | cacheWriteLock.lock(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @SuppressWarnings("unchecked") |
| | | public void clear() { |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void clearBackend(Backend backend) { |
| | | |
| | | cacheWriteLock.lock(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void clearSubtree(DN baseDN) { |
| | | // Determine which backend should be used for the provided base DN. If |
| | | // there is none, then we don't need to do anything. |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void handleLowMemory() { |
| | | // This is about all we can do. |
| | | if (entryCacheEnv != null) { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ArrayList<Attribute> getMonitorData() |
| | | { |
| | | ArrayList<Attribute> attrs = new ArrayList<Attribute>(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Long getCacheCount() |
| | | { |
| | | return new Long(entryCacheIndex.dnMap.size()); |
| | |
| | | primaryData, |
| | | LockMode.DEFAULT) == OperationStatus.SUCCESS) { |
| | | |
| | | Entry entry = Entry.decode(primaryData.getData()); |
| | | Entry entry = Entry.decode( |
| | | ByteString.wrap(primaryData.getData()).asReader()); |
| | | entry.setDN(entryDN); |
| | | return entry; |
| | | } else { |
| | |
| | | /** |
| | | * Encodes and stores the entry in the JE backend db. |
| | | * |
| | | * @param entry The entry to store in the cache. |
| | | * @param backend The backend with which the entry is associated. |
| | | * @param entryID The entry ID within the provided backend that uniquely |
| | | * identifies the specified entry. |
| | |
| | | private boolean putEntryToDB(String dnString, |
| | | Backend backend, |
| | | long entryID, |
| | | byte[] entryBytes) { |
| | | ByteStringBuilder entryBytes) { |
| | | try { |
| | | // Obtain a lock on the cache. If this fails, then don't do anything. |
| | | if (!cacheWriteLock.tryLock(getLockTimeout(), TimeUnit.MILLISECONDS)) { |
| | |
| | | |
| | | // Create data and put this cache entry into the database. |
| | | if (entryCacheDB.put(null, cacheEntryKey, |
| | | new DatabaseEntry(entryBytes)) == OperationStatus.SUCCESS) { |
| | | new DatabaseEntry(entryBytes.getBackingArray(), 0, |
| | | entryBytes.length())) == OperationStatus.SUCCESS) { |
| | | // Add the entry to the cache index maps. |
| | | Map<Long,String> map = |
| | | entryCacheIndex.backendMap.get(backend.getBackendID()); |