use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.
the class MigrationPartialSuccessRollBackState method doAction.
@Override
public void doAction() {
CountDownLatch latch = new CountDownLatch(getHolder().getMigrationShards().size());
StringBuilder errorMessage = new StringBuilder();
for (MigrationShard migrationShard : getHolder().getMigrationShards()) {
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
migrationShard.doRollBack();
} catch (Exception e) {
logger.error("[run]" + migrationShard, e);
errorMessage.append(LogUtils.error(String.format("%s", migrationShard, e.toString())));
} finally {
latch.countDown();
}
}
});
}
try {
latch.await(migrationWaitTimeMilli, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
logger.error("[MigrationRollBackStat][await][shard][doRollBack][fail]", e);
errorMessage.append(LogUtils.error(String.format("[wait time exceed]%s ms", migrationWaitTimeMilli)));
}
String error = errorMessage.toString();
if (StringUtil.isEmpty(error)) {
updateAndProcess(nextAfterSuccess());
} else {
updateAndStop(nextAfterFail());
}
}
use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.
the class MigrationPartialSuccessState method doAction.
@Override
public void doAction() {
for (final MigrationShard shard : getHolder().getMigrationShards()) {
ShardMigrationResult shardMigrationResult = shard.getShardMigrationResult();
if (!shardMigrationResult.stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
shardMigrationResult.stepRetry(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC);
String clusterName = getHolder().clusterName();
String shardName = shard.shardName();
logger.info("[doAction][execute]{}, {}", clusterName, shardName);
executors.execute(new AbstractExceptionLogTask() {
@Override
public void doRun() {
logger.info("[doMigrate][start]{},{}", clusterName, shardName);
shard.doMigrate();
logger.info("[doMigrate][done]{},{}", clusterName, shardName);
}
});
}
}
}
use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.
the class AbstractMigrationMigratingState method refresh.
@Override
public void refresh() {
int setUpNewSuccessCnt = 0;
int currentlyWorkingCnt = 0;
List<MigrationShard> migrationShards = getHolder().getMigrationShards();
final int migrationShardsSize = migrationShards.size();
for (MigrationShard migrationShard : migrationShards) {
if (migrationShard.getShardMigrationResult().stepTerminated(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
if (migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
++setUpNewSuccessCnt;
}
} else {
++currentlyWorkingCnt;
}
}
if (currentlyWorkingCnt == 0) {
if (setUpNewSuccessCnt == migrationShardsSize) {
// all success
int finishedCnt = 0;
for (MigrationShard migrationShard : migrationShards) {
if (migrationShard.getShardMigrationResult().stepTerminated(ShardMigrationStep.MIGRATE)) {
++finishedCnt;
}
}
if (0 == finishedCnt && doOtherDcMigrate.compareAndSet(false, true)) {
doMigrateOtherDc();
} else if (finishedCnt == migrationShardsSize) {
logger.info("[success][continue]{}", getHolder().clusterName());
updateAndProcess(nextAfterSuccess());
}
} else {
// any fail
logger.info("[fail]{}", getHolder().clusterName());
if (this instanceof MigrationMigratingState) {
updateAndProcess(nextAfterFail());
return;
}
if (this instanceof MigrationPartialSuccessState) {
updateAndStop(nextAfterFail());
return;
}
}
}
}
use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.
the class AbstractMigrationMigratingState method doMigrateOtherDc.
protected void doMigrateOtherDc() {
logger.debug("[doMigrateOtherDc]{}", this);
MigrationCluster migrationCluster = getHolder();
String clusterName = migrationCluster.clusterName();
for (MigrationShard migrationShard : migrationCluster.getMigrationShards()) {
executors.execute(new AbstractExceptionLogTask() {
@Override
public void doRun() {
String shardName = migrationShard.shardName();
logger.info("[doOtherDcMigrate][start]{},{}", clusterName, shardName);
migrationShard.doMigrateOtherDc();
logger.info("[doOtherDcMigrate][done]{},{}", clusterName, shardName);
}
});
}
}
use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.
the class AbstractMigrationPublishState method getNewMasters.
public List<InetSocketAddress> getNewMasters() {
List<InetSocketAddress> result = new LinkedList<>();
for (MigrationShard migrationShard : getHolder().getMigrationShards()) {
HostPort newMasterAddress = migrationShard.getNewMasterAddress();
if (newMasterAddress == null) {
// may force publish
logger.warn("[getNewMasters][null master]{}", migrationShard.shardName());
continue;
}
result.add(InetSocketAddress.createUnresolved(newMasterAddress.getHost(), newMasterAddress.getPort()));
}
return result;
}
Aggregations