Skip to content

Commit

Permalink
Issue #4387 is fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Jun 23, 2015
1 parent eff174e commit 1354a1e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 20 deletions.
Expand Up @@ -16,76 +16,122 @@
package com.orientechnologies.orient.core.storage.impl.local.paginated.wal; package com.orientechnologies.orient.core.storage.impl.local.paginated.wal;


import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;


import com.orientechnologies.common.serialization.types.OLongSerializer; import com.orientechnologies.common.serialization.types.OLongSerializer;
import com.orientechnologies.common.types.OModifiableLong;
import com.orientechnologies.orient.core.OOrientListenerAbstract;
import com.orientechnologies.orient.core.Orient;


/** /**
* @author Andrey Lomakin * @author Andrey Lomakin
* @since 06.06.13 * @since 06.06.13
*/ */
public class OOperationUnitId { public class OOperationUnitId {
public static final int SERIALIZED_SIZE = 2 * OLongSerializer.LONG_SIZE; private static final AtomicLong sharedId = new AtomicLong();

private static volatile ThreadLocal<OModifiableLong> localId = new ThreadLocal<OModifiableLong>();
private static volatile ThreadLocal<OModifiableLong> sharedIdCopy = new ThreadLocal<OModifiableLong>();

public static final int SERIALIZED_SIZE = 2 * OLongSerializer.LONG_SIZE;

static {
Orient.instance().registerListener(new OOrientListenerAbstract() {
@Override
public void onStartup() {
if (localId == null)
localId = new ThreadLocal<OModifiableLong>();

if (sharedIdCopy == null)
sharedIdCopy = new ThreadLocal<OModifiableLong>();
}

@Override
public void onShutdown() {
localId = null;
sharedIdCopy = null;
}
});
}

private long lId;
private long sId;


private UUID uuid; public OOperationUnitId(long lId, long sId) {
this.lId = lId;
this.sId = sId;
}


public static OOperationUnitId generateId() { public static OOperationUnitId generateId() {
OOperationUnitId operationUnitId = new OOperationUnitId(); OOperationUnitId operationUnitId = new OOperationUnitId();
operationUnitId.uuid = UUID.randomUUID();
OModifiableLong lId = localId.get();
if (lId == null) {
lId = new OModifiableLong();
localId.set(lId);
}
lId.increment();

OModifiableLong sId = sharedIdCopy.get();
if (sId == null) {
sId = new OModifiableLong(sharedId.incrementAndGet());
sharedIdCopy.set(sId);
}

operationUnitId.lId = lId.getValue();
operationUnitId.sId = sId.getValue();


return operationUnitId; return operationUnitId;
} }


public OOperationUnitId() { public OOperationUnitId() {
} }


public OOperationUnitId(UUID uuid) {
this.uuid = uuid;
}

public int toStream(byte[] content, int offset) { public int toStream(byte[] content, int offset) {
OLongSerializer.INSTANCE.serializeNative(uuid.getMostSignificantBits(), content, offset); OLongSerializer.INSTANCE.serializeNative(sId, content, offset);
offset += OLongSerializer.LONG_SIZE; offset += OLongSerializer.LONG_SIZE;


OLongSerializer.INSTANCE.serializeNative(uuid.getLeastSignificantBits(), content, offset); OLongSerializer.INSTANCE.serializeNative(lId, content, offset);
offset += OLongSerializer.LONG_SIZE; offset += OLongSerializer.LONG_SIZE;


return offset; return offset;
} }


public int fromStream(byte[] content, int offset) { public int fromStream(byte[] content, int offset) {
long most = OLongSerializer.INSTANCE.deserializeNative(content, offset); sId = OLongSerializer.INSTANCE.deserializeNative(content, offset);
offset += OLongSerializer.LONG_SIZE; offset += OLongSerializer.LONG_SIZE;


long least = OLongSerializer.INSTANCE.deserializeNative(content, offset); lId = OLongSerializer.INSTANCE.deserializeNative(content, offset);
offset += OLongSerializer.LONG_SIZE; offset += OLongSerializer.LONG_SIZE;


uuid = new UUID(most, least);

return offset; return offset;
} }


@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o)
return true; return true;
if (o == null || getClass() != o.getClass()) if (!(o instanceof OOperationUnitId))
return false; return false;


OOperationUnitId that = (OOperationUnitId) o; OOperationUnitId that = (OOperationUnitId) o;


if (!uuid.equals(that.uuid)) if (lId != that.lId)
return false; return false;


return true; return sId == that.sId;

} }


@Override @Override
public int hashCode() { public int hashCode() {
return uuid.hashCode(); int result = (int) (lId ^ (lId >>> 32));
result = 31 * result + (int) (sId ^ (sId >>> 32));
return result;
} }


@Override @Override
public String toString() { public String toString() {
return "OOperationUnitId{" + "uuid=" + uuid + "} "; return "OOperationUnitId{" + "lId=" + lId + ", sId=" + sId + '}';
} }
} }
Expand Up @@ -50,7 +50,6 @@ public abstract class OTransactionRealAbstract extends OTransactionAbstract {
* USE THIS AS RESPONSE TO REPORT A DELETED RECORD IN TX * USE THIS AS RESPONSE TO REPORT A DELETED RECORD IN TX
*/ */
public static final ORecordFlat DELETED_RECORD = new ORecordFlat(); public static final ORecordFlat DELETED_RECORD = new ORecordFlat();
private final OOperationUnitId operationUnitId;
protected Map<ORID, ORecord> temp2persistent = new HashMap<ORID, ORecord>(); protected Map<ORID, ORecord> temp2persistent = new HashMap<ORID, ORecord>();
protected Map<ORID, ORecordOperation> allEntries = new HashMap<ORID, ORecordOperation>(); protected Map<ORID, ORecordOperation> allEntries = new HashMap<ORID, ORecordOperation>();
protected Map<ORID, ORecordOperation> recordEntries = new LinkedHashMap<ORID, ORecordOperation>(); protected Map<ORID, ORecordOperation> recordEntries = new LinkedHashMap<ORID, ORecordOperation>();
Expand Down Expand Up @@ -83,7 +82,6 @@ public OTransactionRecordIndexOperation(String index, Object key, OPERATION oper
protected OTransactionRealAbstract(ODatabaseDocumentTx database, int id) { protected OTransactionRealAbstract(ODatabaseDocumentTx database, int id) {
super(database); super(database);
this.id = id; this.id = id;
this.operationUnitId = OOperationUnitId.generateId();
} }


@Override @Override
Expand Down

0 comments on commit 1354a1e

Please sign in to comment.