Skip to content

Commit

Permalink
add more testcases for recover table
Browse files Browse the repository at this point in the history
  • Loading branch information
Vallishp committed Dec 9, 2024
1 parent 974c395 commit 131983c
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 5 deletions.
9 changes: 8 additions & 1 deletion pkg/ccr/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2580,12 +2580,19 @@ func (j *Job) handleRecoverInfo(binlog *festruct.TBinlog) error {
return j.handleRecoverInfoRecord(binlog.GetCommitSeq(), recoverInfo)
}

func isRecoverTable(recoverInfo *record.RecoverInfo) bool {
if recoverInfo.PartitionName == "" || recoverInfo.PartitionId == -1 {
return true
}
return false
}

func (j *Job) handleRecoverInfoRecord(commitSeq int64, recoverInfo *record.RecoverInfo) error {
if j.isBinlogCommitted(recoverInfo.TableId, commitSeq) {
return nil
}

if recoverInfo.PartitionName == "" {
if isRecoverTable(recoverInfo) {
var tableName string
if recoverInfo.NewTableName != "" {
tableName = recoverInfo.NewTableName
Expand Down
7 changes: 4 additions & 3 deletions pkg/ccr/record/recover_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ func NewRecoverInfoFromJson(data string) (*RecoverInfo, error) {
return nil, xerror.Errorf(xerror.Normal, "table id not found")
}

/* need check for db level not supported.
*/

// table name must exist. partition name not checked since optional.
if recoverInfo.TableName == "" {
return nil, xerror.Errorf(xerror.Normal, "Table Name can not be null")
}
return &recoverInfo, nil
}

Expand Down
1 change: 0 additions & 1 deletion pkg/rpc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ enum TBinlogType {
// MIN_UNKNOWN = 18,
// UNKNOWN_3 = 19,
MIN_UNKNOWN = 25,
UNKNOWN_9 = 25,
UNKNOWN_10 = 26,
UNKNOWN_11 = 27,
UNKNOWN_12 = 28,
Expand Down
6 changes: 6 additions & 0 deletions regression-test/common/helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ class Helper {
"""
}

void disableDbBinlog() {
suite.sql """
ALTER DATABASE ${context.dbName} SET properties ("binlog.enable" = "false")
"""
}

Boolean checkShowTimesOf(sqlString, myClosure, times, func = "sql") {
Boolean ret = false
List<List<Object>> res
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !target_sql_content_2 --
0 0
0 1
0 2
10 0
10 1
10 2
11 0
11 1
11 2
12 0
12 1
12 2
13 0
13 1
13 2
14 0
14 1
14 2
15 0
15 1
15 2
16 0
16 1
16 2
17 0
17 1
17 2
18 0
18 1
18 2
19 0
19 1
19 2
20 0
20 1
20 2

-- !sql_source_content_2 --
0 0
0 1
0 2
10 0
10 1
10 2
11 0
11 1
11 2
12 0
12 1
12 2
13 0
13 1
13 2
14 0
14 1
14 2
15 0
15 1
15 2
16 0
16 1
16 2
17 0
17 1
17 2
18 0
18 1
18 2
19 0
19 1
19 2
20 0
20 1
20 2

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !target_sql_content_2 --
0 0
0 1
0 2
10 0
10 1
10 2
11 0
11 1
11 2
12 0
12 1
12 2
13 0
13 1
13 2
14 0
14 1
14 2
15 0
15 1
15 2
16 0
16 1
16 2
17 0
17 1
17 2
18 0
18 1
18 2
19 0
19 1
19 2
20 0
20 1
20 2

-- !sql_source_content_2 --
0 0
0 1
0 2
10 0
10 1
10 2
11 0
11 1
11 2
12 0
12 1
12 2
13 0
13 1
13 2
14 0
14 1
14 2
15 0
15 1
15 2
16 0
16 1
16 2
17 0
17 1
17 2
18 0
18 1
18 2
19 0
19 1
19 2
20 0
20 1
20 2

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.
suite("test_ds_tbl_drop_recover2") {
def helper = new GroovyShell(new Binding(['suite': delegate]))
.evaluate(new File("${context.config.suitePath}/../common", "helper.groovy"))

def tableName = "tbl_recover" + helper.randomSuffix()
def test_num = 0
def insert_num = 3
def opPartitonName = "less"

def exist = { res -> Boolean
return res.size() != 0
}
def notExist = { res -> Boolean
return res.size() == 0
}

helper.ccrJobDelete()

sql """
CREATE TABLE if NOT EXISTS ${tableName}_1
(
`test` INT,
`id` INT
)
ENGINE=OLAP
UNIQUE KEY(`test`, `id`)
PARTITION BY RANGE(`id`)
(
PARTITION `${opPartitonName}_0` VALUES LESS THAN ("0"),
PARTITION `${opPartitonName}_1` VALUES LESS THAN ("1000")
)
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"binlog.enable" = "true"
)
"""



for (int index = 0; index < insert_num; index++) {
sql """
INSERT INTO ${tableName}_1 VALUES (${test_num}, ${index})
"""
}

sql """
DROP TABLE ${tableName}_1
"""
helper.enableDbBinlog()
helper.ccrJobCreate()
int interations = 10;
for(int t = 0; t <= interations; t += 1){
/* first iteration already deleted */
sql """
DROP TABLE if exists ${tableName}_1
"""

assertTrue(helper.checkShowTimesOf(""" SHOW TABLES LIKE "${tableName}_1" """, notExist, 60, "sql")) // check recovered in local
assertTrue(helper.checkShowTimesOf(""" SHOW TABLES LIKE "${tableName}_1" """, notExist, 60, "target"))

sql """
RECOVER TABLE ${tableName}_1
"""
assertTrue(helper.checkShowTimesOf(""" SHOW TABLES LIKE "${tableName}_1" """, exist, 60, "sql")) // check recovered in local
assertTrue(helper.checkShowTimesOf(""" SHOW TABLES LIKE "${tableName}_1" """, exist, 60, "target")) // check recovered in target

assertTrue(helper.checkRestoreFinishTimesOf("${tableName}_1", 60))

test_num = t + 10;
for (int index = 0; index < insert_num; index++) {
sql """
INSERT INTO ${tableName}_1 VALUES (${test_num}, ${index})
"""
}
// need check restore,
assertTrue(helper.checkRestoreFinishTimesOf("${tableName}_1", 60))
// check in remote available.
assertTrue(helper.checkSelectTimesOf("SELECT * FROM ${tableName}_1 WHERE test=${test_num}",
insert_num, 30))

}
order_qt_target_sql_content_2("SELECT * FROM ${tableName}_1")
qt_sql_source_content_2("SELECT * FROM ${tableName}_1")
}
Loading

0 comments on commit 131983c

Please sign in to comment.