@Test public void putTTL() throws Exception { String head = "putTTL0"; RMap map = db.getMap(); int num = 10 * 10000; try { log.debug("start"); for (int i = 0; i < num; i++) { map.putTTL(head, "hello" + i, ("world" + i).getBytes(), 4); if (i == num - 10) { Thread.sleep(3000); } } Thread.sleep(2000); for (int i = 0; i < num; i++) { byte[] bytes = map.get(head, ("hello" + i)); Assert.assertEquals(new String(bytes), ("world" + i)); } Thread.sleep(2000); for (int i = 0; i < num; i++) { byte[] bytes = map.get(head, ("hello" + i)); Assert.assertNull(bytes); } } finally { map.delete(head); } }
public void putTTL(String key, String mkey, byte[] value, int ttl) throws KitDBException { byte[] mkey_b = mkey.getBytes(charset); checkTxStart(); try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); Meta metaV = addCheck(key_b, k_v); if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } if (metaV != null) { if (ttl != -1) { delTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } metaV.size = metaV.size + 1; metaV.setTimestamp(ttl); Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { metaV = new Meta(0, ttl, db.versionSequence().incr()); metaV.size = metaV.size + 1; Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } if (metaV.getTimestamp() != -1) { setTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } commit(); } finally { unlock(lockEntity); release(); } checkTxCommit(); } catch (KitDBException e) { checkTxRollBack(); throw e; } }
RMap extends RCollection { public void putTTL(String key, String mkey, byte[] value, int ttl) throws KitDBException { byte[] mkey_b = mkey.getBytes(charset); checkTxStart(); try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); Meta metaV = addCheck(key_b, k_v); if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } if (metaV != null) { if (ttl != -1) { delTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } metaV.size = metaV.size + 1; metaV.setTimestamp(ttl); Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { metaV = new Meta(0, ttl, db.versionSequence().incr()); metaV.size = metaV.size + 1; Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } if (metaV.getTimestamp() != -1) { setTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } commit(); } finally { unlock(lockEntity); release(); } checkTxCommit(); } catch (KitDBException e) { checkTxRollBack(); throw e; } } }
RMap extends RCollection { public void putTTL(String key, String mkey, byte[] value, int ttl) throws KitDBException { byte[] mkey_b = mkey.getBytes(charset); checkTxStart(); try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); Meta metaV = addCheck(key_b, k_v); if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } if (metaV != null) { if (ttl != -1) { delTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } metaV.size = metaV.size + 1; metaV.setTimestamp(ttl); Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { metaV = new Meta(0, ttl, db.versionSequence().incr()); metaV.size = metaV.size + 1; Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } if (metaV.getTimestamp() != -1) { setTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } commit(); } finally { unlock(lockEntity); release(); } checkTxCommit(); } catch (KitDBException e) { checkTxRollBack(); throw e; } } protected  RMap(DB db); }
RMap extends RCollection { public void putTTL(String key, String mkey, byte[] value, int ttl) throws KitDBException { byte[] mkey_b = mkey.getBytes(charset); checkTxStart(); try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); Meta metaV = addCheck(key_b, k_v); if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } if (metaV != null) { if (ttl != -1) { delTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } metaV.size = metaV.size + 1; metaV.setTimestamp(ttl); Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { metaV = new Meta(0, ttl, db.versionSequence().incr()); metaV.size = metaV.size + 1; Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } if (metaV.getTimestamp() != -1) { setTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } commit(); } finally { unlock(lockEntity); release(); } checkTxCommit(); } catch (KitDBException e) { checkTxRollBack(); throw e; } } protected  RMap(DB db); void put(String key, String mkey, byte[] value); void putTTL(String key, String mkey, byte[] value, int ttl); void put(String key, Map<String, byte[]> map); void putMayTTL(String key, int ttl, Map<String, byte[]> map); void putMayTTL(String key, int ttl, String mkey, byte[] value); Map<String, byte[]> get(String key, String... keys); byte[] get(String key, String mkey); void remove(String key, String... keys); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override RIterator<RMap> iterator(String key); @Override Entry getEntry(RocksIterator iterator); @Override int getTtl(String key); @Override void delTtl(String key); @Override void ttl(String key, int ttl); @Override boolean isExist(String key); @Override int size(String key); }
RMap extends RCollection { public void putTTL(String key, String mkey, byte[] value, int ttl) throws KitDBException { byte[] mkey_b = mkey.getBytes(charset); checkTxStart(); try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); Meta metaV = addCheck(key_b, k_v); if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } if (metaV != null) { if (ttl != -1) { delTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } metaV.size = metaV.size + 1; metaV.setTimestamp(ttl); Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { metaV = new Meta(0, ttl, db.versionSequence().incr()); metaV.size = metaV.size + 1; Key key_ = new Key(key_b.length, key_b, metaV.getVersion(), mkey_b); putDB(key_.convertBytes().toBytes(), value, SstColumnFamily.DEFAULT); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } if (metaV.getTimestamp() != -1) { setTimerCollection(KeyEnum.COLLECT_TIMER, metaV.getTimestamp(), key_b, metaV.convertMetaBytes().toBytesHead()); } commit(); } finally { unlock(lockEntity); release(); } checkTxCommit(); } catch (KitDBException e) { checkTxRollBack(); throw e; } } protected  RMap(DB db); void put(String key, String mkey, byte[] value); void putTTL(String key, String mkey, byte[] value, int ttl); void put(String key, Map<String, byte[]> map); void putMayTTL(String key, int ttl, Map<String, byte[]> map); void putMayTTL(String key, int ttl, String mkey, byte[] value); Map<String, byte[]> get(String key, String... keys); byte[] get(String key, String mkey); void remove(String key, String... keys); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override RIterator<RMap> iterator(String key); @Override Entry getEntry(RocksIterator iterator); @Override int getTtl(String key); @Override void delTtl(String key); @Override void ttl(String key, int ttl); @Override boolean isExist(String key); @Override int size(String key); static byte[] HEAD_B; final static byte[] HEAD_KEY_B; }