Adding in a sync-log. This makes it easier to find colls that sync to much

This commit is contained in:
Olof Larsson 2013-05-27 08:41:06 +02:00
parent 2c8c0b7c7d
commit 1b7a6c45e6
9 changed files with 63 additions and 10 deletions

View File

@ -263,7 +263,7 @@ public class InternalListener implements Listener
public void syncAllForPlayer(Player player)
{
String playerName = player.getName();
for (Coll<?> coll : Coll.instances)
for (Coll<?> coll : Coll.getInstances())
{
if (!(coll instanceof SenderColl)) continue;
SenderColl<?> pcoll = (SenderColl<?>)coll;

View File

@ -103,7 +103,7 @@ public class MCore extends MPlugin
{
public void run()
{
for (Coll<?> coll : Coll.instances)
for (Coll<?> coll : Coll.getInstances())
{
coll.onTick();
}
@ -119,7 +119,9 @@ public class MCore extends MPlugin
{
// This is safe since all plugins using Persist should bukkit-depend this plugin.
// Note this one must be before preEnable. dooh.
Coll.instances.clear();
// TODO: Create something like "deinit all" (perhaps a forloop) to readd this.
// TODO: Test and ensure reload compat.
// Coll.instances.clear();
// Start the examine thread
ExamineThread.get().start();

View File

@ -53,11 +53,10 @@ public abstract class MPlugin extends JavaPlugin implements Listener
public void onDisable()
{
// Collection shutdowns.
for (Coll<?> coll : Coll.instances)
for (Coll<?> coll : Coll.getInstances())
{
if (coll.getPlugin() != this) continue;
coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage...
Coll.instances.remove(coll);
coll.deinit();
}
log("Disabled");

View File

@ -49,7 +49,7 @@ public class CmdMCoreMStoreListcolls extends MCoreCommand
Coll<?> coll = null;
for (Coll<?> collCandidate : Coll.instances)
for (Coll<?> collCandidate : Coll.getInstances())
{
if (!collCandidate.getName().equals(collname)) continue;
if (collCandidate.getDb() != db) continue;

View File

@ -4,6 +4,7 @@ import java.util.List;
import com.massivecraft.mcore.MCorePerm;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.ExamineThread;
import com.massivecraft.mcore.util.Txt;
@ -21,6 +22,13 @@ public class CmdMCoreMStoreStats extends MCoreCommand
{
msg(Txt.titleize("MStore Statistics"));
msg("<k>Last Examine Duration: <v>%d<i>ms", ExamineThread.get().getLastDurationMillis());
msg("<a>== <k>Coll <a>| <k>Sync Count In <a>| <k>Sync Count Out <a>==");
for (String name : Coll.getNames())
{
long in = Coll.getSyncCount(name, true);
long out = Coll.getSyncCount(name, false);
msg("<v>%s <a>| <v>%d <a>| <v>%d", name, in, out);
}
}
}

View File

@ -8,6 +8,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
@ -16,6 +18,7 @@ import org.bukkit.plugin.Plugin;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.MPlugin;
import com.massivecraft.mcore.NaturalOrderComparator;
import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.store.accessor.Accessor;
import com.massivecraft.mcore.xlib.gson.Gson;
@ -27,7 +30,31 @@ public class Coll<E> implements CollInterface<E>
// GLOBAL REGISTRY
// -------------------------------------------- //
public static List<Coll<?>> instances = new CopyOnWriteArrayList<Coll<?>>();
// All instances registered here are considered inited.
private static List<Coll<?>> instances = new CopyOnWriteArrayList<Coll<?>>();
public static List<Coll<?>> getInstances() { return instances; }
private static TreeSet<String> names = new TreeSet<String>(NaturalOrderComparator.get());
public static TreeSet<String> getNames() { return names; }
// Log database syncronization for display in the "/mcore mstore stats" command.
private static Map<String, Long> name2out = new TreeMap<String, Long>(String.CASE_INSENSITIVE_ORDER);
private static Map<String, Long> name2in = new TreeMap<String, Long>(String.CASE_INSENSITIVE_ORDER);
public static long getSyncCount(String name, boolean in)
{
Long count = (in ? name2in.get(name) : name2out.get(name));
if (count == null) return 0;
return count;
}
public static void addSyncCount(String name, boolean in)
{
long count = getSyncCount(name, in);
count++;
Map<String, Long> map = (in ? name2in : name2out);
map.put(name, count);
}
// -------------------------------------------- //
// WHAT DO WE HANDLE?
@ -516,16 +543,20 @@ public class Coll<E> implements CollInterface<E>
case LOCAL_ALTER:
case LOCAL_ATTACH:
this.saveToRemote(id);
if (this.inited()) addSyncCount(this.getName(), false);
break;
case LOCAL_DETACH:
this.removeAtRemote(id);
if (this.inited()) addSyncCount(this.getName(), false);
break;
case REMOTE_ALTER:
case REMOTE_ATTACH:
this.loadFromRemote(id);
if (this.inited()) addSyncCount(this.getName(), true);
break;
case REMOTE_DETACH:
this.removeAtLocal(id);
if (this.inited()) addSyncCount(this.getName(), true);
break;
default:
this.clearIdentifiedChanges(id);
@ -657,8 +688,20 @@ public class Coll<E> implements CollInterface<E>
public void init()
{
if (this.inited()) return;
// TODO: Could this be more efficient by considering it's the first sync?
this.syncAll();
instances.add(this);
names.add(this.getName());
}
@Override
public void deinit()
{
if (!this.inited()) return;
// TODO: Save outwards only? We may want to avoid loads at this stage...
this.syncAll();
instances.remove(this);
names.remove(this.getName());
}
@Override

View File

@ -141,6 +141,7 @@ public interface CollInterface<E>
// -------------------------------------------- //
public void init();
public void deinit();
public boolean inited();

View File

@ -41,7 +41,7 @@ public class ExamineThread extends Thread
try
{
long before = System.currentTimeMillis();
for (Coll<?> coll: Coll.instances)
for (Coll<?> coll : Coll.getInstances())
{
coll.findSuspects();
}

View File

@ -123,7 +123,7 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
public static void setSenderRefferences(String senderId, CommandSender sender)
{
for (Coll<?> coll : Coll.instances)
for (Coll<?> coll : Coll.getInstances())
{
if (!(coll instanceof SenderColl)) continue;
SenderColl<?> senderColl = (SenderColl<?>)coll;