public class GridCacheWriteBehindStore<K,V> extends Object implements CacheStore<K,V>, LifecycleAware
CacheStore
that enables write-behind logic.
The general purpose of this approach is to reduce cache store load under high
store update rate. The idea is to cache all write and remove operations in a pending
map and delegate these changes to the underlying store either after timeout or
if size of a pending map exceeded some pre-configured value. Another performance gain
is achieved due to combining a group of similar operations to a single batch update.
The essential flush size for the write-behind cache should be at least the estimated
count of simultaneously written keys. In case of significantly smaller value there would
be triggered a lot of flush events that will result in a high cache store load.
Since write operations to the cache store are deferred, transaction support is lost; no
transaction objects are passed to the underlying store.
GridCacheWriteBehindStore
doesn't support concurrent modifications of the same key.Modifier and Type | Field and Description |
---|---|
static float |
CACHE_OVERFLOW_RATIO
Overflow ratio for critical cache size calculation.
|
static int |
DFLT_CONCUR_LVL
Default concurrency level of write cache.
|
static int |
DFLT_INITIAL_CAPACITY
Default write cache initial capacity.
|
Constructor and Description |
---|
GridCacheWriteBehindStore(CacheStoreManager storeMgr,
String igniteInstanceName,
String cacheName,
IgniteLogger log,
CacheStore<K,V> store)
Creates a write-behind cache store for the given store.
|
Modifier and Type | Method and Description |
---|---|
void |
delete(Object key) |
void |
deleteAll(Collection<?> keys) |
void |
forceFlush()
Forces all entries collected to be flushed to the underlying store.
|
int |
getWriteBehindBufferSize()
Gets count of entries that were processed by the write-behind store and have not been
flushed to the underlying store yet.
|
int |
getWriteBehindCriticalOverflowCount()
Gets count of write buffer overflow events in progress at the moment.
|
int |
getWriteBehindErrorRetryCount()
Gets count of cache entries that are in a store-retry state.
|
long |
getWriteBehindFlushFrequency()
Gets the cache flush frequency.
|
int |
getWriteBehindFlushSize()
Gets the maximum size of the write-behind buffer.
|
int |
getWriteBehindFlushThreadCount()
Gets the number of flush threads that will perform store update operations.
|
int |
getWriteBehindStoreBatchSize()
Gets the maximum count of similar (put or remove) operations that can be grouped to a single batch.
|
int |
getWriteBehindTotalCriticalOverflowCount()
Gets count of write buffer overflow events since initialization.
|
boolean |
getWriteCoalescing()
Gets the write coalescing flag.
|
V |
load(K key) |
Map<K,V> |
loadAll(Iterable<? extends K> keys) |
void |
loadCache(IgniteBiInClosure<K,V> clo,
Object... args)
Loads all values from underlying persistent storage.
|
void |
sessionEnd(boolean commit)
Tells store to commit or rollback a transaction depending on the value of the
'commit'
parameter. |
void |
setBatchSize(int batchSize)
Sets the maximum count of similar operations that can be grouped to a single batch.
|
void |
setConcurrencyLevel(int concurLvl)
Sets concurrency level for the write cache.
|
void |
setFlushFrequency(long cacheFlushFreq)
Sets the cache flush frequency.
|
void |
setFlushSize(int cacheMaxSize)
Sets the maximum size of the write cache.
|
void |
setFlushThreadCount(int flushThreadCnt)
Sets the number of threads that will perform store update operations.
|
void |
setInitialCapacity(int initCap)
Sets initial capacity for the write cache.
|
void |
setWriteCoalescing(boolean writeCoalescing)
Sets the write coalescing flag.
|
void |
start()
Performs all the initialization logic for write-behind cache store.
|
void |
stop()
Performs shutdown logic for store.
|
CacheStore<K,V> |
store() |
String |
toString() |
void |
write(javax.cache.Cache.Entry<? extends K,? extends V> entry) |
void |
writeAll(Collection<javax.cache.Cache.Entry<? extends K,? extends V>> entries) |
public static final int DFLT_INITIAL_CAPACITY
public static final float CACHE_OVERFLOW_RATIO
public static final int DFLT_CONCUR_LVL
public GridCacheWriteBehindStore(CacheStoreManager storeMgr, String igniteInstanceName, String cacheName, IgniteLogger log, CacheStore<K,V> store)
storeMgr
- Store manager.igniteInstanceName
- Ignite instance name.cacheName
- Cache name.log
- Grid logger.store
- GridCacheStore
that need to be wrapped.public void setInitialCapacity(int initCap)
initCap
- Initial capacity.public void setConcurrencyLevel(int concurLvl)
concurLvl
- Concurrency level.public void setFlushSize(int cacheMaxSize)
cacheMaxSize
- Max cache size.public int getWriteBehindFlushSize()
0
, then flush is performed only on time-elapsing basis. However,
when this value is 0
, the cache critical size is set to
CacheConfiguration.DFLT_WRITE_BEHIND_CRITICAL_SIZE
.public void setFlushThreadCount(int flushThreadCnt)
flushThreadCnt
- Count of worker threads.public int getWriteBehindFlushThreadCount()
public void setWriteCoalescing(boolean writeCoalescing)
writeCoalescing
- Write coalescing flag.public boolean getWriteCoalescing()
public void setFlushFrequency(long cacheFlushFreq)
cacheFlushFreq
- Time interval value in milliseconds.public long getWriteBehindFlushFrequency()
0
, then flush is performed only when buffer size exceeds flush size.public void setBatchSize(int batchSize)
batchSize
- Maximum count of batch.public int getWriteBehindStoreBatchSize()
public int getWriteBehindBufferSize()
public CacheStore<K,V> store()
public void start()
start
in interface LifecycleAware
public int getWriteBehindTotalCriticalOverflowCount()
public int getWriteBehindCriticalOverflowCount()
public int getWriteBehindErrorRetryCount()
public void stop()
stop
in interface LifecycleAware
public void forceFlush() throws IgniteCheckedException
IgniteCheckedException
- If failed.public void loadCache(IgniteBiInClosure<K,V> clo, @Nullable Object... args)
IgniteCache.loadCache(IgniteBiPredicate, Object...)
method is invoked which is usually to preload the cache from persistent storage.
This method is optional, and cache implementation does not depend on this
method to do anything. Default implementation of this method in
CacheStoreAdapter
does nothing.
For every loaded value method IgniteBiInClosure.apply(Object, Object)
should be called on the passed in closure. The closure will then make sure
that the loaded value is stored in cache.
loadCache
in interface CacheStore<K,V>
clo
- Closure for loaded values.args
- Arguments passes into
IgniteCache.loadCache(IgniteBiPredicate, Object...)
method.public void writeAll(Collection<javax.cache.Cache.Entry<? extends K,? extends V>> entries)
public void deleteAll(Collection<?> keys)
public void delete(Object key)
public void sessionEnd(boolean commit)
'commit'
parameter.sessionEnd
in interface CacheStore<K,V>
commit
- True
if transaction should commit, false
for rollback.
Follow @ApacheIgnite
Ignite Fabric : ver. 2.0.0 Release Date : April 30 2017