-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improvement] Add compaction regression test case for different data models #9660
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
regression-test/data/compaction/test_compaction_dup_keys.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !select_default -- | ||
1 2017-10-01 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2020-01-01T00:00 1 30 20 | ||
1 2017-10-01 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2020-01-02T00:00 1 31 19 | ||
2 2017-10-01 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2020-01-02T00:00 1 31 21 | ||
2 2017-10-01 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2020-01-03T00:00 1 32 20 | ||
3 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
3 2017-10-01 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2020-01-03T00:00 1 32 22 | ||
3 2017-10-01 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2020-01-04T00:00 1 33 21 | ||
4 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
|
||
-- !select_default2 -- | ||
1 2017-10-01 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2020-01-01T00:00 1 30 20 | ||
1 2017-10-01 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2020-01-02T00:00 1 31 19 | ||
2 2017-10-01 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2020-01-02T00:00 1 31 21 | ||
2 2017-10-01 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2020-01-03T00:00 1 32 20 | ||
3 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
3 2017-10-01 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2020-01-03T00:00 1 32 22 | ||
3 2017-10-01 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2020-01-04T00:00 1 33 21 | ||
4 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
|
13 changes: 13 additions & 0 deletions
13
regression-test/data/compaction/test_compaction_uniq_keys.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !select_default -- | ||
1 2017-10-01 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2020-01-02T00:00 1 31 19 | ||
2 2017-10-01 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2020-01-03T00:00 1 32 20 | ||
3 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
4 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
|
||
-- !select_default2 -- | ||
1 2017-10-01 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2020-01-02T00:00 1 31 19 | ||
2 2017-10-01 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2020-01-03T00:00 1 32 20 | ||
3 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
4 2017-10-01 Beijing 10 1 \N \N 2020-01-05T00:00 1 34 20 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
regression-test/suites/compaction/test_compaction_dup_keys.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import org.codehaus.groovy.runtime.IOGroovyMethods | ||
|
||
// 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_compaction_dup_keys") { | ||
def tableName = "compaction_dup_keys_regression_test" | ||
|
||
try { | ||
StringBuilder showConfigCommand = new StringBuilder(); | ||
showConfigCommand.append("curl -X GET http://") | ||
showConfigCommand.append(context.config.beHttpAddress) | ||
showConfigCommand.append("/api/show_config") | ||
def process = showConfigCommand.toString().execute() | ||
int code = process.waitFor() | ||
String err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream()))); | ||
String out = process.getText() | ||
logger.info("Show config: code=" + code + ", out=" + out + ", err=" + err) | ||
assertEquals(code, 0) | ||
def configList = parseJson(out.trim()) | ||
assert configList instanceof List | ||
|
||
int cumulativeCompactionSkipWindowSeconds = -1 | ||
boolean disableAutoCompaction = true | ||
for (Object ele in (List) configList) { | ||
assert ele instanceof List<String> | ||
if (((List<String>) ele)[0] == "cumulative_compaction_skip_window_seconds") { | ||
cumulativeCompactionSkipWindowSeconds = Integer.parseInt(((List<String>) ele)[2]) | ||
} else if (((List<String>) ele)[0] == "disable_auto_compaction") { | ||
disableAutoCompaction = Boolean.parseBoolean(((List<String>) ele)[2]) | ||
} | ||
} | ||
|
||
sql """ DROP TABLE IF EXISTS ${tableName} """ | ||
sql """ | ||
CREATE TABLE ${tableName} ( | ||
`user_id` LARGEINT NOT NULL COMMENT "用户id", | ||
`date` DATE NOT NULL COMMENT "数据灌入日期时间", | ||
`city` VARCHAR(20) COMMENT "用户所在城市", | ||
`age` SMALLINT COMMENT "用户年龄", | ||
`sex` TINYINT COMMENT "用户性别", | ||
`last_visit_date` DATETIME DEFAULT "1970-01-01 00:00:00" COMMENT "用户最后一次访问时间", | ||
`last_update_date` DATETIME DEFAULT "1970-01-01 00:00:00" COMMENT "用户最后一次更新时间", | ||
`last_visit_date_not_null` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00" COMMENT "用户最后一次访问时间", | ||
`cost` BIGINT DEFAULT "0" COMMENT "用户总消费", | ||
`max_dwell_time` INT DEFAULT "0" COMMENT "用户最大停留时间", | ||
`min_dwell_time` INT DEFAULT "99999" COMMENT "用户最小停留时间") | ||
DUPLICATE KEY(`user_id`, `date`, `city`, `age`, `sex`) DISTRIBUTED BY HASH(`user_id`) | ||
PROPERTIES ( "replication_num" = "1" ); | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(1, '2017-10-01', 'Beijing', 10, 1, '2020-01-01', '2020-01-01', '2020-01-01', 1, 30, 20) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(1, '2017-10-01', 'Beijing', 10, 1, '2020-01-02', '2020-01-02', '2020-01-02', 1, 31, 19) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(2, '2017-10-01', 'Beijing', 10, 1, '2020-01-02', '2020-01-02', '2020-01-02', 1, 31, 21) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(2, '2017-10-01', 'Beijing', 10, 1, '2020-01-03', '2020-01-03', '2020-01-03', 1, 32, 20) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(3, '2017-10-01', 'Beijing', 10, 1, '2020-01-03', '2020-01-03', '2020-01-03', 1, 32, 22) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(3, '2017-10-01', 'Beijing', 10, 1, '2020-01-04', '2020-01-04', '2020-01-04', 1, 33, 21) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(3, '2017-10-01', 'Beijing', 10, 1, NULL, NULL, '2020-01-05', 1, 34, 20) | ||
""" | ||
|
||
sql """ INSERT INTO ${tableName} VALUES | ||
(4, '2017-10-01', 'Beijing', 10, 1, NULL, NULL, '2020-01-05', 1, 34, 20) | ||
""" | ||
|
||
qt_select_default """ SELECT * FROM ${tableName} t ORDER BY user_id,date,city,age,sex,last_visit_date,last_update_date,last_visit_date_not_null,cost,max_dwell_time,min_dwell_time; """ | ||
String[][] tablets = sql """ show tablets from ${tableName}; """ | ||
|
||
if (cumulativeCompactionSkipWindowSeconds > 0) { | ||
logger.info("Config `cumulative_compaction_skip_window_seconds` is set to " + cumulativeCompactionSkipWindowSeconds + " seconds so sleep for a while.") | ||
Thread.sleep(cumulativeCompactionSkipWindowSeconds * 1000) | ||
} | ||
|
||
// trigger compactions for all tablets in ${tableName} | ||
for (String[] tablet in tablets) { | ||
String tablet_id = tablet[0] | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("curl -X POST http://") | ||
sb.append(context.config.beHttpAddress) | ||
sb.append("/api/compaction/run?tablet_id=") | ||
sb.append(tablet_id) | ||
sb.append("&compact_type=cumulative") | ||
|
||
String command = sb.toString() | ||
process = command.execute() | ||
code = process.waitFor() | ||
err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream()))); | ||
out = process.getText() | ||
logger.info("Run compaction: code=" + code + ", out=" + out + ", err=" + err) | ||
assertEquals(code, 0) | ||
def compactJson = parseJson(out.trim()) | ||
if (compactJson.status.toLowerCase() == "fail") { | ||
assertEquals(disableAutoCompaction, false) | ||
logger.info("Compaction was done automatically!") | ||
} | ||
if (disableAutoCompaction) { | ||
assertEquals("success", compactJson.status.toLowerCase()) | ||
} | ||
} | ||
|
||
// wait for all compactions done | ||
for (String[] tablet in tablets) { | ||
boolean running = true | ||
do { | ||
Thread.sleep(1000) | ||
String tablet_id = tablet[0] | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("curl -X GET http://") | ||
sb.append(context.config.beHttpAddress) | ||
sb.append("/api/compaction/run_status?tablet_id=") | ||
sb.append(tablet_id) | ||
|
||
String command = sb.toString() | ||
process = command.execute() | ||
code = process.waitFor() | ||
err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream()))); | ||
out = process.getText() | ||
logger.info("Get compaction status: code=" + code + ", out=" + out + ", err=" + err) | ||
assertEquals(code, 0) | ||
def compactionStatus = parseJson(out.trim()) | ||
assertEquals("success", compactionStatus.status.toLowerCase()) | ||
running = compactionStatus.run_status | ||
} while (running) | ||
} | ||
|
||
int rowCount = 0 | ||
for (String[] tablet in tablets) { | ||
String tablet_id = tablet[0] | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("curl -X GET http://") | ||
sb.append(context.config.beHttpAddress) | ||
sb.append("/api/compaction/show?tablet_id=") | ||
sb.append(tablet_id) | ||
String command = sb.toString() | ||
// wait for cleaning stale_rowsets | ||
process = command.execute() | ||
code = process.waitFor() | ||
err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream()))); | ||
out = process.getText() | ||
logger.info("Show tablets status: code=" + code + ", out=" + out + ", err=" + err) | ||
assertEquals(code, 0) | ||
def tabletJson = parseJson(out.trim()) | ||
assert tabletJson.rowsets instanceof List | ||
for (String rowset in (List<String>) tabletJson.rowsets) { | ||
rowCount += Integer.parseInt(rowset.split(" ")[1]) | ||
} | ||
} | ||
assert (rowCount <= 8) | ||
qt_select_default2 """ SELECT * FROM ${tableName} t ORDER BY user_id,date,city,age,sex,last_visit_date,last_update_date,last_visit_date_not_null,cost,max_dwell_time,min_dwell_time; """ | ||
} finally { | ||
try_sql("DROP TABLE IF EXISTS ${tableName}") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not move the "import org.xxx.yyy" statement under the license comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @carlvinhust2012 , sorry for late reply. This is generated by IDEA and in a wrong order. I modified this in PR #9672