Skip to content

Commit

Permalink
#302 Prepare new protocol and tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoraka committed Jan 13, 2018
1 parent eaf76e6 commit c796ff7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,39 +106,36 @@ public void stop() {
}

@Override
public boolean lockForFile(String filename, String owner, int lockCount) throws InterruptedException {
public boolean lockForFile(String filename, String owner, int remoteLockCount)
throws InterruptedException {

//TODO: why lock count is for remote locks only?

// if (isIsolated() && lockCount > 1) {
// return false;
// }
if (isIsolated() && remoteLockCount > 0) {
return false;
}

// lock local file if possible
// lock local file
if (!lockFile(filename, owner)) {
return false;
}

// if (isIsolated()) {
// return true;
// }

// remote locking
log.debug("Locking {} nodes {}...", lockCount, idString);
log.debug("Locking {} nodes {}...", remoteLockCount, idString);
//TODO: unlocking looks unsafe
lockingLock.lockInterruptibly();

final int retryCount = 2;
for (int i = 0; i <= retryCount; i++) {

String id = sendLockRequest(filename, owner);
long successLocks = getLockResponse(id, lockCount);
final long successLocks = getLockResponse(id, remoteLockCount);

if (successLocks == lockCount) {
if (successLocks == remoteLockCount) {
incSequence();
log.debug("Remote locking success {}.", idString);
lockingLock.unlock();

return true;
} else if (successLocks > (lockCount / 2)) {
} else if (successLocks > (remoteLockCount / 2)) {
sendForceUnlockRequest(filename, owner);
} else {
break;
Expand Down Expand Up @@ -171,8 +168,7 @@ private void sendForceUnlockRequest(String filename, String owner) {
}

private long getLockResponse(String messageId, int lockCount) {
return responseClient.getResponseWaitSize(
messageId, maxResponseTime, lockCount)
return responseClient.getResponseWaitSize(messageId, maxResponseTime, lockCount)
.orElseGet(ReplicationMessageList::new)
.stream()
.filter(message -> message.getReplicationStatus() == ReplicationStatus.READY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public int neighbourCount() {
return neighbours.size();
}

public int nodeCount() {
return neighbourCount() + 1;
}

@Override
public void saveFile(FileMessage message) throws FileServiceException {
log.debug("Save {}: {}", idString, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public interface RemoteLock extends ServiceStatus {
void stop();

/**
* Locks a file with a given count and return a result.
* Locks a file on a given remote node count nodes. Local file is locked too.
*
* @param filename the filename
* @param owner the owner
* @param lockCount the lock count
* @param remoteLockCount the remote lock count
* @return the locking result
* @throws InterruptedException if locking is interrupted
*/
boolean lockForFile(String filename, String owner, int lockCount) throws InterruptedException;
boolean lockForFile(String filename, String owner, int remoteLockCount) throws InterruptedException;

/**
* Unlocks a file.
Expand Down

0 comments on commit c796ff7

Please sign in to comment.