use of com.ctrip.xpipe.redis.console.annotation.DalTransaction in project x-pipe by ctripcorp.
the class DcClusterShardDao method deleteDcClusterShardsBatch.
@DalTransaction
public void deleteDcClusterShardsBatch(List<DcClusterShardTbl> dcClusterShards) throws DalException {
if (null == dcClusterShards || dcClusterShards.isEmpty()) {
logger.warn("[deleteDcClusterShardsBatch] Empty list: {}", dcClusterShards);
return;
}
List<RedisTbl> redises = new LinkedList<RedisTbl>();
for (final DcClusterShardTbl dcClusterShard : dcClusterShards) {
List<RedisTbl> relatedRedises = redisDao.findAllByDcClusterShard(dcClusterShard.getDcClusterShardId());
if (null != relatedRedises && !relatedRedises.isEmpty()) {
for (RedisTbl redis : relatedRedises) {
redis.setRunId(generateDeletedName(redis.getRunId()));
}
redises.addAll(relatedRedises);
}
}
redisDao.deleteRedisesBatch(redises);
queryHandler.handleBatchDelete(new DalQuery<int[]>() {
@Override
public int[] doQuery() throws DalException {
return dcClusterShardTblDao.deleteDcClusterShardsBatch(dcClusterShards.toArray(new DcClusterShardTbl[dcClusterShards.size()]), DcClusterShardTblEntity.UPDATESET_FULL);
}
}, true);
}
use of com.ctrip.xpipe.redis.console.annotation.DalTransaction in project x-pipe by ctripcorp.
the class DefaultMigrationCluster method updateStat.
@Override
@DalTransaction
public void updateStat(MigrationState stat) {
logger.info("[updateStat]{}-{}, {} -> {}", migrationCluster.getMigrationEventId(), clusterName(), this.currentState.getStatus(), stat.getStatus());
this.currentState = stat;
try {
tryUpdateStartTime(stat.getStatus());
updateStorageClusterStatus();
updateStorageMigrationClusterStatus();
} catch (Exception e) {
logger.error("[updateStat] ", e);
throw new ServerException(e.getMessage());
}
}
use of com.ctrip.xpipe.redis.console.annotation.DalTransaction in project x-pipe by ctripcorp.
the class ClusterDao method createCluster.
@DalTransaction
public ClusterTbl createCluster(final ClusterTbl cluster) throws DalException {
// check for unique cluster name
ClusterTbl clusterWithSameName = queryHandler.handleQuery(new DalQuery<ClusterTbl>() {
@Override
public ClusterTbl doQuery() throws DalException {
return clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL);
}
});
if (null != clusterWithSameName)
throw new BadRequestException("Duplicated cluster name");
cluster.setCreateTime(new Date());
// cluster meta
queryHandler.handleInsert(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return clusterTblDao.insert(cluster);
}
});
// related dc-cluster
ClusterTbl newCluster = clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL);
DcTbl activeDc = dcTblDao.findByPK(cluster.getActivedcId(), DcTblEntity.READSET_FULL);
DcClusterTbl protoDcCluster = dcClusterTblDao.createLocal();
protoDcCluster.setDcId(activeDc.getId()).setClusterId(newCluster.getId());
queryHandler.handleInsert(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return dcClusterTblDao.insert(protoDcCluster);
}
});
return newCluster;
}
use of com.ctrip.xpipe.redis.console.annotation.DalTransaction in project x-pipe by ctripcorp.
the class ClusterServiceImpl method balanceCluster.
// Add transaction for one cluster update, rollback if one 'DcClusterShard' update fails
@VisibleForTesting
@DalTransaction
protected void balanceCluster(Map<String, List<SetinelTbl>> dcToSentinels, final String cluster) {
for (String dcName : dcToSentinels.keySet()) {
List<DcClusterShardTbl> dcClusterShards = dcClusterShardService.findAllByDcCluster(dcName, cluster);
List<SetinelTbl> sentinels = dcToSentinels.get(dcName);
if (dcClusterShards == null || sentinels == null) {
throw new XpipeRuntimeException("DcClusterShard | Sentinels should not be null");
}
long randomlySelectedSentinelId = randomlyChoseSentinels(sentinels);
dcClusterShards.forEach(dcClusterShard -> {
dcClusterShard.setSetinelId(randomlySelectedSentinelId);
try {
dcClusterShardService.updateDcClusterShard(dcClusterShard);
} catch (DalException e) {
throw new XpipeRuntimeException(e.getMessage());
}
});
}
}
use of com.ctrip.xpipe.redis.console.annotation.DalTransaction in project x-pipe by ctripcorp.
the class DcClusterDao method deleteDcClustersBatch.
@DalTransaction
public void deleteDcClustersBatch(final DcClusterTbl dcCluster) throws DalException {
if (null == dcCluster)
throw new DalException("Null cannot be deleted.");
List<DcClusterShardTbl> dcClusterShards = queryHandler.handleQuery(new DalQuery<List<DcClusterShardTbl>>() {
@Override
public List<DcClusterShardTbl> doQuery() throws DalException {
return dcClusterShardTblDao.findAllByDcClusterId(dcCluster.getDcClusterId(), DcClusterShardTblEntity.READSET_FULL);
}
});
if (null != dcClusterShards) {
dcClusterShardDao.deleteDcClusterShardsBatch(dcClusterShards);
}
queryHandler.handleDelete(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return dcClusterTblDao.deleteBatch(dcCluster, DcClusterTblEntity.UPDATESET_FULL);
}
}, true);
}
Aggregations