Author: toad
Date: 2008-07-10 01:45:29 +0000 (Thu, 10 Jul 2008)
New Revision: 21015
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
branches/db4o/freenet/src/freenet/client/async/PendingKeyItem.java
branches/db4o/freenet/src/freenet/node/Node.java
branches/db4o/freenet/src/freenet/node/Version.java
Log:
Crazy db4o hack, but major optimisation: search for keys by their string
representation!
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-07-10 01:14:53 UTC (rev 21014)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-07-10 01:45:29 UTC (rev 21015)
@@ -25,6 +25,7 @@
import freenet.node.SendableGet;
import freenet.node.SendableRequest;
import freenet.support.Db4oSet;
+import freenet.support.HexUtil;
import freenet.support.Logger;
import freenet.support.PrioritizedSerialExecutor;
import freenet.support.RandomGrabArray;
@@ -619,8 +620,10 @@
}
protected boolean inPendingKeys(SendableGet req, final Key key,
ObjectContainer container) {
+ final String pks = HexUtil.bytesToHex(key.getFullKey());
ObjectSet pending = container.query(new Predicate() {
public boolean match(PendingKeyItem item) {
+ if(!pks.equals(item.fullKeyAsBytes)) return
false;
if(!key.equals(item.key)) return false;
if(item.nodeDBHandle != nodeDBHandle) return
false;
return true;
@@ -653,8 +656,10 @@
}
public SendableGet[] getClientsForPendingKey(final Key key,
ObjectContainer container) {
+ final String pks = HexUtil.bytesToHex(key.getFullKey());
ObjectSet pending = container.query(new Predicate() {
public boolean match(PendingKeyItem item) {
+ if(!pks.equals(item.fullKeyAsBytes)) return
false;
if(!key.equals(item.key)) return false;
if(item.nodeDBHandle != nodeDBHandle) return
false;
return true;
@@ -668,8 +673,10 @@
}
public boolean anyWantKey(final Key key, ObjectContainer container) {
+ final String pks = HexUtil.bytesToHex(key.getFullKey());
ObjectSet pending = container.query(new Predicate() {
public boolean match(PendingKeyItem item) {
+ if(!pks.equals(item.fullKeyAsBytes)) return
false;
if(!key.equals(item.key)) return false;
if(item.nodeDBHandle != nodeDBHandle) return
false;
return true;
@@ -679,8 +686,10 @@
}
public SendableGet[] removePendingKey(final Key key, ObjectContainer
container) {
+ final String pks = HexUtil.bytesToHex(key.getFullKey());
ObjectSet pending = container.query(new Predicate() {
public boolean match(PendingKeyItem item) {
+ if(!pks.equals(item.fullKeyAsBytes)) return
false;
if(!key.equals(item.key)) return false;
if(item.nodeDBHandle != nodeDBHandle) return
false;
return true;
@@ -696,8 +705,10 @@
}
public boolean removePendingKey(SendableGet getter, boolean complain,
final Key key, ObjectContainer container) {
+ final String pks = HexUtil.bytesToHex(key.getFullKey());
ObjectSet pending = container.query(new Predicate() {
public boolean match(PendingKeyItem item) {
+ if(!pks.equals(item.fullKeyAsBytes)) return
false;
if(!key.equals(item.key)) return false;
if(item.nodeDBHandle != nodeDBHandle) return
false;
return true;
@@ -729,8 +740,10 @@
// Native version seems to be faster, at least for a few
thousand items...
// I'm not sure whether it's using the index though, we may
need to reconsider for larger queues... FIXME
+ final String pks = HexUtil.bytesToHex(key.getFullKey());
ObjectSet pending = container.query(new Predicate() {
public boolean match(PendingKeyItem item) {
+ if(!pks.equals(item.fullKeyAsBytes)) return
false;
if(!key.equals(item.key)) return false;
if(item.nodeDBHandle != nodeDBHandle) return
false;
return true;
Modified: branches/db4o/freenet/src/freenet/client/async/PendingKeyItem.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/PendingKeyItem.java
2008-07-10 01:14:53 UTC (rev 21014)
+++ branches/db4o/freenet/src/freenet/client/async/PendingKeyItem.java
2008-07-10 01:45:29 UTC (rev 21015)
@@ -5,17 +5,28 @@
import freenet.keys.Key;
import freenet.node.SendableGet;
import freenet.node.SendableRequest;
+import freenet.support.HexUtil;
public class PendingKeyItem {
final long nodeDBHandle;
final Key key;
+ /**
+ * EVIL DB4O HACK:
+ * Db4o does not support indexing objects with a Comparator. It will
only
+ * index by the object id. It will not index by a byte[]. But it WILL
index
+ * by a string quite happily and very fast. So we convert to a string
here.
+ * Not doing so results in db4o instantiating every key in order to
compare
+ * it... whereas doing so results in a fast index lookup.
+ */
+ final String fullKeyAsBytes;
private SendableGet[] getters;
PendingKeyItem(Key key, SendableGet getter, long nodeDBHandle) {
this.key = key;
this.getters = new SendableGet[] { getter };
this.nodeDBHandle = nodeDBHandle;
+ this.fullKeyAsBytes = HexUtil.bytesToHex(key.getFullKey());
}
public void addGetter(SendableGet getter) {
Modified: branches/db4o/freenet/src/freenet/node/Node.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Node.java 2008-07-10 01:14:53 UTC
(rev 21014)
+++ branches/db4o/freenet/src/freenet/node/Node.java 2008-07-10 01:45:29 UTC
(rev 21015)
@@ -724,6 +724,7 @@
Db4o.configure().objectClass(freenet.client.async.RegisterMe.class).objectField("key").indexed(true);
Db4o.configure().objectClass(freenet.client.async.PersistentCooldownQueueItem.class).objectField("time").indexed(true);
Db4o.configure().objectClass(freenet.client.async.PendingKeyItem.class).objectField("key").indexed(true);
+
Db4o.configure().objectClass(freenet.client.async.PendingKeyItem.class).objectField("fullKeyAsBytes").indexed(true);
/** Maybe we want a different query evaluation mode?
* At the moment, a big splitfile insert will result in one
SingleBlockInserter
* for every key, which means one RegisterMe for each ... this
results in a long pause
Modified: branches/db4o/freenet/src/freenet/node/Version.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Version.java 2008-07-10 01:14:53 UTC
(rev 21014)
+++ branches/db4o/freenet/src/freenet/node/Version.java 2008-07-10 01:45:29 UTC
(rev 21015)
@@ -24,11 +24,11 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 1152;
+ private static final int buildNumber = 1153;
/** Oldest build of Fred we will talk to */
private static final int oldLastGoodBuild = 1145;
- private static final int newLastGoodBuild = 1152;
+ private static final int newLastGoodBuild = 1153;
static final long transitionTime;
static {