Skip to content

Commit

Permalink
Issue #4610 was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Jul 24, 2015
1 parent c65031e commit 7d92a6b
Show file tree
Hide file tree
Showing 25 changed files with 469 additions and 627 deletions.
Expand Up @@ -127,11 +127,13 @@ public void remove(final OChannelBinaryAsynchClient conn) {
try {
conn.unlock();
} catch (Exception e) {
OLogManager.instance().error(this, "Can not unlock connection lock", e);
}

try {
conn.close();
} catch (Exception e) {
OLogManager.instance().error(this, "Can not close connection", e);
}

final OResourcePool<String, OChannelBinaryAsynchClient> pool = connections.get(conn.getServerURL());
Expand Down Expand Up @@ -196,6 +198,7 @@ protected void closePool(final OResourcePool<String, OChannelBinaryAsynchClient>
try {
c.close();
} catch (Exception e) {
OLogManager.instance().error(this, "Can not close binary channel", e);
}
pool.close();
}
Expand Down
Expand Up @@ -1725,7 +1725,7 @@ protected void handleException(final OChannelBinaryAsynchClient iNetwork, final
try {
engine.getConnectionManager().remove(iNetwork);
} catch (Exception e) {
// IGNORE ANY EXCEPTION
OLogManager.instance().error(this, "Can not remove connection from connection manager.", e);
}
} else {
OLogManager.instance().warn(this, "Caught I/O errors, trying to reconnect (error: %s)",
Expand Down Expand Up @@ -1785,7 +1785,7 @@ protected void handleException(final OChannelBinaryAsynchClient iNetwork, final
return;

} catch (Throwable t) {
// DO NOTHING BUT CONTINUE IN THE LOOP
OLogManager.instance().error(this, "Error during exception handling", t);
}
}

Expand Down Expand Up @@ -1864,6 +1864,9 @@ protected String openRemoteDatabase() throws IOException {
engine.getConnectionManager().remove(network);
network = null;
}

OLogManager.instance().error(this, "Can not open database with url " + currentURL, e);

} catch (OException e) {
// PROPAGATE ANY OTHER ORIENTDB EXCEPTION
throw e;
Expand All @@ -1874,6 +1877,8 @@ protected String openRemoteDatabase() throws IOException {
engine.getConnectionManager().remove(network);
network = null;
}

OLogManager.instance().error(this, "Can not open database with url " + currentURL, e);
}
} while (engine.getConnectionManager().getAvailableConnections(currentURL) > 0);

