Skip to content

Commit

Permalink
[common] auto generate index when jpa auto-ddl (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Mar 21, 2023
1 parent cab8eac commit b1f27fc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
* @date 2021/12/8 20:41
*/
@Entity
@Table(name = "hzb_alert_define_monitor_bind")
@Table(name = "hzb_alert_define_monitor_bind", indexes = {
@Index(name = "index_alert_define_monitor", columnList = "alertDefineId"),
@Index(name = "index_alert_define_monitor", columnList = "monitor_id")
})
@Data
@Builder
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
* @date 2021/11/14 9:53
*/
@Entity
@Table(name = "hzb_monitor")
@Table(name = "hzb_monitor", indexes = {
@Index(name = "monitor_query_index", columnList = "app"),
@Index(name = "monitor_query_index", columnList = "host"),
@Index(name = "monitor_query_index", columnList = "name")
})
@Data
@Builder
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
* @date 2021/11/13 22:19
*/
@Entity
@Table(name = "hzb_param")
@Table(name = "hzb_param", indexes = { @Index(columnList = "monitorId") },
uniqueConstraints = @UniqueConstraint(columnNames = {"monitorId", "field"}))
@Data
@Builder
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
* @date 2021/11/13 22:19
*/
@Entity
@Table(name = "hzb_tag_monitor_bind")
@Table(name = "hzb_tag_monitor_bind", indexes = {
@Index(name = "index_tag_monitor", columnList = "tag_id"),
@Index(name = "index_tag_monitor", columnList = "monitor_id")
})
@Data
@Builder
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
* @date 2023/2/3 14:13
*/
@Entity
@Table(name = "hzb_history")
@Table(name = "hzb_history", indexes = {
@Index(name = "history_query_index", columnList = "monitorId"),
@Index(name = "history_query_index", columnList = "app"),
@Index(name = "history_query_index", columnList = "metrics"),
@Index(name = "history_query_index", columnList = "metric")
})
@Data
@Builder
@AllArgsConstructor
Expand Down
9 changes: 9 additions & 0 deletions manager/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@
</root>
</springProfile>

<!-- 开发环境配置 -->
<springProfile name="mysql">
<root level="INFO">
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="SystemOutFileAppender"/>
<appender-ref ref="ErrOutFileAppender"/>
</root>
</springProfile>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface HistoryDao extends JpaRepository<History, Long>, JpaSpecificati
*/
@Modifying
@Transactional(rollbackFor = Exception.class)
@Query(value = "delete from hzb_history limit 5000", nativeQuery = true)
@Query(value = "delete from hzb_history limit 20000", nativeQuery = true)
int deleteOlderHistoriesRecord();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class HistoryJpaDatabaseDataStorage extends AbstractHistoryDataStorage {
private WarehouseProperties.StoreProperties.JpaProperties jpaProperties;

private static final int STRING_MAX_LENGTH = 1024;
private static final int MAX_HISTORY_TABLE_RECORD = 200_000;
private static final int MAX_HISTORY_TABLE_RECORD = 60_000;

public HistoryJpaDatabaseDataStorage(WarehouseProperties properties,
HistoryDao historyDao) {
Expand Down

0 comments on commit b1f27fc

Please sign in to comment.