| | |
| | | import org.opends.server.backends.jeb.ConfigurableEnvironment; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.server.types.*; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.loggers.ErrorLogger.logError; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | |
| | | public class FileSystemEntryCache |
| | | extends EntryCache <FileSystemEntryCacheCfg> |
| | | implements ConfigurationChangeListener <FileSystemEntryCacheCfg> { |
| | | /** |
| | | * The tracer object for the debug logger. |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | // Permissions for cache db environment. |
| | | private static final FilePermission CACHE_HOME_PERMISSIONS = |
| | |
| | | try { |
| | | checkAndSetupCacheHome(cacheHome); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Not having any home directory for the cache db environment is a |
| | | // fatal error as we are unable to continue any further without it. |
| | |
| | | logError(message); |
| | | |
| | | } catch (CacheIndexNotFoundException e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Log an error message. |
| | | logError(NOTE_FSCACHE_INDEX_NOT_FOUND.get()); |
| | |
| | | // Clear the entry cache. |
| | | clear(); |
| | | } catch (CacheIndexImpairedException e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Log an error message. |
| | | logError(ERR_FSCACHE_INDEX_IMPAIRED.get()); |
| | |
| | | // Clear the entry cache. |
| | | clear(); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Log an error message. |
| | | logError(ERR_FSCACHE_CANNOT_LOAD_PERSISTENT_DATA.get()); |
| | |
| | | // If we got here it means we have failed to have a proper backend |
| | | // for this entry cache and there is absolutely no point going any |
| | | // farther from here. |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | LocalizableMessage message = |
| | | ERR_FSCACHE_CANNOT_INITIALIZE.get( |
| | |
| | | throw new Exception(); |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Log an error message. |
| | | logError(ERR_FSCACHE_CANNOT_STORE_PERSISTENT_DATA.get()); |
| | |
| | | entryCacheEnv.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // That is ok, JE verification and repair on startup should take care of |
| | | // this so if there are any unrecoverable errors during next startup |
| | |
| | | putEntryToDB(entry.getName().toNormalizedString(), |
| | | backend, entryID, buffer); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | return putEntryToDB(entry.getName().toNormalizedString(), |
| | | backend, entryID, buffer); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | // We can't rule out the possibility of a conflict, so return false. |
| | | return false; |
| | | } |
| | |
| | | entryCacheDB.delete(null, |
| | | new DatabaseEntry(entryDN.toNormalizedString().getBytes("UTF-8"))); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } finally { |
| | | cacheWriteLock.unlock(); |
| | | } |
| | |
| | | classCatalog, FileSystemEntryCacheIndex.class); |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } finally { |
| | | cacheWriteLock.unlock(); |
| | |
| | | // This backend is empty now, remove it from the backend map. |
| | | entryCacheIndex.backendMap.remove(backend.getBackendID()); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } finally { |
| | | cacheWriteLock.unlock(); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | // This shouldn't happen, but there's not much that we can do if it does. |
| | | } |
| | | finally |
| | |
| | | new DatabaseEntry( |
| | | entryDN.toNormalizedString().getBytes("UTF-8"))); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | // Free some main memory/space. |
| | | entryCacheEnv.cleanLog(); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | newJECachePercent : |
| | | EnvironmentConfig.DEFAULT.getCachePercent())); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | errorHandler.reportError( |
| | | ERR_FSCACHE_CANNOT_SET_JE_MEMORY_PCT.get(), |
| | | false, |
| | |
| | | try { |
| | | newMutableEnvConfig.setCacheSize(newJECacheSize); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | errorHandler.reportError( |
| | | ERR_FSCACHE_CANNOT_SET_JE_MEMORY_SIZE.get(), |
| | | false, |
| | |
| | | newEnvConfig = ConfigurableEnvironment.setJEProperties( |
| | | newEnvConfig, newJEProperties, configAttrMap); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | errorHandler.reportError( |
| | | ERR_FSCACHE_CANNOT_SET_JE_PROPERTIES.get(e.getMessage()), |
| | | false, DirectoryServer.getServerErrorResultCode()); |
| | |
| | | jePropertyName); |
| | | errorHandler.reportError(message, true, ResultCode.SUCCESS, |
| | | true); |
| | | if (debugEnabled()) { |
| | | TRACER.debugInfo("The change to the following property " + |
| | | if (logger.isTraceEnabled()) { |
| | | logger.trace("The change to the following property " + |
| | | "will take effect when the component is restarted: " + |
| | | jePropertyName); |
| | | } |
| | |
| | | entryCacheEnv.setMutableConfig(newMutableEnvConfig); |
| | | entryCacheEnv.evictMemory(); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | errorHandler.reportError( |
| | | ERR_FSCACHE_CANNOT_SET_JE_MEMORY_PCT.get(), |
| | | false, |
| | |
| | | entryCacheEnv.setMutableConfig(newMutableEnvConfig); |
| | | entryCacheEnv.evictMemory(); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | errorHandler.reportError( |
| | | ERR_FSCACHE_CANNOT_SET_JE_MEMORY_SIZE.get(), |
| | | false, |
| | |
| | | // properties that are mutable at runtime. |
| | | entryCacheEnv.setMutableConfig(newEnvConfig); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | errorHandler.reportError( |
| | | ERR_FSCACHE_CANNOT_SET_JE_PROPERTIES.get(e.getMessage()), |
| | | false, |
| | |
| | | new Long(maxEntries.longValue()) : new Long(0)) |
| | | ); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } |
| | | |
| | | return attrs; |
| | |
| | | throw new Exception(); |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Log an error message. |
| | | logError(ERR_FSCACHE_CANNOT_RETRIEVE_ENTRY.get()); |
| | |
| | | // the entry due to memory constraints. |
| | | return true; |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | // Log an error message. |
| | | logError( |
| | |
| | | // Remove the the eldest entry from the database. |
| | | entryCacheDB.delete(null, cacheEntryKey); |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | } finally { |
| | | cacheWriteLock.unlock(); |
| | | } |