@Test public void addMayTTL() throws KitDBException, InterruptedException { String head = "addMayTTL0"; RSet set = db.getSet(); int num = 10 * 10000; for (int i = 0; i < num; i++) { set.addMayTTL(head, 5, ("hello world" + i).getBytes()); if (i == num - 5) { Thread.sleep(1000); } } Thread.sleep(4000); Assert.assertTrue(!set.isExist(head)); for (int i = 0; i < num; i++) { Assert.assertTrue(!set.contains(head, ("hello world" + i).getBytes())); } }
public void addMayTTL(String key, int ttl, byte[]... values) throws KitDBException { checkTxStart(); try (CloseLock ignored = checkClose()) { DAssert.notEmpty(values, ErrorType.EMPTY, "values is empty"); DAssert.isTrue(ArrayKits.noRepeate(values), ErrorType.REPEATED_KEY, "Repeated memebers"); byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); MetaV metaV = addCheck(key_b, k_v); if (metaV != null) { setEntry(key_b, metaV, values); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } metaV = new MetaV(0, ttl, db.versionSequence().incr()); setEntry(key_b, metaV, values); 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; } }
RSet extends RCollection { public void addMayTTL(String key, int ttl, byte[]... values) throws KitDBException { checkTxStart(); try (CloseLock ignored = checkClose()) { DAssert.notEmpty(values, ErrorType.EMPTY, "values is empty"); DAssert.isTrue(ArrayKits.noRepeate(values), ErrorType.REPEATED_KEY, "Repeated memebers"); byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); MetaV metaV = addCheck(key_b, k_v); if (metaV != null) { setEntry(key_b, metaV, values); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } metaV = new MetaV(0, ttl, db.versionSequence().incr()); setEntry(key_b, metaV, values); 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; } } }
RSet extends RCollection { public void addMayTTL(String key, int ttl, byte[]... values) throws KitDBException { checkTxStart(); try (CloseLock ignored = checkClose()) { DAssert.notEmpty(values, ErrorType.EMPTY, "values is empty"); DAssert.isTrue(ArrayKits.noRepeate(values), ErrorType.REPEATED_KEY, "Repeated memebers"); byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); MetaV metaV = addCheck(key_b, k_v); if (metaV != null) { setEntry(key_b, metaV, values); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } metaV = new MetaV(0, ttl, db.versionSequence().incr()); setEntry(key_b, metaV, values); 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  RSet(DB db); }
RSet extends RCollection { public void addMayTTL(String key, int ttl, byte[]... values) throws KitDBException { checkTxStart(); try (CloseLock ignored = checkClose()) { DAssert.notEmpty(values, ErrorType.EMPTY, "values is empty"); DAssert.isTrue(ArrayKits.noRepeate(values), ErrorType.REPEATED_KEY, "Repeated memebers"); byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); MetaV metaV = addCheck(key_b, k_v); if (metaV != null) { setEntry(key_b, metaV, values); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } metaV = new MetaV(0, ttl, db.versionSequence().incr()); setEntry(key_b, metaV, values); 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  RSet(DB db); List<byte[]> pop(String key, int num); void remove(String key, byte[]... values); boolean contains(String key, byte[] value); void addMayTTL(String key, int ttl, byte[]... values); void add(String key, byte[]... values); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override @SuppressWarnings("unchecked") RIterator<RSet> iterator(String key); @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); @Override Entry getEntry(RocksIterator iterator); }
RSet extends RCollection { public void addMayTTL(String key, int ttl, byte[]... values) throws KitDBException { checkTxStart(); try (CloseLock ignored = checkClose()) { DAssert.notEmpty(values, ErrorType.EMPTY, "values is empty"); DAssert.isTrue(ArrayKits.noRepeate(values), ErrorType.REPEATED_KEY, "Repeated memebers"); byte[] key_b = getKey(key); LockEntity lockEntity = lock(key); try { start(); byte[] k_v = getDB(key_b, SstColumnFamily.META); MetaV metaV = addCheck(key_b, k_v); if (metaV != null) { setEntry(key_b, metaV, values); putDB(key_b, metaV.convertMetaBytes().toBytes(), SstColumnFamily.META); } else { if (ttl != -1) { ttl = (int) (System.currentTimeMillis() / 1000 + ttl); } metaV = new MetaV(0, ttl, db.versionSequence().incr()); setEntry(key_b, metaV, values); 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  RSet(DB db); List<byte[]> pop(String key, int num); void remove(String key, byte[]... values); boolean contains(String key, byte[] value); void addMayTTL(String key, int ttl, byte[]... values); void add(String key, byte[]... values); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override @SuppressWarnings("unchecked") RIterator<RSet> iterator(String key); @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); @Override Entry getEntry(RocksIterator iterator); final static String HEAD; final static byte[] HEAD_B; final static byte[] HEAD_V_B; }