Class NonSerializedMemoryBlock<K extends java.io.Serializable>
- java.lang.Object
-
- org.apache.nemo.runtime.executor.data.block.NonSerializedMemoryBlock<K>
-
- Type Parameters:
K
- the key type of its partitions.
- All Implemented Interfaces:
Block<K>
@NotThreadSafe public final class NonSerializedMemoryBlock<K extends java.io.Serializable> extends java.lang.Object implements Block<K>
This class represents a block which is stored in local memory and not serialized. Concurrent read is supported, but concurrent write is not supported.
-
-
Constructor Summary
Constructors Constructor Description NonSerializedMemoryBlock(java.lang.String blockId, Serializer serializer, MemoryPoolAssigner memoryPoolAssigner)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<java.util.Map<K,java.lang.Long>>
commit()
Commits this block to prevent further write.void
commitPartitions()
Commits all un-committed partitions.java.lang.String
getId()
boolean
isCommitted()
java.lang.Iterable<NonSerializedPartition<K>>
readPartitions(KeyRange keyRange)
Retrieves theNonSerializedPartition
s in a specific hash range from this block.java.lang.Iterable<SerializedPartition<K>>
readSerializedPartitions(KeyRange keyRange)
Retrieves theSerializedPartition
s in a specific hash range.void
write(K key, java.lang.Object element)
Writes an element to non-committed block.void
writePartitions(java.lang.Iterable<NonSerializedPartition<K>> partitions)
StoresNonSerializedPartition
s to this block.void
writeSerializedPartitions(java.lang.Iterable<SerializedPartition<K>> partitions)
StoresSerializedPartition
s to this block.
-
-
-
Constructor Detail
-
NonSerializedMemoryBlock
public NonSerializedMemoryBlock(java.lang.String blockId, Serializer serializer, MemoryPoolAssigner memoryPoolAssigner)
Constructor.- Parameters:
blockId
- the ID of this block.serializer
- theSerializer
.memoryPoolAssigner
- the MemoryPoolAssigner for memory allocation.
-
-
Method Detail
-
write
public void write(K key, java.lang.Object element) throws BlockWriteException
Writes an element to non-committed block. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.- Specified by:
write
in interfaceBlock<K extends java.io.Serializable>
- Parameters:
key
- the key.element
- the element to write.- Throws:
BlockWriteException
- for any error occurred while trying to write a block.
-
writePartitions
public void writePartitions(java.lang.Iterable<NonSerializedPartition<K>> partitions) throws BlockWriteException
StoresNonSerializedPartition
s to this block. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.- Specified by:
writePartitions
in interfaceBlock<K extends java.io.Serializable>
- Parameters:
partitions
- theNonSerializedPartition
s to store.- Throws:
BlockWriteException
- for any error occurred while trying to write a block.
-
writeSerializedPartitions
public void writeSerializedPartitions(java.lang.Iterable<SerializedPartition<K>> partitions) throws BlockWriteException
StoresSerializedPartition
s to this block. Because all data in this block is stored in a non-serialized form, the data in these partitions have to be deserialized. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.- Specified by:
writeSerializedPartitions
in interfaceBlock<K extends java.io.Serializable>
- Parameters:
partitions
- theSerializedPartition
s to store.- Throws:
BlockWriteException
- for any error occurred while trying to write a block.
-
readPartitions
public java.lang.Iterable<NonSerializedPartition<K>> readPartitions(KeyRange keyRange) throws BlockFetchException
Retrieves theNonSerializedPartition
s in a specific hash range from this block. Invariant: This should not be invoked before this block is committed.- Specified by:
readPartitions
in interfaceBlock<K extends java.io.Serializable>
- Parameters:
keyRange
- the hash range to retrieve.- Returns:
- an iterable of
NonSerializedPartition
s. - Throws:
BlockFetchException
- for any error occurred while trying to fetch a block.
-
readSerializedPartitions
public java.lang.Iterable<SerializedPartition<K>> readSerializedPartitions(KeyRange keyRange) throws BlockFetchException
Retrieves theSerializedPartition
s in a specific hash range. Because the data is stored in a non-serialized form, it have to be serialized. Invariant: This should not be invoked before this block is committed.- Specified by:
readSerializedPartitions
in interfaceBlock<K extends java.io.Serializable>
- Parameters:
keyRange
- the key range to retrieve.- Returns:
- an iterable of
SerializedPartition
s. - Throws:
BlockFetchException
- for any error occurred while trying to fetch a block.
-
commit
public java.util.Optional<java.util.Map<K,java.lang.Long>> commit()
Commits this block to prevent further write.
-
commitPartitions
public void commitPartitions() throws BlockWriteException
Commits all un-committed partitions.- Specified by:
commitPartitions
in interfaceBlock<K extends java.io.Serializable>
- Throws:
BlockWriteException
-
getId
public java.lang.String getId()
-
isCommitted
public boolean isCommitted()
- Specified by:
isCommitted
in interfaceBlock<K extends java.io.Serializable>
- Returns:
- whether this block is committed or not.
-
-