*/
private boolean solveNamingConflict(ModifyOperation op,
ModifyMsg msg)
{
ResultCode result = op.getResultCode();
ModifyContext ctx = (ModifyContext) op.getAttachment(SYNCHROCONTEXT);
String entryUid = ctx.getEntryUid();
if (result == ResultCode.NO_SUCH_OBJECT)
{
/*
* The operation is a modification but
* the entry has been renamed on a different master in the same time.
* search if the entry has been renamed, and return the new dn
* of the entry.
*/
DN newdn = findEntryDN(entryUid);
if (newdn != null)
{
// There is an entry with the same unique id as this modify operation
// replay the modify using the current dn of this entry.
msg.setDn(newdn.toString());
numResolvedNamingConflicts.incrementAndGet();
return false;
}
else
{
// This entry does not exist anymore.
// It has probably been deleted, stop the processing of this operation
numResolvedNamingConflicts.incrementAndGet();
return true;
}
}
else if (result == ResultCode.NOT_ALLOWED_ON_RDN)
{
DN currentDN = findEntryDN(entryUid);
RDN currentRDN = null;
if (currentDN != null)
{
currentRDN = currentDN.getRDN();
}
else
{
// The entry does not exist anymore.
numResolvedNamingConflicts.incrementAndGet();
return true;
}
// The modify operation is trying to delete the value that is
// currently used in the RDN. We need to alter the modify so that it does
// not remove the current RDN value(s).
List<Modification> mods = op.getModifications();
for (Modification mod : mods)
{
AttributeType modAttrType = mod.getAttribute().getAttributeType();
if ((mod.getModificationType() == ModificationType.DELETE) ||
(mod.getModificationType() == ModificationType.REPLACE))
{
if (currentRDN.hasAttributeType(modAttrType))
{
// the attribute can't be deleted because it is used
// in the RDN, turn this operation is a replace with the
// current RDN value(s);
mod.setModificationType(ModificationType.REPLACE);
Attribute newAttribute = mod.getAttribute();
AttributeBuilder attrBuilder;
if (newAttribute == null)
{
attrBuilder = new AttributeBuilder(modAttrType);
}
else
{
attrBuilder = new AttributeBuilder(newAttribute);
}
attrBuilder.add(currentRDN.getAttributeValue(modAttrType));
mod.setAttribute(attrBuilder.toAttribute());
}
}
}
msg.setMods(mods);
numResolvedNamingConflicts.incrementAndGet();
return false;
}
else
{
// The other type of errors can not be caused by naming conflicts.
// Log a message for the repair tool.
Message message = ERR_ERROR_REPLAYING_OPERATION.get(
op.toString(), ctx.getChangeNumber().toString(),
result.toString(), op.getErrorMessage().toString());
logError(message);
return true;
}
}