From b8462509442d89519fdece4ad87c437628bda213 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 1 May 2013 19:41:36 +0200 Subject: [PATCH] Added missing line, the DB cache now works. Added mstore stats and listcolls command. --- plugin.yml | 7 ++ src/com/massivecraft/mcore/MCorePerm.java | 2 + .../mcore/mcorecmd/CmdMCoreMStore.java | 4 + .../mcorecmd/CmdMCoreMStoreListcolls.java | 73 +++++++++++++++++++ .../mcore/mcorecmd/CmdMCoreMStoreStats.java | 26 +++++++ .../massivecraft/mcore/store/DriverMongo.java | 4 +- src/com/massivecraft/mcore/store/MStore.java | 10 ++- 7 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreListcolls.java create mode 100644 src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreStats.java diff --git a/plugin.yml b/plugin.yml index 75ab9715..80a95158 100644 --- a/plugin.yml +++ b/plugin.yml @@ -14,6 +14,8 @@ permissions: mcore.cmd.mcore.id: {description: see the server id, default: false} mcore.cmd.mcore.version: {description: diplay plugin version, default: false} mcore.cmd.mcore.mstore: {description: use the mstore command, default: false} + mcore.cmd.mcore.mstore.stats: {description: show mstore statistics, default: false} + mcore.cmd.mcore.mstore.listcolls: {description: list collections in a database, default: false} mcore.cmd.mcore.mstore.copydb: {description: copy database content, default: false} mcore.cmd.mcore.usys: {description: use the usys command, default: false} mcore.cmd.mcore.usys.multiverse: {description: manage multiverses, default: false} @@ -42,6 +44,8 @@ permissions: mcore.cmd.mcore.id: true mcore.cmd.mcore.version: true mcore.cmd.mcore.mstore: true + mcore.cmd.mcore.mstore.stats: true + mcore.cmd.mcore.mstore.listcolls: true mcore.cmd.mcore.mstore.copydb: true mcore.cmd.mcore.usys: true mcore.cmd.mcore.usys.multiverse: true @@ -81,6 +85,9 @@ permissions: mcore.cmd.mcore: true mcore.cmd.mcore.id: true mcore.cmd.mcore.version: true + mcore.cmd.mcore.mstore: true + mcore.cmd.mcore.mstore.stats: true + mcore.cmd.mcore.mstore.listcolls: true mcore.cmd.mcore.usys: true mcore.cmd.mcore.usys.multiverse: true mcore.cmd.mcore.usys.multiverse.list: true diff --git a/src/com/massivecraft/mcore/MCorePerm.java b/src/com/massivecraft/mcore/MCorePerm.java index b102776c..4b3124a8 100644 --- a/src/com/massivecraft/mcore/MCorePerm.java +++ b/src/com/massivecraft/mcore/MCorePerm.java @@ -14,6 +14,8 @@ public enum MCorePerm CMD_MCORE_ID("cmd.mcore.id"), CMD_MCORE_VERSION("cmd.mcore.version"), CMD_MCORE_MSTORE("cmd.mcore.mstore"), + CMD_MCORE_MSTORE_STATS("cmd.mcore.mstore.stats"), + CMD_MCORE_MSTORE_LISTCOLLS("cmd.mcore.mstore.listcolls"), CMD_MCORE_MSTORE_COPYDB("cmd.mcore.mstore.copydb"), CMD_MCORE_USYS("cmd.mcore.usys"), CMD_MCORE_USYS_MULTIVERSE("cmd.mcore.usys.multiverse"), diff --git a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStore.java b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStore.java index be95cf2b..b8ca3d1e 100644 --- a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStore.java +++ b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStore.java @@ -9,12 +9,16 @@ import com.massivecraft.mcore.util.MUtil; public class CmdMCoreMStore extends MCoreCommand { + public CmdMCoreMStoreStats cmdMCoreMStoreStats = new CmdMCoreMStoreStats(MUtil.list("stats")); + public CmdMCoreMStoreListcolls cmdMCoreMStoreListcolls = new CmdMCoreMStoreListcolls(MUtil.list("listcolls")); public CmdMCoreMStoreCopydb cmdMCoreMStoreCopydb = new CmdMCoreMStoreCopydb(MUtil.list("copydb")); public CmdMCoreMStore(List aliases) { super(aliases); + this.addSubCommand(this.cmdMCoreMStoreStats); + this.addSubCommand(this.cmdMCoreMStoreListcolls); this.addSubCommand(this.cmdMCoreMStoreCopydb); this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE.node)); diff --git a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreListcolls.java b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreListcolls.java new file mode 100644 index 00000000..6dabc91f --- /dev/null +++ b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreListcolls.java @@ -0,0 +1,73 @@ +package com.massivecraft.mcore.mcorecmd; + +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import com.massivecraft.mcore.ConfServer; +import com.massivecraft.mcore.MCorePerm; +import com.massivecraft.mcore.NaturalOrderComparator; +import com.massivecraft.mcore.cmd.arg.ARString; +import com.massivecraft.mcore.cmd.req.ReqHasPerm; +import com.massivecraft.mcore.store.Coll; +import com.massivecraft.mcore.store.Db; +import com.massivecraft.mcore.store.MStore; +import com.massivecraft.mcore.util.Txt; + +public class CmdMCoreMStoreListcolls extends MCoreCommand +{ + public CmdMCoreMStoreListcolls(List aliases) + { + super(aliases); + + this.addOptionalArg("db", ConfServer.dburi); + + this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE_LISTCOLLS.node)); + } + + @Override + public void perform() + { + // Args + final String dbAlias = this.arg(0, ARString.get(), ConfServer.dburi); + final Db db = MStore.getDb(dbAlias); + if (db == null) + { + msg("could not get the database."); + return; + } + + // Prepare + Set collnames = new TreeSet(NaturalOrderComparator.get()); + collnames.addAll(db.getCollnames()); + + // Do it! + msg(Txt.titleize("Collections in "+db.getName())); + for (String collname : collnames) + { + String message = Txt.parse("") + collname; + + Coll coll = null; + + for (Coll collCandidate : Coll.instances) + { + if (!collCandidate.getName().equals(collname)) continue; + if (collCandidate.getDb() != db) continue; + coll = collCandidate; + break; + } + + if (coll == null) + { + message += Txt.parse(" UNUSED"); + } + else + { + message += Txt.parse(" (%d documents)", coll.getIds().size()); + } + + sendMessage(message); + } + } + +} diff --git a/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreStats.java b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreStats.java new file mode 100644 index 00000000..5725814b --- /dev/null +++ b/src/com/massivecraft/mcore/mcorecmd/CmdMCoreMStoreStats.java @@ -0,0 +1,26 @@ +package com.massivecraft.mcore.mcorecmd; + +import java.util.List; + +import com.massivecraft.mcore.MCorePerm; +import com.massivecraft.mcore.cmd.req.ReqHasPerm; +import com.massivecraft.mcore.store.ExamineThread; +import com.massivecraft.mcore.util.Txt; + +public class CmdMCoreMStoreStats extends MCoreCommand +{ + public CmdMCoreMStoreStats(List aliases) + { + super(aliases); + + this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE_STATS.node)); + } + + @Override + public void perform() + { + msg(Txt.titleize("MStore Statistics")); + msg("Last Examine Duration: %dms", ExamineThread.get().getLastDurationMillis()); + } + +} diff --git a/src/com/massivecraft/mcore/store/DriverMongo.java b/src/com/massivecraft/mcore/store/DriverMongo.java index 9ea6d550..8cfa3bec 100644 --- a/src/com/massivecraft/mcore/store/DriverMongo.java +++ b/src/com/massivecraft/mcore/store/DriverMongo.java @@ -53,7 +53,9 @@ public class DriverMongo extends DriverAbstract @Override public Set getCollnames(Db db) { - return ((DbMongo)db).db.getCollectionNames(); + Set ret = ((DbMongo)db).db.getCollectionNames(); + ret.remove("system.indexes"); + return ret; } @Override diff --git a/src/com/massivecraft/mcore/store/MStore.java b/src/com/massivecraft/mcore/store/MStore.java index c63f1cde..b5fec907 100644 --- a/src/com/massivecraft/mcore/store/MStore.java +++ b/src/com/massivecraft/mcore/store/MStore.java @@ -72,12 +72,12 @@ public class MStore public static Db getDb(String alias) { String uri = resolveAlias(alias); - Db ret = uri2db.get(uri); - if (ret != null) return ret; + Db db = uri2db.get(uri); + if (db != null) return db; try { - ret = getDb(new URI(uri)); + db = getDb(new URI(uri)); } catch (URISyntaxException e) { @@ -85,7 +85,9 @@ public class MStore return null; } - return ret; + uri2db.put(uri, db); + + return db; } public static Db getDb(URI uri)