I am investigating transaction management within Apache Ignite and I have created a simple script that:
- Creates a table
- Obtains the row count
- Begins a transaction
- Inserts a row
- Obtains the row count
- Rollsback the transaction
- 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