Skip to content

Commit

Permalink
transaction management refactored for avoid entries copy
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 30, 2015
1 parent f3c5464 commit fb3d44a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
Expand Up @@ -1302,27 +1302,24 @@ public void commit(final OTransaction clientTx, Runnable callback) {
makeStorageDirty();
startStorageTx(clientTx);

final List<ORecordOperation> tmpEntries = new ArrayList<ORecordOperation>();
final Iterable<ORecordOperation> entries = (Iterable<ORecordOperation>) clientTx.getAllRecordEntries();

for (ORecordOperation txEntry : clientTx.getAllRecordEntries())
tmpEntries.add(txEntry);

for (ORecordOperation txEntry : tmpEntries) {
for (ORecordOperation txEntry : entries) {
if (txEntry.type == ORecordOperation.CREATED || txEntry.type == ORecordOperation.UPDATED) {
final ORecord record = txEntry.getRecord();
if (record instanceof ODocument)
((ODocument) record).validate();
}
}

for (ORecordOperation txEntry : tmpEntries) {
for (ORecordOperation txEntry : entries) {
if (txEntry.getRecord().isDirty()) {
if (txEntry.type == ORecordOperation.CREATED)
saveNew(txEntry, clientTx);
}
}

for (ORecordOperation txEntry : tmpEntries) {
for (ORecordOperation txEntry : entries) {
if (txEntry.type != ORecordOperation.CREATED)
// COMMIT ALL THE SINGLE ENTRIES ONE BY ONE
commitEntry(clientTx, txEntry);
Expand All @@ -1333,7 +1330,7 @@ public void commit(final OTransaction clientTx, Runnable callback) {

endStorageTx();

OTransactionAbstract.updateCacheFromEntries(clientTx, clientTx.getAllRecordEntries(), true);
OTransactionAbstract.updateCacheFromEntries(clientTx, entries, true);

} catch (IOException ioe) {
makeRollback(clientTx, ioe);
Expand Down Expand Up @@ -2123,7 +2120,7 @@ public void saveNew(ORecordOperation txEntry, OTransaction tx) throws IOExceptio
nextToInspect = (ORecord) oIdentifiable;
break;
} else {
nextToInspect = oIdentifiable.getRecord();
nextToInspect = tx.getRecord(oIdentifiable.getIdentity());
if (nextToInspect.getIdentity().isNew())
break;
else
Expand Down
Expand Up @@ -451,9 +451,6 @@ public void addRecord(final ORecord iRecord, final byte iStatus, final String iC
}

try {
if (iRecord.getIdentity().isTemporary())
temp2persistent.put(iRecord.getIdentity().copy(), iRecord);

final ORecordId rid = (ORecordId) iRecord.getIdentity();

if (!rid.isValid()) {
Expand Down Expand Up @@ -486,7 +483,7 @@ public void addRecord(final ORecord iRecord, final byte iStatus, final String iC
if (!(rid.isTemporary() && iStatus != ORecordOperation.CREATED)) {
// NEW ENTRY: JUST REGISTER IT
txEntry = new ORecordOperation(iRecord, iStatus);
allEntries.put(rid, txEntry);
allEntries.put(rid.copy(), txEntry);
}
} else {
// UPDATE PREVIOUS STATUS
Expand Down
Expand Up @@ -57,7 +57,7 @@ public abstract class OTransactionRealAbstract extends OTransactionAbstract {
* USE THIS AS RESPONSE TO REPORT A DELETED RECORD IN TX
*/
public static final ORecord DELETED_RECORD = new ORecordBytes();
protected Map<ORID, ORecord> temp2persistent = new HashMap<ORID, ORecord>();
protected Map<ORID, ORID> updatedRids = new HashMap<ORID, ORID>();
protected Map<ORID, ORecordOperation> allEntries = new HashMap<ORID, ORecordOperation>();
protected Map<String, OTransactionIndexChanges> indexEntries = new LinkedHashMap<String, OTransactionIndexChanges>();
protected Map<ORID, List<OTransactionRecordIndexOperation>> recordIndexOperations = new HashMap<ORID, List<OTransactionRecordIndexOperation>>();
Expand Down Expand Up @@ -126,7 +126,7 @@ public void close() {
}

changedDocuments.clear();
temp2persistent.clear();
updatedRids.clear();
allEntries.clear();
indexEntries.clear();
recordIndexOperations.clear();
Expand Down Expand Up @@ -166,16 +166,12 @@ public ORecordOperation getRecordEntry(ORID rid) {
if (e != null)
return e;

if (rid.isTemporary()) {
final ORecord record = temp2persistent.get(rid);
if (record != null && !record.getIdentity().equals(rid))
rid = record.getIdentity();
if(!updatedRids.isEmpty()){
ORID r = updatedRids.get(rid);
if(r != null)
return allEntries.get(r);
}

e = allEntries.get(rid);
if (e != null)
return e;

return null;
}

Expand Down Expand Up @@ -347,8 +343,7 @@ public void updateIdentityAfterCommit(final ORID oldRid, final ORID newRid) {

final ORecordOperation rec = getRecordEntry(oldRid);
if (rec != null) {
if (allEntries.remove(oldRid) != null)
allEntries.put(newRid, rec);
updatedRids.put(newRid,oldRid);

if (!rec.getRecord().getIdentity().equals(newRid)) {
ORecordInternal.onBeforeIdentityChanged(rec.getRecord());
Expand Down Expand Up @@ -423,7 +418,7 @@ protected ODocument serializeIndexChangeEntry(OTransactionIndexChangesPerKey ent
changeDoc.field("o", e.operation.ordinal());

if (e.value instanceof ORecord && e.value.getIdentity().isNew()) {
final ORecord saved = temp2persistent.get(e.value.getIdentity());
final ORecord saved = getRecord(e.value.getIdentity());
if (saved != null)
e.value = saved;
else
Expand Down

0 comments on commit fb3d44a

Please sign in to comment.