| | |
| | | import org.opends.server.api.MonitorProvider; |
| | | import org.opends.server.backends.RebuildConfig; |
| | | import org.opends.server.backends.VerifyConfig; |
| | | import org.opends.server.backends.pluggable.ImportSuffixCommand.SuffixImportStrategy; |
| | | import org.opends.server.backends.pluggable.spi.AccessMode; |
| | | import org.opends.server.backends.pluggable.spi.Storage; |
| | | import org.opends.server.backends.pluggable.spi.StorageInUseException; |
| | |
| | | import org.opends.server.util.LDIFException; |
| | | import org.opends.server.util.RuntimeInformation; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * This is an implementation of a Directory Server Backend which stores entries locally |
| | | * in a pluggable storage. |
| | |
| | | public LDIFImportResult importLDIF(LDIFImportConfig importConfig, ServerContext serverContext) |
| | | throws DirectoryException |
| | | { |
| | | if (importConfig.appendToExistingData() || importConfig.replaceExistingEntries()) |
| | | { |
| | | throw new UnsupportedOperationException("append/replace mode is not supported by this backend."); |
| | | } |
| | | RuntimeInformation.logInfo(); |
| | | |
| | | // If the rootContainer is open, the backend is initialized by something else. |
| | |
| | | { |
| | | throw new DirectoryException(getServerErrorResultCode(), ERR_IMPORT_BACKEND_ONLINE.get()); |
| | | } |
| | | for (DN dn : cfg.getBaseDN()) |
| | | { |
| | | ImportSuffixCommand importCommand = new ImportSuffixCommand(dn, importConfig); |
| | | if (importCommand.getSuffixImportStrategy() == SuffixImportStrategy.MERGE_DB_WITH_LDIF) |
| | | { |
| | | // fail-fast to avoid ending up in an unrecoverable state for the server |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, ERR_IMPORT_UNSUPPORTED_WITH_BRANCH.get()); |
| | | } |
| | | } |
| | | |
| | | try |
| | | { |
| | | if (OnDiskMergeBufferImporter.mustClearBackend(importConfig, cfg)) |
| | | try |
| | | { |
| | | try |
| | | if (importConfig.clearBackend()) |
| | | { |
| | | // clear all files before opening the root container |
| | | storage.removeStorageFiles(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new DirectoryException(getServerErrorResultCode(), ERR_REMOVE_FAIL.get(e.getMessage()), e); |
| | | } |
| | | } |
| | | |
| | | catch (Exception e) |
| | | { |
| | | throw new DirectoryException(getServerErrorResultCode(), ERR_REMOVE_FAIL.get(e.getMessage()), e); |
| | | } |
| | | rootContainer = newRootContainer(AccessMode.READ_WRITE); |
| | | return getImportStrategy().importLDIF(importConfig, rootContainer, serverContext); |
| | | try |
| | | { |
| | | rootContainer.getStorage().close(); |
| | | return getImportStrategy(serverContext, rootContainer).importLDIF(importConfig); |
| | | } |
| | | finally |
| | | { |
| | | rootContainer.getStorage().open(AccessMode.READ_WRITE); |
| | | } |
| | | } |
| | | catch (StorageRuntimeException e) |
| | | { |
| | |
| | | { |
| | | throw new DirectoryException(getServerErrorResultCode(), e.getMessageObject(), e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new DirectoryException(getServerErrorResultCode(), LocalizableMessage.raw(StaticUtils |
| | | .stackTraceToSingleLineString(e, false)), e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | |
| | | } |
| | | } |
| | | |
| | | private ImportStrategy getImportStrategy() throws DirectoryException |
| | | private ImportStrategy getImportStrategy(ServerContext serverContext, RootContainer rootContainer) |
| | | { |
| | | // TODO JNR may call new SuccessiveAddsImportStrategy() depending on configured import strategy |
| | | return new OnDiskMergeBufferImporter.StrategyImpl(cfg); |
| | | return new OnDiskMergeImporter.StrategyImpl(serverContext, rootContainer, cfg); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | { |
| | | rootContainer = newRootContainer(AccessMode.READ_WRITE); |
| | | } |
| | | new OnDiskMergeBufferImporter(rootContainer, rebuildConfig, cfg, serverContext).rebuildIndexes(); |
| | | rootContainer.getStorage().close(); |
| | | try |
| | | { |
| | | getImportStrategy(serverContext, rootContainer).rebuildIndex(rebuildConfig); |
| | | } |
| | | finally |
| | | { |
| | | rootContainer.getStorage().open(AccessMode.READ_WRITE); |
| | | } |
| | | } |
| | | catch (ExecutionException execEx) |
| | | { |
| | |
| | | { |
| | | throw e; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new DirectoryException(getServerErrorResultCode(), LocalizableMessage.raw(stackTraceToSingleLineString(ex)), |
| | | ex); |
| | | } |
| | | finally |
| | | { |
| | | closeTemporaryRootContainer(openRootContainer); |