Skip to content

Commit

Permalink
Issue #1404 New write cache was implemented (without tests).
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Jul 24, 2013
1 parent 94b7b1e commit c051ae6
Show file tree
Hide file tree
Showing 16 changed files with 1,130 additions and 77 deletions.
Expand Up @@ -418,9 +418,9 @@ public void change(final Object iCurrentValue, final Object iNewValue) {

SERVER_CACHE_FILE_STATIC("server.cache.staticFile", "Cache static resources loading", Boolean.class, false),

SERVER_CACHE_2Q_INCREASE_ON_DEMAND("server.cache.2q.increaseOnDemand", "Increase 2q cache on demand", Boolean.class, true),
SERVER_CACHE_INCREASE_ON_DEMAND("server.cache.2q.increaseOnDemand", "Increase 2q cache on demand", Boolean.class, true),

SERVER_CACHE_2Q_INCREASE_STEP("server.cache.2q.increaseStep",
SERVER_CACHE_INCREASE_STEP("server.cache.2q.increaseStep",
"Increase 2q cache step in percent. Will only work if server.cache.2q.increaseOnDemand is true", Float.class, 0.1f),

SERVER_LOG_DUMP_CLIENT_EXCEPTION_LEVEL(
Expand Down
Expand Up @@ -16,12 +16,12 @@

package com.orientechnologies.orient.core.exception;

public class OAllLRUListEntriesAreUsedException extends ODatabaseException {
public OAllLRUListEntriesAreUsedException(String string) {
public class OAllCacheEntriesAreUsedException extends ODatabaseException {
public OAllCacheEntriesAreUsedException(String string) {
super(string);
}

public OAllLRUListEntriesAreUsedException(String message, Throwable cause) {
public OAllCacheEntriesAreUsedException(String message, Throwable cause) {
super(message, cause);
}
}
Expand Up @@ -37,7 +37,7 @@
import com.orientechnologies.common.serialization.types.OLongSerializer;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.exception.OAllLRUListEntriesAreUsedException;
import com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException;
import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.memory.OMemoryWatchDog;
import com.orientechnologies.orient.core.storage.fs.OFileClassic;
Expand All @@ -50,7 +50,7 @@
* @author Artem Loginov
* @since 14.03.13
*/
public class O2QCache implements ODiskCache {
public class O2QDiskCache implements ODiskCache {
public static final long MAGIC_NUMBER = 0xFACB03FEL;

public final int writeQueueLength;
Expand Down Expand Up @@ -91,9 +91,8 @@ public class O2QCache implements ODiskCache {

private final boolean syncOnPageFlush;
private long fileCounter = 1;
private int crcOffset;

public O2QCache(long maxMemory, int writeQueueLength, ODirectMemory directMemory, OWriteAheadLog writeAheadLog, int pageSize,
public O2QDiskCache(long maxMemory, int writeQueueLength, ODirectMemory directMemory, OWriteAheadLog writeAheadLog, int pageSize,
OStorageLocalAbstract storageLocal, boolean syncOnPageFlush) {

this.writeQueueLength = writeQueueLength;
Expand Down Expand Up @@ -543,13 +542,13 @@ private void removeColdestPageIfNeeded() throws IOException {
private void increaseCacheSize() {
String message = "All records in aIn queue in 2q cache are used!";
OLogManager.instance().warn(this, message);
if (OGlobalConfiguration.SERVER_CACHE_2Q_INCREASE_ON_DEMAND.getValueAsBoolean()) {
if (OGlobalConfiguration.SERVER_CACHE_INCREASE_ON_DEMAND.getValueAsBoolean()) {
OLogManager.instance().warn(this, "Cache size will be increased.");
maxSize = (int) Math.ceil(maxSize * (1 + OGlobalConfiguration.SERVER_CACHE_2Q_INCREASE_STEP.getValueAsFloat()));
maxSize = (int) Math.ceil(maxSize * (1 + OGlobalConfiguration.SERVER_CACHE_INCREASE_STEP.getValueAsFloat()));
K_IN = maxSize >> 2;
K_OUT = maxSize >> 1;
} else {
throw new OAllLRUListEntriesAreUsedException(message);
throw new OAllCacheEntriesAreUsedException(message);
}
}

Expand Down
@@ -0,0 +1,105 @@
package com.orientechnologies.orient.core.index.hashindex.local.cache;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.orientechnologies.common.directmemory.ODirectMemory;
import com.orientechnologies.common.directmemory.ODirectMemoryFactory;
import com.orientechnologies.orient.core.storage.fs.OFileClassic;

/**
* @author Andrey Lomakin
* @since 7/24/13
*/
public class O2QReadCache {
private int maxSize;
private int K_IN;
private int K_OUT;

private final int pageSize;

private final LRUList am;
private final LRUList a1out;
private final LRUList a1in;

private final ODirectMemory directMemory = ODirectMemoryFactory.INSTANCE.directMemory();

private final Map<Long, OFileClassic> files;
private final Map<Long, Set<Long>> filePages;

public O2QReadCache(Map<Long, OFileClassic> files, int pageSize) {
this.files = files;
this.filePages = new HashMap<Long, Set<Long>>();

this.pageSize = pageSize;

am = new LRUList();
a1out = new LRUList();
a1in = new LRUList();
}

public OCacheEntry get(long fileId, long pageIndex) {
return null;
}

public OCacheEntry load(long fileId, long pageIndex) {
return null;
}

public void clear(long fileId) {
}

public void clear() {
}

private static final class FileLockKey implements Comparable<FileLockKey> {
private final long fileId;
private final long pageIndex;

private FileLockKey(long fileId, long pageIndex) {
this.fileId = fileId;
this.pageIndex = pageIndex;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

FileLockKey that = (FileLockKey) o;

if (fileId != that.fileId)
return false;
if (pageIndex != that.pageIndex)
return false;

return true;
}

@Override
public int hashCode() {
int result = (int) (fileId ^ (fileId >>> 32));
result = 31 * result + (int) (pageIndex ^ (pageIndex >>> 32));
return result;
}

@Override
public int compareTo(FileLockKey otherKey) {
if (fileId > otherKey.fileId)
return 1;
if (fileId < otherKey.fileId)
return -1;

if (pageIndex > otherKey.pageIndex)
return 1;
if (pageIndex < otherKey.pageIndex)
return -1;

return 0;
}
}

}
@@ -1,21 +1,29 @@
package com.orientechnologies.orient.core.index.hashindex.local.cache;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber;

/**
* @author Andrey Lomakin
* @since 7/23/13
*/
public class OCacheEntry {
long fileId;
long pageIndex;
class OCacheEntry {
final ReadWriteLock lock = new ReentrantReadWriteLock();

long fileId;
long pageIndex;

OLogSequenceNumber loadedLSN;
OLogSequenceNumber loadedLSN;

long dataPointer;
long dataPointer;

boolean isDirty;
int usageCounter;
boolean isDirty;
int usageCounter;

boolean inReadCache;
boolean inWriteCache;

public OCacheEntry(long fileId, long pageIndex, long dataPointer, boolean dirty, OLogSequenceNumber loadedLSN) {
this.fileId = fileId;
Expand All @@ -25,6 +33,14 @@ public OCacheEntry(long fileId, long pageIndex, long dataPointer, boolean dirty,
isDirty = dirty;
}

public void acquireExclusiveLock() {
lock.writeLock().lock();
}

public void releaseExclusiveLock() {
lock.writeLock().unlock();
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down

0 comments on commit c051ae6

Please sign in to comment.