private final static long maxId = 281474976710655L;
/**
* <h1>获取新rowkey</h1>
* @param seqTableName
* @return java.lang.String
* @date 2019/12/15 22:24
* @author dengyw
*/
public final byte[] nextRowKey(String seqTableName) throws AidpException {
long nextId = getNextId(seqTableName);
if(LOGGER.isDebugEnabled()){
LOGGER.debug("get the next:[{}]", nextId);
}
byte[] lowT = Bytes.copy(Bytes.toBytes(maxId - nextId), 2, 6);
short shortId = (short) (Math.random() * Short.MAX_VALUE);
byte[] lowU = Bytes.toBytes(shortId);
return Bytes.add(lowU, lowT);
}
@Override
/**
* <h1>获取预分区rowkey数组<h1/>
* @param prepareRegions 预分区数
* @return
* @throws Exception
* @author dengyw
* @date 2019年6月9日 下午5:22:22
*/
public final byte[][] calcSplitKeys(String seqTableName, short prepareRegions) throws AidpException {
short baseRecord = Short.MAX_VALUE;
int splitKeysNumber = prepareRegions - 1;
int splitKeysBase = baseRecord / prepareRegions;
byte[][] calcSplitKeys = new byte[splitKeysNumber][8];
int count = 0;
for (short i = 0; i < baseRecord; i++){
if ((i != 0) && (i % splitKeysBase == 0) && count != prepareRegions && count < splitKeysNumber) {
byte[] lowT = Bytes.copy(Bytes.toBytes(0L), 2, 6);
byte[] lowU = Bytes.toBytes(i);
calcSplitKeys[count] = Bytes.add(lowU, lowT);
count++;
}
}
return calcSplitKeys;
}