Make stat converter tool go faster and fix incorrect behavior causing rows to be skipped

This commit is contained in:
AlexTheCoder 2017-11-30 05:12:32 -05:00 committed by Alexander Meech
parent a68abf0bb3
commit 70c854d0ab
1 changed files with 7 additions and 62 deletions

View File

@ -2,7 +2,6 @@ package com.mineplex.statconverter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -14,7 +13,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.io.Files;
import com.mineplex.statconverter.database.mysql.DBPool;
import com.mysql.jdbc.exceptions.jdbc4.MySQLDataException;
@ -39,50 +37,20 @@ public class Main
}
}
private File _info;
private boolean _complete = false;
private int _nextStart;
public Main()
{
int start = 0;
try
{
if (new File(new File(".").getCanonicalPath() + File.separator + "complete.dat").exists())
{
return;
}
_info = new File(new File(".").getCanonicalPath() + File.separator + "converterInfo.dat");
System.out.println(_info.getCanonicalPath());
if (_info.exists())
{
String startStr = Files.readFirstLine(_info, Charset.defaultCharset());
if (startStr != null && !startStr.isEmpty())
{
start = Integer.parseInt(startStr);
}
}
else
{
_info.createNewFile();
Files.write(String.valueOf(0).getBytes(), _info);
}
_nextStart = start;
while (!_complete)
{
convertGroup(_nextStart);
try
{
Thread.sleep(5000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
convertGroup();
}
}
catch (IOException e)
@ -92,14 +60,14 @@ public class Main
}
}
private void convertGroup(int start)
private void convertGroup()
{
System.out.println("[INFO] Starting " + start + " to " + (start + 9999));
List<Integer> accounts = new ArrayList<>();
System.out.println("[INFO] Starting next 10000");
List<Integer> accounts = new ArrayList<>(10000);
try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection())
{
try (Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT DISTINCT accountId FROM accountStat LIMIT " + start + ",10000;")
ResultSet rs = s.executeQuery("SELECT DISTINCT accountId FROM accountStat LIMIT 10000;")
)
{
while (rs.next())
@ -219,14 +187,14 @@ public class Main
}
try
{
Thread.sleep(2000);
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
completeGroup(start);
System.out.println("[INFO] Completed group of 10000");
}
else
{
@ -248,27 +216,4 @@ public class Main
_complete = true;
}
}
private void completeGroup(int start)
{
_nextStart = start + 10000;
if (_info.delete())
{
try
{
_info.createNewFile();
Files.write(String.valueOf(_nextStart).getBytes(), _info);
System.out.println("[INFO] Completed " + start + " to " + (_nextStart - 1));
}
catch (IOException e)
{
e.printStackTrace();
_complete = true;
}
}
else
{
_complete = true;
}
}
}