Skip to content

Commit

Permalink
add basic locking logic for record and index keys separted to the sto…
Browse files Browse the repository at this point in the history
…rage locking
  • Loading branch information
tglman committed Oct 30, 2017
1 parent e61d4c7 commit 07c48dc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package com.orientechnologies.orient.server.distributed.impl;

import com.orientechnologies.common.concur.OOfflineNodeException;
import com.orientechnologies.common.concur.lock.OLockManager;
import com.orientechnologies.common.concur.lock.OOneEntryPerKeyLockManager;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.profiler.OAbstractProfiler;
Expand All @@ -31,7 +33,6 @@
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.exception.OSecurityAccessException;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
Expand Down Expand Up @@ -92,6 +93,16 @@ public class ODistributedDatabaseImpl implements ODistributedDatabase {
private final AtomicReference<ODistributedMomentum> filterByMomentum = new AtomicReference<ODistributedMomentum>();

private String localNodeName;
private OLockManager<ORID> recordLockManager = new OOneEntryPerKeyLockManager<>(true, -1, 1000);
private OLockManager<Object> indexKeyLockManager = new OOneEntryPerKeyLockManager<>(true, -1, 1000);

public OLockManager<ORID> getRecordLockManager() {
return recordLockManager;
}

public OLockManager<Object> getIndexKeyLockManager() {
return indexKeyLockManager;
}

public class ODistributedLock {
protected final ODistributedRequestId reqId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public synchronized void lock(ORID rid, long timeout) {
acquiredLocks.add(rid);
}

@Override
public void lockIndexKey(Object rid) {
throw new UnsupportedOperationException();
}

public ODistributedRequestId getReqId() {
return reqId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.orientechnologies.orient.server.distributed.ODistributedTxContext;
import com.orientechnologies.orient.server.distributed.task.ORemoteTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand All @@ -19,6 +20,8 @@ public class ONewDistributedTxContextImpl implements ODistributedTxContext {
private final ODistributedRequestId id;
private final OTransaction tx;
private final long startedOn;
private final List<ORID> lockedRids = new ArrayList<>();
private final List<Object> lockedKeys = new ArrayList<>();

public ONewDistributedTxContextImpl(ODistributedDatabaseImpl shared, ODistributedRequestId reqId, OTransaction tx) {
this.shared = shared;
Expand All @@ -29,13 +32,22 @@ public ONewDistributedTxContextImpl(ODistributedDatabaseImpl shared, ODistribute
}

@Override
public void lock(ORID rid) {
public void lockIndexKey(Object key) {
shared.getIndexKeyLockManager().acquireSharedLock(key);
lockedKeys.add(key);
}

@Override
public void lock(ORID rid) {
shared.getRecordLockManager().acquireExclusiveLock(rid);
lockedRids.add(rid);
}

@Override
public void lock(ORID rid, long timeout) {

//TODO: the timeout is only in the lock manager, this implementation may need evolution
shared.getRecordLockManager().acquireExclusiveLock(rid);
lockedRids.add(rid);
}

@Override
Expand Down Expand Up @@ -76,7 +88,12 @@ public void clearUndo() {

@Override
public void unlock() {

for (ORID lockedRid : lockedRids) {
shared.getRecordLockManager().releaseExclusiveLock(lockedRid);
}
for (Object lockedKey : lockedKeys) {
shared.getIndexKeyLockManager().releaseExclusiveLock(lockedKey);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.server.OServer;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

/**
* Distributed TX test against "plocal" protocol.
*/
public class DistributedSuperNodeTest extends AbstractServerClusterGraphTest {
@Test
@Ignore

This comment has been minimized.

Copy link
@decebal

decebal Oct 31, 2017

why?????

public void test() throws Exception {
final long timeout = OGlobalConfiguration.DISTRIBUTED_ATOMIC_LOCK_TIMEOUT.getValueAsLong();
OGlobalConfiguration.DISTRIBUTED_ATOMIC_LOCK_TIMEOUT.setValue(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface ODistributedTxContext {

void lock(ORID rid, long timeout);

void lockIndexKey(Object rid);

void addUndoTask(ORemoteTask undoTask);

ODistributedRequestId getReqId();
Expand Down

0 comments on commit 07c48dc

Please sign in to comment.