Skip to content

Commit

Permalink
Code observations were fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Oct 12, 2017
1 parent d7f1959 commit c8f7436
Show file tree
Hide file tree
Showing 79 changed files with 630 additions and 1,006 deletions.
Expand Up @@ -82,7 +82,6 @@
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;


/** /**
Expand Down Expand Up @@ -977,12 +976,11 @@ public void setDefaultClusterId(int defaultClusterId) {
this.defaultClusterId = defaultClusterId; this.defaultClusterId = defaultClusterId;
} }


public int addCluster(final String iClusterName, boolean forceListBased, final Object... iArguments) { public int addCluster(final String iClusterName, final Object... iArguments) {
return addCluster(iClusterName, -1, forceListBased, iArguments); return addCluster(iClusterName, -1, iArguments);
} }


public int addCluster(final String iClusterName, final int iRequestedId, final boolean forceListBased, public int addCluster(final String iClusterName, final int iRequestedId, final Object... iParameters) {
final Object... iParameters) {
OAddClusterRequest request = new OAddClusterRequest(iRequestedId, iClusterName); OAddClusterRequest request = new OAddClusterRequest(iRequestedId, iClusterName);
OAddClusterResponse response = networkOperationNoRetry(request, "Error on add new cluster"); OAddClusterResponse response = networkOperationNoRetry(request, "Error on add new cluster");
addNewClusterToConfiguration(response.getClusterId(), iClusterName); addNewClusterToConfiguration(response.getClusterId(), iClusterName);
Expand Down
Expand Up @@ -56,7 +56,6 @@
import com.orientechnologies.orient.core.metadata.OMetadata; import com.orientechnologies.orient.core.metadata.OMetadata;
import com.orientechnologies.orient.core.metadata.OMetadataDefault; import com.orientechnologies.orient.core.metadata.OMetadataDefault;
import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OImmutableClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OSchemaProxy; import com.orientechnologies.orient.core.metadata.schema.OSchemaProxy;
import com.orientechnologies.orient.core.metadata.security.*; import com.orientechnologies.orient.core.metadata.security.*;
Expand All @@ -69,9 +68,7 @@
import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializerFactory; import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializerFactory;
import com.orientechnologies.orient.core.sql.OCommandSQL; import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.executor.OResultSet; import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.parser.OLocalResultSetLifecycleDecorator;
import com.orientechnologies.orient.core.storage.*; import com.orientechnologies.orient.core.storage.*;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import com.orientechnologies.orient.core.storage.impl.local.OFreezableStorageComponent; import com.orientechnologies.orient.core.storage.impl.local.OFreezableStorageComponent;
import com.orientechnologies.orient.core.storage.impl.local.OMicroTransaction; import com.orientechnologies.orient.core.storage.impl.local.OMicroTransaction;
import com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException; import com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException;
Expand Down Expand Up @@ -922,13 +919,13 @@ public boolean isClosed() {
@Override @Override
public int addCluster(final String iClusterName, final Object... iParameters) { public int addCluster(final String iClusterName, final Object... iParameters) {
checkIfActive(); checkIfActive();
return getStorage().addCluster(iClusterName, false, iParameters); return getStorage().addCluster(iClusterName, iParameters);
} }


@Override @Override
public int addCluster(final String iClusterName, final int iRequestedId, final Object... iParameters) { public int addCluster(final String iClusterName, final int iRequestedId, final Object... iParameters) {
checkIfActive(); checkIfActive();
return getStorage().addCluster(iClusterName, iRequestedId, false, iParameters); return getStorage().addCluster(iClusterName, iRequestedId, iParameters);
} }


@Override @Override
Expand Down
Expand Up @@ -440,8 +440,6 @@ public void close(boolean flush) {
if (nullPointerSupport) if (nullPointerSupport)
readCache.closeFile(nullBucketFileId, flush, writeCache); readCache.closeFile(nullBucketFileId, flush, writeCache);


} catch (IOException e) {
throw OException.wrapException(new OSBTreeException("Error during close of index " + getName(), this), e);
} finally { } finally {
releaseExclusiveLock(); releaseExclusiveLock();
} }
Expand Down
Expand Up @@ -295,8 +295,6 @@ public void close(boolean flush) {
Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId); Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
try { try {
readCache.closeFile(fileId, flush, writeCache); readCache.closeFile(fileId, flush, writeCache);
} catch (IOException e) {
throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during close of index " + getName(), this), e);
} finally { } finally {
lock.unlock(); lock.unlock();
} }
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/com/orientechnologies/orient/core/storage/OAutoshardedStorage.java 100644 → 100755
Expand Up @@ -42,8 +42,6 @@ public interface OAutoshardedStorage {


/** /**
* Check if the distributed need to run only as local env * Check if the distributed need to run only as local env
*
* @return
*/ */
boolean isLocalEnv(); boolean isLocalEnv();
} }
11 changes: 1 addition & 10 deletions core/src/main/java/com/orientechnologies/orient/core/storage/OCluster.java 100644 → 100755
Expand Up @@ -28,7 +28,7 @@
public interface OCluster { public interface OCluster {


enum ATTRIBUTES { enum ATTRIBUTES {
NAME, USE_WAL, RECORD_GROW_FACTOR, RECORD_OVERFLOW_GROW_FACTOR, CONFLICTSTRATEGY, STATUS, ENCRYPTION NAME, RECORD_GROW_FACTOR, RECORD_OVERFLOW_GROW_FACTOR, CONFLICTSTRATEGY, STATUS, ENCRYPTION
} }


void configure(OStorage iStorage, int iId, String iClusterName, Object... iParameters) throws IOException; void configure(OStorage iStorage, int iId, String iClusterName, Object... iParameters) throws IOException;
Expand All @@ -54,7 +54,6 @@ enum ATTRIBUTES {
/** /**
* Truncates the cluster content. All the entries will be removed. * Truncates the cluster content. All the entries will be removed.
* *
* @throws IOException
*/ */
void truncate() throws IOException; void truncate() throws IOException;


Expand All @@ -64,8 +63,6 @@ enum ATTRIBUTES {
* @param recordType the type of record of which allocate the position. * @param recordType the type of record of which allocate the position.
* *
* @return the allocated position. * @return the allocated position.
*
* @throws IOException
*/ */
OPhysicalPosition allocatePosition(byte recordType) throws IOException; OPhysicalPosition allocatePosition(byte recordType) throws IOException;


Expand All @@ -78,8 +75,6 @@ enum ATTRIBUTES {
* @param allocatedPosition the eventual allocated position or null if there is no allocated position. * @param allocatedPosition the eventual allocated position or null if there is no allocated position.
* *
* @return the position where the record si created. * @return the position where the record si created.
*
* @throws IOException
*/ */
OPhysicalPosition createRecord(byte[] content, int recordVersion, byte recordType, OPhysicalPosition allocatedPosition) OPhysicalPosition createRecord(byte[] content, int recordVersion, byte recordType, OPhysicalPosition allocatedPosition)
throws IOException; throws IOException;
Expand All @@ -101,8 +96,6 @@ OPhysicalPosition createRecord(byte[] content, int recordVersion, byte recordTyp


/** /**
* Fills and return the PhysicalPosition object received as parameter with the physical position of logical record iPosition * Fills and return the PhysicalPosition object received as parameter with the physical position of logical record iPosition
*
* @throws IOException
*/ */
OPhysicalPosition getPhysicalPosition(OPhysicalPosition iPPosition) throws IOException; OPhysicalPosition getPhysicalPosition(OPhysicalPosition iPPosition) throws IOException;


Expand All @@ -124,8 +117,6 @@ OPhysicalPosition createRecord(byte[] content, int recordVersion, byte recordTyp


/** /**
* Returns the size of the records contained in the cluster in bytes. * Returns the size of the records contained in the cluster in bytes.
*
* @return
*/ */
long getRecordsSize() throws IOException; long getRecordsSize() throws IOException;


Expand Down
Expand Up @@ -47,6 +47,7 @@ public OClusterEntryIterator(final OCluster iCluster) {
positionsIndex = -1; positionsIndex = -1;
} }


@Override
public boolean hasNext() { public boolean hasNext() {
if (min == ORID.CLUSTER_POS_INVALID) if (min == ORID.CLUSTER_POS_INVALID)
return false; return false;
Expand All @@ -57,6 +58,7 @@ public boolean hasNext() {
return positionsToProcess.length != 0; return positionsToProcess.length != 0;
} }


@Override
public OPhysicalPosition next() { public OPhysicalPosition next() {
try { try {
if (positionsIndex == -1) { if (positionsIndex == -1) {
Expand All @@ -81,6 +83,7 @@ public OPhysicalPosition next() {
} }
} }


@Override
public void remove() { public void remove() {
throw new UnsupportedOperationException("remove"); throw new UnsupportedOperationException("remove");
} }
Expand Down
Expand Up @@ -29,7 +29,7 @@
import java.io.ObjectOutput; import java.io.ObjectOutput;


public class OPhysicalPosition implements OSerializableStream, Externalizable { public class OPhysicalPosition implements OSerializableStream, Externalizable {
public static final int binarySize = OBinaryProtocol.SIZE_LONG + OBinaryProtocol.SIZE_BYTE + OBinaryProtocol.SIZE_INT private static final int binarySize = OBinaryProtocol.SIZE_LONG + OBinaryProtocol.SIZE_BYTE + OBinaryProtocol.SIZE_INT
+ OBinaryProtocol.SIZE_INT; + OBinaryProtocol.SIZE_INT;
public long clusterPosition; public long clusterPosition;
public byte recordType; public byte recordType;
Expand All @@ -52,11 +52,7 @@ public OPhysicalPosition(final long iClusterPosition, final int iVersion) {
recordVersion = iVersion; recordVersion = iVersion;
} }


public static int binarySize() { private void copyTo(final OPhysicalPosition iDest) {
return binarySize;
}

public void copyTo(final OPhysicalPosition iDest) {
iDest.clusterPosition = clusterPosition; iDest.clusterPosition = clusterPosition;
iDest.recordType = recordType; iDest.recordType = recordType;
iDest.recordVersion = recordVersion; iDest.recordVersion = recordVersion;
Expand All @@ -72,6 +68,7 @@ public String toString() {
return "rid(?:" + clusterPosition + ") record(type:" + recordType + " size:" + recordSize + " v:" + recordVersion + ")"; return "rid(?:" + clusterPosition + ") record(type:" + recordType + " size:" + recordSize + " v:" + recordVersion + ")";
} }


@Override
public OSerializableStream fromStream(final byte[] iStream) throws OSerializationException { public OSerializableStream fromStream(final byte[] iStream) throws OSerializationException {
int pos = 0; int pos = 0;


Expand All @@ -89,8 +86,9 @@ public OSerializableStream fromStream(final byte[] iStream) throws OSerializatio
return this; return this;
} }


@Override
public byte[] toStream() throws OSerializationException { public byte[] toStream() throws OSerializationException {
final byte[] buffer = new byte[binarySize()]; final byte[] buffer = new byte[binarySize];
int pos = 0; int pos = 0;


OBinaryProtocol.long2bytes(clusterPosition, buffer, pos); OBinaryProtocol.long2bytes(clusterPosition, buffer, pos);
Expand Down Expand Up @@ -126,13 +124,15 @@ public int hashCode() {
return result; return result;
} }


@Override
public void writeExternal(final ObjectOutput out) throws IOException { public void writeExternal(final ObjectOutput out) throws IOException {
out.writeLong(clusterPosition); out.writeLong(clusterPosition);
out.writeByte(recordType); out.writeByte(recordType);
out.writeInt(recordSize); out.writeInt(recordSize);
out.writeInt(recordVersion); out.writeInt(recordVersion);
} }


@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
clusterPosition = in.readLong(); clusterPosition = in.readLong();
recordType = in.readByte(); recordType = in.readByte();
Expand Down
Expand Up @@ -48,21 +48,21 @@ public ORawBuffer(final byte[] buffer, final int version, final byte recordType)


/** /**
* Creates a new object by the record received. * Creates a new object by the record received.
*
* @param iRecord
*/ */
public ORawBuffer(final ORecord iRecord) { public ORawBuffer(final ORecord iRecord) {
this.buffer = iRecord.toStream(); this.buffer = iRecord.toStream();
this.version = iRecord.getVersion(); this.version = iRecord.getVersion();
this.recordType = ORecordInternal.getRecordType(iRecord); this.recordType = ORecordInternal.getRecordType(iRecord);
} }


@Override
public void readExternal(final ObjectInput iInput) throws IOException, ClassNotFoundException { public void readExternal(final ObjectInput iInput) throws IOException, ClassNotFoundException {
super.readExternal(iInput); super.readExternal(iInput);
version = iInput.readInt(); version = iInput.readInt();
recordType = iInput.readByte(); recordType = iInput.readByte();
} }


@Override
public void writeExternal(final ObjectOutput iOutput) throws IOException { public void writeExternal(final ObjectOutput iOutput) throws IOException {
super.writeExternal(iOutput); super.writeExternal(iOutput);
iOutput.writeInt(version); iOutput.writeInt(version);
Expand Down
Expand Up @@ -123,15 +123,14 @@ OStorageOperationResult<Integer> updateRecord(ORecordId iRecordId, boolean updat
* *
* @param iClusterName name of the cluster * @param iClusterName name of the cluster
*/ */
int addCluster(String iClusterName, boolean forceListBased, Object... iParameters); int addCluster(String iClusterName, Object... iParameters);


/** /**
* Add a new cluster into the storage. * Add a new cluster into the storage.
* * @param iClusterName name of the cluster
* @param iClusterName name of the cluster
* @param iRequestedId requested id of the cluster * @param iRequestedId requested id of the cluster
*/ */
int addCluster(String iClusterName, int iRequestedId, boolean forceListBased, Object... iParameters); int addCluster(String iClusterName, int iRequestedId, Object... iParameters);


boolean dropCluster(String iClusterName, final boolean iTruncate); boolean dropCluster(String iClusterName, final boolean iTruncate);


Expand Down
Expand Up @@ -25,8 +25,6 @@
import com.orientechnologies.common.exception.OException; import com.orientechnologies.common.exception.OException;
import com.orientechnologies.orient.core.Orient; import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.OStorageConfiguration; import com.orientechnologies.orient.core.config.OStorageConfiguration;
import com.orientechnologies.orient.core.db.OLiveQueryMonitor;
import com.orientechnologies.orient.core.db.OLiveQueryResultListener;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory; import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.exception.OStorageException; import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.record.ORecordVersionHelper; import com.orientechnologies.orient.core.record.ORecordVersionHelper;
Expand Down Expand Up @@ -67,10 +65,10 @@ public abstract class OStorageAbstract implements OStorage, OSharedContainer {
protected volatile OStorageConfiguration configuration; protected volatile OStorageConfiguration configuration;
protected volatile OCurrentStorageComponentsFactory componentsFactory; protected volatile OCurrentStorageComponentsFactory componentsFactory;
protected String name; protected String name;
protected AtomicLong version = new AtomicLong(); private final AtomicLong version = new AtomicLong();
protected volatile STATUS status = STATUS.CLOSED; protected volatile STATUS status = STATUS.CLOSED;


protected final OSharedContainerImpl sharedContainer = new OSharedContainerImpl(); private final OSharedContainerImpl sharedContainer = new OSharedContainerImpl();


public OStorageAbstract(final String name, final String iURL, final String mode) { public OStorageAbstract(final String name, final String iURL, final String mode) {
this.name = normalizeName(name); this.name = normalizeName(name);
Expand Down Expand Up @@ -105,36 +103,45 @@ protected String normalizeName(String name) {
} }
} }


@Override
public abstract OCluster getClusterByName(final String iClusterName); public abstract OCluster getClusterByName(final String iClusterName);


@Override
public OStorage getUnderlying() { public OStorage getUnderlying() {
return this; return this;
} }


@Override
public OStorageConfiguration getConfiguration() { public OStorageConfiguration getConfiguration() {
return configuration; return configuration;
} }


@Override
public boolean isClosed() { public boolean isClosed() {
return status == STATUS.CLOSED; return status == STATUS.CLOSED;
} }


@Override
public boolean checkForRecordValidity(final OPhysicalPosition ppos) { public boolean checkForRecordValidity(final OPhysicalPosition ppos) {
return ppos != null && !ORecordVersionHelper.isTombstone(ppos.recordVersion); return ppos != null && !ORecordVersionHelper.isTombstone(ppos.recordVersion);
} }


@Override
public String getName() { public String getName() {
return name; return name;
} }


@Override
public String getURL() { public String getURL() {
return url; return url;
} }


@Override
public void close() { public void close() {
close(false, false); close(false, false);
} }


@Override
public void close(final boolean iForce, boolean onDelete) { public void close(final boolean iForce, boolean onDelete) {
sharedContainer.clearResources(); sharedContainer.clearResources();
} }
Expand All @@ -157,14 +164,17 @@ public <T> T getResource(String iName, Callable<T> iCallback) {
/** /**
* Returns current storage's version as serial. * Returns current storage's version as serial.
*/ */
@Override
public long getVersion() { public long getVersion() {
return version.get(); return version.get();
} }


@Override
public boolean dropCluster(final String iClusterName, final boolean iTruncate) { public boolean dropCluster(final String iClusterName, final boolean iTruncate) {
return dropCluster(getClusterIdByName(iClusterName), iTruncate); return dropCluster(getClusterIdByName(iClusterName), iTruncate);
} }


@Override
public long countRecords() { public long countRecords() {
long tot = 0; long tot = 0;


Expand All @@ -175,6 +185,7 @@ public long countRecords() {
return tot; return tot;
} }


@Override
public <V> V callInLock(final Callable<V> iCallable, final boolean iExclusiveLock) { public <V> V callInLock(final Callable<V> iCallable, final boolean iExclusiveLock) {
stateLock.acquireReadLock(); stateLock.acquireReadLock();
try { try {
Expand All @@ -195,6 +206,7 @@ public String toString() {
return url != null ? url : "?"; return url != null ? url : "?";
} }


@Override
public STATUS getStatus() { public STATUS getStatus() {
return status; return status;
} }
Expand Down
Expand Up @@ -26,7 +26,6 @@
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import java.util.Arrays;


/** /**
* This class represent CRUD operation result RET is the actual result Stores addition information about command execution process * This class represent CRUD operation result RET is the actual result Stores addition information about command execution process
Expand Down

0 comments on commit c8f7436

Please sign in to comment.