Skip to content

Commit

Permalink
Issue #1899 - initial fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Feb 22, 2014
1 parent a0e3bb2 commit 94f3e63
Show file tree
Hide file tree
Showing 24 changed files with 159 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import com.orientechnologies.orient.core.config.OStorageConfiguration;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OCurrentStorageVersions;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ORecordOperation;
Expand Down Expand Up @@ -202,9 +202,8 @@ public void open(final String iUserName, final String iUserPassword, final Map<S

configuration = new OStorageConfiguration(this);
configuration.load();
// Can't be loaded earlier for remote storage
OBinarySerializerFactory.registerFactory(new OCurrentStorageVersions(configuration));

componentsFactory = new OCurrentStorageComponentsFactory(configuration);
} catch (Exception e) {
if (!OGlobalConfiguration.STORAGE_KEEP_OPEN.getValueAsBoolean())
close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.command.OCommandRequestText;
import com.orientechnologies.orient.core.config.OStorageConfiguration;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager;
import com.orientechnologies.orient.core.id.OClusterPosition;
import com.orientechnologies.orient.core.id.ORID;
Expand Down Expand Up @@ -185,7 +186,7 @@ public void close() {
try {
delegate.close();

Orient.instance().unregisterStorage(this);
Orient.instance().unregisterStorage(this);
} finally {
popSession();
}
Expand Down Expand Up @@ -216,7 +217,8 @@ public Set<String> getClusterNames() {
}

@Override
public void backup(OutputStream out, Map<String, Object> options, final Callable<Object> callable, final OCommandOutputListener iListener, int compressionLevel, int bufferSize) throws IOException {
public void backup(OutputStream out, Map<String, Object> options, final Callable<Object> callable,
final OCommandOutputListener iListener, int compressionLevel, int bufferSize) throws IOException {
throw new UnsupportedOperationException("backup");
}

Expand Down Expand Up @@ -667,6 +669,11 @@ public void beginResponse(final OChannelBinaryAsynchClient iNetwork) throws IOEx
}
}

@Override
public OCurrentStorageComponentsFactory getComponentsFactory() {
return delegate.getComponentsFactory();
}

public OLevel2RecordCache getLevel2Cache() {
return delegate.getLevel2Cache();
}
Expand Down Expand Up @@ -727,13 +734,13 @@ public String getType() {

@Override
public boolean equals(final Object iOther) {
if (iOther instanceof OStorageRemoteThread)
return iOther == this;
if (iOther instanceof OStorageRemoteThread)
return iOther == this;

if (iOther instanceof OStorageRemote)
return iOther == delegate;
if (iOther instanceof OStorageRemote)
return iOther == delegate;

return false;
return false;
}

protected void pushSession() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,37 @@
*/
@SuppressWarnings("serial")
public class OStorageConfiguration implements OSerializableStream {
public static final ORecordId CONFIG_RID = new OImmutableRecordId(0,
OClusterPositionFactory.INSTANCE.valueOf(0));
public static final ORecordId CONFIG_RID = new OImmutableRecordId(0,
OClusterPositionFactory.INSTANCE.valueOf(0));

public static final String DEFAULT_CHARSET = "UTF-8";
public static final String DEFAULT_CHARSET = "UTF-8";

public static final int CURRENT_VERSION = 7;
public static final int CURRENT_STORAGE_VERSION = 10;
public static final int CURRENT_VERSION = 7;
public static final int CURRENT_BINARY_FORMAT_VERSION = 10;

public int version = -1;
public int version = -1;
public String name;
public String schemaRecordId;
public String dictionaryRecordId;
public String indexMgrRecordId;

private String localeLanguage = Locale.getDefault().getLanguage();
private String localeCountry = Locale.getDefault().getCountry();
public String dateFormat = "yyyy-MM-dd";
public String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
private TimeZone timeZone = TimeZone.getDefault();
private String charset = DEFAULT_CHARSET;
private String localeLanguage = Locale.getDefault().getLanguage();
private String localeCountry = Locale.getDefault().getCountry();
public String dateFormat = "yyyy-MM-dd";
public String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
private TimeZone timeZone = TimeZone.getDefault();
private String charset = DEFAULT_CHARSET;

public int storageVersion;
public int binaryFormatVersion;

public OStorageSegmentConfiguration fileTemplate;

public List<OStorageClusterConfiguration> clusters = new ArrayList<OStorageClusterConfiguration>();
public List<OStorageDataConfiguration> dataSegments = new ArrayList<OStorageDataConfiguration>();
public List<OStorageClusterConfiguration> clusters = new ArrayList<OStorageClusterConfiguration>();
public List<OStorageDataConfiguration> dataSegments = new ArrayList<OStorageDataConfiguration>();

public OStorageTxConfiguration txSegment = new OStorageTxConfiguration();
public OStorageTxConfiguration txSegment = new OStorageTxConfiguration();

public List<OStorageEntryConfiguration> properties = new ArrayList<OStorageEntryConfiguration>();
public List<OStorageEntryConfiguration> properties = new ArrayList<OStorageEntryConfiguration>();

private transient Locale localeInstance;
private transient DecimalFormatSymbols unusualSymbols;
Expand All @@ -87,7 +87,7 @@ public OStorageConfiguration(final OStorage iStorage) {
storage = iStorage;
fileTemplate = new OStorageSegmentConfiguration();

storageVersion = CURRENT_STORAGE_VERSION;
binaryFormatVersion = CURRENT_BINARY_FORMAT_VERSION;
}

/**
Expand Down Expand Up @@ -267,11 +267,11 @@ else if (clusterType.equals("d")) {
}

if (version >= 7)
storageVersion = Integer.parseInt(read(values[index++]));
binaryFormatVersion = Integer.parseInt(read(values[index++]));
else if (version == 6)
storageVersion = 9;
binaryFormatVersion = 9;
else
storageVersion = 8;
binaryFormatVersion = 8;

return this;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ public byte[] toStream() throws OSerializationException {
for (OStorageEntryConfiguration e : properties)
entryToStream(buffer, e);

write(buffer, storageVersion);
write(buffer, binaryFormatVersion);

// PLAIN: ALLOCATE ENOUGHT SPACE TO REUSE IT EVERY TIME
buffer.append("|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ public OBinarySerializerFactory getSerializerFactory() {
return underlying.getSerializerFactory();
}

public void setSerializerFactory(OBinarySerializerFactory factory) {
underlying.setSerializerFactory(factory);
}

public OTransaction getTransaction() {
return underlying.getTransaction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.ODatabaseComplex;
import com.orientechnologies.orient.core.db.ODatabaseRecordWrapperAbstract;
import com.orientechnologies.orient.core.db.record.OCurrentStorageVersions;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.ODatabaseRecordTx;
import com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager;
import com.orientechnologies.orient.core.exception.OConcurrentModificationException;
Expand Down Expand Up @@ -482,7 +482,7 @@ public OSBTreeCollectionManager getSbTreeCollectionManager() {
}

@Override
public OCurrentStorageVersions getStorageVersions() {
public OCurrentStorageComponentsFactory getStorageVersions() {
return underlying.getStorageVersions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import com.orientechnologies.orient.core.db.ODatabaseLifecycleListener;
import com.orientechnologies.orient.core.db.ODatabaseListener;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OCurrentStorageVersions;
import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory;
import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.exception.ORecordNotFoundException;
Expand Down Expand Up @@ -110,14 +110,7 @@ public <DB extends ODatabase> DB open(final String iUserName, final String iUser
if (storage == null)
storage = Orient.instance().loadStorage(url);

final OStorageConfiguration configuration = storage.getConfiguration();
if (configuration != null) {
if (!(storage instanceof OStorageMemory))
configuration.load();
OBinarySerializerFactory.registerFactory(new OCurrentStorageVersions(configuration));
}

storage.open(iUserName, iUserPassword, properties);
storage.open(iUserName, iUserPassword, properties);

status = STATUS.OPEN;

Expand All @@ -141,7 +134,6 @@ public <DB extends ODatabase> DB create() {
if (storage == null)
storage = Orient.instance().loadStorage(url);

OBinarySerializerFactory.registerFactory(new OCurrentStorageVersions(storage.getConfiguration()));
storage.create(properties);

status = STATUS.OPEN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
package com.orientechnologies.orient.core.db.record;

import com.orientechnologies.orient.core.config.OStorageConfiguration;
import com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory;

/**
* @author Andrey Lomakin <a href="mailto:lomakin.andrey@gmail.com">Andrey Lomakin</a>
* @since 2/14/14
*/
public class OCurrentStorageVersions {
public final int storageVersion;
public class OCurrentStorageComponentsFactory {
public final int binaryFormatVersion;
public final OBinarySerializerFactory binarySerializerFactory;

public OCurrentStorageVersions(OStorageConfiguration configuration) {
this.storageVersion = configuration.storageVersion;
public OCurrentStorageComponentsFactory(OStorageConfiguration configuration) {
this.binaryFormatVersion = configuration.binaryFormatVersion;

binarySerializerFactory = OBinarySerializerFactory.create(binaryFormatVersion);
}

/**
* @return Whether class of is detected by cluster id or it is taken from documents serialized content.
* @since 1.7
*/
public boolean classesAreDetectedByClusterId() {
return storageVersion >= 10;
}

public boolean legacyStringSerializer() {
return storageVersion <= 8;
return binaryFormatVersion >= 10;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ public <REC extends ORecordInternal<?>> ORecordIteratorCluster<REC> browseCluste

public OSBTreeCollectionManager getSbTreeCollectionManager();

public OCurrentStorageVersions getStorageVersions();
public OCurrentStorageComponentsFactory getStorageVersions();

OBinarySerializerFactory getSerializerFactory();

void setSerializerFactory(OBinarySerializerFactory oBinarySerializerFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public abstract class ODatabaseRecordAbstract extends ODatabaseWrapperAbstract<O
private boolean mvcc;
private boolean validation;
private ODataSegmentStrategy dataSegmentStrategy = new ODefaultDataSegmentStrategy();
private OCurrentStorageVersions currentStorageVersions;
private OBinarySerializerFactory binarySerializerFactory;
private OCurrentStorageComponentsFactory componentsFactory;

public ODatabaseRecordAbstract(final String iURL, final byte iRecordType) {
super(new ODatabaseRaw(iURL));
Expand All @@ -141,9 +140,7 @@ public <DB extends ODatabase> DB open(final String iUserName, final String iUser

try {
super.open(iUserName, iUserPassword);

final OStorage storage = getStorage();
currentStorageVersions = new OCurrentStorageVersions(storage.getConfiguration());
componentsFactory = getStorage().getComponentsFactory();

sbTreeCollectionManager = new OSBTreeCollectionManagerProxy(this, getStorage().getResource(
OSBTreeCollectionManager.class.getSimpleName(), new Callable<OSBTreeCollectionManager>() {
Expand Down Expand Up @@ -220,9 +217,7 @@ public <DB extends ODatabase> DB create() {

try {
super.create();

final OStorage storage = getStorage();
currentStorageVersions = new OCurrentStorageVersions(storage.getConfiguration());
componentsFactory = getStorage().getComponentsFactory();

sbTreeCollectionManager = new OSBTreeCollectionManagerProxy(this, getStorage().getResource(
OSBTreeCollectionManager.class.getSimpleName(), new Callable<OSBTreeCollectionManager>() {
Expand Down Expand Up @@ -281,17 +276,12 @@ public OSBTreeCollectionManager call() throws Exception {

@Override
public OBinarySerializerFactory getSerializerFactory() {
return binarySerializerFactory;
}

@Override
public void setSerializerFactory(OBinarySerializerFactory factory) {
binarySerializerFactory = factory;
return componentsFactory.binarySerializerFactory;
}

@Override
public OCurrentStorageVersions getStorageVersions() {
return currentStorageVersions;
public OCurrentStorageComponentsFactory getStorageVersions() {
return componentsFactory;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class OWOWCache {
public static final long MAGIC_NUMBER = 0xFACB03FEL;

private final ConcurrentSkipListMap<GroupKey, WriteGroup> writeGroups = new ConcurrentSkipListMap<GroupKey, WriteGroup>();
private OBinarySerializer<String> stringSerializer;
private final OBinarySerializer<String> stringSerializer;

private Map<String, Long> nameIdMap;

Expand Down Expand Up @@ -125,6 +125,9 @@ public OWOWCache(boolean syncOnPageFlush, int pageSize, long groupTTL, OWriteAhe
this.cacheMaxSize = cacheMaxSize;
this.storageLocal = storageLocal;

final OBinarySerializerFactory binarySerializerFactory = storageLocal.getComponentsFactory().binarySerializerFactory;
this.stringSerializer = binarySerializerFactory.getObjectSerializer(OType.STRING);

if (checkMinSize && this.cacheMaxSize < MIN_CACHE_SIZE)
this.cacheMaxSize = MIN_CACHE_SIZE;

Expand All @@ -136,9 +139,6 @@ public long openFile(String fileName) throws IOException {
synchronized (syncObject) {
initNameIdMapping();

if (stringSerializer == null)
stringSerializer = OBinarySerializerFactory.getInstance().getObjectSerializer(OType.STRING);

Long fileId = nameIdMap.get(fileName);
OFileClassic fileClassic;
if (fileId == null)
Expand Down Expand Up @@ -711,10 +711,15 @@ public void delete() throws IOException {
doDeleteFile(fileId);

if (nameIdMapHolderFile != null) {
nameIdMapHolder.close();
if (nameIdMapHolderFile.exists()) {
nameIdMapHolder.close();

if (!nameIdMapHolderFile.delete())
throw new OStorageException("Can not delete disk cache file which contains name-id mapping.");
}

if (!nameIdMapHolderFile.delete())
throw new OStorageException("Can not delete disk cache file which contains name-id mapping.");
nameIdMapHolder = null;
nameIdMapHolderFile = null;
}
}

Expand Down
Loading

0 comments on commit 94f3e63

Please sign in to comment.