Adding in a sync-log. This makes it easier to find colls that sync to much
This commit is contained in:
parent
2c8c0b7c7d
commit
1b7a6c45e6
@ -263,7 +263,7 @@ public class InternalListener implements Listener
|
|||||||
public void syncAllForPlayer(Player player)
|
public void syncAllForPlayer(Player player)
|
||||||
{
|
{
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
for (Coll<?> coll : Coll.instances)
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (!(coll instanceof SenderColl)) continue;
|
if (!(coll instanceof SenderColl)) continue;
|
||||||
SenderColl<?> pcoll = (SenderColl<?>)coll;
|
SenderColl<?> pcoll = (SenderColl<?>)coll;
|
||||||
|
@ -103,7 +103,7 @@ public class MCore extends MPlugin
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
for (Coll<?> coll : Coll.instances)
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
coll.onTick();
|
coll.onTick();
|
||||||
}
|
}
|
||||||
@ -119,7 +119,9 @@ public class MCore extends MPlugin
|
|||||||
{
|
{
|
||||||
// This is safe since all plugins using Persist should bukkit-depend this plugin.
|
// This is safe since all plugins using Persist should bukkit-depend this plugin.
|
||||||
// Note this one must be before preEnable. dooh.
|
// 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
|
// Start the examine thread
|
||||||
ExamineThread.get().start();
|
ExamineThread.get().start();
|
||||||
|
@ -53,11 +53,10 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
|||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
// Collection shutdowns.
|
// Collection shutdowns.
|
||||||
for (Coll<?> coll : Coll.instances)
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (coll.getPlugin() != this) continue;
|
if (coll.getPlugin() != this) continue;
|
||||||
coll.syncAll(); // TODO: Save outwards only? We may want to avoid loads at this stage...
|
coll.deinit();
|
||||||
Coll.instances.remove(coll);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Disabled");
|
log("Disabled");
|
||||||
|
@ -49,7 +49,7 @@ public class CmdMCoreMStoreListcolls extends MCoreCommand
|
|||||||
|
|
||||||
Coll<?> coll = null;
|
Coll<?> coll = null;
|
||||||
|
|
||||||
for (Coll<?> collCandidate : Coll.instances)
|
for (Coll<?> collCandidate : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (!collCandidate.getName().equals(collname)) continue;
|
if (!collCandidate.getName().equals(collname)) continue;
|
||||||
if (collCandidate.getDb() != db) continue;
|
if (collCandidate.getDb() != db) continue;
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.MCorePerm;
|
import com.massivecraft.mcore.MCorePerm;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
|
import com.massivecraft.mcore.store.Coll;
|
||||||
import com.massivecraft.mcore.store.ExamineThread;
|
import com.massivecraft.mcore.store.ExamineThread;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
@ -21,6 +22,13 @@ public class CmdMCoreMStoreStats extends MCoreCommand
|
|||||||
{
|
{
|
||||||
msg(Txt.titleize("MStore Statistics"));
|
msg(Txt.titleize("MStore Statistics"));
|
||||||
msg("<k>Last Examine Duration: <v>%d<i>ms", ExamineThread.get().getLastDurationMillis());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
@ -16,6 +18,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
import com.massivecraft.mcore.MPlugin;
|
import com.massivecraft.mcore.MPlugin;
|
||||||
|
import com.massivecraft.mcore.NaturalOrderComparator;
|
||||||
import com.massivecraft.mcore.Predictate;
|
import com.massivecraft.mcore.Predictate;
|
||||||
import com.massivecraft.mcore.store.accessor.Accessor;
|
import com.massivecraft.mcore.store.accessor.Accessor;
|
||||||
import com.massivecraft.mcore.xlib.gson.Gson;
|
import com.massivecraft.mcore.xlib.gson.Gson;
|
||||||
@ -27,7 +30,31 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
// GLOBAL REGISTRY
|
// 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?
|
// WHAT DO WE HANDLE?
|
||||||
@ -516,16 +543,20 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
case LOCAL_ALTER:
|
case LOCAL_ALTER:
|
||||||
case LOCAL_ATTACH:
|
case LOCAL_ATTACH:
|
||||||
this.saveToRemote(id);
|
this.saveToRemote(id);
|
||||||
|
if (this.inited()) addSyncCount(this.getName(), false);
|
||||||
break;
|
break;
|
||||||
case LOCAL_DETACH:
|
case LOCAL_DETACH:
|
||||||
this.removeAtRemote(id);
|
this.removeAtRemote(id);
|
||||||
|
if (this.inited()) addSyncCount(this.getName(), false);
|
||||||
break;
|
break;
|
||||||
case REMOTE_ALTER:
|
case REMOTE_ALTER:
|
||||||
case REMOTE_ATTACH:
|
case REMOTE_ATTACH:
|
||||||
this.loadFromRemote(id);
|
this.loadFromRemote(id);
|
||||||
|
if (this.inited()) addSyncCount(this.getName(), true);
|
||||||
break;
|
break;
|
||||||
case REMOTE_DETACH:
|
case REMOTE_DETACH:
|
||||||
this.removeAtLocal(id);
|
this.removeAtLocal(id);
|
||||||
|
if (this.inited()) addSyncCount(this.getName(), true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.clearIdentifiedChanges(id);
|
this.clearIdentifiedChanges(id);
|
||||||
@ -657,8 +688,20 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
if (this.inited()) return;
|
if (this.inited()) return;
|
||||||
|
// TODO: Could this be more efficient by considering it's the first sync?
|
||||||
this.syncAll();
|
this.syncAll();
|
||||||
instances.add(this);
|
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
|
@Override
|
||||||
|
@ -141,6 +141,7 @@ public interface CollInterface<E>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public void init();
|
public void init();
|
||||||
|
public void deinit();
|
||||||
public boolean inited();
|
public boolean inited();
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class ExamineThread extends Thread
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
for (Coll<?> coll: Coll.instances)
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
coll.findSuspects();
|
coll.findSuspects();
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
|
|||||||
|
|
||||||
public static void setSenderRefferences(String senderId, CommandSender sender)
|
public static void setSenderRefferences(String senderId, CommandSender sender)
|
||||||
{
|
{
|
||||||
for (Coll<?> coll : Coll.instances)
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (!(coll instanceof SenderColl)) continue;
|
if (!(coll instanceof SenderColl)) continue;
|
||||||
SenderColl<?> senderColl = (SenderColl<?>)coll;
|
SenderColl<?> senderColl = (SenderColl<?>)coll;
|
||||||
|
Loading…
Reference in New Issue
Block a user