Interface Block<K extends java.io.Serializable>
-
- Type Parameters:
K
- the key type of its partitions.
- All Known Implementing Classes:
FileBlock
,NonSerializedMemoryBlock
,SerializedMemoryBlock
public interface Block<K extends java.io.Serializable>
This interface represents a block, which is the output of a specific task.
-
-
Method Summary
All Methods Instance Methods Abstract 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<K> keyRange)
Retrieves theNonSerializedPartition
s in a specific key range from this block.java.lang.Iterable<SerializedPartition<K>>
readSerializedPartitions(KeyRange<K> keyRange)
Retrieves theSerializedPartition
s in a specific key 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.
-
-
-
Method Detail
-
write
void write(K key, java.lang.Object element)
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.- Parameters:
key
- the key.element
- the element to write. Classes implementing this interface may throw org.apache.nemo.common.exception.BlockWriteException for any error occurred while trying to write a block. (This exception will be thrown to the scheduler throughExecutor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
writePartitions
void writePartitions(java.lang.Iterable<NonSerializedPartition<K>> partitions)
StoresNonSerializedPartition
s to this block. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.- Parameters:
partitions
- theNonSerializedPartition
s to store. Classes implementing this interface may throw org.apache.nemo.common.exception.BlockWriteException for any error occurred while trying to write a block. (This exception will be thrown to the scheduler throughExecutor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
writeSerializedPartitions
void writeSerializedPartitions(java.lang.Iterable<SerializedPartition<K>> partitions)
StoresSerializedPartition
s to this block. Invariant: This should not be invoked after this block is committed. Invariant: This method does not support concurrent write.- Parameters:
partitions
- theSerializedPartition
s to store. Classes implementing this interface may throw org.apache.nemo.common.exception.BlockWriteException for any error occurred while trying to write a block. (This exception will be thrown to the scheduler throughExecutor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
readPartitions
java.lang.Iterable<NonSerializedPartition<K>> readPartitions(KeyRange<K> keyRange)
Retrieves theNonSerializedPartition
s in a specific key range from this block. If the data is serialized, deserializes it. Invariant: This should not be invoked before this block is committed.- Parameters:
keyRange
- the key range to retrieve.- Returns:
- an iterable of
NonSerializedPartition
s. Classes implementing this interface may throw org.apache.nemo.common.exception.BlockFetchException for any error occurred while trying to fetch a block. (This exception will be thrown to the scheduler throughExecutor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
readSerializedPartitions
java.lang.Iterable<SerializedPartition<K>> readSerializedPartitions(KeyRange<K> keyRange)
Retrieves theSerializedPartition
s in a specific key range. Invariant: This should not be invoked before this block is committed.- Parameters:
keyRange
- the hash range to retrieve.- Returns:
- an iterable of
SerializedPartition
s. Classes implementing this interface may throw org.apache.nemo.common.exception.BlockFetchException for any error occurred while trying to fetch a block. (This exception will be thrown to the scheduler throughExecutor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
commit
java.util.Optional<java.util.Map<K,java.lang.Long>> commit()
Commits this block to prevent further write.- Returns:
- the size of each partition if the data in the block is serialized.
Classes implementing this interface may throw
org.apache.nemo.common.exception.BlockWriteException for any error occurred while trying to commit a block.
(This exception will be thrown to the scheduler
through
Executor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
commitPartitions
void commitPartitions()
Commits all un-committed partitions. This method can be useful if partitions in a block should be committed before the block is committed totally. For example, non-committed partitions in a file block can be flushed to storage from memory. If another element is written after this method is called, a new non-committed partition should be created for the element even if a partition with the same key is committed already. Classes implementing this interface may throw org.apache.nemo.common.exception.BlockWriteException for any error occurred while trying to commit partitions. (This exception will be thrown to the scheduler throughExecutor
and have to be handled by the scheduler with fault tolerance mechanism.)
-
getId
java.lang.String getId()
- Returns:
- the ID of this block.
-
isCommitted
boolean isCommitted()
- Returns:
- whether this block is committed or not.
-
-