actiontech/dble

auto_increment_increment should not be a constant value by rwsplituser

ylinzhu opened this issue · 0 comments

user.xml

  <rwSplitUser name="rw1" password="111111" dbGroup="ha_group3" />
    <dbGroup rwSplitMode="0" name="ha_group3" delayThreshold="100" >
        <heartbeat>select user()</heartbeat>
        <dbInstance name="hostM3" password="111111" url="xxxx:3306" user="test" maxCon="1000" minCon="10" primary="true" />
    </dbGroup>
  • steps:
    • 8066 读写分离用户建表 create table log( logid int(4) primary key not null auto_increment, logtitle varchar(32) not null);
    • 登录mysql后端 执行语句set global auto_increment_increment=2;
    • 重启dble(目的是让dble感知mysql设置的参数)
    • 执行java脚本(参考test1.java)脚本的输出是

res=9res=10-------end------
sucess-1rw1

mysql端查询的表


mysql>  select * from log;
+-------+----------------------------------+
| logid | logtitle                         |
+-------+----------------------------------+
|     9 | 802bee57456646baab00807f4df59250 |
|    11 | 8ac277707db2fa86017deb27525900a6 |
+-------+----------------------------------+

结论:
步长增长不一致

test1.java

package jdbc;

import com.google.common.io.Files;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class test1 {
    static AtomicInteger index = new AtomicInteger();
    static AtomicInteger indexs = new AtomicInteger();
    static StringBuffer sb = new StringBuffer();

    static volatile Connection conn = null;
    private static List<Connection> list = new ArrayList<>();

    private static int update(PreparedStatement psmt, String sql) throws SQLException {
        psmt = conn.prepareStatement(sql);
        psmt.setInt(1, 12);
        psmt.setInt(2, 12);
        int i = psmt.executeUpdate();
        return i;
    }

    private static void createConn(String name) {
        String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://127.0.0.1:8066/db1?useSSL=false&allowMultiQueries=true";
//        String url = "jdbc:mysql://10.186.62.41:3309?useSSL=false&useServerPrepStmts=true";
        String username = name;
        String password = "123456";
        try {
            // 注册 JDBC 驱动
            Class.forName(JDBC_DRIVER);
            Connection conn = DriverManager.getConnection(url, username, password);
            list.add(conn);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }


    private static void test() {

        String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://127.0.0.1:8066?useSSL=false&allowMultiQueries=true";
//        String url = "jdbc:mysql://110.186.62.41:3309?useSSL=false&useServerPrepStmts=true";
        String username = "root";
        String password = "123456";
        //String sql = "show @@connection.sql";
        String sql = "INSERT INTO log(logid,logtitle)values(null,'802bee57456646baab00807f4df59250'), (null,'8ac277707db2fa86017deb27525900a6');";
        ResultSet rs = null;
        Statement stmt;
        PreparedStatement ps = null;
        try {
            // 注册 JDBC 驱动
            Class.forName(JDBC_DRIVER);
            //            if (conn == null)
            conn = list.get(0);

            stmt = conn.createStatement();
            rs = stmt.executeQuery("use db1;");
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.executeUpdate();
            ResultSet resultSet = ps.getGeneratedKeys();
            while(resultSet.next()){
                System.out.print("res=" + resultSet.getInt(1) );
            }

            while (resultSet.next()) {
                System.out.println("dddd " + resultSet.toString());
            }
            System.out.println("-------end------");
            System.out.println("sucess" + index.decrementAndGet() + username);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        // int size = 10;
        //  ThreadPoolExecutor executor = new ThreadPoolExecutor(size, size, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        int sizes = 5;

       //     createConn("root");
            createConn("s3");
            test();
    }
}