Added missing line, the DB cache now works. Added mstore stats and listcolls command.

This commit is contained in:
Olof Larsson 2013-05-01 19:41:36 +02:00
parent 9a8a792315
commit b846250944
7 changed files with 121 additions and 5 deletions

View File

@ -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

View File

@ -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"),

View File

@ -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<String> aliases)
{
super(aliases);
this.addSubCommand(this.cmdMCoreMStoreStats);
this.addSubCommand(this.cmdMCoreMStoreListcolls);
this.addSubCommand(this.cmdMCoreMStoreCopydb);
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE.node));

View File

@ -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<String> 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("<b>could not get the database.");
return;
}
// Prepare
Set<String> collnames = new TreeSet<String>(NaturalOrderComparator.get());
collnames.addAll(db.getCollnames());
// Do it!
msg(Txt.titleize("Collections in "+db.getName()));
for (String collname : collnames)
{
String message = Txt.parse("<h>") + 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(" <b>UNUSED");
}
else
{
message += Txt.parse(" <i>(%d documents)", coll.getIds().size());
}
sendMessage(message);
}
}
}

View File

@ -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<String> aliases)
{
super(aliases);
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE_STATS.node));
}
@Override
public void perform()
{
msg(Txt.titleize("MStore Statistics"));
msg("<k>Last Examine Duration: <v>%d<i>ms", ExamineThread.get().getLastDurationMillis());
}
}

View File

@ -53,7 +53,9 @@ public class DriverMongo extends DriverAbstract
@Override
public Set<String> getCollnames(Db db)
{
return ((DbMongo)db).db.getCollectionNames();
Set<String> ret = ((DbMongo)db).db.getCollectionNames();
ret.remove("system.indexes");
return ret;
}
@Override

View File

@ -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)