Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeniy Zuykin <[email protected]>
  • Loading branch information
SHaaD94 authored and Evgeniy Zuykin committed Jan 13, 2025
1 parent 3a8e612 commit ce900f3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 50 deletions.
14 changes: 10 additions & 4 deletions fe/fe-core/src/main/java/com/starrocks/meta/SqlBlackList.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.starrocks.common.AnalysisException;
import com.starrocks.common.ErrorCode;
import com.starrocks.common.ErrorReport;
import com.starrocks.persist.AddSqlBlackList;
import com.starrocks.persist.SqlBlackListPersistInfo;
import com.starrocks.persist.ImageWriter;

Check failure on line 23 in fe/fe-core/src/main/java/com/starrocks/meta/SqlBlackList.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'com.starrocks.persist.ImageWriter' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. Raw Output: /github/workspace/./fe/fe-core/src/main/java/com/starrocks/meta/SqlBlackList.java:23:1: error: Wrong lexicographical order for 'com.starrocks.persist.ImageWriter' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import com.starrocks.persist.metablock.SRMetaBlockEOFException;
import com.starrocks.persist.metablock.SRMetaBlockException;
Expand Down Expand Up @@ -63,8 +63,8 @@ public void load(SRMetaBlockReader reader) throws IOException, SRMetaBlockExcept
try (LockCloseable ignored = new LockCloseable(rwLock.writeLock())) {
int cnt = reader.readInt();
for (int i = 0; i < cnt; i++) {
AddSqlBlackList addSqlBlackList = reader.readJson(AddSqlBlackList.class);
put(addSqlBlackList.id, Pattern.compile(addSqlBlackList.pattern));
SqlBlackListPersistInfo sqlBlackListPersistInfo = reader.readJson(SqlBlackListPersistInfo.class);
put(sqlBlackListPersistInfo.id, Pattern.compile(sqlBlackListPersistInfo.pattern));
}
LOG.info("loaded {} SQL blacklist patterns", sqlBlackListMap.size());
}
Expand Down Expand Up @@ -105,6 +105,12 @@ public void delete(long id) {
}
}

public void delete(List<Long> ids) {
for (Long id : ids) {
this.delete(id);
}
}

