Skip to content

Commit

Permalink
[feature][dingo-executor] Add back up update resolve lock safe point (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
githubgxll authored Dec 23, 2024
1 parent 3f84fcf commit 8b5e9e2
Show file tree
Hide file tree
Showing 23 changed files with 1,150 additions and 383 deletions.
6 changes: 6 additions & 0 deletions dingo-calcite/src/main/codegen/config.fmpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ data: {
"io.dingodb.calcite.grammar.dql.SqlShowStartTs"
"io.dingodb.calcite.grammar.dql.SqlShowStatus"
"io.dingodb.calcite.grammar.dql.SqlSelect"
"io.dingodb.calcite.grammar.dql.SqlStartGc"
"io.dingodb.calcite.grammar.dql.SqlBackUpTsoPoint"
"io.dingodb.calcite.grammar.dql.SqlBackUpTimePoint"
"io.dingodb.calcite.grammar.dql.ExportOptions"
"io.dingodb.calcite.grammar.dml.SqlExecute"
"io.dingodb.calcite.grammar.dml.SqlPrepare"
Expand Down Expand Up @@ -245,6 +248,9 @@ data: {
"DISK_ANN_STATUS"
"DISK_ANN_RESET"
"DISK_ANN_COUNT_MEMORY"
"BACK_UP_TIME_POINT"
"BACK_UP_TSO_POINT"
"START_GC"
"CACHE"
"MODIFY"
"CHANGE"
Expand Down
13 changes: 12 additions & 1 deletion dingo-calcite/src/main/codegen/includes/Admin.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

SqlAdmin SqlAdmin(): {
BigInteger txnId;
BigInteger point;
String timeStr = null;
final Span s;
} {
<ADMIN> { s = span(); }
Expand All @@ -27,6 +29,15 @@ SqlAdmin SqlAdmin(): {
{ txnId = new BigInteger(token.image); }
{ return new SqlAdminRollback(s.end(this), txnId); }
|
<RESET> <AUTO_INCREMENT> { return new SqlAdminResetAutoInc(s.end(this)); }
<RESET> <AUTO_INCREMENT> { return new SqlAdminResetAutoInc(s.end(this)); }
|
<BACK_UP_TSO_POINT> { point = new BigInteger(getNextToken().image); }
{ return new SqlBackUpTsoPoint(s.end(this), point); }
|
<BACK_UP_TIME_POINT> { timeStr = getNextToken().image.toUpperCase().replace("'", ""); }
{ return new SqlBackUpTimePoint(s.end(this), timeStr); }
|
<START_GC>
{ return new SqlStartGc(s.end(this)); }
)
}
2 changes: 1 addition & 1 deletion dingo-calcite/src/main/codegen/includes/parserImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void TableElement(List<SqlNode> list) :
|
<CONSTRAINT> { s.add(this); } [name = SimpleIdentifier()] <CHECK> <LPAREN>
checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY)
<RPAREN> [<NOT>] [<ENFORCED>]
<RPAREN> [<NOT>] [<ENFORCED>]
)*
{
if (e == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@
import io.dingodb.calcite.grammar.dml.SqlPrepare;
import io.dingodb.calcite.grammar.dql.ExportOptions;
import io.dingodb.calcite.grammar.dql.FlashBackSqlIdentifier;
import io.dingodb.calcite.grammar.dql.SqlBackUpTimePoint;
import io.dingodb.calcite.grammar.dql.SqlBackUpTsoPoint;
import io.dingodb.calcite.grammar.dql.SqlNextAutoIncrement;
import io.dingodb.calcite.grammar.dql.SqlShow;
import io.dingodb.calcite.grammar.dql.SqlStartGc;
import io.dingodb.calcite.meta.DingoRelMetadataProvider;
import io.dingodb.calcite.program.DecorrelateProgram;
import io.dingodb.calcite.rel.DingoCost;
Expand Down Expand Up @@ -378,7 +381,10 @@ protected static boolean compatibleMysql(SqlNode sqlNode, PlanProfile planProfil
|| sqlNode instanceof SqlKillConnection
|| sqlNode instanceof SqlLoadData
|| sqlNode instanceof SqlCall
|| sqlNode instanceof SqlAdminRollback;
|| sqlNode instanceof SqlAdminRollback
|| sqlNode instanceof SqlStartGc
|| sqlNode instanceof SqlBackUpTimePoint
|| sqlNode instanceof SqlBackUpTsoPoint;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.dingodb.calcite.executor;

import io.dingodb.common.mysql.util.DataTimeUtils;
import io.dingodb.common.util.Pair;
import io.dingodb.transaction.api.GcService;
import io.dingodb.tso.TsoService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

@Slf4j
public class AdminBackUpTimePointExecutor extends QueryExecutor {

public static final List<String> COLUMNS = Arrays.asList(
"STATUS", "SAFE_POINT"
);
public static final int INDEX_STATUS = 0;

public static final int INDEX_TSO = 1;

@Getter
private final String timeStr;

public AdminBackUpTimePointExecutor(String timeStr) {
this.timeStr = timeStr;
}

@Override
public Iterator getIterator() {
long time = DataTimeUtils.parseDate(timeStr);
long point = TsoService.getDefault().tso(time);
long latestTso = TsoService.getDefault().tso();
if (point > latestTso) {
throw new RuntimeException("The specified time:"+ timeStr +" is greater than the " +
"current latest tso:" + latestTso);
}
Pair<String, Long> stringLongPair = GcService.getDefault().startBackUpSafeByPoint(point, latestTso);
List<Object[]> gcColumns = new ArrayList<>();
Object[] objects = new Object[COLUMNS.size()];
objects[INDEX_STATUS] = stringLongPair.getKey();
objects[INDEX_TSO] = stringLongPair.getValue();
gcColumns.add(objects);
return gcColumns.iterator();
}

@Override
public List<String> columns() {
return COLUMNS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.dingodb.calcite.executor;

import io.dingodb.common.util.Pair;
import io.dingodb.transaction.api.GcService;
import io.dingodb.tso.TsoService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

@Slf4j
public class AdminBackUpTsoPointExecutor extends QueryExecutor {

public static final List<String> COLUMNS = Arrays.asList(
"STATUS", "SAFE_POINT"
);
public static final int INDEX_STATUS = 0;

public static final int INDEX_TSO = 1;

@Getter
private final long point;

public AdminBackUpTsoPointExecutor(long point) {
this.point = point;
}

@Override
public Iterator getIterator() {
long latestTso = TsoService.getDefault().tso();
if (point > latestTso) {
throw new RuntimeException("The specified tso:"+ point +" is greater than the " +
"current latest tso:" + latestTso);
}
Pair<String, Long> stringLongPair = GcService.getDefault().startBackUpSafeByPoint(point, latestTso);
List<Object[]> gcColumns = new ArrayList<>();
Object[] objects = new Object[COLUMNS.size()];
objects[INDEX_STATUS] = stringLongPair.getKey();
objects[INDEX_TSO] = stringLongPair.getValue();
gcColumns.add(objects);
return gcColumns.iterator();
}

@Override
public List<String> columns() {
return COLUMNS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.dingodb.calcite.executor;

import io.dingodb.common.util.Pair;
import io.dingodb.transaction.api.GcService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

@Slf4j
public class AdminStartGcExecutor extends QueryExecutor {

public static final List<String> COLUMNS = Arrays.asList(
"STATUS", "SAFE_POINT"
);
public static final int INDEX_STATUS = 0;

public static final int INDEX_TSO = 1;

public AdminStartGcExecutor() {
}

@Override
public Iterator getIterator() {
Pair<String, Long> stringLongPair = GcService.getDefault().startSafePointUpdate();
List<Object[]> gcColumns = new ArrayList<>();
Object[] objects = new Object[COLUMNS.size()];
objects[INDEX_STATUS] = stringLongPair.getKey();
objects[INDEX_TSO] = stringLongPair.getValue();
gcColumns.add(objects);
return gcColumns.iterator();
}

@Override
public List<String> columns() {
return COLUMNS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import io.dingodb.calcite.grammar.ddl.SqlRollback;
import io.dingodb.calcite.grammar.ddl.SqlUnLockBlock;
import io.dingodb.calcite.grammar.ddl.SqlUnLockTable;
import io.dingodb.calcite.grammar.dql.SqlBackUpTimePoint;
import io.dingodb.calcite.grammar.dql.SqlBackUpTsoPoint;
import io.dingodb.calcite.grammar.dql.SqlDescTable;
import io.dingodb.calcite.grammar.dql.SqlNextAutoIncrement;
import io.dingodb.calcite.grammar.dql.SqlShowCharset;
Expand All @@ -56,6 +58,7 @@
import io.dingodb.calcite.grammar.dql.SqlShowTriggers;
import io.dingodb.calcite.grammar.dql.SqlShowVariables;
import io.dingodb.calcite.grammar.dql.SqlShowWarnings;
import io.dingodb.calcite.grammar.dql.SqlStartGc;
import io.dingodb.exec.transaction.base.TransactionType;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlSetOption;
Expand Down Expand Up @@ -247,6 +250,14 @@ public static Optional<Executor> convert(SqlNode sqlNode, Connection connection,
} else if (sqlNode instanceof SqlAdminRollback) {
SqlAdminRollback sqlAdminRollback = (SqlAdminRollback) sqlNode;
return Optional.of(new AdminRollbackExecutor(sqlAdminRollback.txnId));
} else if (sqlNode instanceof SqlStartGc) {
return Optional.of(new AdminStartGcExecutor());
} else if (sqlNode instanceof SqlBackUpTimePoint) {
SqlBackUpTimePoint sqlBackUpTimePoint = (SqlBackUpTimePoint) sqlNode;
return Optional.of(new AdminBackUpTimePointExecutor(sqlBackUpTimePoint.timeStr));
} else if (sqlNode instanceof SqlBackUpTsoPoint) {
SqlBackUpTsoPoint sqlBackUpTsoPoint = (SqlBackUpTsoPoint) sqlNode;
return Optional.of(new AdminBackUpTsoPointExecutor(sqlBackUpTsoPoint.point));
} else {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.dingodb.calcite.grammar.dql;

import io.dingodb.calcite.grammar.ddl.SqlAdmin;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
import org.apache.calcite.sql.SqlWriter;
import org.apache.calcite.sql.parser.SqlParserPos;


public class SqlBackUpTimePoint extends SqlAdmin {
public String timeStr;

private static final SqlOperator OPERATOR =
new SqlSpecialOperator("ADMIN BACK_UP_TIME_POINT", SqlKind.SELECT);

public SqlBackUpTimePoint(SqlParserPos pos, String timeStr) {
super(OPERATOR, pos);
if (timeStr != null) {
this.timeStr = timeStr;
}
}

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("ADMIN BACK_UP_TIME_POINT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.dingodb.calcite.grammar.dql;

import io.dingodb.calcite.grammar.ddl.SqlAdmin;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
import org.apache.calcite.sql.SqlWriter;
import org.apache.calcite.sql.parser.SqlParserPos;

import java.math.BigInteger;

public class SqlBackUpTsoPoint extends SqlAdmin {
public long point;

private static final SqlOperator OPERATOR =
new SqlSpecialOperator("ADMIN BACK_UP_TSO_POINT", SqlKind.SELECT);

public SqlBackUpTsoPoint(SqlParserPos pos, BigInteger point) {
super(OPERATOR, pos);
if (point != null) {
this.point = point.longValue();
}
}

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("ADMIN BACK_UP_TSO_POINT");
}
}
Loading

0 comments on commit 8b5e9e2

Please sign in to comment.