long2ice commented on code in PR #3449:
URL: https://github.com/apache/incubator-devlake/pull/3449#discussion_r996711468


##########
plugins/starrocks/tasks.go:
##########
@@ -162,13 +163,27 @@ func createTable(starrocks *sql.DB, db dal.Dal, 
starrocksTable string, table str
 
 func loadData(starrocks *sql.DB, c core.SubTaskContext, starrocksTable string, 
table string, columnMap map[string]string, db dal.Dal, config *StarRocksConfig) 
error {
        offset := 0
-       starrocksTmpTable := starrocksTable + "_tmp"
-       // create tmp table in starrocks
-       _, execErr := starrocks.Exec(fmt.Sprintf("drop table if exists %s; 
create table %s like %s", starrocksTmpTable, starrocksTmpTable, starrocksTable))
+       var err error
+
+       // step1: create starrocksNewTable
+       starrocksNewTable := starrocksTable + "_new"
+       _, execErr := starrocks.Exec(fmt.Sprintf("drop table if exists %s; 
create table %s like %s", starrocksNewTable, starrocksNewTable, starrocksTable))
        if execErr != nil {
                return execErr
        }
-       var err error
+
+       // step2: renmae starrocksTable to starrocksOldTable

Review Comment:
   rename拼写错误



##########
plugins/starrocks/tasks.go:
##########
@@ -162,13 +163,27 @@ func createTable(starrocks *sql.DB, db dal.Dal, 
starrocksTable string, table str
 
 func loadData(starrocks *sql.DB, c core.SubTaskContext, starrocksTable string, 
table string, columnMap map[string]string, db dal.Dal, config *StarRocksConfig) 
error {
        offset := 0
-       starrocksTmpTable := starrocksTable + "_tmp"
-       // create tmp table in starrocks
-       _, execErr := starrocks.Exec(fmt.Sprintf("drop table if exists %s; 
create table %s like %s", starrocksTmpTable, starrocksTmpTable, starrocksTable))
+       var err error
+
+       // step1: create starrocksNewTable
+       starrocksNewTable := starrocksTable + "_new"
+       _, execErr := starrocks.Exec(fmt.Sprintf("drop table if exists %s; 
create table %s like %s", starrocksNewTable, starrocksNewTable, starrocksTable))
        if execErr != nil {
                return execErr
        }
-       var err error
+
+       // step2: renmae starrocksTable to starrocksOldTable
+       starrocksOldTable := starrocksTable + "_old"
+       _, err = starrocks.Exec(fmt.Sprintf("alter table %s rename %s", 
starrocksTable, starrocksOldTable))

Review Comment:
   这里先把starrocksTable改为old了,那么在数据导入过程中这个表都不可用,不可用的时间会变长



##########
plugins/starrocks/tasks.go:
##########
@@ -162,13 +163,27 @@ func createTable(starrocks *sql.DB, db dal.Dal, 
starrocksTable string, table str
 
 func loadData(starrocks *sql.DB, c core.SubTaskContext, starrocksTable string, 
table string, columnMap map[string]string, db dal.Dal, config *StarRocksConfig) 
error {
        offset := 0
-       starrocksTmpTable := starrocksTable + "_tmp"
-       // create tmp table in starrocks
-       _, execErr := starrocks.Exec(fmt.Sprintf("drop table if exists %s; 
create table %s like %s", starrocksTmpTable, starrocksTmpTable, starrocksTable))
+       var err error
+
+       // step1: create starrocksNewTable
+       starrocksNewTable := starrocksTable + "_new"
+       _, execErr := starrocks.Exec(fmt.Sprintf("drop table if exists %s; 
create table %s like %s", starrocksNewTable, starrocksNewTable, starrocksTable))
        if execErr != nil {
                return execErr
        }
-       var err error
+
+       // step2: renmae starrocksTable to starrocksOldTable
+       starrocksOldTable := starrocksTable + "_old"
+       _, err = starrocks.Exec(fmt.Sprintf("alter table %s rename %s", 
starrocksTable, starrocksOldTable))
+       defer func() {
+               if err != nil {
+                       _, err = starrocks.Exec(fmt.Sprintf("alter table %s 
rename %s", starrocksTable, starrocksOldTable))

Review Comment:
   这里是想在导入出错的时候把old恢复吧,好像反了



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to