0

Here is our code:

@Override
public boolean delete(String instance, final String storeName, String... keys) {
    final Boolean[] isSuccess = {false};
    final List<String> keyList = Arrays.asList(keys);
    final Environment env = Environments.newInstance(xodusRoot + instance);
    env.executeInTransaction(new TransactionalExecutable() {
        @Override
        public void execute(@NotNull final Transaction txn) {
            final Store store = env.openStore(storeName, StoreConfig.WITHOUT_DUPLICATES, txn);
            for (String key : keyList) {
                isSuccess[0] = store.delete(txn, StringBinding.stringToEntry(key));
            }
        }
    });
    env.close();
    return isSuccess[0];
}

I have two question for this.

  • Is this transactional, since this function is for deleting multiple keys, would this work like if one key fails to delete the other keys will not be deleted. Like all or nothing?
  • If in case within the txn an exception happened due to some reason, like key or storeName being null, how should that be handled? Or it does not matter since if there is an exception the transcation would fail and roll back automatically?
quarks
  • 33,478
  • 73
  • 290
  • 513
  • BTW, if an exception is thrown environment would not be closed. Also, what return value of the method is expected to mean? – Vyacheslav Lukianov Aug 14 '18 at 14:40
  • @VyacheslavLukianov how should exception be handled so Environment would close properly? Just put a catch statement and call the env.close on the catch? How about txn rollback? – quarks Aug 14 '18 at 15:32
  • executeInTransaction method will roll back the transaction. I'd just close the environemnt in the finally block. – Vyacheslav Lukianov Aug 14 '18 at 15:35
  • But how can the environment close, since you said that in an event of an exception the environment will not close... – quarks Aug 14 '18 at 15:37
  • I mean something like this: final Environment env = ...; try { /* execute transaction */ } finally { env.close(); } – Vyacheslav Lukianov Aug 14 '18 at 15:40

1 Answers1

2

Xodus is an ACID-compliant transactional database. Among other things it means that mutations of data in transactions are consistent. In your case either all specified keys (transaction is committed) or no keys (transaction aborted) would be deleted. If a transaction is interrupted for some reason (exception, system/hardware failure) nothing is modified and the transaction automatically rolls back.

Vyacheslav Lukianov
  • 1,913
  • 8
  • 12