Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Add RawCompare to DXMem and fix an issue that ChunkState is ok althou…
Browse files Browse the repository at this point in the history
…gh resize was not successful
  • Loading branch information
Lars Mehnert committed May 15, 2019
1 parent bd150bc commit 643b1ff
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 73 deletions.
70 changes: 28 additions & 42 deletions src/main/java/de/hhu/bsinfo/dxmem/DXMem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,12 @@

import java.io.File;

import de.hhu.bsinfo.dxmem.operations.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.hhu.bsinfo.dxmem.core.Context;
import de.hhu.bsinfo.dxmem.core.MemoryRuntimeException;
import de.hhu.bsinfo.dxmem.operations.Analyze;
import de.hhu.bsinfo.dxmem.operations.CIDStatus;
import de.hhu.bsinfo.dxmem.operations.Create;
import de.hhu.bsinfo.dxmem.operations.CreateReserved;
import de.hhu.bsinfo.dxmem.operations.Dump;
import de.hhu.bsinfo.dxmem.operations.Exists;
import de.hhu.bsinfo.dxmem.operations.Get;
import de.hhu.bsinfo.dxmem.operations.Lock;
import de.hhu.bsinfo.dxmem.operations.Pinning;
import de.hhu.bsinfo.dxmem.operations.Put;
import de.hhu.bsinfo.dxmem.operations.RawRead;
import de.hhu.bsinfo.dxmem.operations.RawWrite;
import de.hhu.bsinfo.dxmem.operations.Recovery;
import de.hhu.bsinfo.dxmem.operations.Remove;
import de.hhu.bsinfo.dxmem.operations.Reserve;
import de.hhu.bsinfo.dxmem.operations.Resize;
import de.hhu.bsinfo.dxmem.operations.Size;
import de.hhu.bsinfo.dxmem.operations.Stats;
import de.hhu.bsinfo.dxmonitor.state.MemState;
import de.hhu.bsinfo.dxmonitor.state.StateUpdateException;
import de.hhu.bsinfo.dxutils.unit.StorageUnit;
Expand Down Expand Up @@ -69,6 +52,7 @@ public class DXMem {
private Pinning m_pinning;
private RawRead m_rawRead;
private RawWrite m_rawWrite;
private RawCompare m_rawCompare;

private CIDStatus m_cidStatus;
private Stats m_stats;
Expand All @@ -82,8 +66,7 @@ public class DXMem {
* Constructor
* Load a memory dump from a file and initialize DXMem with it.
*
* @param p_memdumpFile
* Path to memory dump file
* @param p_memdumpFile Path to memory dump file
*/
public DXMem(final String p_memdumpFile) {
this(p_memdumpFile, false);
Expand All @@ -93,14 +76,12 @@ public DXMem(final String p_memdumpFile) {
* Constructor
* Load a memory dump from a file and initialize DXMem with it.
*
* @param p_memdumpFile
* Path to memory dump file
* @param p_disableChunkLock
* Disable the chunk lock mechanism which increases performance but blocks the remove
* and resize operations. All lock operation arguments provided on operation calls are
* ignored. DXMem cannot guarantee application data consistency on parallel writes to
* the same chunk. Useful for read only applications or if the application handles
* synchronization when writing to chunks.
* @param p_memdumpFile Path to memory dump file
* @param p_disableChunkLock Disable the chunk lock mechanism which increases performance but blocks the remove
* and resize operations. All lock operation arguments provided on operation calls are
* ignored. DXMem cannot guarantee application data consistency on parallel writes to
* the same chunk. Useful for read only applications or if the application handles
* synchronization when writing to chunks.
*/
public DXMem(final String p_memdumpFile, final boolean p_disableChunkLock) {
checkSufficientMemory(new StorageUnit(new File(p_memdumpFile).length(), StorageUnit.BYTE));
Expand All @@ -118,10 +99,8 @@ public DXMem(final String p_memdumpFile, final boolean p_disableChunkLock) {
* Constructor
* Create a new empty heap and initialize DXMem.
*
* @param p_nodeId
* Node id of current instance
* @param p_heapSize
* Size of heap to create (in bytes)
* @param p_nodeId Node id of current instance
* @param p_heapSize Size of heap to create (in bytes)
*/
public DXMem(final short p_nodeId, final long p_heapSize) {
this(p_nodeId, p_heapSize, false);
Expand All @@ -131,16 +110,13 @@ public DXMem(final short p_nodeId, final long p_heapSize) {
* Constructor
* Create a new empty heap and initialize DXMem.
*
* @param p_nodeId
* Node id of current instance
* @param p_heapSize
* Size of heap to create (in bytes)
* @param p_disableChunkLock
* Disable the chunk lock mechanism which increases performance but blocks the remove
* and resize operations. All lock operation arguments provided on operation calls are
* ignored. DXMem cannot guarantee application data consistency on parallel writes to
* the same chunk. Useful for read only applications or if the application handles
* synchronization when writing to chunks.
* @param p_nodeId Node id of current instance
* @param p_heapSize Size of heap to create (in bytes)
* @param p_disableChunkLock Disable the chunk lock mechanism which increases performance but blocks the remove
* and resize operations. All lock operation arguments provided on operation calls are
* ignored. DXMem cannot guarantee application data consistency on parallel writes to
* the same chunk. Useful for read only applications or if the application handles
* synchronization when writing to chunks.
*/
public DXMem(final short p_nodeId, final long p_heapSize, final boolean p_disableChunkLock) {
checkSufficientMemory(new StorageUnit(p_heapSize, StorageUnit.BYTE));
Expand Down Expand Up @@ -292,6 +268,15 @@ public RawWrite rawWrite() {
return m_rawWrite;
}

/**
* Return the rawCompare Operation.
*
* @return the rawCompare Operation.
*/
public RawCompare rawCompare() {
return m_rawCompare;
}

/**
* Get the cidStatus operation
*
Expand Down Expand Up @@ -355,6 +340,7 @@ private void initOperations() {
m_pinning = new Pinning(m_context);
m_rawRead = new RawRead(m_context);
m_rawWrite = new RawWrite(m_context);
m_rawCompare = new RawCompare(m_context);

m_cidStatus = new CIDStatus(m_context);
m_stats = new Stats(m_context);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/de/hhu/bsinfo/dxmem/data/ChunkState.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public enum ChunkState {
* Typically, one simply issues the timed out operation again (maybe add a short delay).
*/
REMOTE_REQUEST_TIMEOUT,
}

/**
* Chunk could not resized.
*/
RESIZE_FAILED
}
7 changes: 4 additions & 3 deletions src/main/java/de/hhu/bsinfo/dxmem/operations/RawCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean compare(final long p_address, final int p_offset, final byte p_su
* Compares a byte array at a given address + offset with a given byte array.
* It iterates over the byte array and will return if it found a unequal at current iteration.
* <p>
* Special attention to the range it will ce compare. The length of the given byte array is equal to the
* Special attention to the range it will compare. The length of the given byte array is equal to the
* number of iterations.
* For the byte comparison it uses the {@link #compare(long, int, byte)} method.
*
Expand All @@ -48,8 +48,9 @@ public boolean compare(final long p_address, final int p_offset, final byte p_su
*/
public boolean compare(final long p_address, final int p_offset, final byte[] p_suspect) {
int offset = p_offset;
for (int i = 0; i < p_suspect.length; i++) {
if (compare(p_address, offset, p_suspect[i]))

for (byte b : p_suspect) {
if (!compare(p_address, offset, b))
return false;
offset += Byte.BYTES;
}
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/de/hhu/bsinfo/dxmem/operations/RawRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class RawRead {
/**
* Constructor
*
* @param p_context
* Context
* @param p_context Context
*/
public RawRead(final Context p_context) {
m_context = p_context;
Expand Down Expand Up @@ -103,42 +102,48 @@ public void read(final long p_address, final int p_addressOffset, final float[]
}

public void read(final long p_address, final int p_addressOffset, final boolean[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readBooleans(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final byte[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readBytes(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final short[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readShorts(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final char[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readChars(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final int[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readInts(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final long[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readLongs(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final double[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readDoubles(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public void read(final long p_address, final int p_addressOffset, final float[] p_array, final int p_offset,
final int p_length) {
final int p_length) {
m_context.getHeap().readFloats(p_address, p_addressOffset, p_array, p_offset, p_length);
}

public byte[] read(final long p_address, final int p_addressOffset, final int p_length) {
byte[] arr = new byte[p_length];
this.read(p_address, p_addressOffset, arr);
return arr;
}
}
29 changes: 12 additions & 17 deletions src/main/java/de/hhu/bsinfo/dxmem/operations/Resize.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public class Resize {
/**
* Constructor
*
* @param p_context
* Context
* @param p_context Context
*/
public Resize(final Context p_context) {
m_context = p_context;
Expand All @@ -54,10 +53,8 @@ public Resize(final Context p_context) {
/**
* Resize an existing chunk
*
* @param p_cid
* CID of chunk to resize
* @param p_newSize
* New size for chunk
* @param p_cid CID of chunk to resize
* @param p_newSize New size for chunk
* @return True if succcessful, false on failure
*/
public ChunkState resize(final long p_cid, final int p_newSize) {
Expand All @@ -67,19 +64,15 @@ public ChunkState resize(final long p_cid, final int p_newSize) {
/**
* Resize an existing chunk
*
* @param p_cid
* CID of chunk to resize
* @param p_newSize
* New size for chunk
* @param p_lockOperation
* Lock operation to execute for chunk to resize
* @param p_lockTimeoutMs
* If a lock operation is set, set to -1 for infinite retries (busy polling) until the lock operation
* succeeds. 0 for a one shot try and &gt; 0 for a timeout value in ms
* @param p_cid CID of chunk to resize
* @param p_newSize New size for chunk
* @param p_lockOperation Lock operation to execute for chunk to resize
* @param p_lockTimeoutMs If a lock operation is set, set to -1 for infinite retries (busy polling) until the lock operation
* succeeds. 0 for a one shot try and &gt; 0 for a timeout value in ms
* @return True if succcessful, false on failure
*/
public ChunkState resize(final long p_cid, final int p_newSize, final ChunkLockOperation p_lockOperation,
final int p_lockTimeoutMs) {
final int p_lockTimeoutMs) {
assert assertLockOperationSupport(p_lockOperation);
assert p_newSize > 0;

Expand Down Expand Up @@ -114,7 +107,9 @@ public ChunkState resize(final long p_cid, final int p_newSize, final ChunkLockO
return ChunkState.DOES_NOT_EXIST;
}

m_context.getHeap().resize(tableEntry, p_newSize);
if (!m_context.getHeap().resize(tableEntry, p_newSize)) {
return ChunkState.RESIZE_FAILED;
}

// update cid table entry
m_context.getCIDTable().entryUpdate(tableEntry);
Expand Down

0 comments on commit 643b1ff

Please sign in to comment.