[freenet-cvs] r16922 - trunk/freenet/src/freenet/store
toad at freenetproject.org
toad at freenetproject.org
Sat Jan 5 21:24:34 UTC 2008
Author: toad
Date: 2008-01-05 21:24:34 +0000 (Sat, 05 Jan 2008)
New Revision: 16922
Modified:
trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
trunk/freenet/src/freenet/store/FreenetStore.java
Log:
Delete old redundant methods for fetching/storing SSK/CHK/pubkeys
Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2008-01-05 21:19:08 UTC (rev 16921)
+++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2008-01-05 21:24:34 UTC (rev 16922)
@@ -35,17 +35,8 @@
import com.sleepycat.je.log.LogFileNotFoundException;
import com.sleepycat.je.util.DbLoad;
-import freenet.crypt.CryptFormatException;
-import freenet.crypt.DSAPublicKey;
import freenet.crypt.RandomSource;
-import freenet.keys.CHKBlock;
-import freenet.keys.CHKVerifyException;
-import freenet.keys.Key;
-import freenet.keys.KeyBlock;
import freenet.keys.KeyVerifyException;
-import freenet.keys.NodeCHK;
-import freenet.keys.NodeSSK;
-import freenet.keys.SSKBlock;
import freenet.keys.SSKVerifyException;
import freenet.node.SemiOrderedShutdownHook;
import freenet.support.Fields;
@@ -98,7 +89,6 @@
private boolean closed;
private boolean reallyClosed;
- private final static byte[] dummy = new byte[0];
public static String getName(boolean isStore, short type) {
String newDBPrefix = typeName(type)+ '-' +(isStore ? "store" : "cache")+ '-';
@@ -1237,139 +1227,6 @@
}
/**
- * Retrieve a block.
- * @param dontPromote If true, don't promote data if fetched.
- * @return null if there is no such block stored, otherwise the block.
- */
- public CHKBlock fetch(NodeCHK chk, boolean dontPromote) throws IOException {
- assert(storeType == TYPE_CHK);
- synchronized(this) {
- if(closed)
- return null;
- }
-
- byte[] routingkey = chk.getRoutingKey();
- DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
- DatabaseEntry blockDBE = new DatabaseEntry();
- Cursor c = null;
- Transaction t = null;
- try {
- t = environment.beginTransaction(null,null);
- c = keysDB.openCursor(t,null);
-
- if(logMINOR) Logger.minor(this, "Fetching "+chk+" dontPromote="+dontPromote);
- if(c.getSearchKey(routingkeyDBE,blockDBE,LockMode.RMW)
- !=OperationStatus.SUCCESS) {
- c.close();
- c = null;
- t.abort();
- t = null;
- synchronized(this) {
- misses++;
- }
- return null;
- }
-
- StoreBlock storeBlock = (StoreBlock) storeBlockTupleBinding.entryToObject(blockDBE);
-
- CHKBlock block = null;
- try {
- byte[] header = new byte[headerBlockSize];
- byte[] data = new byte[dataBlockSize];
- try {
- synchronized(storeRAF) {
- if(logMINOR) Logger.minor(this, "Reading data from store...");
- long seekTarget = storeBlock.offset*(long)(dataBlockSize+headerBlockSize);
- try {
- storeRAF.seek(seekTarget);
- } catch (IOException ioe) {
- if(seekTarget > (2l*1024*1024*1024)) {
- Logger.error(this, "Environment does not support files bigger than 2 GB?");
- System.out.println("Environment does not support files bigger than 2 GB? (exception to follow)");
- }
- Logger.error(this, "Caught IOException on storeRAF.seek("+seekTarget+ ')');
- throw ioe;
- }
- storeRAF.readFully(header);
- storeRAF.readFully(data);
- }
- } catch (EOFException e) {
- Logger.error(this, "No block");
- c.close();
- c = null;
- keysDB.delete(t, routingkeyDBE);
- t.commit();
- t = null;
- addFreeBlock(storeBlock.offset, true, "Data off end of store file");
- return null;
- }
-
-
- block = new CHKBlock(data,header,chk);
-
- if(!dontPromote) {
- if(logMINOR) Logger.minor(this, "Promoting...");
- storeBlock.updateRecentlyUsed();
- DatabaseEntry updateDBE = new DatabaseEntry();
- storeBlockTupleBinding.objectToEntry(storeBlock, updateDBE);
- c.putCurrent(updateDBE);
- c.close();
- c = null;
- t.commit();
- t = null;
- synchronized(storeRAF) {
- lruRAF.seek(storeBlock.offset * 8);
- lruRAF.writeLong(storeBlock.recentlyUsed);
- }
- } else {
- c.close();
- c = null;
- t.abort();
- t = null;
- }
-
- if(logMINOR) {
- Logger.minor(this, "Get key: " + chk);
- Logger.minor(this, "Headers: " + header.length+" bytes, hash " + Fields.hashCode(header));
- Logger.minor(this, "Data: " + data.length + " bytes, hash " + Fields.hashCode(data) + " fetching " + chk);
- }
-
- } catch(CHKVerifyException ex) {
- Logger.error(this, "CHKBlock: Does not verify ("+ex+"), setting accessTime to 0 for : "+chk);
- System.err.println("Does not verify (CHK block "+storeBlock.offset+ ')');
- c.close();
- c = null;
- keysDB.delete(t, routingkeyDBE);
- t.commit();
- t = null;
- addFreeBlock(storeBlock.offset, true, "CHK does not verify");
- synchronized(this) {
- misses++;
- }
- return null;
- }
- synchronized(this) {
- hits++;
- }
- return block;
- } catch(Throwable ex) { // FIXME: ugly
- if(c!=null) {
- try{c.close();}catch(DatabaseException ex2){}
- }
- if(t!=null)
- try{t.abort();}catch(DatabaseException ex2){}
- Logger.error(this, "Caught "+ex, ex);
- ex.printStackTrace();
- checkSecondaryDatabaseError(ex);
- IOException e = new IOException(ex.getMessage());
- e.initCause(ex);
- throw e;
- }
-
-// return null;
- }
-
- /**
* Retrieve a block.
* @param dontPromote If true, don't promote data to the top of the LRU if we fetch it.
* @return null if there is no such block stored, otherwise the block.
@@ -1491,293 +1348,6 @@
}
}
- /**
- * Retrieve a block.
- * @param dontPromote If true, don't promote data if fetched.
- * @return null if there is no such block stored, otherwise the block.
- */
- public SSKBlock fetch(NodeSSK chk, boolean dontPromote) throws IOException {
- assert(storeType == TYPE_SSK);
- synchronized(this) {
- if(closed)
- return null;
- }
-
- byte[] routingkey = chk.getRoutingKey();
- DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
- DatabaseEntry blockDBE = new DatabaseEntry();
- Cursor c = null;
- Transaction t = null;
- try {
- t = environment.beginTransaction(null,null);
- c = keysDB.openCursor(t,null);
-
- // Explanation of locking is in fetchPubKey.
- // Basically, locking the whole element saves us all sorts of trouble, especially
- // since we will usually be writing here if only to promote it.
- if(logMINOR) Logger.minor(this, "Fetching "+chk+" dontPromote="+dontPromote);
- if(c.getSearchKey(routingkeyDBE,blockDBE,LockMode.RMW)
- !=OperationStatus.SUCCESS) {
- c.close();
- c = null;
- t.abort();
- t = null;
- synchronized(this) {
- misses++;
- }
- return null;
- }
-
- StoreBlock storeBlock = (StoreBlock) storeBlockTupleBinding.entryToObject(blockDBE);
-
- SSKBlock block = null;
- try {
- byte[] header = new byte[headerBlockSize];
- byte[] data = new byte[dataBlockSize];
- try {
- synchronized(storeRAF) {
- storeRAF.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
- storeRAF.readFully(header);
- storeRAF.readFully(data);
- }
- } catch (EOFException e) {
- Logger.error(this, "No block");
- c.close();
- c = null;
- keysDB.delete(t, routingkeyDBE);
- t.commit();
- t = null;
- addFreeBlock(storeBlock.offset, true, "Data off end of store file");
- return null;
- }
-
-
- block = new SSKBlock(data,header,chk, false);
-
- if(!dontPromote) {
- storeBlock.updateRecentlyUsed();
- DatabaseEntry updateDBE = new DatabaseEntry();
- storeBlockTupleBinding.objectToEntry(storeBlock, updateDBE);
- c.putCurrent(updateDBE);
- c.close();
- c = null;
- t.commit();
- t = null;
- synchronized(storeRAF) {
- lruRAF.seek(storeBlock.offset * 8);
- lruRAF.writeLong(storeBlock.recentlyUsed);
- }
- } else {
- c.close();
- c = null;
- t.abort();
- t = null;
- }
-
- if(logMINOR) {
- Logger.minor(this, "Headers: " + header.length+" bytes, hash " + Fields.hashCode(header));
- Logger.minor(this, "Data: " + data.length + " bytes, hash " + Fields.hashCode(data) + " fetching " + chk);
- }
-
- } catch(SSKVerifyException ex) {
- Logger.normal(this, "SSKBlock: Does not verify ("+ex+"), setting accessTime to 0 for : "+chk, ex);
- keysDB.delete(t, routingkeyDBE);
- c.close();
- c = null;
- t.commit();
- t = null;
- addFreeBlock(storeBlock.offset, true, "SSK does not verify");
- synchronized(this) {
- misses++;
- }
- return null;
- }
- synchronized(this) {
- hits++;
- }
- return block;
- } catch(Throwable ex) { // FIXME: ugly
- if(c!=null) {
- try{c.close();}catch(DatabaseException ex2){}
- }
- if(t!=null) {
- try{t.abort();}catch(DatabaseException ex2){}
- }
- checkSecondaryDatabaseError(ex);
- Logger.error(this, "Caught "+ex, ex);
- ex.printStackTrace();
- throw new IOException(ex.getMessage());
- }
-
-// return null;
- }
-
- // FIXME do this with interfaces etc.
-
- public DSAPublicKey fetchPubKey(byte[] hash, boolean dontPromote) throws IOException {
- return fetchPubKey(hash, null, dontPromote);
- }
-
- /**
- * Retrieve a block.
- * @param dontPromote If true, don't promote data if fetched.
- * @param replacement If non-null, and the data exists but is corrupt, replace it with this.
- * @return null if there is no such block stored, otherwise the block.
- */
- public DSAPublicKey fetchPubKey(byte[] hash, DSAPublicKey replacement, boolean dontPromote) throws IOException {
- assert(storeType == TYPE_PUBKEY);
- synchronized(this) {
- if(closed)
- return null;
- }
-
- DatabaseEntry routingkeyDBE = new DatabaseEntry(hash);
- DatabaseEntry blockDBE = new DatabaseEntry();
- Cursor c = null;
- Transaction t = null;
- try {
- if(logMINOR) Logger.minor(this, "Fetching pubkey: "+HexUtil.bytesToHex(hash));
- t = environment.beginTransaction(null,null);
- c = keysDB.openCursor(t,null);
-
- // Lock the records as soon as we find them.
- // RMW - nobody else may access this key until we are finished.
- // This is advantageous as we will usually promote it and we may replace its content;
- // if two readers accessed it at once both might try to. Also IIRC we can deadlock
- // if we don't.
- if(c.getSearchKey(routingkeyDBE,blockDBE,LockMode.RMW)
- !=OperationStatus.SUCCESS) {
- c.close();
- c = null;
- t.abort();
- t = null;
- synchronized(this) {
- misses++;
- }
- return null;
- }
-
- StoreBlock storeBlock = (StoreBlock) storeBlockTupleBinding.entryToObject(blockDBE);
-
- // Promote the key (we can always demote it later; promoting it here means it shouldn't be deallocated
- // FIXME the locking/concurrency in this class is a bit dodgy!
-
- if(!dontPromote) {
- storeBlock.updateRecentlyUsed();
- DatabaseEntry updateDBE = new DatabaseEntry();
- storeBlockTupleBinding.objectToEntry(storeBlock, updateDBE);
- c.putCurrent(updateDBE);
- }
-
- DSAPublicKey block = null;
-
- byte[] data = new byte[dataBlockSize];
- if(logMINOR) Logger.minor(this, "Reading from store... "+storeBlock.offset+" ("+storeBlock.recentlyUsed+ ')');
- // When will java have pread/pwrite? :(
- try {
- synchronized(storeRAF) {
- storeRAF.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
- storeRAF.readFully(data);
- }
- } catch (EOFException e) {
- Logger.error(this, "No block");
- c.close();
- c = null;
- keysDB.delete(t, routingkeyDBE);
- t.commit();
- t = null;
- addFreeBlock(storeBlock.offset, true, "Data off end of store file");
- return null;
- }
- if(logMINOR) Logger.minor(this, "Read");
-
- try {
- block = DSAPublicKey.create(data);
- } catch (CryptFormatException e) {
- Logger.error(this, "Could not read key: "+e, e);
- finishKey(storeBlock, c, t, routingkeyDBE, hash, replacement);
- return replacement;
- }
-
- if(!Arrays.equals(block.asBytesHash(), hash)) {
- finishKey(storeBlock, c, t, routingkeyDBE, hash, replacement);
- synchronized(storeRAF) {
- lruRAF.seek(storeBlock.offset * 8);
- lruRAF.writeLong(storeBlock.recentlyUsed);
- }
- return replacement;
- }
-
- // Finished, commit.
- c.close();
- c = null;
- t.commit();
- t = null;
-
- if(logMINOR) {
- Logger.minor(this, "Data: " + data.length + " bytes, hash " + Fields.hashCode(data) + " fetching "+HexUtil.bytesToHex(hash));
- }
-
- synchronized(this) {
- hits++;
- }
- return block;
- } catch(Throwable ex) { // FIXME: ugly
- // Clean up.
- // Reports of wierd NPEs when aborting a transaction, deal with it
- if(c!=null) {
- try {
- c.close();
- } catch(Throwable ex2) {
- Logger.error(this, "Caught "+ex2+" closing in finally block", ex2);
- }
- }
- if(t!=null) {
- try {
- t.abort();
- } catch(Throwable ex2) {
- Logger.error(this, "Caught "+ex2+" aborting in finally block", ex2);
- }
- }
- checkSecondaryDatabaseError(ex);
- Logger.error(this, "Caught "+ex, ex);
- ex.printStackTrace();
- throw new IOException(ex.getMessage());
- }
-
-// return null;
- }
-
- private boolean finishKey(StoreBlock storeBlock, Cursor c, Transaction t, DatabaseEntry routingkeyDBE, byte[] hash, DSAPublicKey replacement) throws IOException, DatabaseException {
- if(replacement != null) {
- Logger.normal(this, "Replacing corrupt DSAPublicKey ("+HexUtil.bytesToHex(hash));
- synchronized(storeRAF) {
- storeRAF.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
- byte[] toWrite = replacement.asPaddedBytes();
- storeRAF.write(toWrite);
- if(keysRAF != null) {
- keysRAF.seek(storeBlock.offset * keyLength);
- keysRAF.write(hash);
- }
- }
- c.close();
- t.commit();
- return true;
- } else {
- Logger.error(this, "DSAPublicKey: Does not verify (unequal hashes), setting accessTime to 0 for : "+HexUtil.bytesToHex(hash));
- c.close();
- c = null;
- keysDB.delete(t, routingkeyDBE);
- t.commit();
- t = null;
- addFreeBlock(storeBlock.offset, true, "pubkey does not verify");
- synchronized(this) {
- misses++;
- }
- return false;
- }
- }
-
private void addFreeBlock(long offset, boolean loud, String reason) {
if(freeBlocks.push(offset)) {
if(loud) {
@@ -1791,15 +1361,6 @@
}
}
- public void put(CHKBlock b) throws IOException {
- assert(storeType == TYPE_CHK);
- NodeCHK chk = (NodeCHK) b.getKey();
- CHKBlock oldBlock = fetch(chk, false);
- if(oldBlock != null)
- return;
- innerPut(b);
- }
-
public void put(StorableBlock block, byte[] routingkey, byte[] fullKey, byte[] data, byte[] header,
boolean overwrite) throws KeyCollisionException, IOException {
StorableBlock oldBlock = fetch(routingkey, fullKey, false);
@@ -1817,23 +1378,6 @@
}
}
- public void put(SSKBlock b, boolean overwrite) throws IOException, KeyCollisionException {
- assert(storeType == TYPE_SSK);
- NodeSSK ssk = (NodeSSK) b.getKey();
- SSKBlock oldBlock = fetch(ssk, false);
- if(oldBlock != null) {
- if(!b.equals(oldBlock)) {
- if(!overwrite)
- throw new KeyCollisionException();
- else {
- overwrite(b);
- }
- }
- } else {
- innerPut(b);
- }
- }
-
private boolean overwrite(StorableBlock block, byte[] routingkey, byte[] fullKey, byte[] data, byte[] header) throws IOException {
synchronized(this) {
if(closed)
@@ -1895,75 +1439,6 @@
return true;
}
- /**
- * Overwrite an SSK with a new SSK of the same key.
- */
- private boolean overwrite(SSKBlock b) throws IOException {
- assert(storeType == TYPE_SSK);
- synchronized(this) {
- if(closed)
- return false;
- }
-
- NodeSSK chk = (NodeSSK) b.getKey();
- byte[] routingkey = chk.getRoutingKey();
- DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
- DatabaseEntry blockDBE = new DatabaseEntry();
- Cursor c = null;
- Transaction t = null;
- try {
- t = environment.beginTransaction(null,null);
- c = keysDB.openCursor(t,null);
-
- // Lock the record.
- if(c.getSearchKey(routingkeyDBE,blockDBE,LockMode.RMW)
- !=OperationStatus.SUCCESS) {
- c.close();
- c = null;
- t.abort();
- t = null;
- return false;
- }
-
- StoreBlock storeBlock = (StoreBlock) storeBlockTupleBinding.entryToObject(blockDBE);
-
- byte[] header = b.getRawHeaders();
- byte[] data = b.getRawData();
- synchronized(storeRAF) {
- storeRAF.seek(storeBlock.offset*(long)(dataBlockSize+headerBlockSize));
- storeRAF.write(header);
- storeRAF.write(data);
- if(keysRAF != null) {
- keysRAF.seek(storeBlock.offset * keyLength);
- keysRAF.write(chk.getFullKey());
- }
- }
-
- // Unlock record.
- c.close();
- c = null;
- t.commit();
- t = null;
-
- } catch(Throwable ex) { // FIXME: ugly
- checkSecondaryDatabaseError(ex);
- Logger.error(this, "Caught "+ex, ex);
- ex.printStackTrace();
- throw new IOException(ex.getMessage());
- } finally {
- if(c!=null) {
- try{c.close();}catch(DatabaseException ex2){}
-
- }
- if(t!=null) {
- try{t.abort();}catch(DatabaseException ex2){}
- }
-
- }
-
- return true;
- }
-
private void innerPut(StorableBlock block, byte[] routingkey, byte[] fullKey, byte[] data, byte[] header) throws IOException {
synchronized(this) {
if(closed)
@@ -2032,89 +1507,6 @@
}
}
- /**
- * Store a block.
- */
- private void innerPut(KeyBlock block) throws IOException {
- synchronized(this) {
- if(closed)
- return;
- }
-
- byte[] routingkey = block.getKey().getRoutingKey();
- byte[] fullKey = keysRAF == null ? null : block.getKey().getFullKey();
- byte[] data = block.getRawData();
- byte[] header = block.getRawHeaders();
-
- if(data.length!=dataBlockSize) {
- Logger.error(this, "This data is "+data.length+" bytes. Should be "+dataBlockSize);
- return;
- }
- if(header.length!=headerBlockSize) {
- Logger.error(this, "This header is "+data.length+" bytes. Should be "+headerBlockSize);
- return;
- }
-
- Transaction t = null;
-
- try {
- t = environment.beginTransaction(null,null);
- DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
-
- DatabaseEntry blockDBE = new DatabaseEntry();
-
- // Check whether it already exists
-
- if(logMINOR) Logger.minor(this, "Putting key "+block+" - checking whether it exists first");
- OperationStatus result = keysDB.get(t, routingkeyDBE, blockDBE, LockMode.RMW);
-
- if(result == OperationStatus.SUCCESS || result == OperationStatus.KEYEXIST) {
- if(logMINOR) Logger.minor(this, "Key already exists");
- // Key already exists!
- // But is it valid?
- t.abort();
- if(fetchKey(block.getKey(), false) != null) return; // old key was valid, we are not overwriting
- // If we are here, it was corrupt, or it was just deleted, so we can replace it.
- if(logMINOR) Logger.minor(this, "Old key was invalid, adding anyway");
- innerPut(block);
- return;
- } else if(result == OperationStatus.KEYEMPTY) {
- Logger.error(this, "Got KEYEMPTY - record deleted? Shouldn't be possible with record locking...!");
- // Put it in anyway
- } else if(result == OperationStatus.NOTFOUND) {
- // Good
- } else
- throw new IllegalStateException("Unknown operation status: "+result);
-
- writeBlock(header, data, t, routingkeyDBE, fullKey);
-
- t.commit();
- t = null;
-
- if(logMINOR) {
- Logger.minor(this, "Headers: "+header.length+" bytes, hash "+Fields.hashCode(header));
- Logger.minor(this, "Data: "+data.length+" bytes, hash "+Fields.hashCode(data)+" putting "+block.getKey());
- }
-
- } catch(Throwable ex) { // FIXME: ugly
- if(t!=null){
- try{t.abort();}catch(DatabaseException ex2){};
- }
- checkSecondaryDatabaseError(ex);
- Logger.error(this, "Caught "+ex, ex);
- ex.printStackTrace();
- if(ex instanceof IOException) throw (IOException) ex;
- else throw new IOException(ex.getMessage());
- }
- }
-
- private KeyBlock fetchKey(Key key, boolean b) throws IOException {
- if(key instanceof NodeCHK)
- return fetch((NodeCHK)key, b);
- else
- return fetch((NodeSSK)key, b);
- }
-
private void overwriteLRUBlock(byte[] header, byte[] data, Transaction t, DatabaseEntry routingkeyDBE, byte[] fullKey) throws DatabaseException, IOException {
// Overwrite an other block
Cursor c = accessTimeDB.openCursor(t,null);
@@ -2242,93 +1634,6 @@
}
}
- /**
- * Store a pubkey.
- */
- public void put(byte[] hash, DSAPublicKey key) throws IOException {
- assert(storeType == TYPE_PUBKEY);
- innerPut(hash, key);
- }
-
- /**
- * Store a block.
- */
- private void innerPut(byte[] hash, DSAPublicKey key) throws IOException {
- synchronized(this) {
- if(closed)
- return;
- }
-
- byte[] routingkey = hash;
- byte[] data = key.asPaddedBytes();
-
- if(!(Arrays.equals(hash, key.asBytesHash()))) {
- Logger.error(this, "Invalid hash!: " + HexUtil.bytesToHex(hash) + " : " + HexUtil.bytesToHex(key.asBytesHash()));
- }
-
- if(data.length!=dataBlockSize) {
- Logger.error(this, "This data is "+data.length+" bytes. Should be "+dataBlockSize);
- return;
- }
-
- Transaction t = null;
-
- try {
- t = environment.beginTransaction(null,null);
- DatabaseEntry routingkeyDBE = new DatabaseEntry(routingkey);
- DatabaseEntry blockDBE = new DatabaseEntry();
-
- // Check whether it already exists
-
- if(logMINOR) Logger.minor(this, "Putting key: "+HexUtil.bytesToHex(hash)+" : "+key+" - checking whether it exists already...");
- OperationStatus result = keysDB.get(t, routingkeyDBE, blockDBE, LockMode.RMW);
-
- if(result == OperationStatus.SUCCESS || result == OperationStatus.KEYEXIST) {
- // Key already exists!
- // But is it valid?
- if(logMINOR)
- Logger.minor(this, "Putting "+HexUtil.bytesToHex(hash)+" : already exists - aborting transaction");
- t.abort();
- if(logMINOR)
- Logger.minor(this, "Fetching (replacing) key");
- if(fetchPubKey(hash, key, false) != null) {
- if(logMINOR) Logger.minor(this, "Fetch/replace succeeded");
- return; // replaced key
- }
- if(logMINOR) Logger.minor(this, "Fetch failed after key already exists");
- // If we are here, it was corrupt, and it got deleted before it could be replaced.
- innerPut(hash, key);
- return;
- } else if(result == OperationStatus.KEYEMPTY) {
- Logger.error(this, "Got KEYEMPTY - record deleted? Shouldn't be possible with record locking...!");
- // Put it in anyway
- } else if(result == OperationStatus.NOTFOUND) {
- // Good
- } else
- throw new IllegalStateException("Unknown operation status: "+result);
-
- writeBlock(dummy, data, t, routingkeyDBE, keysRAF == null ? null : hash);
-
- t.commit();
- t = null;
-
- if(logMINOR) {
- Logger.minor(this, "Data: "+data.length+" bytes, hash "+Fields.hashCode(data)+" putting "+HexUtil.bytesToHex(hash)+" : "+key);
- }
-
- } catch(Throwable ex) { // FIXME: ugly
- Logger.error(this, "Caught "+ex, ex);
- System.err.println("Caught: "+ex);
- ex.printStackTrace();
- if(t!=null){
- try{t.abort();}catch(DatabaseException ex2){};
- }
- checkSecondaryDatabaseError(ex);
- if(ex instanceof IOException) throw (IOException) ex;
- else throw new IOException(ex.getMessage());
- }
- }
-
private void writeBlock(byte[] header, byte[] data, Transaction t, DatabaseEntry routingkeyDBE, byte[] fullKey) throws DatabaseException, IOException {
long blockNum;
Modified: trunk/freenet/src/freenet/store/FreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/FreenetStore.java 2008-01-05 21:19:08 UTC (rev 16921)
+++ trunk/freenet/src/freenet/store/FreenetStore.java 2008-01-05 21:24:34 UTC (rev 16922)
@@ -4,12 +4,6 @@
import com.sleepycat.je.DatabaseException;
-import freenet.crypt.DSAPublicKey;
-import freenet.keys.CHKBlock;
-import freenet.keys.NodeCHK;
-import freenet.keys.NodeSSK;
-import freenet.keys.SSKBlock;
-
/**
* Datastore interface
*/
@@ -24,25 +18,6 @@
*/
StorableBlock fetch(byte[] routingKey, byte[] fullKey, boolean dontPromote) throws IOException;
- /**
- * Retrieve a block.
- * @param dontPromote If true, don't promote data if fetched.
- * @return null if there is no such block stored, otherwise the block.
- */
- public CHKBlock fetch(NodeCHK key, boolean dontPromote) throws IOException;
-
- /**
- * Retrieve a block.
- * @param dontPromote If true, don't promote data if fetched.
- * @return null if there is no such block stored, otherwise the block.
- */
- public SSKBlock fetch(NodeSSK key, boolean dontPromote) throws IOException;
-
- /**
- * Fetch a public key.
- */
- public DSAPublicKey fetchPubKey(byte[] hash, boolean dontPromote) throws IOException;
-
/** Store a block.
* @throws KeyCollisionException If the key already exists but has different contents.
* @param ignoreAndOverwrite If true, overwrite old content rather than throwing a KeyCollisionException.
@@ -51,23 +26,6 @@
boolean overwrite) throws IOException, KeyCollisionException;
/**
- * Store a block.
- * @throws KeyCollisionException If the key already exists but has different contents.
- * @param ignoreAndOverwrite If true, overwrite old content rather than throwing a KeyCollisionException.
- */
- public void put(SSKBlock block, boolean ignoreAndOverwrite) throws IOException, KeyCollisionException;
-
- /**
- * Store a block.
- */
- public void put(CHKBlock block) throws IOException;
-
- /**
- * Store a public key.
- */
- public void put(byte[] hash, DSAPublicKey key) throws IOException;
-
- /**
* Change the store size.
* @param maxStoreKeys The maximum number of keys to be cached.
* @param shrinkNow If false, don't shrink the store immediately.
More information about the cvs
mailing list