dble icon indicating copy to clipboard operation
dble copied to clipboard

使用MySQL-offset-step作为全局序列号,执行sql时报错

Open ken2333 opened this issue 4 years ago • 1 comments

  • dble version: 2.20.0.4
  • preconditions :
    no
  • configs:

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (C) 2016-2019 ActionTech.
  ~ License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
  -->

<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE dble:server SYSTEM "server.dtd">
<dble:server xmlns:dble="http://dble.cloud/" version="3.0">
    <system>
        <!-- base config -->
        <!--<property name="bindIp">0.0.0.0</property>-->
        <property name="serverPort">8066</property>
        <property name="managerPort">9066</property>
        <!--<property name="maxCon">0</property> -->
        <!--<property name="processors">4</property>-->
        <!--<property name="backendProcessors">12</property>-->
        <!--<property name="processorExecutor">4</property> -->
        <!--<property name="backendProcessorExecutor">12</property> -->
        <!--<property name="complexExecutor">8</property> -->
        <!--<property name="writeToBackendExecutor">4</property> -->

        <!--<property name="fakeMySQLVersion">5.6.20</property>-->
        <property name="sequnceHandlerType">1</property>
        <!-- serverBacklog size,default 2048-->
        <property name="serverBacklog">2048</property>
        <!--<property name="serverNodeId">1</property>-->
        <!--<property name="showBinlogStatusTimeout">60000</property>-->

        <!--option-->
        <!--<property name="useCompression">1</property>-->
        <!--<property name="usingAIO">0</property>-->
        <!--<property name="useZKSwitch">true</property>-->
        <!--<property name="useThreadUsageStat">0</property>-->
        <!--<property name="usePerformanceMode">0</property>-->

        <!-- query time cost statistics-->
        <!--<property name="useCostTimeStat">0</property>-->
        <!--<property name="maxCostStatSize">100</property>-->
        <!--<property name="costSamplePercent">1</property>-->

        <!--connection -->
        <!--<property name="charset">utf8</property>-->
        <!--<property name="maxPacketSize">4194304</property>-->
        <!--<property name="txIsolation">3</property>-->

        <!--consistency-->
        <!-- check the consistency of table structure between nodes,default not -->
        <property name="checkTableConsistency">0</property>
        <!-- check periodt, he default period is 60000 milliseconds -->
        <property name="checkTableConsistencyPeriod">60000</property>

        <!-- heartbeat check period -->
        <property name="dataNodeIdleCheckPeriod">300000</property>
        <property name="dataNodeHeartbeatPeriod">10000</property>

        <!-- processor check conn-->
        <property name="processorCheckPeriod">1000</property><!-- unit millisecond -->
        <property name="sqlExecuteTimeout">300</property><!-- unit second -->
        <property name="idleTimeout">1800000</property><!-- unit millisecond -->

        <!-- transaction log -->
        <!-- 1 enable record the transaction log, 0 disable -->
        <property name="recordTxn">0</property>
        <!--<property name="transactionLogBaseDir">/txlogs</property>-->
        <!--<property name="transactionLogBaseName">server-tx</property>-->
        <!--<property name="transactionRotateSize">16</property>--><!-- unit M -->

        <!-- XA transaction -->
        <!-- use XA transaction ,if the mysql service crash,the unfinished XA commit/rollback will retry for several times
       it is the check period for ,default is 1000 milliseconds-->
        <property name="xaSessionCheckPeriod">1000</property>
        <!-- use XA transaction ,the finished XA log will removed. the default period is 1000 milliseconds-->
        <property name="xaLogCleanPeriod">1000</property>
        <!-- XA Recovery Log path -->
        <!--<property name="xaRecoveryLogBaseDir">/tmlogs/</property>-->
        <!-- XA Recovery Log name -->
        <!--<property name="xaRecoveryLogBaseName">tmlog</property>-->
        <!-- XA Retry count, retry times in backend, 0 means always retry until success -->
        <!--<property name="xaRetryCount">0</property>-->

        <!-- true is use JoinStrategy, default false-->
        <property name="useJoinStrategy">true</property>
        <property name="nestLoopConnSize">4</property>
        <property name="nestLoopRowsSize">2000</property>

        <!-- query memory used for per session,unit is M-->
        <property name="otherMemSize">4</property>
        <property name="orderMemSize">4</property>
        <property name="joinMemSize">4</property>

        <!-- off Heap unit:bytes-->
        <property name="bufferPoolChunkSize">4096</property>
        <property name="bufferPoolPageNumber">256</property>
        <property name="bufferPoolPageSize">2097152</property>
        <!--<property name="mappedFileSize">2097152</property>-->

        <!-- sql statistics-->
        <!-- 1 means use SQL statistics, 0 means not -->
        <property name="useSqlStat">0</property>
        <!--<property name="bufferUsagePercent">80</property>-->
        <!--<property name="clearBigSQLResultSetMapMs">600000</property>-->
        <!--<property name="sqlRecordCount">10</property>-->
        <!--<property name="maxResultSet">524288</property>-->

        <!-- backSocket unit:bytes-->
        <!--<property name="backSocketSoRcvbuf">4194304</property>-->
        <!--<property name="backSocketSoSndbuf">1048576</property>-->
        <!--<property name="backSocketNoDelay">1</property>-->

        <!-- frontSocket-->
        <!--<property name="frontSocketSoRcvbuf">1048576</property>-->
        <!--<property name="frontSocketSoSndbuf">4194304</property>-->
        <!--<property name="frontSocketNoDelay">1</property>-->

        <!-- for join tmp results -->
        <!--<property name="mergeQueueSize">1024</property>-->
        <!--<property name="orderByQueueSize">1024</property>-->
        <!--<property name="joinQueueSize">1024</property>-->

        <!-- if enable the slow query log -->
        <property name="enableSlowLog">0</property>
        <!-- the slow query log location -->
        <!--<property name="slowLogBaseDir">./slowlogs</property>-->
        <!--<property name="slowLogBaseName">slow-query</property>-->
        <!-- the max period for flushing the slow query log from memory to disk  after last time , unit is second -->
        <property name="flushSlowLogPeriod">1</property>
        <!-- the max records for flushing the slow query log from memory to disk after last time -->
        <property name="flushSlowLogSize">1000</property>
        <!-- the threshold for judging if the query is slow , unit is millisecond -->
        <property name="sqlSlowTime">100</property>
        <!-- used for load data,maxCharsPerColumn means max chars length for per column when load data  -->
        <!--<property name="maxCharsPerColumn">65535</property>-->
        <!-- used for load data, because dble need save to disk if loading file contains large size -->
        <!--<property name="maxRowSizeToFile">10000</property>-->

	<!-- used for outerHa ,when the value is true ,one dataHost can only has one writeHost,and dataHost commands would be available-->
        <property name="useOuterHa">false</property>
    </system>

    <!-- firewall config -->
    <!--
    <firewall>
    <whitehost>
          <host host="127.0.0.1" user="root"/>
          <host host="0:0:0:0:0:0:0:1" user="root"/>
       </whitehost>
       <blacklist check="true">
       <property name="selelctAllow">false</property>
       </blacklist>
    </firewall>
    -->
    <user name="man1">
        <property name="password">123456</property>
        <property name="manager">true</property>
        <!-- manager user can't set schema-->
    </user>

    <user name="root">
        <property name="password">123456</property>
        <property name="schemas">testdb100</property>

        <!-- table's DML privileges  INSERT/UPDATE/SELECT/DELETE -->
        <!--
        <privileges check="false">
            <schema name="TESTDB" dml="0110" >
                <table name="tb01" dml="0000"></table>
                <table name="tb02" dml="1111"></table>
            </schema>
        </privileges>
         -->
    </user>

  

