Make stat converter tool go faster and fix incorrect behavior causing rows to be skipped
This commit is contained in:
parent
a68abf0bb3
commit
70c854d0ab
@ -2,7 +2,6 @@ package com.mineplex.statconverter;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -14,7 +13,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
|
||||||
import com.mineplex.statconverter.database.mysql.DBPool;
|
import com.mineplex.statconverter.database.mysql.DBPool;
|
||||||
import com.mysql.jdbc.exceptions.jdbc4.MySQLDataException;
|
import com.mysql.jdbc.exceptions.jdbc4.MySQLDataException;
|
||||||
|
|
||||||
@ -39,50 +37,20 @@ public class Main
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File _info;
|
|
||||||
|
|
||||||
private boolean _complete = false;
|
private boolean _complete = false;
|
||||||
|
|
||||||
private int _nextStart;
|
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
int start = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (new File(new File(".").getCanonicalPath() + File.separator + "complete.dat").exists())
|
if (new File(new File(".").getCanonicalPath() + File.separator + "complete.dat").exists())
|
||||||
{
|
{
|
||||||
return;
|
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)
|
while (!_complete)
|
||||||
{
|
{
|
||||||
convertGroup(_nextStart);
|
convertGroup();
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(5000);
|
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
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));
|
System.out.println("[INFO] Starting next 10000");
|
||||||
List<Integer> accounts = new ArrayList<>();
|
List<Integer> accounts = new ArrayList<>(10000);
|
||||||
try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection())
|
try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection())
|
||||||
{
|
{
|
||||||
try (Statement s = c.createStatement();
|
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())
|
while (rs.next())
|
||||||
@ -219,14 +187,14 @@ public class Main
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(2000);
|
Thread.sleep(500);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
completeGroup(start);
|
System.out.println("[INFO] Completed group of 10000");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -248,27 +216,4 @@ public class Main
|
|||||||
_complete = true;
|
_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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user