bamaer commented on code in PR #9447: URL: https://github.com/apache/hop/pull/9447#discussion_r4555046039
########## plugins/misc/reflection/src/main/java/org/apache/hop/reflection/RunMetadata.java: ########## @@ -0,0 +1,94 @@ +/* + * 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.hop.reflection; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.metadata.api.IHopMetadata; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.engine.IPipelineEngine; +import org.apache.hop.workflow.engine.IWorkflowEngine; + +/** + * The metadata objects of a type as they were when a run first needed them. + * + * <p>Pipeline logs, workflow logs and pipeline probes are looked at every time a pipeline or + * workflow starts. A run that starts thousands of child pipelines (a Pipeline executor, a mapping, + * a loop in a workflow) would read the same metadata from disk thousands of times. Here the objects + * are read once per run and type: the run is the top-level pipeline or workflow, and everything it + * starts shares what was read. A change to this metadata while the run is going on takes effect + * with the next run. + */ +public final class RunMetadata { + + /** Per top-level pipeline or workflow; an entry goes away with the engine it belongs to. */ + private static final Map<Object, Map<Class<?>, List<?>>> RUNS = + Collections.synchronizedMap(new WeakHashMap<>()); + + private RunMetadata() {} + + /** + * @param engine the pipeline or workflow that starts + * @param metadataProvider where to read the objects when the run does not have them yet + * @param type the metadata type + * @return all objects of the type, read once per run; do not change the list or its objects + */ + @SuppressWarnings("unchecked") + public static <T extends IHopMetadata> List<T> loadAll( Review Comment: **Should fix:** this changes which pipeline logs, workflow logs and probes child runs see, and no integration test covers logging of child pipelines (`integration-tests/logging` only has top-level fail-parent cases). Suggest adding to `integration-tests/logging`: - a pipeline with a Pipeline executor (group size 1, 3 input rows); - a pipeline log with "logging parents only" off, writing one row per run to a file; - a `main-003-*.hwf` that checks the file has 4 rows (the parent and 3 children). -- 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]