</dble:server>

schema.xml

<?xml version="1.0"?>
<!--
  ~ Copyright (C) 2016-2019 ActionTech.
  ~ License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
  -->

<!DOCTYPE dble:schema SYSTEM "schema.dtd">
<dble:schema xmlns:dble="http://dble.cloud/" version="3.0">


	 
	<schema name="testdb100" >
	 <table name="t_user" dataNode="dn101,dn102" rule="rule_common_hash" incrementColumn="id" />
    </schema>
 
    <dataNode name="dn101" dataHost="mysql1" database="db100"/>
    <dataNode name="dn102" dataHost="mysql2" database="db101"/>

	    <dataHost name="mysql1" maxCon="300" minCon="10" balance="0" slaveThreshold="100">
        <heartbeat>show slave status</heartbeat>
        <writeHost host="hostM1" url="172.18.0.2:3306" user="root"
                   password="123456">
        </writeHost>
    </dataHost>
	    <dataHost name="mysql2" maxCon="300" minCon="10" balance="0" slaveThreshold="100">
        <heartbeat>show slave status</heartbeat>
        <writeHost host="hostM1" url="172.18.0.3:3306" user="root"
                   password="123456">
        </writeHost>
    </dataHost>
</dble:schema>

rule.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (C) 2016-2019 ActionTech.
  ~ License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
  -->

<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
	- you may not use this file except in compliance with the License. - You
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
	- - Unless required by applicable law or agreed to in writing, software -
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
	License for the specific language governing permissions and - limitations
	under the License. -->
