opends/src/server/org/opends/server/replication/plugin/AttrHistorical.java
@@ -23,12 +23,11 @@ * * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions Copyright 2013 ForgeRock, AS. */ package org.opends.server.replication.plugin; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import org.opends.server.replication.common.ChangeNumber; import org.opends.server.types.AttributeType; @@ -94,8 +93,8 @@ * * @return the List of ValueInfo */ public abstract Map<AttrValueHistorical,AttrValueHistorical> getValuesHistorical(); public abstract ArrayList<AttrValueHistorical> getValuesHistorical(); /** * Returns the last time when this attribute was deleted. opends/src/server/org/opends/server/replication/plugin/AttrHistoricalMultiple.java
@@ -27,9 +27,8 @@ */ package org.opends.server.replication.plugin; import java.util.HashMap; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import org.opends.server.replication.common.ChangeNumber; import org.opends.server.types.Attribute; @@ -40,6 +39,7 @@ import org.opends.server.types.Modification; import org.opends.server.types.ModificationType; /** * This classes is used to store historical information for multiple valued * attributes. @@ -51,11 +51,9 @@ */ public class AttrHistoricalMultiple extends AttrHistorical { /** Last time when the attribute was deleted. */ private ChangeNumber deleteTime; /** Last time the attribute was modified. */ private ChangeNumber lastUpdateTime; private final Map<AttrValueHistorical, AttrValueHistorical> valuesHist; private ChangeNumber deleteTime, // last time when the attribute was deleted lastUpdateTime; // last time the attribute was modified private ArrayList<AttrValueHistorical> valuesHist; /** * Create a new object from the provided informations. @@ -65,12 +63,12 @@ */ public AttrHistoricalMultiple(ChangeNumber deleteTime, ChangeNumber updateTime, Map<AttrValueHistorical, AttrValueHistorical> valuesHist) ArrayList<AttrValueHistorical> valuesHist) { this.deleteTime = deleteTime; this.lastUpdateTime = updateTime; if (valuesHist == null) this.valuesHist = new HashMap<AttrValueHistorical,AttrValueHistorical>(); this.valuesHist = new ArrayList<AttrValueHistorical>(); else this.valuesHist = valuesHist; } @@ -82,7 +80,7 @@ { this.deleteTime = null; this.lastUpdateTime = null; this.valuesHist = new HashMap<AttrValueHistorical,AttrValueHistorical>(); this.valuesHist = new ArrayList<AttrValueHistorical>(); } /** @@ -98,7 +96,6 @@ * Returns the last time when the attribute was deleted. * @return the last time when the attribute was deleted */ @Override public ChangeNumber getDeleteTime() { return deleteTime; @@ -128,7 +125,7 @@ // iterate through the values in the valuesInfo // and suppress all the values that have not been added // after the date of this delete. Iterator<AttrValueHistorical> it = this.valuesHist.keySet().iterator(); Iterator<AttrValueHistorical> it = this.valuesHist.iterator(); while (it.hasNext()) { AttrValueHistorical info = it.next(); @@ -157,7 +154,8 @@ protected void delete(AttributeValue val, ChangeNumber CN) { AttrValueHistorical info = new AttrValueHistorical(val, null, CN); this.valuesHist.put(info, info); this.valuesHist.remove(info); this.valuesHist.add(info); if (CN.newer(lastUpdateTime)) { lastUpdateTime = CN; @@ -178,7 +176,8 @@ for (AttributeValue val : attr) { AttrValueHistorical info = new AttrValueHistorical(val, null, CN); this.valuesHist.put(info, info); this.valuesHist.remove(info); this.valuesHist.add(info); if (CN.newer(lastUpdateTime)) { lastUpdateTime = CN; @@ -197,7 +196,8 @@ protected void add(AttributeValue addedValue, ChangeNumber CN) { AttrValueHistorical info = new AttrValueHistorical(addedValue, CN, null); this.valuesHist.put(info, info); this.valuesHist.remove(info); valuesHist.add(info); if (CN.newer(lastUpdateTime)) { lastUpdateTime = CN; @@ -217,7 +217,8 @@ for (AttributeValue val : attr) { AttrValueHistorical info = new AttrValueHistorical(val, CN, null); this.valuesHist.put(info, info); this.valuesHist.remove(info); valuesHist.add(info); if (CN.newer(lastUpdateTime)) { lastUpdateTime = CN; @@ -230,8 +231,7 @@ * * @return the list of historical informations for the values. */ @Override public Map<AttrValueHistorical, AttrValueHistorical> getValuesHistorical() public ArrayList<AttrValueHistorical> getValuesHistorical() { return valuesHist; } @@ -239,7 +239,6 @@ /** * {@inheritDoc} */ @Override public boolean replayOperation( Iterator<Modification> modsIterator, ChangeNumber changeNumber, Entry modifiedEntry, Modification m) @@ -332,7 +331,6 @@ * @param changeNumber The changeNumber of the operation to process * @param mod The modify operation to process. */ @Override public void processLocalOrNonConflictModification(ChangeNumber changeNumber, Modification mod) { @@ -419,10 +417,10 @@ m.setModificationType(ModificationType.REPLACE); AttributeBuilder builder = new AttributeBuilder(modAttr, true); Iterator<AttrValueHistorical> it = this.valuesHist.keySet().iterator(); while (it.hasNext()) for (Iterator<AttrValueHistorical> it = getValuesHistorical().iterator(); it.hasNext();) { AttrValueHistorical valInfo = it.next(); AttrValueHistorical valInfo; valInfo = it.next(); if (changeNumber.older(valInfo.getValueUpdateTime())) { @@ -459,21 +457,25 @@ } else { // we are processing DELETE of some attribute values /* * we are processing DELETE of some attribute values */ ArrayList<AttrValueHistorical> valuesInfo = getValuesHistorical(); AttributeBuilder builder = new AttributeBuilder(modAttr); for (AttributeValue val : modAttr) { boolean deleteIt = true; // true if the delete must be done boolean addedInCurrentOp = false; Boolean deleteIt = true; // true if the delete must be done Boolean addedInCurrentOp = false; /* update historical information */ AttrValueHistorical valInfo = new AttrValueHistorical(val, null, changeNumber); AttrValueHistorical oldValInfo = valuesHist.get(valInfo); if (oldValInfo != null) int index = valuesInfo.indexOf(valInfo); if (index != -1) { /* this value already exist in the historical information */ AttrValueHistorical oldValInfo = valuesInfo.get(index); if (changeNumber.equals(oldValInfo.getValueUpdateTime())) { // This value was added earlier in the same operation @@ -483,7 +485,8 @@ if (changeNumber.newerOrEquals(oldValInfo.getValueDeleteTime()) && changeNumber.newerOrEquals(oldValInfo.getValueUpdateTime())) { valuesHist.put(valInfo, valInfo); valuesInfo.remove(index); valuesInfo.add(valInfo); } else if (oldValInfo.isUpdate()) { @@ -492,7 +495,7 @@ } else { valuesHist.put(valInfo, valInfo); valuesInfo.add(valInfo); } /* if the attribute value is not to be deleted @@ -560,19 +563,21 @@ AttributeBuilder builder = new AttributeBuilder(m.getAttribute()); for (AttributeValue addVal : m.getAttribute()) { ArrayList<AttrValueHistorical> valuesInfo = getValuesHistorical(); AttrValueHistorical valInfo = new AttrValueHistorical(addVal, changeNumber, null); if (!valuesHist.containsKey(valInfo)) int index = valuesInfo.indexOf(valInfo); if (index == -1) { /* this values does not exist yet * add it in the historical information * let the operation process normally */ valuesHist.put(valInfo, valInfo); valuesInfo.add(valInfo); } else { AttrValueHistorical oldValueInfo = valuesHist.get(valInfo); AttrValueHistorical oldValueInfo = valuesInfo.get(index); if (oldValueInfo.isUpdate()) { /* if the value is already present @@ -582,7 +587,8 @@ */ if (changeNumber.newer(oldValueInfo.getValueUpdateTime())) { valuesHist.put(valInfo, valInfo); valuesInfo.remove(index); valuesInfo.add(valInfo); } builder.remove(addVal); } @@ -598,7 +604,8 @@ * and add our more recent one * let the operation process */ valuesHist.put(valInfo, valInfo); valuesInfo.remove(index); valuesInfo.add(valInfo); } else { opends/src/server/org/opends/server/replication/plugin/AttrHistoricalSingle.java
@@ -27,9 +27,8 @@ */ package org.opends.server.replication.plugin; import java.util.HashMap; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import org.opends.server.replication.common.ChangeNumber; import org.opends.server.types.Attribute; @@ -49,17 +48,13 @@ */ public class AttrHistoricalSingle extends AttrHistorical { /** Last time when the attribute was deleted. */ private ChangeNumber deleteTime = null; /** Last time when a value was added. */ private ChangeNumber addTime = null; /** Last added value. */ private AttributeValue value = null; private ChangeNumber deleteTime = null; // last time when the attribute was // deleted private ChangeNumber addTime = null; // last time when a value was added private AttributeValue value = null; // last added value /** * last operation applied. This is only used for multiple mods on the same * single valued attribute in the same modification. */ // last operation applied. This is only used for multiple mods on the same // single valued attribute in the same modification. private HistAttrModificationKey lastMod = null; /** @@ -75,18 +70,17 @@ * {@inheritDoc} */ @Override public Map<AttrValueHistorical, AttrValueHistorical> getValuesHistorical() public ArrayList<AttrValueHistorical> getValuesHistorical() { if (addTime == null) { return new HashMap<AttrValueHistorical,AttrValueHistorical>(0); return new ArrayList<AttrValueHistorical>(); } else { HashMap<AttrValueHistorical,AttrValueHistorical> values = new HashMap<AttrValueHistorical,AttrValueHistorical>(1); AttrValueHistorical val = new AttrValueHistorical(value, addTime, null); values.put(val, val); ArrayList<AttrValueHistorical> values = new ArrayList<AttrValueHistorical>(); values.add(new AttrValueHistorical(value, addTime, null)); return values; } } opends/src/server/org/opends/server/replication/plugin/EntryHistorical.java
@@ -23,7 +23,7 @@ * * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions Copyright 2011-2013 ForgeRock AS * Portions Copyright 2011-2012 ForgeRock AS */ package org.opends.server.replication.plugin; @@ -493,8 +493,7 @@ delAttr = true; } for (AttrValueHistorical attrValHist : attrHist.getValuesHistorical() .keySet()) for (AttrValueHistorical attrValHist : attrHist.getValuesHistorical()) { // Encode an attribute value String strValue; opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/AttrInfoTest.java
@@ -23,12 +23,10 @@ * * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions Copyright 2013 ForgeRock, AS. */ package org.opends.server.replication.plugin; import java.util.HashMap; import java.util.Map; import java.util.ArrayList; import org.opends.server.core.DirectoryServer; import org.opends.server.replication.ReplicationTestCase; @@ -91,15 +89,15 @@ // Check add(AttributeValue val, ChangeNumber CN) attrInfo1.add(att, updateTime); Map<AttrValueHistorical,AttrValueHistorical> values1 = attrInfo1.getValuesHistorical(); ArrayList<AttrValueHistorical> values1 = attrInfo1.getValuesHistorical(); assertTrue(values1.size() == 1); AttrValueHistorical valueInfo1 = new AttrValueHistorical(att, updateTime, null); assertTrue(values1.containsKey(valueInfo1)); assertTrue(values1.get(0).equals(valueInfo1)); // Check constructor with parameter AttrValueHistorical valueInfo2 = new AttrValueHistorical(att, updateTime, deleteTime); HashMap<AttrValueHistorical,AttrValueHistorical> values = new HashMap<AttrValueHistorical,AttrValueHistorical>(); values.put(valueInfo2, valueInfo2); ArrayList<AttrValueHistorical> values = new ArrayList<AttrValueHistorical>(); values.add(valueInfo2); AttrHistoricalMultiple attrInfo2 = new AttrHistoricalMultiple(deleteTime, updateTime, values); // Check equality @@ -108,14 +106,14 @@ // Check constructor with time parameter and not Value AttrHistoricalMultiple attrInfo3 = new AttrHistoricalMultiple(deleteTime, updateTime, null); attrInfo3.add(att, updateTime); Map<AttrValueHistorical,AttrValueHistorical> values3 = attrInfo3.getValuesHistorical(); ArrayList<AttrValueHistorical> values3 = attrInfo3.getValuesHistorical(); assertTrue(values3.size() == 1); valueInfo1 = new AttrValueHistorical(att, updateTime, null); assertTrue(values3.containsKey(valueInfo1)); assertTrue(values3.get(0).equals(valueInfo1)); // Check duplicate AttrHistoricalMultiple attrInfo4 = attrInfo3.duplicate(); Map<AttrValueHistorical,AttrValueHistorical> values4 = attrInfo4.getValuesHistorical(); ArrayList<AttrValueHistorical> values4 = attrInfo4.getValuesHistorical(); assertTrue(attrInfo4.getDeleteTime().compareTo(attrInfo3.getDeleteTime())==0); assertEquals(values4.size(), values3.size()); opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -23,7 +23,7 @@ * * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions Copyright 2011-2013 ForgeRock AS * Portions Copyright 2011-2012 ForgeRock AS */ package org.opends.server.replication.plugin; @@ -1395,13 +1395,14 @@ } /* * Check that the historical information attributes produced are * equivalent. (The attribute values may be in a different order.) * Check that the encoding decoding of historical information * works by encoding decoding and checking that the result is the same * as the initial value. */ entry.removeAttribute(historicalAttrType); entry.addAttribute(hist.encodeAndPurge(), null); EntryHistorical hist2 = EntryHistorical.newInstanceFromEntry(entry); assertEquals(hist2.encodeAndPurge(), hist.encodeAndPurge()); assertEquals(hist2.encodeAndPurge().toString(), hist.encodeAndPurge().toString()); return mods; }