【问题标题】:Apache Ignite SQL Transaction ManagementApache Ignite SQL 事务管理
【发布时间】:2019-09-24 01:49:11
【问题描述】:

我正在研究 Apache Ignite 中的事务管理,并创建了一个简单的脚本:

  1. 创建表
  2. 获取行数
  3. 开始交易
  4. 插入一行
  5. 获取行数
  6. 回滚交易
  7. 获取行数

第 1 步到第 5 步按预期工作,但第 6 步无法回滚在第 4 步插入的行,第 7 步的行数仍为 1。

我知道需要对缓存/模式进行一些配置,我想知道我是否有这个错误。 documentation 建议我需要将“TRANSACTIONAL_SNAPTSHOT”用于原子性模式。

“集群”只有一个节点。

Apache Ignite 配置文件

    <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>

测试脚本

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()

脚本输出

开始行数:0

后插入行数:1

结束行数:1

【问题讨论】:

    标签: python-3.x ignite


    【解决方案1】:

    您错误地声明了缓存,因此它仍然具有 PARTITIONED 原子性模式(您需要声明缓存模板)。

    但主要问题是瘦客户端目前不支持事务: https://issues.apache.org/jira/browse/IGNITE-9410

    我假设它仅在持续时间内自动提交。我建议将 JDBC Python 绑定与 Ignite Thin JDBC 驱动程序一起使用。

    【讨论】:

    • 谢谢,我会看看缓存模板。我看到提到的 JIRA 任务最近发布了一个补丁,在过去的几天里,有没有办法让我成为“早期采用者”,看看是否可以与我们的项目一起使用。
    • 仅在 IGNITE-9410 中启用了对 Java 瘦客户端的支持。如果您准备好将此事务支持添加到 Python,那么只需向我们发送电子邮件至 Ignite 开发列表。这不应该是一项耗时的任务。
    猜你喜欢
    • 2023-01-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2019-07-20
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多