segmentstore/server/src/main/java/io/pravega/segmentstore/server/tables/SegmentKeyCache.java
/**
         * Inserts or updates the Cache for the given KeyHash with given CacheValue, but only if it has a higher offset
         * than the existing value.
         *
         * @param keyHash           The Key Hash to update.
         * @param segmentOffset     See {@link ContainerKeyCache#includeExistingKey} segmentOffset.
         * @param currentGeneration The current Cache Generation (from the Cache Manager).
         */
Inserts or updates the Cache for the given KeyHash with given CacheValue, but only if it has a higher offset
than the existing value.

@param keyHash           The Key Hash to update.
Inserts or updates the Cache for the given KeyHash with given CacheValue but only if it has a higher offset than the existing value . @param keyHash The Key Hash to update .
synchronized boolean update(UUID keyHash, long segmentOffset, int currentGeneration) {
            ArrayView entryData = getFromCache();
            int entryOffset = locate(keyHash, entryData);
            if (entryOffset < 0) {
                if (entryData == null) {
                    entryData = new ByteArraySegment(new byte[ENTRY_LENGTH]);
                    entryOffset = HEADER_LENGTH;
                } else {
                    ByteArraySegment newData = new ByteArraySegment(new byte[entryData.getLength() + HASH_LENGTH + VALUE_SERIALIZATION_LENGTH]);
                    newData.copyFrom(entryData, 0, entryData.getLength());
                    entryOffset = entryData.getLength();
                    entryData = newData;
                }
                entryData.setInt(0, entryData.getInt(0) + 1);
                serializeHash(entryData, entryOffset, keyHash);
                entryOffset += HASH_LENGTH;
            }
            entryData.setLong(entryOffset, segmentOffset);
            try {
                storeInCache(entryData);
                this.generation = currentGeneration;
                this.highestOffset = Math.max(this.highestOffset, segmentOffset);
            } catch (CacheEntryEvictedException cex) {
                throw cex;
            } catch (CacheDisabledException cex) {
                log.debug("SegmentKeyCache[{}]: Not updating cache for {} due to non-essential cache entries disabled.", segmentId, this);
                return false;
            } catch (Throwable ex) {
                log.warn("SegmentKeyCache[{}]: Cache Entry update failed for {}.", segmentId, this, ex);
                return false;
            }
            return true;
        }
synchronized boolean update ( UUID keyHash , long segmentOffset , int currentGeneration ) { ArrayView entryData = getFromCache ( ) ; int entryOffset = locate ( keyHash , entryData ) ; if ( entryOffset < 0 ) { if ( entryData == null ) { entryData = new ByteArraySegment ( new byte [ ENTRY_LENGTH ] ) ; entryOffset = HEADER_LENGTH ; } else { ByteArraySegment newData = new ByteArraySegment ( new byte [ entryData . getLength ( ) + HASH_LENGTH + VALUE_SERIALIZATION_LENGTH ] ) ; newData . copyFrom ( entryData , 0 , entryData . getLength ( ) ) ; entryOffset = entryData . getLength ( ) ; entryData = newData ; } entryData . setInt ( 0 , entryData . getInt ( 0 ) + 1 ) ; serializeHash ( entryData , entryOffset , keyHash ) ; entryOffset += HASH_LENGTH ; } entryData . setLong ( entryOffset , segmentOffset ) ; try { storeInCache ( entryData ) ; this . generation = currentGeneration ; this . highestOffset = Math . max ( this . highestOffset , segmentOffset ) ; } catch ( CacheEntryEvictedException cex ) { throw cex ; } catch ( CacheDisabledException cex ) { log . debug ( "SegmentKeyCache[{}]: Not updating cache for {} due to non-essential cache entries disabled." , segmentId , this ) ; return false ; } catch ( Throwable ex ) { log . warn ( "SegmentKeyCache[{}]: Cache Entry update failed for {}." , segmentId , this , ex ) ; return false ; } return true ; }
Inserts or updates the Cache for the given KeyHash with given CacheValue, but only if it has a higher offset
 than the existing value.
Inserts or updates the Cache for the given KeyHash with given CacheValue but only if it has a higher offset than the existing value .
// No match. Need to create a new array, copy any existing data and add new Cache Value. // Increment the count. // Write the Key Hash at the latest offset. // Update the value. // Update the cache and stats. // Pass-through exception. If this is the case, the entry has already been evicted so not more we can do. // There is nothing we can do here. Invoke the general handler to remove this from the cache.