Skip to content

Commit

Permalink
Prjhub issue #5687 was fixed, but tests still need to be added.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Dec 8, 2015
1 parent 0d271e6 commit c0a2263
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 76 deletions.
Expand Up @@ -26,6 +26,7 @@
import com.orientechnologies.orient.core.OConstants; import com.orientechnologies.orient.core.OConstants;
import com.orientechnologies.orient.core.Orient; import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.cache.ORecordCacheWeakRefs; import com.orientechnologies.orient.core.cache.ORecordCacheWeakRefs;
import com.orientechnologies.orient.core.engine.local.OEngineLocalPaginated;
import com.orientechnologies.orient.core.metadata.OMetadataDefault; import com.orientechnologies.orient.core.metadata.OMetadataDefault;
import com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary; import com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary;
import com.orientechnologies.orient.core.storage.cache.local.O2QCache; import com.orientechnologies.orient.core.storage.cache.local.O2QCache;
Expand Down Expand Up @@ -85,7 +86,27 @@ public enum OGlobalConfiguration {
"Minimal amount of time (in seconds), since the last System.gc(), when called after tree optimization.", Long.class, 600), "Minimal amount of time (in seconds), since the last System.gc(), when called after tree optimization.", Long.class, 600),


// STORAGE // STORAGE
DISK_CACHE_SIZE("storage.diskCache.bufferSize", "Size of disk buffer in megabytes.", Integer.class, 4 * 1024), DISK_CACHE_PINNED_PAGES("storage.diskCache.pinnedPages", "Maximum amount of pinned pages which may be contained in cache,"
+ " if this percent is reached next pages will be left in unpinned state. You can not set value more than 50", Integer.class,
20, false),

DISK_CACHE_SIZE("storage.diskCache.bufferSize", "Size of disk buffer in megabytes, disk size may be changed at runtime, "
+ "but if does not enough to contain all pinned pages exception will be thrown.", Integer.class, 4 * 1024,
new OConfigurationChangeCallback() {
@Override
public void change(Object currentValue, Object newValue) {
final OEngineLocalPaginated engineLocalPaginated = (OEngineLocalPaginated) Orient.instance()
.getEngine(OEngineLocalPaginated.NAME);

if (engineLocalPaginated == null) {
OLogManager.instance().error(this,
"Can not change cache size in runtime because storage engine " + OEngineLocalPaginated.NAME
+ " was not registered");
} else {
engineLocalPaginated.changeCacheSize(((Integer) (newValue)) * 1024L * 1024L);
}
}
}),


DISK_WRITE_CACHE_PART("storage.diskCache.writeCachePart", "Percentage of disk cache, which is used as write cache", Integer.class, DISK_WRITE_CACHE_PART("storage.diskCache.writeCachePart", "Percentage of disk cache, which is used as write cache", Integer.class,
15), 15),
Expand Down Expand Up @@ -692,11 +713,11 @@ public void change(final Object iCurrentValue, final Object iNewValue) {
private final String key; private final String key;
private final Object defValue; private final Object defValue;
private final Class<?> type; private final Class<?> type;
private Object value = null; private volatile Object value = null;
private String description; private final String description;
private OConfigurationChangeCallback changeCallback = null; private final OConfigurationChangeCallback changeCallback;
private Boolean canChangeAtRuntime; private final Boolean canChangeAtRuntime;
private boolean hidden = false; private final boolean hidden;


// AT STARTUP AUTO-CONFIG // AT STARTUP AUTO-CONFIG
static { static {
Expand All @@ -706,7 +727,12 @@ public void change(final Object iCurrentValue, final Object iNewValue) {


OGlobalConfiguration(final String iKey, final String iDescription, final Class<?> iType, final Object iDefValue, OGlobalConfiguration(final String iKey, final String iDescription, final Class<?> iType, final Object iDefValue,
final OConfigurationChangeCallback iChangeAction) { final OConfigurationChangeCallback iChangeAction) {
this(iKey, iDescription, iType, iDefValue, true); key = iKey;
description = iDescription;
defValue = iDefValue;
type = iType;
canChangeAtRuntime = true;
hidden = false;
changeCallback = iChangeAction; changeCallback = iChangeAction;
} }


Expand All @@ -727,6 +753,7 @@ public void change(final Object iCurrentValue, final Object iNewValue) {
type = iType; type = iType;
canChangeAtRuntime = iCanChange; canChangeAtRuntime = iCanChange;
hidden = iHidden; hidden = iHidden;
changeCallback = null;
} }


public static void dumpConfiguration(final PrintStream out) { public static void dumpConfiguration(final PrintStream out) {
Expand Down
Expand Up @@ -20,6 +20,7 @@


package com.orientechnologies.orient.core.engine.local; package com.orientechnologies.orient.core.engine.local;


import java.io.IOException;
import java.util.Map; import java.util.Map;


import com.orientechnologies.common.exception.OException; import com.orientechnologies.common.exception.OException;
Expand All @@ -41,15 +42,26 @@ public class OEngineLocalPaginated extends OEngineAbstract {
private final O2QCache readCache; private final O2QCache readCache;


public OEngineLocalPaginated() { public OEngineLocalPaginated() {
readCache = new O2QCache( readCache = new O2QCache(calculateReadCacheMaxMemory(OGlobalConfiguration.DISK_CACHE_SIZE.getValueAsLong() * 1024 * 1024),
(long) (OGlobalConfiguration.DISK_CACHE_SIZE.getValueAsLong() * 1024 * 1024 * ((100 - OGlobalConfiguration.DISK_WRITE_CACHE_PART OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger() * 1024, true,
.getValueAsInteger()) / 100.0)), OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger() * 1024, true); OGlobalConfiguration.DISK_CACHE_PINNED_PAGES.getValueAsInteger());
try { try {
readCache.registerMBean(); readCache.registerMBean();
} catch (Exception e) { } catch (Exception e) {
OLogManager.instance().error(this, "MBean for read cache cannot be registered", e); OLogManager.instance().error(this, "MBean for read cache cannot be registered", e);
} }
}

private long calculateReadCacheMaxMemory(final long cacheSize) {
return (long) (cacheSize * ((100 - OGlobalConfiguration.DISK_WRITE_CACHE_PART.getValueAsInteger()) / 100.0));
}


/**
* @param cacheSize Cache size in bytes.
* @see O2QCache#changeMaximumAmountOfMemory(long)
*/
public void changeCacheSize(final long cacheSize) {
readCache.changeMaximumAmountOfMemory(calculateReadCacheMaxMemory(cacheSize));
} }


public OStorage createStorage(final String dbName, final Map<String, String> configuration) { public OStorage createStorage(final String dbName, final Map<String, String> configuration) {
Expand Down

0 comments on commit c0a2263

Please sign in to comment.