public boolean corruptionTest(long hash) { Integer index = f.hashToIndex(hash); try { if (index != null) { f.corruptIndex(index); return true; } else { System.out.println(hash + " doesn't exist, cannot corrupt"); return false; } } catch (IOException e) { return false; } }
public byte[] get(Long key, byte[] data) throws IOException { byte[] value = cache.get(key); if (value != null) { return value; } value = overwriteBackup.get(key); if (value != null) { return value; } value = f.readByHash(key, data); return value; }
public void put(Long key, byte[] data) throws IOException { Integer index = f.hashToIndex(key); if (index != null) { return; } index = f.getIndex(); f.incrementIndex(); Long oldHash = f.indexToHash(index); byte[] oldData = new byte[(int) size]; oldData = f.readByIndex(index, oldData); if (oldData != null) { overwriteBackup.put(oldHash, oldData); overwriteQueue.add(oldHash); } f.write(index, key, data); if (!cache.contains(key)) { byte[] dataCopy = new byte[data.length]; System.arraycopy(data, 0, dataCopy, 0, data.length); cache.put(key, dataCopy); } }
public Long getHash(int index) { return f.indexToHash(index); }
public Integer getIndex(long key) { return f.hashToIndex(key); }
public void wipeFile() throws IOException { f.wipe(); }