public class WriteRetentionStore extends DelegatingStore
DelegatingStore that retains all writes
(#storeChanges(MetaInformation, String, String, ColumnFamilyData, Map, Map)
and delete(MetaInformation, String, String), that is PersistingElement.store() and
PersistingElement.delete()) during a certain amount of time. This kind of store is obviously
thread safe, and interesting in case rows are often updated by dramatically lowering the number of
write requests on the actual store.
Writes are actually issued to the actual store after a
given time. If other writes for the same persisting element occur during
this period, they are merged with retained write for this persisting element and eventually sent.
As an example, if a persisting element is stored at time t1, changed and stored again at time t2
such that t2-t1 is less than the retention time, only one store request
is issued to the actual store, after t1+retention time.
Reads (as DelegatingStore.get(MetaInformation, String, String, Set), PersistingElement.activate(String...))
do not explore data "retended" here. As a example, activating, changing, storing, and then
activating again a persisting element using this kind of store can re-activate it as it was before the change.
Same remark holds for testing an element of existence, counting element, or getting a list of elements
that match criteria.
This store can be deactivated ; in the latter case, it merely acts as a delegating store with no delay.
To en/de-activate, use setEnabledByDefault(boolean). A thread can anyway be authorized to activate for
itself (and only itself) any de-activated write retention store if calling before
setEnabledForCurrentThread(boolean).
This store can be supervised using getPendingRequests(). To grab more metrics (such as the number of
requests {getRequestsIn() in}, out,
time between a request should be sent and is sent...), you need to enable
setCapureHitRatio(boolean) to true, which is not the case by default as it introduces some overhead.
It is possible to enable and then disable addtional capture on a regular basis to get metrics samples.
In this latter case, older metrics can be reseted.
This store can be activated using the @Persisting annotation on a class
or by setting the with-write-retention property on the
storage.properties file.
| Modifier and Type | Method and Description |
|---|---|
void |
delete(MetaInformation meta,
String table,
String id)
Deletes a particular element.
|
boolean |
equals(Object obj) |
boolean |
flush(String table,
String identifier)
Sends immediately planned requests for the given element.
|
static int |
getActiveSenderThreads()
The approximate number of sending threads.
|
static long |
getAverageLatencyMs()
The average latency (ms) between time at which a request should have been sent and the time it is actually sent
|
static long |
getCumulativeLatencyMs()
The cumulative latency (ms) between time at which a request should have been sent and the time it is actually sent
|
static double |
getHitRatio()
The hit ratio (requests asked / requests (to be)sent ;
isCapureHitRatio() should be on to capture this metric |
static long |
getLatencySamples()
Number of latencies accumulated by
getCumulativeLatencyMs() |
static int |
getMaxSenderThreads()
Maximum global number of threads used for sending requests to store ; default is 40.
|
static int |
getPendingRequests()
The approximate number of pending write requests.
|
static long |
getRequestsIn()
Number of requests asked ;
isCapureHitRatio() should be on to capture this metric |
static long |
getRequestsOut()
Number of requests sent ;
isCapureHitRatio() should be on to capture this metric |
long |
getWriteRetentionMs()
Minimum time in ms during which and update (i.e. a
store or a delete)
are retained before being sent to the actual
store. |
static WriteRetentionStore |
getWriteRetentionStore(long writeRetentionMs,
Store s)
Returns a
WriteRetentionStore with s as delegate ;
in case s is already a WriteRetentionStore with a different getWriteRetentionMs(),
returns another WriteRetentionStore with same delegate
as s. |
int |
hashCode() |
static boolean |
isCapureHitRatio()
Whether hit ratio metrics should be captured
|
boolean |
isEnabledByDefault()
Whether write retention is enabled by default for thread that did not call
setEnabledForCurrentThread(boolean). |
static boolean |
isEnabledForCurrentThread()
Whether write retention should be enabled for this thread even for
de-activated write-retention stores. |
static void |
resetCapureHitRatioMetrics()
Resets any hit-ratio-related metrics
getHitRatio(), getRequestsIn(), getRequestsOut(), and getAverageLatencyMs() |
static void |
setCapureHitRatio(boolean captureHitRatio)
Whether hit ratio metrics should be captured
|
void |
setEnabledByDefault(boolean enabled)
Whether write retention is enabled by default for thread that did not call
setEnabledForCurrentThread(boolean). |
static void |
setEnabledForCurrentThread(boolean enabled)
Whether write retention should be enabled for this thread even for
de-activated write-retention stores. |
static void |
setMaxSenderThreads(int maxSenderThreads)
Maximum global number of threads used for sending requests to store
|
void |
start()
Called once the store is created ; only one store is instanciated with
the same properties.
|
void |
storeChanges(MetaInformation meta,
String table,
String id,
Row.ColumnFamilyData changed,
Map<String,Set<String>> removed,
Map<String,Map<String,Number>> increments)
Stores given piece of information.
|
count, exists, exists, get, get, get, get, get, getActualStore, getActualStore, getDeepActualStore, hasTablepublic static final Logger logger
public static WriteRetentionStore getWriteRetentionStore(long writeRetentionMs, Store s)
WriteRetentionStore with s as delegate ;
in case s is already a WriteRetentionStore with a different getWriteRetentionMs(),
returns another WriteRetentionStore with same delegate
as s.writeRetentionMs - time during which updates are retended to delegate stores - the actual store, or a WriteRetentionStore with delegating to the actual storeIllegalArgumentException - if s is a delegation chain that already contains a WriteRetentionStorepublic static boolean isEnabledForCurrentThread()
de-activated write-retention stores.public static void setEnabledForCurrentThread(boolean enabled)
de-activated write-retention stores.public static int getMaxSenderThreads()
public static void setMaxSenderThreads(int maxSenderThreads)
public static int getActiveSenderThreads()
getMaxSenderThreads() in case it was recently set to a lower value.ThreadPoolExecutor.getActiveCount()public static int getPendingRequests()
public static boolean isCapureHitRatio()
public static void setCapureHitRatio(boolean captureHitRatio)
public static void resetCapureHitRatioMetrics()
getHitRatio(), getRequestsIn(), getRequestsOut(), and getAverageLatencyMs()public static long getRequestsIn()
isCapureHitRatio() should be on to capture this metricpublic static long getRequestsOut()
isCapureHitRatio() should be on to capture this metricpublic static double getHitRatio()
isCapureHitRatio() should be on to capture this metricpublic static long getCumulativeLatencyMs()
public static long getLatencySamples()
getCumulativeLatencyMs()public static long getAverageLatencyMs()
public long getWriteRetentionMs()
store or a delete)
are retained before being sent to the actual
store. During this time, updates are merged to dramatically reduce
number of updates on a same row.public boolean isEnabledByDefault()
setEnabledForCurrentThread(boolean).public void setEnabledByDefault(boolean enabled)
setEnabledForCurrentThread(boolean).public void start()
throws DatabaseNotReachedException
Storestart in interface Storestart in class DelegatingStoreDatabaseNotReachedExceptionpublic boolean flush(String table, String identifier)
table - the table of the elementidentifier - the identifier of the elementpublic void delete(MetaInformation meta, String table, String id) throws DatabaseNotReachedException
Storedelete in interface Storedelete in class DelegatingStoreDatabaseNotReachedExceptionpublic void storeChanges(MetaInformation meta, String table, String id, Row.ColumnFamilyData changed, Map<String,Set<String>> removed, Map<String,Map<String,Number>> increments) throws DatabaseNotReachedException
StorestoreChanges in interface StorestoreChanges in class DelegatingStoreDatabaseNotReachedExceptionCopyright © 2016. All Rights Reserved.