Skip to content

Commit f96aa3d

Browse files
committed
Complete the materialized view log implementation of ob mysql in db-browser
1 parent d2d0014 commit f96aa3d

16 files changed

+480
-8
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2023 OceanBase.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.oceanbase.tools.dbbrowser.model;
17+
18+
import lombok.AllArgsConstructor;
19+
import lombok.Data;
20+
import lombok.NoArgsConstructor;
21+
22+
/**
23+
* @description:
24+
* @author: zijia.cj
25+
* @date: 2025/7/14 10:22
26+
* @since: 4.4.0
27+
*/
28+
@Data
29+
@AllArgsConstructor
30+
@NoArgsConstructor
31+
public class DBMViewLogPurgeParameter {
32+
33+
private String schemaName;
34+
35+
private String mViewLogName;
36+
37+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2023 OceanBase.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.oceanbase.tools.dbbrowser.model;
17+
18+
import java.util.Date;
19+
20+
import lombok.AllArgsConstructor;
21+
import lombok.Data;
22+
import lombok.NoArgsConstructor;
23+
24+
/**
25+
* @description:
26+
* @author: zijia.cj
27+
* @date: 2025/7/14 15:00
28+
* @since: 4.4.0
29+
*/
30+
@Data
31+
@AllArgsConstructor
32+
@NoArgsConstructor
33+
public class DBMViewLogPurgeSchedule {
34+
35+
private StartStrategy startStrategy;
36+
37+
private Date startWith;
38+
39+
private Long interval;
40+
41+
private TimeUnit unit;
42+
43+
private Date startDate;
44+
45+
private String nextExpression;
46+
47+
public enum TimeUnit {
48+
SECOND,
49+
MINUTE,
50+
HOUR,
51+
DAY,
52+
// just for ob mysql
53+
WEEK,
54+
MONTH,
55+
YEAR;
56+
}
57+
58+
public enum StartStrategy {
59+
START_NOW,
60+
START_AT;
61+
}
62+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2023 OceanBase.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.oceanbase.tools.dbbrowser.model;
17+
18+
import java.util.Date;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
23+
/**
24+
* @description:
25+
* @author: zijia.cj
26+
* @date: 2025/7/14 10:24
27+
* @since: 4.4.0
28+
*/
29+
@Setter
30+
@Getter
31+
public class DBMaterializedViewLog implements DBObject {
32+
33+
private String mViewLogName;
34+
35+
private String baseTableName;
36+
/**
37+
* The materialized view log and the base table belong to the same schema. if null, use
38+
* defaultSchemaName in current connection.
39+
*/
40+
private String schemaName;
41+
/**
42+
* The parallelism degree of purging expired data in the materialized view log.
43+
*/
44+
private Long purgeParallelismDegree;
45+
/**
46+
* The configuration for automatic cleaning, if null, indicates that it is not enabled
47+
*/
48+
private DBMViewLogPurgeSchedule purgeSchedule;
49+
50+
private Date lastPurgeDate;
51+
52+
private Boolean includeNewValues;
53+
54+
@Override
55+
public String name() {
56+
return this.mViewLogName;
57+
}
58+
59+
@Override
60+
public DBObjectType type() {
61+
return DBObjectType.MATERIALIZED_VIEW_LOG;
62+
}
63+
}

libs/db-browser/src/main/java/com/oceanbase/tools/dbbrowser/schema/DBSchemaAccessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
import com.oceanbase.tools.dbbrowser.model.DBColumnGroupElement;
2222
import com.oceanbase.tools.dbbrowser.model.DBDatabase;
2323
import com.oceanbase.tools.dbbrowser.model.DBFunction;
24+
import com.oceanbase.tools.dbbrowser.model.DBMViewLogPurgeParameter;
2425
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshParameter;
2526
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecord;
2627
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecordParam;
2728
import com.oceanbase.tools.dbbrowser.model.DBMaterializedView;
29+
import com.oceanbase.tools.dbbrowser.model.DBMaterializedViewLog;
2830
import com.oceanbase.tools.dbbrowser.model.DBObjectIdentity;
2931
import com.oceanbase.tools.dbbrowser.model.DBPLObjectIdentity;
3032
import com.oceanbase.tools.dbbrowser.model.DBPackage;
@@ -168,6 +170,21 @@ default List<String> showExternalTables(String schemaName) {
168170
*/
169171
List<DBTableIndex> listMViewIndexes(String schemaName, String mViewName);
170172

173+
/**
174+
* List all materialized view logs as DBObjectIdentity in the specified schema
175+
*/
176+
List<DBObjectIdentity> listMViewLogs(String schemaName);
177+
178+
/**
179+
* Purge expired data in the materialized view log
180+
*/
181+
Boolean purgeMViewLog(DBMViewLogPurgeParameter parameter);
182+
183+
/**
184+
* Get materialized view log details
185+
*/
186+
DBMaterializedViewLog getMViewLog(String schemaName, String mViewLogName);
187+
171188
/**
172189
* List all variables
173190
*/

libs/db-browser/src/main/java/com/oceanbase/tools/dbbrowser/schema/doris/DorisSchemaAccessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@
5757
import com.oceanbase.tools.dbbrowser.model.DBFunction;
5858
import com.oceanbase.tools.dbbrowser.model.DBIndexAlgorithm;
5959
import com.oceanbase.tools.dbbrowser.model.DBIndexType;
60+
import com.oceanbase.tools.dbbrowser.model.DBMViewLogPurgeParameter;
6061
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshParameter;
6162
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecord;
6263
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecordParam;
6364
import com.oceanbase.tools.dbbrowser.model.DBMaterializedView;
65+
import com.oceanbase.tools.dbbrowser.model.DBMaterializedViewLog;
6466
import com.oceanbase.tools.dbbrowser.model.DBObjectIdentity;
6567
import com.oceanbase.tools.dbbrowser.model.DBObjectType;
6668
import com.oceanbase.tools.dbbrowser.model.DBPLObjectIdentity;
@@ -119,6 +121,21 @@ public DorisSchemaAccessor(@NonNull JdbcOperations jdbcOperations) {
119121
this.sqlMapper = DBSchemaAccessorSqlMappers.get(StatementsFiles.MYSQL_5_7_x);
120122
}
121123

124+
@Override
125+
public List<DBObjectIdentity> listMViewLogs(String schemaName) {
126+
throw new UnsupportedOperationException("not support yet");
127+
}
128+
129+
@Override
130+
public Boolean purgeMViewLog(DBMViewLogPurgeParameter parameter) {
131+
throw new UnsupportedOperationException("not support yet");
132+
}
133+
134+
@Override
135+
public DBMaterializedViewLog getMViewLog(String schemaName, String mViewLogName) {
136+
throw new UnsupportedOperationException("not support yet");
137+
}
138+
122139
@Override
123140
public List<String> showDatabases() {
124141
MySQLSqlBuilder sb = new MySQLSqlBuilder();

libs/db-browser/src/main/java/com/oceanbase/tools/dbbrowser/schema/mysql/MySQLNoLessThan5700SchemaAccessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@
5858
import com.oceanbase.tools.dbbrowser.model.DBFunction;
5959
import com.oceanbase.tools.dbbrowser.model.DBIndexAlgorithm;
6060
import com.oceanbase.tools.dbbrowser.model.DBIndexType;
61+
import com.oceanbase.tools.dbbrowser.model.DBMViewLogPurgeParameter;
6162
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshParameter;
6263
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecord;
6364
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecordParam;
6465
import com.oceanbase.tools.dbbrowser.model.DBMaterializedView;
66+
import com.oceanbase.tools.dbbrowser.model.DBMaterializedViewLog;
6567
import com.oceanbase.tools.dbbrowser.model.DBObjectIdentity;
6668
import com.oceanbase.tools.dbbrowser.model.DBObjectType;
6769
import com.oceanbase.tools.dbbrowser.model.DBPLObjectIdentity;
@@ -386,6 +388,21 @@ public List<DBTableIndex> listMViewIndexes(String schemaName, String mViewName)
386388
throw new UnsupportedOperationException("not support yet");
387389
}
388390

391+
@Override
392+
public List<DBObjectIdentity> listMViewLogs(String schemaName) {
393+
throw new UnsupportedOperationException("not support yet");
394+
}
395+
396+
@Override
397+
public Boolean purgeMViewLog(DBMViewLogPurgeParameter parameter) {
398+
throw new UnsupportedOperationException("not support yet");
399+
}
400+
401+
@Override
402+
public DBMaterializedViewLog getMViewLog(String schemaName, String mViewLogName) {
403+
throw new UnsupportedOperationException("not support yet");
404+
}
405+
389406
@Override
390407
public List<DBVariable> showVariables() {
391408
String sql = "show variables";

libs/db-browser/src/main/java/com/oceanbase/tools/dbbrowser/schema/mysql/OBMySQLBetween2277And3XSchemaAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* @Description: []
5656
*/
5757
@Slf4j
58-
public class OBMySQLBetween2277And3XSchemaAccessor extends OBMySQLSchemaAccessor {
58+
public class OBMySQLBetween2277And3XSchemaAccessor extends OBMySQLBetween400And432SchemaAccessor {
5959

6060
/**
6161
* 以下对象名为 mysql schema 下的视图,但 table_type='BASE_TYPE'

libs/db-browser/src/main/java/com/oceanbase/tools/dbbrowser/schema/mysql/OBMySQLBetween432And4352SchemaAccessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
import org.springframework.jdbc.core.JdbcOperations;
2222

23+
import com.oceanbase.tools.dbbrowser.model.DBMViewLogPurgeParameter;
2324
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshParameter;
2425
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecord;
2526
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecordParam;
2627
import com.oceanbase.tools.dbbrowser.model.DBMaterializedView;
28+
import com.oceanbase.tools.dbbrowser.model.DBMaterializedViewLog;
2729
import com.oceanbase.tools.dbbrowser.model.DBObjectIdentity;
2830
import com.oceanbase.tools.dbbrowser.model.DBTableColumn;
2931
import com.oceanbase.tools.dbbrowser.model.DBTableConstraint;
@@ -41,6 +43,21 @@ public OBMySQLBetween432And4352SchemaAccessor(JdbcOperations jdbcOperations) {
4143
super(jdbcOperations);
4244
}
4345

46+
@Override
47+
public List<DBObjectIdentity> listMViewLogs(String schemaName) {
48+
throw new UnsupportedOperationException("not support yet");
49+
}
50+
51+
@Override
52+
public Boolean purgeMViewLog(DBMViewLogPurgeParameter parameter) {
53+
throw new UnsupportedOperationException("not support yet");
54+
}
55+
56+
@Override
57+
public DBMaterializedViewLog getMViewLog(String schemaName, String mViewLogName) {
58+
throw new UnsupportedOperationException("not support yet");
59+
}
60+
4461
@Override
4562
public List<DBObjectIdentity> listMViews(String schemaName) {
4663
throw new UnsupportedOperationException("not support yet");

libs/db-browser/src/main/java/com/oceanbase/tools/dbbrowser/schema/mysql/OBMySQLSchemaAccessor.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525
import java.util.Set;
26+
import java.util.regex.Pattern;
2627
import java.util.stream.Collectors;
2728

2829
import org.apache.commons.collections4.CollectionUtils;
@@ -32,10 +33,13 @@
3233
import com.oceanbase.tools.dbbrowser.model.DBColumnGroupElement;
3334
import com.oceanbase.tools.dbbrowser.model.DBDatabase;
3435
import com.oceanbase.tools.dbbrowser.model.DBIndexAlgorithm;
36+
import com.oceanbase.tools.dbbrowser.model.DBMViewLogPurgeParameter;
37+
import com.oceanbase.tools.dbbrowser.model.DBMViewLogPurgeSchedule;
3538
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshParameter;
3639
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecord;
3740
import com.oceanbase.tools.dbbrowser.model.DBMViewRefreshRecordParam;
3841
import com.oceanbase.tools.dbbrowser.model.DBMaterializedView;
42+
import com.oceanbase.tools.dbbrowser.model.DBMaterializedViewLog;
3943
import com.oceanbase.tools.dbbrowser.model.DBMaterializedViewRefreshMethod;
4044
import com.oceanbase.tools.dbbrowser.model.DBObjectIdentity;
4145
import com.oceanbase.tools.dbbrowser.model.DBObjectType;
@@ -68,6 +72,8 @@
6872
@Slf4j
6973
public class OBMySQLSchemaAccessor extends MySQLNoLessThan5700SchemaAccessor {
7074

75+
private static final String MVIEW_LOG_PREFIX = "mlog$_";
76+
7177
protected static final Set<String> ESCAPE_SCHEMA_SET = new HashSet<>(4);
7278

7379
static {
@@ -82,6 +88,54 @@ public OBMySQLSchemaAccessor(JdbcOperations jdbcOperations) {
8288
this.sqlMapper = DBSchemaAccessorSqlMappers.get(StatementsFiles.OBMYSQL_432x);
8389
}
8490

91+
@Override
92+
public List<DBObjectIdentity> listMViewLogs(String schemaName) {
93+
MySQLSqlBuilder sb = new MySQLSqlBuilder();
94+
sb.append("SELECT LOG_TABLE FROM oceanbase.DBA_MVIEW_LOGS WHERE LOG_OWNER = ")
95+
.value(schemaName);
96+
return jdbcOperations.query(sb.toString(),
97+
(rs, rowNum) -> DBObjectIdentity.of(schemaName, DBObjectType.MATERIALIZED_VIEW_LOG, rs.getString(1)));
98+
}
99+
100+
@Override
101+
public Boolean purgeMViewLog(DBMViewLogPurgeParameter parameter) {
102+
MySQLSqlBuilder sb = new MySQLSqlBuilder();
103+
sb.append("call DBMS_MVIEW.PURGE_LOG('");
104+
if (Objects.nonNull(parameter.getSchemaName())) {
105+
sb.append(parameter.getSchemaName()).append(".");
106+
}
107+
sb.append(parameter.getMViewLogName().replaceFirst(Pattern.quote(MVIEW_LOG_PREFIX), "")).append("');");
108+
jdbcOperations.execute(sb.toString());
109+
return Boolean.TRUE;
110+
}
111+
112+
@Override
113+
public DBMaterializedViewLog getMViewLog(String schemaName, String mViewLogName) {
114+
MySQLSqlBuilder getOptions = new MySQLSqlBuilder();
115+
getOptions.append(
116+
"SELECT MASTER,INCLUDE_NEW_VALUES,PURGE_START,PURGE_INTERVAL,LAST_PURGE_DATE,PURGE_DOP FROM OCEANBASE.DBA_MVIEW_LOGS WHERE LOG_OWNER = ")
117+
.value(schemaName)
118+
.append(" AND LOG_TABLE = ")
119+
.value(mViewLogName);
120+
DBMaterializedViewLog mViewLog = new DBMaterializedViewLog();
121+
mViewLog.setMViewLogName(mViewLogName);
122+
mViewLog.setSchemaName(schemaName);
123+
jdbcOperations.query(getOptions.toString(), (rs) -> {
124+
mViewLog.setBaseTableName(rs.getString("MASTER"));
125+
mViewLog.setIncludeNewValues(rs.getBoolean("INCLUDE_NEW_VALUES"));
126+
if (rs.getDate("PURGE_START") != null || rs.getDate("PURGE_INTERVAL") != null) {
127+
DBMViewLogPurgeSchedule dbmViewLogPurgeSchedule = new DBMViewLogPurgeSchedule();
128+
dbmViewLogPurgeSchedule.setStartDate(rs.getDate("PURGE_START"));
129+
dbmViewLogPurgeSchedule.setNextExpression(rs.getString("PURGE_INTERVAL"));
130+
mViewLog.setPurgeSchedule(dbmViewLogPurgeSchedule);
131+
}
132+
mViewLog.setLastPurgeDate(rs.getDate("LAST_PURGE_DATE"));
133+
mViewLog.setPurgeParallelismDegree(rs.getLong("PURGE_DOP"));
134+
});
135+
return mViewLog;
136+
137+
}
138+
85139
@Override
86140
public List<DBObjectIdentity> listMViews(String schemaName) {
87141
MySQLSqlBuilder sb = new MySQLSqlBuilder();

0 commit comments

Comments
 (0)