mapdb java_java - 为什么在重新打开数据库时MapDB不会工作? - 堆栈内存溢出

所以我创建了一个像这样工作的数据库:

static class Record implements Serializable

{

final String action;

final String categoryOfAction;

final String personWhoPerformedAction;

final Long timeOfOccurrence;

public record(String actn, String cat, String person, Long time)

{

action = actn;

categoryOfAction = cat;

personWhoPerformedAction = person;

timeOfOccurence = time;

}

}

static void main(String[] args)

{

DB thedb = DBMaker.newFileDB(new File("D:\\thedb.db")

.compressionEnable()

.closeOnJvmShutdown()

.mmapFileEnableIfSupported()

.transactionDisable()

.asyncWriteEnable()

.make();

//primaryMap maps each record to a unique ID

BTreeMap primaryMap = thedb.createTreeMap("pri")

.keySerializer(BTreeKeySerializer.INTEGER)

.makeOrGet();;

//this map holds the unique ID of every record in primaryMap with a common action

NavigableSet map_commonAction = thedb.createTreeSet("com_a")

.comparator(Fun.COMPARABLE_ARRAY_COMPARATOR)

.makeOrGet();

//this map holds the unique ID of every record in primaryMap with a common person

NavigableSet map_commonPerson = thedb.createTreeSet("com_p")

.comparator(Fun.COMPARABLE_ARRAY_COMPARATOR)

.makeOrGet();

//binding map_commonAction to primaryMap so it is updated with primary

Bind.secondaryKey(primaryMap, map_commonAction, new Fun.Function2() {

@Override

public String run(Integer recordID, Record r) {

return r.action;

}

});

//binding map_commonPerson to primaryMap so it is updated with primary

Bind.secondaryKey(primaryMap, map_commonPerson, new Fun.Function2() {

@Override

public String run(Integer recordID, Record r) {

return r.personWhoPerformedAction;

}

});

//method used to attain all records with some action

for (Object[] k : Fun.filter(map_commonAction, "someAction"))

{

Record obtainedRecord = primary.get(k[1]);

}

//method used to attain all records with some person

for (Object[] k : Fun.filter(map_commonPerson, "somePerson"))

{

Record obtainedRecord = primary.get(k[1]);

}

}

创建之后,我插入了190亿个项目。 通过某些动作或人获得所有记录的方法完美地工作。 我关闭了数据库,然后我再次尝试运行它,除了这次数据库已经构建并插入了所有项目,因此无需插入190亿个项目。 一旦我通过一些动作或人员调用了获取所有记录的方法之一,我就会收到此错误:

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Comparable

at org.mapdb.Fun$1.compare(Fun.java:31)

at org.mapdb.BTreeKeySerializer$BasicKeySerializer.compare(BTreeKeySerializer.java:206)

at org.mapdb.BTreeKeySerializer$BasicKeySerializer.compare(BTreeKeySerializer.java:156)

at org.mapdb.BTreeKeySerializer.compareIsSmaller(BTreeKeySerializer.java:48)

at org.mapdb.BTreeKeySerializer.findChildren(BTreeKeySerializer.java:89)

at org.mapdb.BTreeMap.nextDir(BTreeMap.java:843)

at org.mapdb.BTreeMap.findLargerNode(BTreeMap.java:1673)

at org.mapdb.BTreeMap$BTreeIterator.(BTreeMap.java:1068)

at org.mapdb.BTreeMap$BTreeKeyIterator.(BTreeMap.java:1323)

at org.mapdb.BTreeMap$SubMap.keyIterator(BTreeMap.java:2483)

at org.mapdb.BTreeMap$KeySet.iterator(BTreeMap.java:1900)

at org.mapdb.Fun$12.iterator(Fun.java:369)

at test.main(test.java:187)

然后检查每张地图的大小

System.out.println(map_commonAction.size()); //returned correct size: 19billion

System.out.println(map_commonPerson.size()); //returned correct size: 19billion

System.out.println(primaryMap.size()); //returned correct size: 19billion

然后我检查了primaryMap是否工作,并检查了几个int值,它返回了一个像它应该的记录

Record r1 = primaryMap.get(1);

Record r2 = primaryMap.get(2);

System.out.println(r1.toString());

System.out.println(r2.toString());

它只在我尝试迭代Fun.filter(map_common *,“something”)给出的内容时失败,但调用它的行为不会使它失败,只是试图迭代它。 我测试它是这样的:

//this method fails and causes and exception to be thrown

for (Object[] k : Fun.filter(map_commonPerson, "person"))

{

System.out.println(primaryMap.get(k[1]).toString());

}

//this method doesn't cause an exception to be thrown

Iterable x = Fun.filter(map_commonPerson, "person");

所以现在我被卡住了,我不知道我的地图有什么问题。 一旦我创建了一个新数据库并插入了190亿个项目,它就能完美运行,但是一旦我关闭它并尝试重新打开它以获得更多读取它就会失败。

有人可以帮忙吗? 谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值