Hi guys,

If you execute the following code, you will find that cache.iterator() does not return a result. If the transaction is not started, the returned result is correct.
Is this a bug or a known technical limitation?

server side just start ignite.sh

public class CacheTransactionExample {

    public static void main(String[] args) throws IgniteException {
        Ignition.setClientMode(true);
        try (Ignite ignite = Ignition.start()) {
            System.out.println();

            CacheConfiguration<Integer, Account> cfg = new CacheConfiguration<>("Account");

cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
            IgniteCache<Integer, Account> cache = ignite.getOrCreateCache(cfg);

            try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) {
                cache.put(1, new Account(1, 100));
                cache.put(2, new Account(1, 200));

                System.out.println();
                System.out.println(">>> " + cache.get(1));
                System.out.println(">>> " + cache.get(2));

                Iterator it = cache.iterator();
                while(it.hasNext()) {
                    Cache.Entry<Integer, Account> acc = (Cache.Entry<Integer, Account>)it.next();
                    System.out.println("<<<" + acc.getValue());
                }
                tx.commit();
            }
            finally {
                ignite.destroyCache("Account");
            }
        }
    }

    private static class Account implements Serializable {
        private int id;

        private double balance;

        Account(int id, double balance) {
            this.id = id;
            this.balance = balance;
        }

        void update(double amount) {
            balance += amount;
        }

        @Override public String toString() {
            return "Account [id=" + id + ", balance=$" + balance + ']';
        }
    }
}

Reply via email to