37MyCat - 分片规则(按单月小时拆分)

此规则是单月内按照小时拆分,最小粒度是小时,可以一天最多24个分片,最少1个分片,一个月完后下月从头开始循环。每个月月尾,需要手工清理数据。


	 
		 create_time
		 sharding-by-hour
	 
 
 

	 24 
 

配置说明:

columns: 拆分字段,字符串类型(yyyymmddHH)splitOneDay : 一天切分的分片数

 LatestMonthPartion partion = new LatestMonthPartion();
 partion.setSplitOneDay(24);
 Integer val = partion.calculate("2015020100");
 assertTrue(val == 0);
 val = partion.calculate("2015020216");
 assertTrue(val == 40);
 val = partion.calculate("2015022823");
 assertTrue(val == 27 * 24 + 23);
 Integer[] span = partion.calculateRange("2015020100", "2015022823");
 assertTrue(span.length == 27 * 24 + 23 + 1);
 assertTrue(span[0] == 0 && span[span.length - 1] == 27 * 24 + 23);
 span = partion.calculateRange("2015020100", "2015020123");
 assertTrue(span.length == 24);
 assertTrue(span[0] == 0 && span[span.length - 1] == 23);

你可能感兴趣的:(#,中间件,-,MyCat)