0
votes

I am investigating transaction management within Apache Ignite and I have created a simple script that:

  1. Creates a table
  2. Obtains the row count
  3. Begins a transaction
  4. Inserts a row
  5. Obtains the row count
  6. Rollsback the transaction
  7. Obtains the row count

Steps 1 through 5 work as expected, but step 6 fails to rollback the row that was inserted at step 4 and the row count at step 7 is still 1.

I understand there is some configuration for the cache/schema that needs to be made and I wonder if I have this wrong. The documentation suggests I need to use "TRANSACTIONAL_SNAPTSHOT" for the atomicity mode.

The "cluster" has a single node.

Apache Ignite configuration file

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd">
        <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
            <property name="sqlSchemas">
                <list>
                    <value>SAMPLE</value>
                </list>
            </property>

            <!-- Enabling transactions for the "SAMPLE" cache/schema   -->
            <!-- See: https://apacheignite.readme.io/docs/transactions -->
            <property name="cacheConfiguration">
                <list>
                    <bean class="org.apache.ignite.configuration.CacheConfiguration">
                        <property name="name" value="SAMPLE"/>
                        <property name="atomicityMode" value="TRANSACTIONAL_SNAPSHOT"/>
                        <property name="backups" value="1"/>
                    </bean>
                </list>
            </property>

            <!-- Enabling Apache Ignite Persistent Store. -->
            <property name="dataStorageConfiguration">
                <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                    <property name="defaultDataRegionConfiguration">
                        <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                            <property name="persistenceEnabled" value="true"/>
                        </bean>
                    </property>
                </bean>
            </property>

            <!-- Explicitly configure TCP discovery SPI to provide a list of initial nodes. -->
            <property name="discoverySpi">
                <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                    <property name="ipFinder">
                        <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
                        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <!-- <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> -->
                            <property name="addresses">
                                <list>
                                    <!-- In distributed environment, replace with actual host IP address. -->
                                    <value>10.0.1.217:47500</value>
                                </list>
                            </property>
                        </bean>
                    </property>
                </bean>
            </property>
        </bean>
    </beans>

Test Script

from pyignite import Client


def get_rowcount(client):
    result = client.sql('SELECT COUNT(*) FROM SAMPLE.T1')
    row_count = next(result)[0]
    return row_count


def main():
    client = Client()
    client.connect('ignite-host', 10800)
    client.sql('CREATE TABLE IF NOT EXISTS SAMPLE.T1 (k int, v varchar, PRIMARY key(k))')
    client.sql('DELETE SAMPLE.T1')
    start_row_count = get_rowcount(client)        # Expected row count = 0

    client.sql("BEGIN TRANSACTION")
    client.sql("INSERT INTO SAMPLE.T1 (k, v) values (1, 'Line 1')")
    post_insert_row_count = get_rowcount(client)  # Expected row count = 1

    client.sql("ROLLBACK TRANSACTION")
    end_row_count = get_rowcount(client)          # Expected row count = 0, but is 1

    client.close()
    print('Start row count      : {}'.format(start_row_count))
    print('Post insert row count: {}'.format(post_insert_row_count))
    print('End row count        : {}'.format(end_row_count))


if __name__ == '__main__':
    main()

Script Output

Start row count : 0

Post insert row count: 1

End row count : 1

1

1 Answers

0
votes

You're declaring your cache incorrectly so that it would still have PARTITIONED atomicity mode (you need to declare a cache template).

But the main issue is that Thin Client does not have transaction support currently: https://issues.apache.org/jira/browse/IGNITE-9410

I assume that it's autocommit only for the duration. I recommend using JDBC Python bindings with Ignite Thin JDBC driver.