Skip to content

Commit

Permalink
fixed bug in multithread multiclient delete of a record, issue #4940
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Sep 9, 2015
1 parent 2f8fa1d commit 21b4e43
Showing 1 changed file with 21 additions and 16 deletions.
Expand Up @@ -19,15 +19,17 @@
*/
package com.orientechnologies.orient.server.tx;

import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ORecordLazyList;
import com.orientechnologies.orient.core.db.record.ORecordOperation;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.exception.ORecordNotFoundException;
import com.orientechnologies.orient.core.exception.OSerializationException;
import com.orientechnologies.orient.core.exception.OTransactionAbortedException;
import com.orientechnologies.orient.core.exception.OTransactionException;
import com.orientechnologies.orient.core.exception.*;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.index.OCompositeKey;
Expand All @@ -41,20 +43,12 @@
import com.orientechnologies.orient.core.tx.OTransactionOptimistic;
import com.orientechnologies.orient.core.tx.OTransactionRealAbstract;
import com.orientechnologies.orient.core.version.ORecordVersion;
import com.orientechnologies.orient.core.version.OSimpleVersion;
import com.orientechnologies.orient.core.version.OVersionFactory;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelBinary;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryProtocol;
import com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class OTransactionOptimisticProxy extends OTransactionOptimistic {
private final Map<ORID, ORecordOperation> tempEntries = new LinkedHashMap<ORID, ORecordOperation>();
private final Map<ORecordId, ORecord> createdRecords = new HashMap<ORecordId, ORecord>();
Expand All @@ -77,6 +71,8 @@ public OTransactionOptimisticProxy(final ODatabaseDocumentTx iDatabase, final OC
@Override
public void begin() {
super.begin();
// Needed for keep the exception and insure that all data is read from the socket.
OException toThrow = null;

try {
setUsingLog(channel.readByte() == 1);
Expand All @@ -93,8 +89,8 @@ public void begin() {

switch (recordStatus) {
case ORecordOperation.CREATED:
oNetworkProtocolBinary.fillRecord(rid, channel.readBytes(), OVersionFactory.instance().createVersion(),
entry.getRecord(), database);
oNetworkProtocolBinary.fillRecord(rid, channel.readBytes(), OVersionFactory.instance().createVersion(), entry.getRecord(),
database);

// SAVE THE RECORD TO RETRIEVE THEM FOR THE NEW RID TO SEND BACK TO THE REQUESTER
createdRecords.put(rid.copy(), entry.getRecord());
Expand All @@ -111,7 +107,12 @@ public void begin() {
case ORecordOperation.DELETED:
// LOAD RECORD TO BE SURE IT HASN'T BEEN DELETED BEFORE + PROVIDE CONTENT FOR ANY HOOK
final ORecord rec = rid.getRecord();
ORecordInternal.setVersion(rec, channel.readVersion().getCounter());
ORecordVersion deleteVersion = channel.readVersion();
if (rec == null)
toThrow = new OConcurrentModificationException(rid.getIdentity(), new OSimpleVersion(-1), deleteVersion,
ORecordOperation.DELETED);

ORecordInternal.setVersion(rec, deleteVersion.getCounter());
entry.setRecord(rec);
break;

Expand All @@ -123,10 +124,14 @@ public void begin() {
tempEntries.put(entry.getRecord().getIdentity(), entry);
}

if (toThrow != null)
throw toThrow;

if (lastTxStatus == -1)
// ABORT TX
throw new OTransactionAbortedException("Transaction aborted by the client");


final ODocument remoteIndexEntries = new ODocument(channel.readBytes());
fillIndexOperations(remoteIndexEntries);

Expand Down

0 comments on commit 21b4e43

Please sign in to comment.