Browse Source

[Improvement][Dao] SQL optimization - limit one piece of data #5061 (#6940)

* [Feature][unittest] Recover UT in AlertPluginManagerTest.java #6619

* use throws exception instead of try-catch to catch exceptions in AlertPluginManagerTest.java

* change the assert result from assertNull to assertNotNull

* [Improvement][Dao] SQL optimization - limit one piece of data #5069

* Improve the code to A rate

Co-authored-by: linkai <linkai@bigo.sg>
3.0.0/version-upgrade
LinKai 3 years ago committed by GitHub
parent
commit
ad33d43498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java
  2. 9
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java
  3. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java
  4. 1
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml
  5. 8
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineTest.java

5
dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java

@ -116,11 +116,10 @@ public class EmailAlertPluginTest {
alertPluginInstance.setCreateTime(new Date()); alertPluginInstance.setCreateTime(new Date());
alertPluginInstance.setInstanceName("test email alert"); alertPluginInstance.setInstanceName("test email alert");
List<PluginDefine> pluginDefineList = pluginDao.getPluginDefineMapper().queryByNameAndType("Email", "alert"); PluginDefine pluginDefine = pluginDao.getPluginDefineMapper().queryByNameAndType("Email", "alert");
if (pluginDefineList == null || pluginDefineList.size() == 0) { if (pluginDefine == null) {
throw new RuntimeException("no alert plugin be load"); throw new RuntimeException("no alert plugin be load");
} }
PluginDefine pluginDefine = pluginDefineList.get(0);
alertPluginInstance.setPluginDefineId(pluginDefine.getId()); alertPluginInstance.setPluginDefineId(pluginDefine.getId());
alertPluginInstance.setPluginInstanceParams(getEmailAlertParams()); alertPluginInstance.setPluginInstanceParams(getEmailAlertParams());
alertDao.getAlertPluginInstanceMapper().insert(alertPluginInstance); alertDao.getAlertPluginInstanceMapper().insert(alertPluginInstance);

9
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java

@ -22,10 +22,6 @@ import static java.util.Objects.requireNonNull;
import org.apache.dolphinscheduler.dao.entity.PluginDefine; import org.apache.dolphinscheduler.dao.entity.PluginDefine;
import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper;
import org.apache.commons.collections.CollectionUtils;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -63,14 +59,13 @@ public class PluginDao {
requireNonNull(pluginDefine.getPluginName(), "pluginName is null"); requireNonNull(pluginDefine.getPluginName(), "pluginName is null");
requireNonNull(pluginDefine.getPluginType(), "pluginType is null"); requireNonNull(pluginDefine.getPluginType(), "pluginType is null");
List<PluginDefine> pluginDefineList = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType()); PluginDefine currPluginDefine = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType());
if (CollectionUtils.isEmpty(pluginDefineList)) { if (currPluginDefine == null) {
if (pluginDefineMapper.insert(pluginDefine) == 1 && pluginDefine.getId() > 0) { if (pluginDefineMapper.insert(pluginDefine) == 1 && pluginDefine.getId() > 0) {
return pluginDefine.getId(); return pluginDefine.getId();
} }
throw new IllegalStateException("Failed to insert plugin definition"); throw new IllegalStateException("Failed to insert plugin definition");
} }
PluginDefine currPluginDefine = pluginDefineList.get(0);
if (!currPluginDefine.getPluginParams().equals(pluginDefine.getPluginParams())) { if (!currPluginDefine.getPluginParams().equals(pluginDefine.getPluginParams())) {
currPluginDefine.setUpdateTime(pluginDefine.getUpdateTime()); currPluginDefine.setUpdateTime(pluginDefine.getUpdateTime());
currPluginDefine.setPluginParams(pluginDefine.getPluginParams()); currPluginDefine.setPluginParams(pluginDefine.getPluginParams());

2
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java

@ -64,5 +64,5 @@ public interface PluginDefineMapper extends BaseMapper<PluginDefine> {
* @param pluginType * @param pluginType
* @return * @return
*/ */
List<PluginDefine> queryByNameAndType(@Param("pluginName") String pluginName, @Param("pluginType") String pluginType); PluginDefine queryByNameAndType(@Param("pluginName") String pluginName, @Param("pluginType") String pluginType);
} }

1
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml

@ -38,6 +38,7 @@
select * select *
from t_ds_plugin_define from t_ds_plugin_define
where plugin_name = #{pluginName} and plugin_type = #{pluginType} where plugin_name = #{pluginName} and plugin_type = #{pluginType}
limit 1
</select> </select>
<select id="queryDetailById" resultType="org.apache.dolphinscheduler.dao.entity.PluginDefine"> <select id="queryDetailById" resultType="org.apache.dolphinscheduler.dao.entity.PluginDefine">

8
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineTest.java

@ -49,10 +49,10 @@ public class PluginDefineTest extends BaseDaoTest {
@Test @Test
public void testQueryByNameAndType() { public void testQueryByNameAndType() {
PluginDefine pluginDefine = createPluginDefine(); PluginDefine pluginDefine = createPluginDefine();
List<PluginDefine> pluginDefines = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType()); PluginDefine pluginDefineSaved = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType());
Assert.assertTrue(pluginDefines.size() > 0); Assert.assertNotNull(pluginDefineSaved);
Assert.assertEquals(pluginDefines.get(0).getPluginType(), pluginDefine.getPluginType()); Assert.assertEquals(pluginDefineSaved.getPluginType(), pluginDefine.getPluginType());
Assert.assertEquals(pluginDefines.get(0).getPluginName(), pluginDefine.getPluginName()); Assert.assertEquals(pluginDefineSaved.getPluginName(), pluginDefine.getPluginName());
} }
/** /**

Loading…
Cancel
Save