public void save(ImageWriter imageWriter) throws IOException, SRMetaBlockException {
try (LockCloseable ignored = new LockCloseable(rwLock.readLock())) {
// one for self and N for patterns
Expand All @@ -114,7 +120,7 @@ public void save(ImageWriter imageWriter) throws IOException, SRMetaBlockExcepti
// write patterns
writer.writeInt(sqlBlackListMap.size());
for (BlackListSql p : sqlBlackListMap.values()) {
writer.writeJson(new AddSqlBlackList(p.id, p.pattern.pattern()));
writer.writeJson(new SqlBlackListPersistInfo(p.id, p.pattern.pattern()));
}
writer.close();
}
Expand Down
8 changes: 3 additions & 5 deletions fe/fe-core/src/main/java/com/starrocks/persist/EditLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1113,16 +1113,14 @@ public void loadJournal(GlobalStateMgr globalStateMgr, JournalEntity journal)
break;
}
case OperationType.OP_ADD_SQL_QUERY_BLACK_LIST: {
AddSqlBlackList addBlacklistRequest = (AddSqlBlackList) journal.data();
SqlBlackListPersistInfo addBlacklistRequest = (SqlBlackListPersistInfo) journal.data();
GlobalStateMgr.getCurrentState().getSqlBlackList()
.put(addBlacklistRequest.id, Pattern.compile(addBlacklistRequest.pattern));
break;
}
case OperationType.OP_DELETE_SQL_QUERY_BLACK_LIST: {
DeleteSqlBlackLists deleteBlackListsRequest = (DeleteSqlBlackLists) journal.data();
for (int i = 0; i < deleteBlackListsRequest.ids.size(); i++) {
GlobalStateMgr.getCurrentState().getSqlBlackList().delete(deleteBlackListsRequest.ids.get(i));
}
GlobalStateMgr.getCurrentState().getSqlBlackList().delete(deleteBlackListsRequest.ids);
break;
}
default: {
Expand Down Expand Up @@ -1809,7 +1807,7 @@ public void logAlterMaterializedViewProperties(ModifyTablePropertyOperationLog l
logEdit(OperationType.OP_ALTER_MATERIALIZED_VIEW_PROPERTIES, log);
}

public void logAddSQLBlackList(AddSqlBlackList addBlackList) {
public void logAddSQLBlackList(SqlBlackListPersistInfo addBlackList) {
logEdit(OperationType.OP_ADD_SQL_QUERY_BLACK_LIST, addBlackList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public class EditLogDeserializer {
.put(OperationType.OP_ALTER_WAREHOUSE, Warehouse.class)
.put(OperationType.OP_DROP_WAREHOUSE, DropWarehouseLog.class)
.put(OperationType.OP_CLUSTER_SNAPSHOT_LOG, ClusterSnapshotLog.class)
.put(OperationType.OP_ADD_SQL_QUERY_BLACK_LIST, AddSqlBlackList.class)
.put(OperationType.OP_ADD_SQL_QUERY_BLACK_LIST, SqlBlackListPersistInfo.class)
.put(OperationType.OP_DELETE_SQL_QUERY_BLACK_LIST, DeleteSqlBlackLists.class)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ public class OperationType {
public static final short OP_CLUSTER_SNAPSHOT_LOG = 13513;

@IgnorableOnReplayFailed
public static final short OP_ADD_SQL_QUERY_BLACK_LIST = 13700;
public static final short OP_ADD_SQL_QUERY_BLACK_LIST = 13520;
@IgnorableOnReplayFailed
public static final short OP_DELETE_SQL_QUERY_BLACK_LIST = 13701;
public static final short OP_DELETE_SQL_QUERY_BLACK_LIST = 13521;

/**
* NOTICE: OperationType cannot use a value exceeding 20000, please follow the above sequence number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.util.Objects;

public class AddSqlBlackList extends JsonWriter {
public AddSqlBlackList(long id, String pattern) {
public class SqlBlackListPersistInfo extends JsonWriter {
public SqlBlackListPersistInfo(long id, String pattern) {
this.id = id;
this.pattern = pattern;
}
Expand All @@ -39,7 +39,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
AddSqlBlackList that = (AddSqlBlackList) o;
SqlBlackListPersistInfo that = (SqlBlackListPersistInfo) o;
return id == that.id && Objects.equals(pattern, that.pattern);
}

Expand Down
9 changes: 2 additions & 7 deletions fe/fe-core/src/main/java/com/starrocks/qe/StmtExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
import com.starrocks.mysql.MysqlCommand;
import com.starrocks.mysql.MysqlEofPacket;
import com.starrocks.mysql.MysqlSerializer;
import com.starrocks.persist.AddSqlBlackList;
import com.starrocks.persist.SqlBlackListPersistInfo;
import com.starrocks.persist.CreateInsertOverwriteJobLog;
import com.starrocks.persist.DeleteSqlBlackLists;

Check failure on line 111 in fe/fe-core/src/main/java/com/starrocks/qe/StmtExecutor.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'com.starrocks.persist.DeleteSqlBlackLists' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. Raw Output: /github/workspace/./fe/fe-core/src/main/java/com/starrocks/qe/StmtExecutor.java:111:1: error: Wrong lexicographical order for 'com.starrocks.persist.DeleteSqlBlackLists' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import com.starrocks.persist.gson.GsonUtils;
Expand Down Expand Up @@ -446,11 +446,6 @@ private boolean initForwardToLeaderState() {
}
}

// always redirect sql blacklist related queries to the leader
if (parsedStmt instanceof AddSqlBlackListStmt || parsedStmt instanceof DelSqlBlackListStmt) {
return true;
}

if (redirectStatus == null) {
return false;
} else {
Expand Down Expand Up @@ -1699,7 +1694,7 @@ private void handleAddSqlBlackListStmt() {
AddSqlBlackListStmt addSqlBlackListStmt = (AddSqlBlackListStmt) parsedStmt;
long id = GlobalStateMgr.getCurrentState().getSqlBlackList().put(addSqlBlackListStmt.getSqlPattern());
GlobalStateMgr.getCurrentState().getEditLog()
.logAddSQLBlackList(new AddSqlBlackList(id, addSqlBlackListStmt.getSqlPattern().pattern()));
.logAddSQLBlackList(new SqlBlackListPersistInfo(id, addSqlBlackListStmt.getSqlPattern().pattern()));
}

private void handleDelSqlBlackListStmt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public <R, C> R accept(AstVisitor<R, C> visitor, C context) {

@Override
public RedirectStatus getRedirectStatus() {
return RedirectStatus.NO_FORWARD;
return RedirectStatus.FORWARD_NO_SYNC;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public <R, C> R accept(AstVisitor<R, C> visitor, C context) {

@Override
public RedirectStatus getRedirectStatus() {
return RedirectStatus.NO_FORWARD;
return RedirectStatus.FORWARD_NO_SYNC;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

package com.starrocks.server;

import com.starrocks.ha.FrontendNodeType;
import com.starrocks.analysis.RedirectStatus;
import com.starrocks.meta.BlackListSql;
import com.starrocks.meta.SqlBlackList;
import com.starrocks.persist.AddSqlBlackList;
import com.starrocks.persist.SqlBlackListPersistInfo;
import com.starrocks.persist.DeleteSqlBlackLists;

Check failure on line 21 in fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'com.starrocks.persist.DeleteSqlBlackLists' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. Raw Output: /github/workspace/./fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java:21:1: error: Wrong lexicographical order for 'com.starrocks.persist.DeleteSqlBlackLists' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import com.starrocks.persist.EditLog;

Check failure on line 22 in fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Wrong lexicographical order for 'com.starrocks.persist.EditLog' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. Raw Output: /github/workspace/./fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java:22:1: error: Wrong lexicographical order for 'com.starrocks.persist.EditLog' import. Should be before 'com.starrocks.persist.SqlBlackListPersistInfo'. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import com.starrocks.qe.ConnectContext;
import com.starrocks.qe.StmtExecutor;
import com.starrocks.sql.analyzer.AnalyzeTestUtil;
import com.starrocks.sql.ast.AddSqlBlackListStmt;
import com.starrocks.sql.ast.DelSqlBlackListStmt;
import com.starrocks.sql.ast.StatementBase;
import com.starrocks.utframe.UtFrameUtils;
Expand Down Expand Up @@ -68,7 +69,7 @@ public EditLog getEditLog() {

new Expectations(editLog) {
{
editLog.logAddSQLBlackList(new AddSqlBlackList(0, ".+"));
editLog.logAddSQLBlackList(new SqlBlackListPersistInfo(0, ".+"));
times = 1;
}
};
Expand Down Expand Up @@ -120,27 +121,9 @@ public EditLog getEditLog() {
}

@Test
public void testRedirectBlacklistOperationIfNotLeader() {
MockUp<GlobalStateMgr> mockUp = new MockUp<GlobalStateMgr>() {
@Mock
public FrontendNodeType getFeType() {
return FrontendNodeType.FOLLOWER;
}

@Mock
public boolean isLeader() {
return false;
}
};
ConnectContext connectContext = UtFrameUtils.createDefaultCtx();

StatementBase addStatement = parseSql("ADD SQLBLACKLIST \".+\";");
StmtExecutor addStatementExecutor = new StmtExecutor(connectContext, addStatement);
Assert.assertTrue(addStatementExecutor.isForwardToLeader());

StatementBase deleteStatement = parseSql("DELETE SQLBLACKLIST 1,2,3;");
StmtExecutor deleteStatementExecutor = new StmtExecutor(connectContext, deleteStatement);
Assert.assertTrue(deleteStatementExecutor.isForwardToLeader());
public void testRedirectStatus() {
Assert.assertEquals(new AddSqlBlackListStmt("ADD SQLBLACKLIST \".+\";").getRedirectStatus(), RedirectStatus.FORWARD_NO_SYNC);

Check failure on line 125 in fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Line is longer than 130 characters (found 133). Raw Output: /github/workspace/./fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java:125:0: error: Line is longer than 130 characters (found 133). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
Assert.assertEquals(new DelSqlBlackListStmt(List.of(1L, 2L)).getRedirectStatus(), RedirectStatus.FORWARD_NO_SYNC);
}

@Test
Expand All @@ -164,8 +147,8 @@ public void testSqlBlacklistJournalOperations() throws Exception {

// add blacklists

GlobalStateMgr.getCurrentState().getEditLog().logAddSQLBlackList(new AddSqlBlackList(123, "p1"));
GlobalStateMgr.getCurrentState().getEditLog().logAddSQLBlackList(new AddSqlBlackList(1234, "p2"));
GlobalStateMgr.getCurrentState().getEditLog().logAddSQLBlackList(new SqlBlackListPersistInfo(123, "p1"));
GlobalStateMgr.getCurrentState().getEditLog().logAddSQLBlackList(new SqlBlackListPersistInfo(1234, "p2"));
UtFrameUtils.PseudoJournalReplayer.replayJournalToEnd();

Assertions.assertIterableEquals(
Expand Down

0 comments on commit ce900f3

Please sign in to comment.