<!DOCTYPE dble:rule SYSTEM "rule.dtd">
<dble:rule xmlns:dble="http://dble.cloud/" version="3.0">
    <tableRule name="rule_enum">
        <rule>
            <columns>code</columns>
            <algorithm>func_enum</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_range">
        <rule>
            <columns>id</columns>
            <algorithm>func_range</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_common_hash">
        <rule>
            <columns>id</columns>
            <algorithm>func_common_hash</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_common_hash2">
        <rule>
            <columns>id2</columns>
            <algorithm>func_common_hash</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_uneven_hash">
        <rule>
            <columns>id</columns>
            <algorithm>func_uneven_hash</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_mod">
        <rule>
            <columns>id</columns>
            <algorithm>func_mod</algorithm>
        </rule>
    </tableRule>
    <tableRule name="rule_jumpHash">
        <rule>
            <columns>code</columns>
            <algorithm>func_jumpHash</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_hashString">
        <rule>
            <columns>code</columns>
            <algorithm>func_hashString</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_date">
        <rule>
            <columns>create_date</columns>
            <algorithm>func_date</algorithm>
        </rule>
    </tableRule>

    <tableRule name="rule_pattern">
        <rule>
            <columns>id</columns>
            <algorithm>func_pattern</algorithm>
        </rule>
    </tableRule>


    <!-- enum partition -->
    <function name="func_enum" class="Enum">
        <property name="mapFile">partition-enum.txt</property>
        <property name="defaultNode">0</property><!--the default is -1,means unexpected value will report error-->
        <property name="type">0</property><!--0 means key is a number, 1 means key is a string-->
    </function>

    <!-- number range partition -->
    <function name="func_range" class="NumberRange">
        <property name="mapFile">partition-number-range.txt</property>
        <property name="defaultNode">0</property><!--he default is -1,means unexpected value will report error-->
    </function>


    <!-- Hash partition,when partitionLength=1, it is a mod partition-->
    <!--MAX(sum(count*length[i]) must not more then 2880-->
    <function name="func_common_hash" class="Hash">
        <property name="partitionCount">2</property>
        <property name="partitionLength">512</property>
    </function>
    <!-- Hash partition,when partitionLength=1, it is a mod partition-->
    <!--MAX(sum(count*length[i]) must not more then 2880-->
    <function name="func_uneven_hash" class="Hash">
        <property name="partitionCount">2,1</property>
        <property name="partitionLength">256,512</property>
    </function>

    <!-- eg:  mod 4 -->
    <function name="func_mod" class="Hash">
        <property name="partitionCount">4</property>
        <property name="partitionLength">1</property>
    </function>

    <!-- jumpStringHash partition for string-->
    <function name="func_jumpHash" class="jumpStringHash">
        <property name="partitionCount">2</property>
        <property name="hashSlice">0:2</property>
    </function>

    <!-- Hash partition for string-->
    <function name="func_hashString" class="StringHash">
        <property name="partitionCount">4</property>
        <property name="partitionLength">256</property>
        <property name="hashSlice">0:2</property>
        <!--<property name="hashSlice">-4:0</property> -->
    </function>

    <!-- date partition -->
    <!-- 4 case:
    1.set sEndDate and defaultNode: input <sBeginDate ,router to defaultNode; input>sEndDate ,mod the period
    2.set sEndDate, but no defaultNode:input <sBeginDate report error; input>sEndDate ,mod the period
    3.set defaultNode without sEndDate: input <sBeginDate router to defaultNode;input>sBeginDate + (node size)*sPartionDay-1 will report error(expected is defaultNode,but can't control now)
    4.sEndDate and defaultNode are all not set: input <sBeginDate report error;input>sBeginDate + (node size)*sPartionDay-1 will report error
     -->
    <function name="func_date" class="Date">
        <property name="dateFormat">yyyy-MM-dd</property>
        <property name="sBeginDate">2015-01-01</property>
        <property name="sEndDate">2015-01-31
        </property> <!--if not set sEndDate,then in fact ,the sEndDate = sBeginDate+ (node size)*sPartionDay-1 -->
        <property name="sPartionDay">10</property>
        <property name="defaultNode">0</property><!--the default is -1-->
    </function>

    <!-- pattern partition -->
    <!--mapFile must contains all value of 0~patternValue-1,key and value must be Continuous increase-->
    <function name="func_pattern" class="PatternRange">
        <property name="mapFile">partition-pattern.txt</property>
        <property name="patternValue">1024</property>
        <property name="defaultNode">0</property><!--contains string which is not number,router to default node-->
    </function>


</dble:rule>

sequence_db_conf.properties

#
# Copyright (C) 2016-2020 ActionTech.
# License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
#

#sequence stored in datanode
`testdb100`.`t_user`=dn101

t_user.sql

CREATE TABLE `t_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `c_user_id` varchar(36) NOT NULL DEFAULT '',
  `c_name` varchar(22) NOT NULL DEFAULT '',
  `c_province_id` int(11) NOT NULL,
  `c_city_id` int(11) NOT NULL,
  `create_time` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_user_id` (`c_user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4
  • steps:
    step1. 在dble中执行插入语句 INSERT INTO t_user (c_user_id, c_name, c_province_id, c_city_id, create_time) VALUES('1','1','1','1','2022-05-28 06:30:48');

  • expect result:
    插入成功

  • real result:
    错误代码: 1064 can't fetch sequence in db,sequence :testdb100.t_user detail:null

  • supplements: 使用MySQL-offset-step作为全局序列号,执行sql时报错

ken2333 avatar May 28 '22 09:05 ken2333

今天一早起来,重启了dble后发现插入语句可以了,我用reload @@config ,reload @@metadata 来重载sequence_db_conf配置是无效的, 只有重启dble才能起效

ken2333 avatar May 29 '22 02:05 ken2333