专栏名称: 亿级流量网站架构
开涛技术点滴
目录
相关文章推荐
稀土掘金技术社区  ·  一个vue3指令让el-table自动轮播 ·  昨天  
程序员的那些事  ·  安卓重大更新!Android 16 ... ·  昨天  
程序员的那些事  ·  外网热议:为什么 DeepSeek ... ·  3 天前  
51好读  ›  专栏  ›  亿级流量网站架构

高可用高性能可扩展的单号生成方案

亿级流量网站架构  · 公众号  · 程序员  · 2017-07-07 08:44

正文

请到「今天看啥」查看全文


;
} catch (SequenceOutOfRangeException ex){
LOGGER.error( "gen error SequenceOutOfRangeException index {} total available {}" ,
currentPartitionIndex,
availablePartitionIndices.size());
hasError= true ;

LOGGER.error( "set {} to SKIP" ,currentPartitionIndex);
this .innerSequences.set(currentPartitionIndex,SkipSequence.INSTANCE);
onError(ownerKey,currentPartitionIndex,innerGen,ex);
LOGGER.error( "after onError total available {}/{}" ,currentPartitionIndex,
availablePartitionIndices.size());

} catch (Exception ex){
LOGGER.error( "gen error index {} total available {}" ,currentPartitionIndex,
availablePartitionIndices.size());
LOGGER.error( "gen error " ,ex);
hasError= true ;
onError(ownerKey,currentPartitionIndex,innerGen,ex);
LOGGER.error( "after onError total available {}/{}" ,currentPartitionIndex,
availablePartitionIndices.size());
} finally {
long usedTime=System. currentTimeMillis ()-startTime;
boolean isTimeout=usedTime>timeoutThresholdInMilliseconds;
if (!hasError&&isTimeout){
onTimeout(currentPartitionIndex,innerGen,usedTime);
}
LOGGER.trace( "gen usedTime {}" ,usedTime);
}
} while ( true );
return sequence;
}

使用时配置bean使用即可, 如下spring bean xml配置:

<bean id="highAvailableSequenceGen" class="com.jd.coo.sa.sequence.ha.BitwiseLoadBalanceSequenceGen">

   <constructor-arg index="0" value="2"/>

   <constructor-arg index="1">
<map>

       <entry key="0">
<bean class="com.jd.coo.sa.sequence.AutoIncrementTablesSequenceGen">
<property name="dataSource" ref="dataSourceA"/>
<property name="sequenceTableFormat" value="%s_code_%d"/>
bean>
entry>
<entry key="1">
<bean class="com.jd.coo.sa.sequence.AutoIncrementTablesSequenceGen">
<property name="dataSource" ref="dataSourceB"/>
<property name="sequenceTableFormat" value="%s_code_%d"/>
bean>
entry>
<entry key="2">
<bean class






请到「今天看啥」查看全文