This is an automated email from the ASF dual-hosted git repository. pingsutw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push: new 6686f189 SUBMARINE-1342. Remove experiment template cache in server (#1088) 6686f189 is described below commit 6686f189fd5ad9fab0da760d86729a0f1a2a608d Author: Thinking Chen <cdmikec...@apache.org> AuthorDate: Thu Jul 20 20:00:40 2023 +0800 SUBMARINE-1342. Remove experiment template cache in server (#1088) * Remove cache * Fix test case check --- .../server/manager/ExperimentTemplateManager.java | 39 +++++----------------- .../rest/ExperimentTemplateManagerRestApiTest.java | 3 +- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/submarine-server/server-core/src/main/java/org/apache/submarine/server/manager/ExperimentTemplateManager.java b/submarine-server/server-core/src/main/java/org/apache/submarine/server/manager/ExperimentTemplateManager.java index 0cbea4a2..4b50d75a 100644 --- a/submarine-server/server-core/src/main/java/org/apache/submarine/server/manager/ExperimentTemplateManager.java +++ b/submarine-server/server-core/src/main/java/org/apache/submarine/server/manager/ExperimentTemplateManager.java @@ -25,8 +25,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -72,14 +70,6 @@ public class ExperimentTemplateManager { .registerTypeAdapter(ExperimentId.class, new ExperimentIdDeserializer()); private static final Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss").create(); - - - /** - * ExperimentTemplate Cache. - */ - private final ConcurrentMap<String, ExperimentTemplate> cachedExperimentTemplates = - new ConcurrentHashMap<>(); - /** * Get the singleton instance. * @@ -174,8 +164,6 @@ public class ExperimentTemplateManager { throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(), "Unable to parse the experimentTemplate spec: " + e.getMessage()); } - // Update cache - cachedExperimentTemplates.put(spec.getName(), experimentTemplate); return experimentTemplate; } @@ -206,8 +194,6 @@ public class ExperimentTemplateManager { experimentTemplateMapper.delete(name); sqlSession.commit(); - // Invalidate cache - cachedExperimentTemplates.remove(name); return tpl; } catch (Exception e) { LOG.error(e.getMessage(), e); @@ -239,12 +225,7 @@ public class ExperimentTemplateManager { * @throws SubmarineRuntimeException the service error */ public List<ExperimentTemplate> listExperimentTemplates(String status) throws SubmarineRuntimeException { - List<ExperimentTemplate> tpls = new ArrayList<>(cachedExperimentTemplates.values()); - - // Is it available in cache? - if (tpls.size() != 0) { - return tpls; - } + List<ExperimentTemplate> tpls = new ArrayList<>(); try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { ExperimentTemplateMapper experimentTemplateMapper = sqlSession.getMapper(ExperimentTemplateMapper.class); @@ -253,12 +234,10 @@ public class ExperimentTemplateManager { for (ExperimentTemplateEntity experimentTemplateEntity : experimentTemplateEntities) { if (experimentTemplateEntity != null) { ExperimentTemplate tpl = new ExperimentTemplate(); - tpl.setExperimentTemplateSpec( gson.fromJson(experimentTemplateEntity.getExperimentTemplateSpec(), ExperimentTemplateSpec.class)); tpls.add(tpl); - cachedExperimentTemplates.put(tpl.getExperimentTemplateSpec().getName(), tpl); } } } catch (Exception e) { @@ -276,20 +255,18 @@ public class ExperimentTemplateManager { } } + /** + * Get experiment template by name + * + * @param name experiment template name + */ private ExperimentTemplate getExperimentTemplateDetails(String name) throws SubmarineRuntimeException { - - // Is it available in cache? - ExperimentTemplate tpl = cachedExperimentTemplates.get(name); - if (tpl != null) { - return tpl; - } - ExperimentTemplateEntity experimentTemplateEntity; + ExperimentTemplate tpl = null; try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) { ExperimentTemplateMapper experimentTemplateMapper = sqlSession.getMapper(ExperimentTemplateMapper.class); - experimentTemplateEntity = experimentTemplateMapper.select(name); - + ExperimentTemplateEntity experimentTemplateEntity = experimentTemplateMapper.select(name); if (experimentTemplateEntity != null) { tpl = new ExperimentTemplate(); tpl.setExperimentTemplateSpec( diff --git a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentTemplateManagerRestApiTest.java b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentTemplateManagerRestApiTest.java index 9ff1070c..5a925adf 100644 --- a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentTemplateManagerRestApiTest.java +++ b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentTemplateManagerRestApiTest.java @@ -135,7 +135,8 @@ public class ExperimentTemplateManagerRestApiTest extends AbstractSubmarineServe gson.fromJson(gson.toJson(jsonResponse.getResult()), new TypeToken<List<ExperimentTemplate>>() { }.getType()); - Assert.assertEquals(TPL_NAME, getExperimentTemplates.get(0).getExperimentTemplateSpec().getName()); + Assert.assertTrue(getExperimentTemplates.stream() + .anyMatch(t -> TPL_NAME.equals(t.getExperimentTemplateSpec().getName()))); deleteExperimentTemplate(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@submarine.apache.org For additional commands, e-mail: dev-h...@submarine.apache.org