Expand Down Expand Up @@ -2057,18 +2062,20 @@ protected OChannelBinaryAsynchClient getAvailableNetwork(final String iCurrentUR

String lastURL = iCurrentURL;
do {
Exception cause = null;
try {
network = engine.getConnectionManager().acquire(lastURL, clientConfiguration, connectionOptions, asynchEventListener);
} catch (Exception e) {
// CATCH ANY EXCEPTION AND TRY WITH A NEXT ONE IF ANY
OLogManager.instance().error(this, "Error during acquiring of connection to URL " + lastURL, e);
network = null;
cause = e;
}

if (network == null) {
lastURL = useNewServerURL(lastURL);
if (lastURL == null) {
parseServerURLs();
throw new OIOException("Cannot open a connection to remote server: " + iCurrentURL);
throw new OIOException("Cannot open a connection to remote server: " + iCurrentURL, cause);
}
} else if (!network.isConnected()) {
// DISCONNECTED NETWORK, GET ANOTHER ONE
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/orientechnologies/common/concur/lock/OAdaptiveLock.java 100644 → 100755
Expand Up @@ -20,6 +20,7 @@
package com.orientechnologies.common.concur.lock;

import com.orientechnologies.common.concur.OTimeoutException;
import com.orientechnologies.common.log.OLogManager;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -128,6 +129,7 @@ public void close() {
if (lock.isLocked())
lock.unlock();
} catch (Exception e) {
OLogManager.instance().error(this, "Can not unlock lock", e);
}
}

Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.common.concur.ONeedRetryException;
import com.orientechnologies.common.concur.resource.OPartitionedObjectPool;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.command.OCommandDistributedReplicateRequest;
Expand All @@ -38,6 +39,7 @@
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;
import com.orientechnologies.orient.core.storage.ORecordDuplicatedException;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation;
import com.orientechnologies.orient.core.tx.OTransaction;

import javax.script.*;
Expand Down Expand Up @@ -309,6 +311,7 @@ protected void waitForNextRetry() {
try {
Thread.sleep(new Random().nextInt(MAX_DELAY - 1) + 1);
} catch (InterruptedException e) {
OLogManager.instance().error(this, "Wait was interrupted", e);
}
}

Expand Down Expand Up @@ -404,6 +407,7 @@ private void executeSleep(String lastCommand) {
try {
Thread.sleep(Integer.parseInt(sleepTimeInMs));
} catch (InterruptedException e) {
OLogManager.instance().error(this, "Sleep was interrupted", e);
}
}

Expand Down
Expand Up @@ -140,23 +140,28 @@ protected void internalOpen() {

@Override
public void close() {
final PoolData data = poolData.get();
if (data.acquireCount == 0)
return;
if (poolData != null) {
final PoolData data = poolData.get();
if (data.acquireCount == 0)
return;

data.acquireCount--;
data.acquireCount--;

if (data.acquireCount > 0)
return;
if (data.acquireCount > 0)
return;

PoolPartition p = partition;
partition = null;
PoolPartition p = partition;
partition = null;

super.close();
data.acquiredDatabase = null;
super.close();

p.queue.offer(this);
p.acquiredConnections.decrementAndGet();
data.acquiredDatabase = null;

p.queue.offer(this);
p.acquiredConnections.decrementAndGet();
} else {
super.close();
}
}
}

Expand Down
Expand Up @@ -309,6 +309,7 @@ public OCacheEntry allocateNewPage(long fileId, OWriteCache writeCache) throws I
fileLock = fileLockManager.acquireExclusiveLock(fileId);
try {
final long filledUpTo = writeCache.getFilledUpTo(fileId);
assert filledUpTo >= 0;
cacheResult = doLoad(fileId, filledUpTo, false, true, writeCache);
} finally {
fileLockManager.releaseLock(fileLock);
Expand Down
Expand Up @@ -623,7 +623,7 @@ public long getFilledUpTo(long fileId) throws IOException {

filesLock.acquireReadLock();
try {
return files.get(intId).getFilledUpTo() / pageSize;
return files.get(intId).getFileSize() / pageSize;
} finally {
filesLock.releaseReadLock();
}
Expand Down Expand Up @@ -852,7 +852,7 @@ public OPageDataVerificationError[] checkStoredPages(OCommandOutputListener comm

long time = System.currentTimeMillis();

long filledUpTo = fileClassic.getFilledUpTo();
long filledUpTo = fileClassic.getFileSize();
fileIsCorrect = true;

for (long pos = 0; pos < filledUpTo; pos += pageSize) {
Expand Down Expand Up @@ -1092,9 +1092,8 @@ private void initNameIdMapping() throws IOException {
}

private OFileClassic createFile(String fileName) {
OFileClassic fileClassic = new OFileClassic();
String path = storageLocal.getVariableParser().resolveVariables(storageLocal.getStoragePath() + File.separator + fileName);
fileClassic.init(path, storageLocal.getMode());
OFileClassic fileClassic = new OFileClassic(path, storageLocal.getMode());
return fileClassic;
}

Expand Down Expand Up @@ -1212,13 +1211,13 @@ private OCachePointer cacheFileContent(long fileId, int intId, long pageIndex, b
else
lastLsn = new OLogSequenceNumber(-1, -1);

if (fileClassic.getFilledUpTo() >= endPosition) {
if (fileClassic.getFileSize() >= endPosition) {
fileClassic.read(startPosition, content, content.length - 2 * PAGE_PADDING, PAGE_PADDING);
final ODirectMemoryPointer pointer = new ODirectMemoryPointer(content);

dataPointer = new OCachePointer(pointer, lastLsn, fileId, pageIndex);
} else if (addNewPages) {
final int space = (int) (endPosition - fileClassic.getFilledUpTo());
final int space = (int) (endPosition - fileClassic.getFileSize());
fileClassic.allocateSpace(space);

addAllocatedSpace(space);
Expand Down
Expand Up @@ -24,25 +24,12 @@
import java.nio.channels.FileLock;

/**
* Interface to represent low-level File access. To use 3rd party implementations register them to the {@link OFileFactory}
* singleton instance.
* Interface to represent low-level File access.
*
* @author Luca Garulli (l.garulli--at--orientechnologies.com)
*
*/
public interface OFile {

/**
* Initializes the file passing name and open mode.
*
* @param iFileName
* File name
* @param iOpenMode
* Opening mode between "r" = read-only and "rw" for read write
* @return
*/
OFile init(String iFileName, String iOpenMode);

/**
* Opens the file.
*
Expand Down Expand Up @@ -72,12 +59,6 @@ public interface OFile {
*/
void delete() throws IOException;

void setSize(long iSize) throws IOException;

void writeHeaderLong(int iPosition, long iValue) throws IOException;

long readHeaderLong(int iPosition) throws IOException;

boolean synch() throws IOException;

void read(long iOffset, byte[] iDestBuffer, int iLenght) throws IOException;
Expand Down Expand Up @@ -114,14 +95,6 @@ public interface OFile {

void unlock() throws IOException;

/**
* Cuts bytes from the tail of the file reducing the filledUpTo size.
*
*
* @param iSizeToShrink
* @throws IOException
*/
void removeTail(long iSizeToShrink) throws IOException;

/**
* Shrink the file content (filledUpTo attribute only)
Expand All @@ -142,32 +115,14 @@ public interface OFile {

long allocateSpace(final long iSize) throws IOException;

long getFreeSpace();

long getFileSize();

long getFilledUpTo();

boolean canOversize(final int iRecordSize);

String toString();

long getMaxSize();

void setMaxSize(int maxSize);

int getIncrementSize();

void setIncrementSize(int incrementSize);

boolean isOpen();

boolean exists();

boolean isFailCheck();

void setFailCheck(boolean failCheck);

void read(long iOffset, byte[] iData, int iLength, int iArrayOffset) throws IOException;

void write(long iOffset, byte[] iData, int iSize, int iArrayOffset) throws IOException;
Expand Down

0 comments on commit 7d92a6b

Please sign in to comment.