@Test public void testLoopAndReopen() throws IOException, ClassNotFoundException { long createdTime = System.nanoTime(); int loop = 32 * 1024; mapTable = new FCMapTable(testDir, 1, createdTime, loop); assertTrue(mapTable.getLevel() == 1); assertTrue(mapTable.getCreatedTime() == createdTime); assertTrue(mapTable.getAppendedSize() == 0); assertTrue(mapTable.isEmpty()); assertTrue(mapTable.getBackFileSize() == HashMapTable.INIT_INDEX_FILE_SIZE + HashMapTable.INIT_DATA_FILE_SIZE + HashMapTable.INDEX_ITEM_LENGTH); assertFalse(mapTable.isUsable()); List<byte[]> list = new ArrayList<byte[]>(); for(int i = 0; i < loop; i++) { list.add(("key" + i).getBytes()); } Collections.sort(list, new Comparator<byte[]>() { @Override public int compare(byte[] arg0, byte[] arg1) { int hash0 = Arrays.hashCode(arg0); int hash1 = Arrays.hashCode(arg1); if (hash0 < hash1) return -1; else if (hash0 > hash1) return 1; else return 0; } }); for(int i = 0; i < loop; i++) { mapTable.appendNew(list.get(i), ("value" + i).getBytes(), -1); } assertTrue(mapTable.getAppendedSize() == loop); long start = System.currentTimeMillis(); for(int i = 0; i < loop; i++) { GetResult result = mapTable.get(("key" + i).getBytes()); assertTrue(result.isFound()); } long time = System.currentTimeMillis() - start; System.out.printf("Get %,d K ops per second%n", (int) (loop / time)); GetResult result = mapTable.get(("key" + loop).getBytes()); assertFalse(result.isFound()); assertFalse(result.isDeleted() || result.isExpired()); mapTable.markUsable(true); mapTable.saveMetadata(); mapTable.close(); mapTable = new FCMapTable(testDir, mapTable.getFileName()); assertTrue(mapTable.isUsable()); assertTrue(mapTable.getAppendedSize() == loop); for(int i = 0; i < loop; i++) { result = mapTable.get(("key" + i).getBytes()); assertTrue(result.isFound()); } result = mapTable.get(("key" + loop).getBytes()); assertFalse(result.isFound()); assertFalse(result.isDeleted() || result.isExpired()); mapTable.markUsable(false); mapTable.saveMetadata(); mapTable.close(); mapTable = new FCMapTable(testDir, mapTable.getFileName()); assertFalse(mapTable.isUsable()); assertTrue(mapTable.getAppendedSize() == loop); for(int i = 0; i < loop; i++) { result = mapTable.get(("key" + i).getBytes()); assertTrue(result.isFound()); } }
public IMapEntry appendNew(byte[] key, byte[] value, long timeToLive) throws IOException { return this.appendNew(key, Arrays.hashCode(key), value, timeToLive, System.currentTimeMillis(), false, false); }
FCMapTable extends AbstractSortedMapTable { public IMapEntry appendNew(byte[] key, byte[] value, long timeToLive) throws IOException { return this.appendNew(key, Arrays.hashCode(key), value, timeToLive, System.currentTimeMillis(), false, false); } }
FCMapTable extends AbstractSortedMapTable { public IMapEntry appendNew(byte[] key, byte[] value, long timeToLive) throws IOException { return this.appendNew(key, Arrays.hashCode(key), value, timeToLive, System.currentTimeMillis(), false, false); } FCMapTable(String dir, int level, long createdTime, int expectedInsertions);  FCMapTable(String dir, short shard, int level, long createdTime, int expectedInsertions);  FCMapTable(String dir, String fileName); }
FCMapTable extends AbstractSortedMapTable { public IMapEntry appendNew(byte[] key, byte[] value, long timeToLive) throws IOException { return this.appendNew(key, Arrays.hashCode(key), value, timeToLive, System.currentTimeMillis(), false, false); } FCMapTable(String dir, int level, long createdTime, int expectedInsertions);  FCMapTable(String dir, short shard, int level, long createdTime, int expectedInsertions);  FCMapTable(String dir, String fileName); IMapEntry appendNew(byte[] key, byte[] value, long timeToLive); @Override IMapEntry appendNew(byte[] key, int keyHash, byte[] value, long timeToLive, long createdTime, boolean deleted, boolean compressed); @Override IMapEntry getMapEntry(int index); }
FCMapTable extends AbstractSortedMapTable { public IMapEntry appendNew(byte[] key, byte[] value, long timeToLive) throws IOException { return this.appendNew(key, Arrays.hashCode(key), value, timeToLive, System.currentTimeMillis(), false, false); } FCMapTable(String dir, int level, long createdTime, int expectedInsertions);  FCMapTable(String dir, short shard, int level, long createdTime, int expectedInsertions);  FCMapTable(String dir, String fileName); IMapEntry appendNew(byte[] key, byte[] value, long timeToLive); @Override IMapEntry appendNew(byte[] key, int keyHash, byte[] value, long timeToLive, long createdTime, boolean deleted, boolean compressed); @Override IMapEntry getMapEntry(int index);  }