I - input payload data typeO - output payload data typepublic class BoundedInMemoryQueue<I,O> extends Object implements HoodieMessageQueue<I,O>, Iterable<O>
memoryLimit. Unlike standard bounded queue
implementations, this queue bounds the size by memory bytes occupied by its tenants. The standard implementation
bounds by the number of entries in the queue.
It internally samples every RECORD_SAMPLING_RATEth record and adjusts number of records in queue
accordingly. This is done to ensure that we don't OOM.
This queue supports multiple producer single consumer pattern.| Modifier and Type | Field and Description |
|---|---|
long |
avgRecordSizeInBytes
Indicates avg record size in bytes.
|
int |
currentRateLimit
indicates rate limit (number of records to cache).
|
Semaphore |
rateLimiter
It indicates number of records to cache.
|
static int |
RECORD_POLL_INTERVAL_SEC
Interval used for polling records in the queue.
|
static int |
RECORD_SAMPLING_RATE
Rate used for sampling records to determine avg record size in bytes.
|
AtomicLong |
samplingRecordCounter
Used for sampling records with "recordSamplingRate" frequency.
|
| Constructor and Description |
|---|
BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction)
Construct BoundedInMemoryQueue with default SizeEstimator.
|
BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction,
SizeEstimator<O> payloadSizeEstimator) |
BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction,
SizeEstimator<O> payloadSizeEstimator,
int recordSamplingRate,
int recordCacheLimit)
Construct BoundedInMemoryQueue with passed in size estimator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Shuts down the queue, cleaning up the resources
|
Throwable |
getThrowable() |
void |
insertRecord(I t)
Inserts record into queue after applying transformation.
|
boolean |
isEmpty() |
Iterator<O> |
iterator() |
void |
markAsFailed(Throwable e)
API to allow producers and consumer to communicate termination due to failure.
|
Option<O> |
readNextRecord()
Reader interface but never exposed to outside world as this is a single consumer queue.
|
void |
seal()
Puts an empty entry to queue to denote termination.
|
long |
size()
Returns the number of elements in this queue.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static final int RECORD_POLL_INTERVAL_SEC
public static final int RECORD_SAMPLING_RATE
public final Semaphore rateLimiter
public final AtomicLong samplingRecordCounter
public int currentRateLimit
public long avgRecordSizeInBytes
public BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction)
memoryLimit - MemoryLimit in bytestransformFunction - Transformer Function to convert input payload type to stored payload typepublic BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction,
SizeEstimator<O> payloadSizeEstimator)
public BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction,
SizeEstimator<O> payloadSizeEstimator,
int recordSamplingRate,
int recordCacheLimit)
memoryLimit - MemoryLimit in bytestransformFunction - Transformer Function to convert input payload type to stored payload typepayloadSizeEstimator - Payload Size EstimatorrecordSamplingRate - record sampling raterecordCacheLimit - record cache limitpublic long size()
HoodieMessageQueuesize in interface HoodieMessageQueue<I,O>public void insertRecord(I t) throws Exception
insertRecord in interface HoodieMessageQueue<I,O>t - Item to be queuedExceptionpublic Option<O> readNextRecord()
readNextRecord in interface HoodieMessageQueue<I,O>public void seal()
seal in interface HoodieMessageQueue<I,O>public void close()
HoodieMessageQueueclose in interface Closeableclose in interface AutoCloseableclose in interface HoodieMessageQueue<I,O>public void markAsFailed(Throwable e)
markAsFailed in interface HoodieMessageQueue<I,O>public Throwable getThrowable()
getThrowable in interface HoodieMessageQueue<I,O>public boolean isEmpty()
isEmpty in interface HoodieMessageQueue<I,O>Copyright © 2024 The Apache Software Foundation. All rights reserved.