Skip to content

Commit

Permalink
further fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahshahid committed Oct 11, 2018
1 parent 5ca9cff commit 7bab066
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,13 @@ private static Object insertToRowLocation(GemFireContainer container,
}

if (oldValue instanceof WrapperRowLocationForTxn && insertedValue instanceof WrapperRowLocationForTxn
) {
WrapperRowLocationForTxn e1 = (WrapperRowLocationForTxn) oldValue;
&& oldValue.equals(insertedValue)) {
/*WrapperRowLocationForTxn e1 = (WrapperRowLocationForTxn) oldValue;
WrapperRowLocationForTxn e2 = (WrapperRowLocationForTxn) insertedValue;
if (e1.getTXId().equals(e2.getTXId()) && e1.getRegionEntry() == e2.getRegionEntry()) {
return insertedValue;
}
} */
return insertedValue;
}
RowLocation[] newValues = new RowLocation[2];
newValues[0] = oldValue;
Expand All @@ -528,6 +529,7 @@ private static Object insertToRowLocationArray(
numExistingValues + 1, 0.60f,
ObjectEqualsHashingStrategy.getInstance(), container
.getBaseContainer().getRegion().getRegionPerfStats());
boolean skipIfSameTxEntry = false;
for (int i = 0; i < numExistingValues; i++) {
// should not happen when a duplicate entry from both GII and create
// will be converted to an update by GFE and handled properly by
Expand All @@ -542,10 +544,25 @@ private static Object insertToRowLocationArray(
GemFireXDUtils.newDuplicateEntryViolation(
container.getQualifiedTableName(), existingValues[i],
insertedValue));
} else {
skipIfSameTxEntry = insertedValue instanceof WrapperRowLocationForTxn &&
existingValues[i] instanceof WrapperRowLocationForTxn &&
insertedValue.equals(existingValues[i]);
/*
if (insertedValue instanceof WrapperRowLocationForTxn) {
if (existingValues[i] instanceof WrapperRowLocationForTxn) {
skipIfSameTxEntry = ((WrapperRowLocationForTxn)existingValues[i]).getTXId().equals(
((WrapperRowLocationForTxn)insertedValue).getTXId()) &&
((WrapperRowLocationForTxn)existingValues[i]).getRegionEntry() ==
((WrapperRowLocationForTxn)insertedValue).getRegionEntry();
}
} */
}
set.add(existingValues[i]);
}
set.add(insertedValue);
if (!skipIfSameTxEntry) {
set.add(insertedValue);
}
return set;
}
else {
Expand All @@ -565,15 +582,18 @@ private static Object insertToRowLocationArray(
container.getQualifiedTableName(), existingValues[i],
insertedValue));
} else {
boolean isTxSame = false;
if (insertedValue instanceof WrapperRowLocationForTxn ) {
boolean isTxSame = insertedValue instanceof WrapperRowLocationForTxn &&
existingValues[i] instanceof WrapperRowLocationForTxn
&& insertedValue.equals(existingValues[i]);

/*if (insertedValue instanceof WrapperRowLocationForTxn ) {
if (existingValues[i] instanceof WrapperRowLocationForTxn) {
isTxSame = ((WrapperRowLocationForTxn)existingValues[i]).getTXId().equals(
((WrapperRowLocationForTxn)insertedValue).getTXId()) &&
((WrapperRowLocationForTxn)existingValues[i]).getRegionEntry() ==
((WrapperRowLocationForTxn)insertedValue).getRegionEntry();
}
}
} */
if (isTxSame) {
return existingValues;
}
Expand All @@ -597,19 +617,24 @@ private static Object insertToHashSet(GemFireContainer container, Object key,
final ConcurrentTHashSet<Object> set =
(ConcurrentTHashSet<Object>)oldValue;


Object oldRowLocObj;
if ((oldRowLocObj = set.addKey(insertedValue)) == null || isPutDML) {
return set;
}
assert oldRowLocObj.equals(insertedValue);
// should not happen when a duplicate entry from both GII and create
// will be converted to an update by GFE and handled properly by
// GfxdIndexManager#onEvent();
// can happen in case update is fired on index column updating to the
// old value itself
throw new IndexMaintenanceException(
GemFireXDUtils.newDuplicateEntryViolation(
container.getQualifiedTableName(), oldRowLocObj, insertedValue));
if (!(oldRowLocObj instanceof WrapperRowLocationForTxn && insertedValue instanceof WrapperRowLocationForTxn)) {
// should not happen when a duplicate entry from both GII and create
// will be converted to an update by GFE and handled properly by
// GfxdIndexManager#onEvent();
// can happen in case update is fired on index column updating to the
// old value itself
throw new IndexMaintenanceException(
GemFireXDUtils.newDuplicateEntryViolation(
container.getQualifiedTableName(), oldRowLocObj, insertedValue));
} else {
return set;
}
}

static final class ReplaceValue extends UpdateReplacementValue {
Expand Down Expand Up @@ -685,28 +710,45 @@ private static RowLocation[] replaceRowLocationArray(
// GfxdIndexManager#onEvent();
// can happen in case update is fired on index column updating to the
// old value itself

/*
boolean isTxSame = false;
if (insertedValue instanceof WrapperRowLocationForTxn ) {
/* if (existingValue instanceof RegionEntry) {
isTxSame = ((WrapperRowLocationForTxn)insertedValue).getRegionEntry() == existingValue;
} else*/ if (existingValue instanceof WrapperRowLocationForTxn) {
} else*/ /* if (existingValue instanceof WrapperRowLocationForTxn) {
isTxSame = ((WrapperRowLocationForTxn)existingValue).getTXId().equals(
((WrapperRowLocationForTxn)insertedValue).getTXId()) &&
((WrapperRowLocationForTxn)existingValue).getRegionEntry() ==
((WrapperRowLocationForTxn)insertedValue).getRegionEntry();
}
}
} */
boolean isTxSame = insertedValue instanceof WrapperRowLocationForTxn
&& existingValue instanceof WrapperRowLocationForTxn &&
insertedValue.equals(existingValue);

if (insertedValue != existingValue && !isTxSame) {
if (oldValue != existingValue) {
try {
newValues[++index] = existingValue;
} catch (ArrayIndexOutOfBoundsException ae) {
// throw back a proper exception for the case when value to be
// replaced is not found
throw new IndexMaintenanceException(
GemFireXDUtils.newOldValueNotFoundException(key, oldValue,
existingValues, container));



if (insertedValue != existingValue ) {
if (isTxSame) {
//do not add this value as we wil add inserted value to 0 position
foundOldValue = true;
} else if (oldValue != existingValue) {
if (oldValue instanceof TXEntryState &&
((TXEntryState)oldValue).getOriginalValue() == existingValue) {
//do not add this value as we wil add inserted value to 0 position
foundOldValue = true;
} else {
try {
newValues[++index] = existingValue;
} catch (ArrayIndexOutOfBoundsException ae) {
// throw back a proper exception for the case when value to be
// replaced is not found
throw new IndexMaintenanceException(
GemFireXDUtils.newOldValueNotFoundException(key, oldValue,
existingValues, container));
}
}
}
else if (!foundOldValue) {
Expand Down Expand Up @@ -746,10 +788,16 @@ private static ConcurrentTHashSet<Object> replaceInHashSet(
final ConcurrentTHashSet<Object> set =
(ConcurrentTHashSet<Object>)existingValue;

// TODO: Asif : How to conflate two WrapperRowLocationTxn? May be that situation does not arise?
if (set.replace(oldValue, insertedValue)) {
return set;
}
else {
if (oldValue instanceof TXEntryState ) {
if (set.replace(((TXEntryState)oldValue).getOriginalValue(), insertedValue)) {
return set;
}
}
// throw back a proper exception for the case when value to be
// replaced is not found
throw new IndexMaintenanceException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ public WrapperRowLocationForTxn(GfxdTXEntryState rowLocationToBeWrapped,
this.createdForUpdateOperation = forUpdateOp;
}


@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof WrapperRowLocationForTxn && this.actualRowLocation != null
&& ((WrapperRowLocationForTxn)obj).actualRowLocation != null) {
WrapperRowLocationForTxn that = (WrapperRowLocationForTxn) obj;
return this.actualRowLocation.equals(that.actualRowLocation);
} else {
return false;
}
}

@Override
public int hashCode() {
int h = 17;
// h = h * 37 + this.indexContainer.hashCode();
// h = h * 37 + this.indexKey.hashCode();
h = h * 37 + (this.actualRowLocation != null ? this.actualRowLocation.hashCode() : super.hashCode());
return h;
}

public boolean wasCreatedForUpdateOp() {
return this.createdForUpdateOperation;
}
Expand Down

0 comments on commit 7bab066

Please sign in to comment.