AttrHistoricalMultiple.java revision 0b6ab457f704afb95fc3d8389d50bf951eb9353e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* This class is used to store historical information for multiple valued attributes.
* One object of this type is created for each attribute that was changed in the entry.
* It allows to record the last time a given value was added,the last
* time a given value was deleted and the last time the whole attribute was deleted.
*/
public class AttrHistoricalMultiple extends AttrHistorical
{
/** Last time when the attribute was deleted. */
private CSN deleteTime;
/** Last time the attribute was modified. */
private CSN lastUpdateTime;
/**
* Change history for the values of this attribute.
* <p>
* We are using a LinkedHashMap here because we want:
* <ol>
* <li>Fast access for removing/adding a AttrValueHistorical keyed by the attribute value => Use a Map</li>
* <li>Ordering changes according to the CSN of each changes => Use a LinkedHashMap</li>
* </ol>
*/
/**
* Create a new object from the provided information.
* @param deleteTime the last time this attribute was deleted
* @param updateTime the last time this attribute was updated
* @param valuesHist the new attribute values when updated.
*/
{
this.deleteTime = deleteTime;
this.lastUpdateTime = updateTime;
if (valuesHist != null)
{
}
}
/** Creates a new object. */
public AttrHistoricalMultiple()
{
this.deleteTime = null;
this.lastUpdateTime = null;
}
/**
* Returns the last time when the attribute was updated.
* @return the last time when the attribute was updated
*/
private CSN getLastUpdateTime()
{
return lastUpdateTime;
}
public CSN getDeleteTime()
{
return deleteTime;
}
/**
* Duplicate an object. CSNs are duplicated by references.
* <p>
* Method only called in tests
*
* @return the duplicated object.
*/
{
}
/**
* Delete all historical information that is older than the provided CSN for
* this attribute type.
* Add the delete attribute state information
* @param csn time when the delete was done
*/
{
// iterate through the values in the valuesInfo and suppress all the values
// that have not been added after the date of this delete.
{
{
}
}
{
deleteTime = csn;
}
{
}
}
/**
* Update the historical of this attribute after deleting a set of values.
*
* @param attr
* the attribute containing the set of values that were deleted
* @param csn
* time when the delete was done
*/
{
{
}
}
/**
* Update the historical of this attribute after a delete value.
*
* @param val value that was deleted
* @param csn time when the delete was done
*/
{
}
/**
* Update the historical information when values are added.
*
* @param attr
* the attribute containing the set of added values
* @param csn
* time when the add is done
*/
{
{
}
}
/**
* Update the historical information when a value is added.
*
* @param addedValue
* values that was added
* @param csn
* time when the value was added
*/
{
}
{
{
}
}
{
return valuesHist.keySet();
}
{
// We are replaying an operation that was already done
// on another master server and this operation has a potential
// conflict with some more recent operations on this same entry
// we need to take the more complex path to solve them
{
// the attribute was modified after this change -> conflict
switch (m.getModificationType().asEnum())
{
case DELETE:
{
/* this delete is already obsoleted by a more recent delete
* skip this mod
*/
break;
}
{
}
break;
case ADD:
break;
case REPLACE:
{
/* this replace is already obsoleted by a more recent delete
* skip this mod
*/
break;
}
/* save the values that are added by the replace operation
* into addedValues
* first process the replace as a delete operation -> this generate
* a list of values that should be kept
* then process the addedValues as if they were coming from a add
* -> this generate the list of values that needs to be added
* concatenate the 2 generated lists into a replace
*/
break;
case INCREMENT:
// TODO : FILL ME
break;
}
return true;
}
else
{
return false;// the attribute was not modified more recently
}
}
{
/*
* The operation is either a non-conflicting operation or a local operation
* so there is no need to check the historical information for conflicts.
* If this is a local operation, then this code is run after
* the pre-operation phase.
* If this is a non-conflicting replicated operation, this code is run
* during the handleConflictResolution().
*/
{
case DELETE:
{
}
else
{
}
break;
case ADD:
if (type.isSingleValue())
{
}
break;
case REPLACE:
/* TODO : can we replace specific attribute values ????? */
break;
case INCREMENT:
/* FIXME : we should update CSN */
break;
}
}
/**
* Process a delete attribute values that is conflicting with a previous
* modification.
*
* @param csn The CSN of the currently processed change
* @param m the modification that is being processed
* @param modifiedEntry the entry that is modified (before current mod)
* @return false if there is nothing to do
*/
{
/*
* We are processing a conflicting DELETE modification
*
* This code is written on the assumption that conflict are
* rare. We therefore don't care much about the performance
* However since it is rarely executed this code needs to be
* as simple as possible to make sure that all paths are tested.
* In this case the most simple seem to change the DELETE
* in a REPLACE modification that keeps all values
* more recent that the DELETE.
* we are therefore going to change m into a REPLACE that will keep
* all the values that have been updated after the DELETE time
* If a value is present in the entry without any state information
* it must be removed so we simply ignore them
*/
{
// We are processing a DELETE attribute modification
{
{
// this value has been updated after this delete,
// therefore this value must be kept
}
{
/*
* this value is going to be deleted, remove it from historical
* information unless it is a Deleted attribute value that is
* more recent than this DELETE
*/
}
}
{
deleteTime = csn;
}
{
}
}
else
{
// we are processing DELETE of some attribute values
{
boolean deleteIt = true; // true if the delete must be done
boolean addedInCurrentOp = false;
// update historical information
if (oldValInfo != null)
{
// this value already exist in the historical information
{
// This value was added earlier in the same operation
// we need to keep the delete.
addedInCurrentOp = true;
}
{
}
else if (oldValInfo.isUpdate())
{
deleteIt = false;
}
}
else
{
}
/* if the attribute value is not to be deleted
* or if attribute value is not present suppress it from the
* MOD to make sure the delete is going to succeed
*/
if (!deleteIt
{
// this value was already deleted before and therefore
// this should not be replayed.
{
// This was the last values in the set of values to be deleted.
// this MOD must therefore be skipped.
return false;
}
}
}
{
}
}
return true;
}
/**
* Process a add attribute values that is conflicting with a previous
* modification.
*
* @param csn the historical info associated to the entry
* @param m the modification that is being processed
* @param modsIterator iterator on the list of modification
*/
{
/*
* if historicalattributedelete is newer forget this mod else find
* attr value if does not exist add historicalvalueadded timestamp
* add real value in entry else if timestamp older and already was
* historicalvalueadded update historicalvalueadded else if
* timestamp older and was historicalvaluedeleted change
* historicalvaluedeleted into historicalvalueadded add value in
* real entry
*/
{
/* A delete has been done more recently than this add
* forget this MOD ADD
*/
return;
}
{
if (oldValInfo == null)
{
/* this value does not exist yet
* add it in the historical information
* let the operation process normally
*/
}
else
{
if (oldValInfo.isUpdate())
{
/* if the value is already present
* check if the updateTime must be updated
* in all cases suppress this value from the value list
* as it is already present in the entry
*/
{
}
}
else
{ // it is a delete
/* this value is marked as a deleted value
* check if this mod is more recent the this delete
*/
{
/* this add is more recent,
* remove the old delete historical information
* and add our more recent one
* let the operation process
*/
}
else
{
/* the delete that is present in the historical information
* is more recent so it must win,
* remove this value from the list of values to add
* don't update the historical information
*/
}
}
}
}
m.setAttribute(attr);
{
}
{
}
}
{
switch (histKey)
{
case ADD:
{
}
break;
case DEL:
{
}
break;
case REPL:
{
}
break;
case ATTRDEL:
break;
}
}
{
boolean deleteAppended = false;
if (deleteTime != null)
{
deleteAppended = true;
}
if (lastUpdateTime != null)
{
if (deleteAppended)
{
}
}
}
}