| 69 |
69 |
** 025 AS 20261103 Added putUniqueMiss() and isUniqueMiss(), a unique-key miss proving an index unique.
|
| 70 |
70 |
** Misses are kept apart from query results; invalidateQueries() spares them. They honor
|
| 71 |
71 |
** the disabled switch and the invalidation generation.
|
|
72 |
** 026 SP 20261110 Temp-table instances size their L2/L3 maps from the TT-L2/TT-L3 cache sizes (default 10
|
|
73 |
** and 100), not from the L2/L3 sizes of the permanent databases.
|
| 72 |
74 |
*/
|
| 73 |
75 |
|
| 74 |
76 |
/*
|
| ... | ... | |
| 161 |
163 |
* lookup tables - it is used as a key leading to appropriate cache instance.
|
| 162 |
164 |
* <p>
|
| 163 |
165 |
* The first two levels of cache size are not limited. They are the table and indexes unique ids and are
|
| 164 |
|
* stable, governed by database structure. Only the very last level is an actual {@code LRUCache} object
|
| 165 |
|
* whose size will need to be configured based on how many records should be cached for each index of a
|
| 166 |
|
* table. However, since the invalidation of the cache will occur quite often, the value can be kept small.
|
|
166 |
* stable, governed by database structure. The L3 maps are not limited either: the LRU cache of the reverse
|
|
167 |
* lookup (cache size discriminator {@code ReverseLookup}) bounds the number of results cached by an
|
|
168 |
* instance and removes the evicted results from their L3 maps. The cache sizes with the discriminators
|
|
169 |
* {@code L2} and {@code L3} (permanent databases) and {@code TT-L2} and {@code TT-L3} (temp-tables) are only
|
|
170 |
* the initial capacities of the L2 and L3 maps.
|
| 167 |
171 |
* <p>
|
| 168 |
172 |
* Cache Invalidation: the cache is individually invalidated for each affected index when a record is updated.
|
| 169 |
173 |
* On insert and delete operations all indices are invalidated for respective table. On a rollback event all
|
| ... | ... | |
| 235 |
239 |
|
| 236 |
240 |
/** Invalidation generation: incremented by every invalidation (see {@link #put(Key, Record, long)}). */
|
| 237 |
241 |
private final AtomicLong generation = new AtomicLong();
|
| 238 |
|
|
|
242 |
|
|
243 |
/** Cache size discriminator of the initial capacity of the L2 maps (index id to L3 map). */
|
|
244 |
private final String l2Discriminator;
|
|
245 |
|
|
246 |
/** Cache size discriminator of the initial capacity of the L3 maps (key to cached result). */
|
|
247 |
private final String l3Discriminator;
|
|
248 |
|
| 239 |
249 |
/**
|
| 240 |
250 |
* Constructor for internal use.
|
| 241 |
251 |
*
|
| ... | ... | |
| 247 |
257 |
this.isPermanent = isPermanent;
|
| 248 |
258 |
this.database = database;
|
| 249 |
259 |
this.disabled = isPermanent && !permanentEnabled;
|
| 250 |
|
|
|
260 |
|
|
261 |
// A temp-table drops its L2/L3 maps whenever its multiplex scope closes, so sizing them like the
|
|
262 |
// long-lived maps of a permanent database allocates a large table for every scope. The "!" prefix
|
|
263 |
// stops CacheManager from falling back to a size configured for this class without a discriminator.
|
|
264 |
this.l2Discriminator = isPermanent ? "L2" : "!TT-L2";
|
|
265 |
this.l3Discriminator = isPermanent ? "L3" : "!TT-L3";
|
|
266 |
|
| 251 |
267 |
if (disabled && disabledLogged.compareAndSet(false, true))
|
| 252 |
268 |
{
|
| 253 |
269 |
LOG.info("FastFindCache for permanent databases disabled (setting " + ENABLED_NODE + ")");
|
| ... | ... | |
| 876 |
892 |
*/
|
| 877 |
893 |
private void putImpl(Key k, Record value)
|
| 878 |
894 |
{
|
| 879 |
|
// There are multiple configured sizes for the caches, the discriminator for the
|
| 880 |
|
// L2 and L3 caches should not be changes since it is must be the same one
|
| 881 |
|
// used in the directory configuration.
|
|
895 |
// The discriminators name the cache sizes in the directory configuration, so they must not change.
|
| 882 |
896 |
Map<Integer, Map<L2Key, FastFindCacheEntry>> l2Cache =
|
| 883 |
897 |
cache.computeIfAbsent(k.tableId, x -> CacheManager.createLinkedMapCache(FastFindCache.class,
|
| 884 |
|
"L2",
|
|
898 |
l2Discriminator,
|
| 885 |
899 |
10));
|
| 886 |
900 |
|
| 887 |
901 |
Map<L2Key, FastFindCacheEntry> l3Cache =
|
| 888 |
902 |
l2Cache.computeIfAbsent(k.indexId, x -> CacheManager.createResizableMapCache(FastFindCache.class,
|
| 889 |
|
"L3",
|
| 890 |
|
100));
|
|
903 |
l3Discriminator,
|
|
904 |
100));
|
| 891 |
905 |
|
| 892 |
906 |
// for a positive result (i.e., a record was found), ensure we use the canonical instance of the
|
| 893 |
907 |
// record identifier, so that if it is stored in the reverse lookup cache, the weak keys can be
|