yunfengzhou-hub commented on code in PR #1138: URL: https://github.com/apache/flink-agents/pull/1138#discussion_r4217314753
########## runtime/src/main/java/org/apache/flink/agents/runtime/memory/IsolatedCachedMemoryStore.java: ########## @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.flink.agents.runtime.memory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +/** + * Child memory store that reads through to the parent's unpersisted cache but keeps writes to + * itself. {@link #persistCache()} discards child writes with a warning — cross-scope persist + * behavior is not yet designed. + */ +public class IsolatedCachedMemoryStore extends CachedMemoryStore { + + private static final Logger LOG = LoggerFactory.getLogger(IsolatedCachedMemoryStore.class); + + private final CachedMemoryStore parent; + private final Map<String, MemoryObjectImpl.MemoryItem> ownCache = new HashMap<>(); + + public IsolatedCachedMemoryStore(CachedMemoryStore parent) { + super(null); + this.parent = parent; + } + + @Override + public MemoryObjectImpl.MemoryItem get(String key) throws Exception { + if (ownCache.containsKey(key)) { + return ownCache.get(key); + } + return parent.get(key); Review Comment: Fixed. The parent `MemoryItem` is copied with an independent `subKeys` set before being exposed to the child scope, so a child field write no longer mutates the parent's field list. `childFieldWriteDoesNotLeakIntoParentFieldList` and `childNestedWriteDoesNotLeakIntoParentObject` cover it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
