Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat(diff): make first diff changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 7, 2022
1 parent 656a33e commit fcd00db
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ public void execute() {
logger.info("insert {} finished, spend: {}", totalInsert, (stop - start) / 1000);
}

public void executeByTable(String table) {
long start = System.currentTimeMillis();
int totalInsert = 0;

List<Map<String, String>> values = insertStore.get(table);
if (values != null && !values.isEmpty()) {
totalInsert = totalInsert + values.size();
String sql = generateBatchInsertSql(table, values);
logger.debug(sql);
write(sql + ";", table + ".sql");
}

insertStore.clear();

long stop = System.currentTimeMillis();
logger.info("insert {} finished, spend: {}", totalInsert, (stop - start) / 1000);
}

public static void write(String sql, String path) {
List<String> ls = new ArrayList<>();
ls.add(sql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import org.archguard.scanner.common.RepositoryHelper.generateId
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

class DiffRepository(val systemId: String, val language: String, val since: String, val until: String) {
class DiffRepository(
val systemId: String,
val language: String,
val since: String,
val until: String,
val tableName: String
) {
private val batch: SourceBatch = SourceBatch()
private val count = AtomicInteger(0)
private val batchStep = 100
Expand Down Expand Up @@ -45,11 +51,11 @@ class DiffRepository(val systemId: String, val language: String, val since: Stri
}

private fun flush() {
batch.execute()
batch.executeByTable(tableName)
}

fun close() {
batch.execute()
batch.executeByTable(tableName)
batch.close()
}
}
16 changes: 10 additions & 6 deletions diff_changes/src/main/kotlin/org/archguard/diff/changes/Runner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ class Runner : CliktCommand() {
logger.info("start insert data into Mysql")
val sqlStart = System.currentTimeMillis()

val diffRepository = DiffRepository(systemId, language, since, until)
diffRepository.saveDiff(changedCalls)
diffRepository.close()
val tableName = "scm_diff_change"
val repository = DiffRepository(systemId, language, since, until, tableName)

repository.saveDiff(changedCalls)
repository.close()

storeDatabase(systemId)
storeDatabase(systemId, tableName)

val sqlEnd = System.currentTimeMillis()
logger.info("Insert into MySql spend: {} s", (sqlEnd - sqlStart) / 1000)
SqlExecuteThreadPool.close()
}

private fun storeDatabase(systemId: String) {
private fun storeDatabase(systemId: String, tableName: String) {
store.disableForeignCheck()
store.initConnectionPool()
val tableName = "scm_diff_change"

logger.info("--------------------------------------------------------")
val phaser = Phaser(1)
deleteByTable(tableName, phaser, systemId)
phaser.arriveAndAwaitAdvance()

logger.info("------------ system {} clean db is done --------------", systemId)
saveByTables(arrayOf(tableName), phaser)
phaser.arriveAndAwaitAdvance()

logger.info("------------ system {} update db is done --------------", systemId)
logger.info("--------------------------------------------------------")
store.enableForeignCheck()
Expand Down

0 comments on commit fcd00db

Please sign in to comment.