Search in sources :

Example 66 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class ParallelUpdateOperationQueue method getChangeRecord.

/**
 * Retrieves the next LDIF change record to be processed.  This method will
 * block if the queue is currently empty but the end of the LDIF file has not
 * yet been reached, or if all of the operations currently held in the queue
 * are dependent upon an operation in progress.
 *
 * @param  completedDNs  The DNs of the entries targeted by the last change.
 *                       It should be empty for the first request processed by
 *                       a thread, should have a single element if the last
 *                       change was an add, delete, or modify, and should have
 *                       two elements if the last change was a modify DN.
 *
 * @return  The next LDIF change record to be processed, or {@code null} if
 *          there are no more change records to process and the end of the
 *          LDIF file has been reached.
 */
@Nullable()
LDIFChangeRecord getChangeRecord(@NotNull final DN... completedDNs) {
    synchronized (queueLock) {
        for (final DN dn : completedDNs) {
            activeChanges.remove(dn);
        }
        while (!(endOfLDIF && opQueue.isEmpty())) {
            if (opQueue.isEmpty()) {
                try {
                    queueLock.wait(1000L);
                } catch (final InterruptedException e) {
                    Debug.debugException(e);
                }
                continue;
            }
            final Iterator<LDIFChangeRecord> iterator = opQueue.iterator();
            iteratorLoop: while (iterator.hasNext()) {
                final LDIFChangeRecord r = iterator.next();
                // Get the parsed target DN for the change record.
                final DN targetDN;
                try {
                    targetDN = r.getParsedDN();
                } catch (final LDAPException e) {
                    // This should never happen, but if it does then reject the change.
                    parallelUpdate.reject(r, e);
                    iterator.remove();
                    size--;
                    continue;
                }
                // conflict with any active operations.
                if (!activeChanges.isEmpty()) {
                    for (final DN activeDN : activeChanges) {
                        if (activeDN.isAncestorOf(targetDN, true)) {
                            continue iteratorLoop;
                        }
                    }
                    if (r instanceof LDIFDeleteChangeRecord) {
                        for (final DN activeDN : activeChanges) {
                            if (activeDN.isDescendantOf(targetDN, false)) {
                                continue iteratorLoop;
                            }
                        }
                    } else if (r instanceof LDIFModifyDNChangeRecord) {
                        final LDIFModifyDNChangeRecord modDNRecord = (LDIFModifyDNChangeRecord) r;
                        final DN newDN;
                        try {
                            newDN = modDNRecord.getNewDN();
                        } catch (final LDAPException e) {
                            // We could not parse the new DN, so reject the change.
                            parallelUpdate.reject(r, e);
                            iterator.remove();
                            size--;
                            continue iteratorLoop;
                        }
                        for (final DN activeDN : activeChanges) {
                            if (activeDN.isDescendantOf(targetDN, false) || activeDN.isAncestorOf(newDN, true) || activeDN.isDescendantOf(newDN, false)) {
                                continue iteratorLoop;
                            }
                        }
                        // At this point, we know that the modify DN will be processed so
                        // reserve the new DN as well.  The target DN will be reserved
                        // below.
                        activeChanges.add(newDN);
                    }
                }
                // At this point, the change will be processed so remove it from the
                // queue and add it to the list of active changes.  Also, notify any
                // threads that might be waiting on the queue lock in case
                // addChangeRecord is waiting on available space.
                activeChanges.add(targetDN);
                iterator.remove();
                size--;
                queueLock.notifyAll();
                return r;
            }
            // complete before trying again.
            try {
                queueLock.wait(1000L);
            } catch (final InterruptedException e) {
                Debug.debugException(e);
            }
        }
    }
    // If we've gotten here, then there is no more data to be processed.
    return null;
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) LDAPException(com.unboundid.ldap.sdk.LDAPException) DN(com.unboundid.ldap.sdk.DN) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Nullable(com.unboundid.util.Nullable)

Example 67 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class ParallelUpdateOperationThread method run.

/**
 * Operates in a loop, retrieving changes from the operation queue and
 * processing them.
 */
@Override()
public void run() {
    LDIFChangeRecord r = opQueue.getChangeRecord();
    // Various controls that might be present on the requests.
    final Control undeleteRequestControl = new UndeleteRequestControl();
    while (r != null) {
        if (rateLimiter != null) {
            rateLimiter.await();
        }
        DN parsedDN = null;
        DN parsedNewDN = null;
        final long startTime = System.currentTimeMillis();
        try {
            parsedDN = r.getParsedDN();
            if (r instanceof LDIFAddChangeRecord) {
                final AddRequest addRequest = ((LDIFAddChangeRecord) r).toAddRequest();
                addRequest.addControls(addControls);
                if (allowUndelete && addRequest.hasAttribute(ATTR_UNDELETE_FROM_DN)) {
                    addRequest.addControl(undeleteRequestControl);
                }
                connectionPool.add(addRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else if (r instanceof LDIFDeleteChangeRecord) {
                final DeleteRequest deleteRequest = ((LDIFDeleteChangeRecord) r).toDeleteRequest();
                deleteRequest.addControls(deleteControls);
                connectionPool.delete(deleteRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else if (r instanceof LDIFModifyChangeRecord) {
                final ModifyRequest modifyRequest = ((LDIFModifyChangeRecord) r).toModifyRequest();
                modifyRequest.addControls(modifyControls);
                connectionPool.modify(modifyRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else if (r instanceof LDIFModifyDNChangeRecord) {
                final LDIFModifyDNChangeRecord modifyDNChangeRecord = (LDIFModifyDNChangeRecord) r;
                parsedNewDN = modifyDNChangeRecord.getNewDN();
                final ModifyDNRequest modifyDNRequest = modifyDNChangeRecord.toModifyDNRequest();
                modifyDNRequest.addControls(modifyDNControls);
                connectionPool.modifyDN(modifyDNRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else {
                // This should never happen.
                r.processChange(connectionPool);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            }
        } catch (final LDAPException e) {
            Debug.debugException(e);
            parallelUpdate.opFailed(r, e, (System.currentTimeMillis() - startTime));
        }
        if (parsedNewDN == null) {
            r = opQueue.getChangeRecord(parsedDN);
        } else {
            r = opQueue.getChangeRecord(parsedDN, parsedNewDN);
        }
    }
}
Also used : LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) DN(com.unboundid.ldap.sdk.DN) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) AddRequest(com.unboundid.ldap.sdk.AddRequest) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Control(com.unboundid.ldap.sdk.Control) UndeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) UndeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest)

Aggregations

LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)67 Test (org.testng.annotations.Test)58 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)29 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)20 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)18 LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)17 Calendar (java.util.Calendar)17 GregorianCalendar (java.util.GregorianCalendar)17 Entry (com.unboundid.ldap.sdk.Entry)10 Attribute (com.unboundid.ldap.sdk.Attribute)9 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)9 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)9 DN (com.unboundid.ldap.sdk.DN)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)6 File (java.io.File)5 Schema (com.unboundid.ldap.sdk.schema.Schema)4 Nullable (com.unboundid.util.Nullable)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)3 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)3 Modification (com.unboundid.ldap.sdk.Modification)3